Search in sources :

Example 1 with MySynccitUpdateTask

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();
    }
}
Also used : ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) MySynccitUpdateTask(me.ccrama.redditslide.Synccit.MySynccitUpdateTask) AccountManager(net.dean.jraw.managers.AccountManager) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException)

Example 2 with MySynccitUpdateTask

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();
    }
}
Also used : CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) ArrayList(java.util.ArrayList) MySynccitUpdateTask(me.ccrama.redditslide.Synccit.MySynccitUpdateTask) AccountManager(net.dean.jraw.managers.AccountManager)

Example 3 with MySynccitUpdateTask

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();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) SharedPreferences(android.content.SharedPreferences) MySynccitUpdateTask(me.ccrama.redditslide.Synccit.MySynccitUpdateTask) View(android.view.View) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MySynccitReadTask(me.ccrama.redditslide.Synccit.MySynccitReadTask)

Aggregations

MySynccitUpdateTask (me.ccrama.redditslide.Synccit.MySynccitUpdateTask)3 ArrayList (java.util.ArrayList)2 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)2 AccountManager (net.dean.jraw.managers.AccountManager)2 Dialog (android.app.Dialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 MySynccitReadTask (me.ccrama.redditslide.Synccit.MySynccitReadTask)1 ApiException (net.dean.jraw.ApiException)1 NetworkException (net.dean.jraw.http.NetworkException)1