Search in sources :

Example 1 with MySynccitReadTask

use of me.ccrama.redditslide.Synccit.MySynccitReadTask 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

Dialog (android.app.Dialog)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 MySynccitUpdateTask (me.ccrama.redditslide.Synccit.MySynccitUpdateTask)1