use of me.ccrama.redditslide.Synccit.MySynccitUpdateTask in project Slide by ccrama.
the class MainActivity method onPause.
@Override
public void onPause() {
super.onPause();
changed = false;
if (!SettingValues.synccitName.isEmpty()) {
new MySynccitUpdateTask().execute(SynccitRead.newVisited.toArray(new String[SynccitRead.newVisited.size()]));
}
if (Authentication.isLoggedIn && Authentication.me != null && Authentication.me.hasGold() && !SynccitRead.newVisited.isEmpty()) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String[] returned = new String[SynccitRead.newVisited.size()];
int i = 0;
for (String s : SynccitRead.newVisited) {
if (!s.contains("t3_")) {
s = "t3_" + s;
}
returned[i] = s;
i++;
}
new AccountManager(Authentication.reddit).storeVisits(returned);
SynccitRead.newVisited = new ArrayList<>();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// Upon leaving MainActivity--hide the toolbar search if it is visible
if (findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
findViewById(R.id.close_search_toolbar).performClick();
}
}
use of me.ccrama.redditslide.Synccit.MySynccitUpdateTask in project Slide by ccrama.
the class NewsActivity method onPause.
@Override
public void onPause() {
super.onPause();
changed = false;
if (!SettingValues.synccitName.isEmpty()) {
new MySynccitUpdateTask().execute(SynccitRead.newVisited.toArray(new String[SynccitRead.newVisited.size()]));
}
if (Authentication.isLoggedIn && Authentication.me != null && Authentication.me.hasGold() && !SynccitRead.newVisited.isEmpty()) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
String[] returned = new String[SynccitRead.newVisited.size()];
int i = 0;
for (String s : SynccitRead.newVisited) {
if (!s.contains("t3_")) {
s = "t3_" + s;
}
returned[i] = s;
i++;
}
new AccountManager(Authentication.reddit).storeVisits(returned);
SynccitRead.newVisited = new ArrayList<>();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// Upon leaving MainActivity--hide the toolbar search if it is visible
if (findViewById(R.id.toolbar_search).getVisibility() == View.VISIBLE) {
findViewById(R.id.close_search_toolbar).performClick();
}
}
use of me.ccrama.redditslide.Synccit.MySynccitUpdateTask in project Slide by ccrama.
the class SettingsSynccit method onCreate.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
applyColorTheme();
setContentView(R.layout.activity_settings_synccit);
setupAppBar(R.id.toolbar, R.string.settings_synccit, true, true);
name = (EditText) findViewById(R.id.name);
auth = (EditText) findViewById(R.id.auth);
name.setText(SettingValues.synccitName);
auth.setText(SettingValues.synccitAuth);
if (SettingValues.synccitAuth.isEmpty()) {
(findViewById(R.id.remove)).setEnabled(false);
}
findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!SettingValues.synccitAuth.isEmpty()) {
new AlertDialogWrapper.Builder(SettingsSynccit.this).setTitle(R.string.settings_synccit_delete).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SettingValues.synccitName = "";
SettingValues.synccitAuth = "";
SharedPreferences.Editor e = SettingValues.prefs.edit();
e.putString(SettingValues.SYNCCIT_NAME, SettingValues.synccitName);
e.putString(SettingValues.SYNCCIT_AUTH, SettingValues.synccitAuth);
e.apply();
name.setText(SettingValues.synccitName);
auth.setText(SettingValues.synccitAuth);
SynccitRead.visitedIds.removeAll(Collections.singleton("16noez"));
}
}).setNegativeButton(R.string.btn_no, null).show();
}
}
});
findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog d = new MaterialDialog.Builder(SettingsSynccit.this).title(R.string.settings_synccit_authenticate).progress(true, 100).content(R.string.misc_please_wait).cancelable(false).show();
new MySynccitUpdateTask().execute("16noez");
SettingValues.synccitName = name.getText().toString();
SettingValues.synccitAuth = auth.getText().toString();
try {
new MySynccitReadTask().execute("16noez").get();
if (SynccitRead.visitedIds.contains("16noez")) {
// success
d.dismiss();
SharedPreferences.Editor e = SettingValues.prefs.edit();
e.putString(SettingValues.SYNCCIT_NAME, SettingValues.synccitName);
e.putString(SettingValues.SYNCCIT_AUTH, SettingValues.synccitAuth);
e.apply();
(findViewById(R.id.remove)).setEnabled(true);
new AlertDialogWrapper.Builder(SettingsSynccit.this).setTitle(R.string.settings_synccit_connected).setMessage(R.string.settings_synccit_active).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
}).show();
} else {
d.dismiss();
new AlertDialogWrapper.Builder(SettingsSynccit.this).setTitle(R.string.settings_synccit_failed).setMessage(R.string.settings_synccit_failed_msg).setPositiveButton(R.string.btn_ok, null).show();
}
} catch (Exception e) {
d.dismiss();
new AlertDialogWrapper.Builder(SettingsSynccit.this).setTitle(R.string.settings_synccit_failed).setMessage(R.string.settings_synccit_failed_msg).setPositiveButton(R.string.btn_ok, null).show();
}
}
});
}
Aggregations