Search in sources :

Example 6 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project sexytopo by richsmith.

the class DeviceActivity method updateBluetooth.

@SuppressWarnings("RedundantIfStatement")
private void updateBluetooth() {
    if (BLUETOOTH_ADAPTER == null) {
        Toast.makeText(getApplicationContext(), "No Bluetooth capabilities detected", Toast.LENGTH_SHORT).show();
    }
    SwitchCompat bluetoothSwitch = findViewById(R.id.bluetoothSwitch);
    if (BLUETOOTH_ADAPTER == null) {
        bluetoothSwitch.setChecked(false);
        bluetoothSwitch.setEnabled(false);
    } else if (BLUETOOTH_ADAPTER.isEnabled()) {
        bluetoothSwitch.setChecked(true);
    } else {
        bluetoothSwitch.setChecked(false);
    }
    findViewById(R.id.pairButton).setEnabled(bluetoothSwitch.isChecked());
    findViewById(R.id.unpairButton).setEnabled(bluetoothSwitch.isChecked());
}
Also used : SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 7 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project sexytopo by richsmith.

the class DeviceActivity method toggleBluetooth.

public void toggleBluetooth(View view) {
    SwitchCompat bluetoothSwitch = (SwitchCompat) view;
    if (bluetoothSwitch.isChecked()) {
        BluetoothAdapter.getDefaultAdapter().enable();
    } else {
        BluetoothAdapter.getDefaultAdapter().disable();
    }
    updateBluetooth();
}
Also used : SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 8 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.

the class MainActivity method doDrawer.

public void doDrawer() {
    drawerSubList = (ListView) findViewById(R.id.drawerlistview);
    drawerSubList.setDividerHeight(0);
    drawerSubList.setDescendantFocusability(ListView.FOCUS_BEFORE_DESCENDANTS);
    final LayoutInflater inflater = getLayoutInflater();
    final View header;
    if (Authentication.isLoggedIn && Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedin, drawerSubList, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        drawerSubList.addHeaderView(header, null, false);
        ((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
        header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                if (runAfterLoad == null) {
                    Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                    MainActivity.this.startActivity(inte);
                }
            }
        });
        header.findViewById(R.id.multi).setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
                return true;
            }
        });
        header.findViewById(R.id.discover).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Discover.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.prof_click).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.saved).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SAVED, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.later).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, PostReadLater.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.history).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_HISTORY, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.commented).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_COMMENT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.submitted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_SUBMIT, true);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.upvoted).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Profile.class);
                inte.putExtra(Profile.EXTRA_PROFILE, Authentication.name);
                inte.putExtra(Profile.EXTRA_UPVOTE, true);
                MainActivity.this.startActivity(inte);
            }
        });
        /**
         * If the user is a known mod, show the "Moderation" drawer item quickly to
         * stop the UI from jumping
         */
        if (modOf != null && !modOf.isEmpty() && Authentication.mod) {
            header.findViewById(R.id.mod).setVisibility(View.VISIBLE);
        }
        // update notification badge
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    header.setContentDescription(getResources().getString(R.string.btn_collapse));
                    AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                } else {
                    collapse(profStuff);
                    header.setContentDescription(getResources().getString(R.string.btn_expand));
                    AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                }
            }
        });
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            LogUtil.v("Adding click to " + ((TextView) t.findViewById(R.id.name)).getText());
            t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
                        Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
                        Set<String> done = new HashSet<>();
                        for (String s : accounts2) {
                            if (!s.contains(accName)) {
                                done.add(s);
                            }
                        }
                        Authentication.authentication.edit().putStringSet("accounts", done).commit();
                        dialog2.dismiss();
                        accountList.removeView(t);
                        if (accName.equalsIgnoreCase(Authentication.name)) {
                            boolean d = false;
                            for (String s : keys) {
                                if (!s.equalsIgnoreCase(accName)) {
                                    d = true;
                                    LogUtil.v("Switching to " + s);
                                    for (Map.Entry<String, String> e : accounts.entrySet()) {
                                        LogUtil.v(e.getKey() + ":" + e.getValue());
                                    }
                                    if (accounts.containsKey(s) && !accounts.get(s).isEmpty()) {
                                        Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                    } else {
                                        ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
                                        int index = keys.indexOf(s);
                                        if (keys.indexOf(s) > tokens.size()) {
                                            index -= 1;
                                        }
                                        Authentication.authentication.edit().putString("lasttoken", tokens.get(index)).remove("backedCreds").commit();
                                    }
                                    Authentication.name = s;
                                    UserSubscriptions.switchAccounts();
                                    Reddit.forceRestart(MainActivity.this, true);
                                    break;
                                }
                            }
                            if (!d) {
                                Authentication.name = "LOGGEDOUT";
                                Authentication.isLoggedIn = false;
                                Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                UserSubscriptions.switchAccounts();
                                Reddit.forceRestart(MainActivity.this, true);
                            }
                        } else {
                            accounts.remove(accName);
                            keys.remove(accName);
                        }
                    }).setPositiveButton(R.string.btn_cancel, null).show();
                }
            });
            t.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String accName = ((TextView) t.findViewById(R.id.name)).getText().toString();
                    LogUtil.v("Found name is " + accName);
                    if (!accName.equalsIgnoreCase(Authentication.name)) {
                        LogUtil.v("Switching to " + accName);
                        if (!accounts.get(accName).isEmpty()) {
                            LogUtil.v("Using token " + accounts.get(accName));
                            Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").apply();
                        } else {
                            ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                            Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").apply();
                        }
                        Authentication.name = accName;
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.godown).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                LinearLayout body = header.findViewById(R.id.expand_profile);
                if (body.getVisibility() == View.GONE) {
                    expand(body);
                    AnimatorUtil.flipAnimator(false, view).start();
                    view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_collapse));
                } else {
                    collapse(body);
                    AnimatorUtil.flipAnimator(true, view).start();
                    view.findViewById(R.id.godown).setContentDescription(getResources().getString(R.string.btn_expand));
                }
            }
        });
        header.findViewById(R.id.guest_mode).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                Authentication.name = "LOGGEDOUT";
                Authentication.isLoggedIn = false;
                Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").apply();
                UserSubscriptions.switchAccounts();
                Reddit.forceRestart(MainActivity.this, true);
            }
        });
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this, false);
            }
        });
        header.findViewById(R.id.inbox).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Inbox.class);
                MainActivity.this.startActivityForResult(inte, INBOX_RESULT);
            }
        });
        headerMain = header;
        if (runAfterLoad == null) {
            new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else if (Authentication.didOnline) {
        header = inflater.inflate(R.layout.drawer_loggedout, drawerSubList, false);
        drawerSubList.addHeaderView(header, null, false);
        headerMain = header;
        hea = header.findViewById(R.id.back);
        final LinearLayout profStuff = header.findViewById(R.id.accountsarea);
        profStuff.setVisibility(View.GONE);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (profStuff.getVisibility() == View.GONE) {
                    expand(profStuff);
                    AnimatorUtil.flipAnimator(false, header.findViewById(R.id.headerflip)).start();
                    header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_collapse));
                } else {
                    collapse(profStuff);
                    AnimatorUtil.flipAnimator(true, header.findViewById(R.id.headerflip)).start();
                    header.findViewById(R.id.headerflip).setContentDescription(getResources().getString(R.string.btn_expand));
                }
            }
        });
        final HashMap<String, String> accounts = new HashMap<>();
        for (String s : Authentication.authentication.getStringSet("accounts", new HashSet<String>())) {
            if (s.contains(":")) {
                accounts.put(s.split(":")[0], s.split(":")[1]);
            } else {
                accounts.put(s, "");
            }
        }
        final ArrayList<String> keys = new ArrayList<>(accounts.keySet());
        final LinearLayout accountList = header.findViewById(R.id.accountsarea);
        for (final String accName : keys) {
            LogUtil.v(accName);
            final View t = getLayoutInflater().inflate(R.layout.account_textview_white, accountList, false);
            ((TextView) t.findViewById(R.id.name)).setText(accName);
            t.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(R.string.profile_remove).setMessage(R.string.profile_remove_account).setNegativeButton(R.string.btn_delete, (dialog2, which2) -> {
                        Set<String> accounts2 = Authentication.authentication.getStringSet("accounts", new HashSet<>());
                        Set<String> done = new HashSet<>();
                        for (String s : accounts2) {
                            if (!s.contains(accName)) {
                                done.add(s);
                            }
                        }
                        Authentication.authentication.edit().putStringSet("accounts", done).commit();
                        dialog2.dismiss();
                        accountList.removeView(t);
                        if (accName.equalsIgnoreCase(Authentication.name)) {
                            boolean d = false;
                            for (String s : keys) {
                                if (!s.equalsIgnoreCase(accName)) {
                                    d = true;
                                    LogUtil.v("Switching to " + s);
                                    if (!accounts.get(s).isEmpty()) {
                                        Authentication.authentication.edit().putString("lasttoken", accounts.get(s)).remove("backedCreds").commit();
                                    } else {
                                        ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<>()));
                                        Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(s))).remove("backedCreds").commit();
                                    }
                                    Authentication.name = s;
                                    UserSubscriptions.switchAccounts();
                                    Reddit.forceRestart(MainActivity.this, true);
                                }
                            }
                            if (!d) {
                                Authentication.name = "LOGGEDOUT";
                                Authentication.isLoggedIn = false;
                                Authentication.authentication.edit().remove("lasttoken").remove("backedCreds").commit();
                                UserSubscriptions.switchAccounts();
                                Reddit.forceRestart(MainActivity.this, true);
                            }
                        } else {
                            accounts.remove(accName);
                            keys.remove(accName);
                        }
                    }).setPositiveButton(R.string.btn_cancel, null).show();
                }
            });
            t.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View v) {
                    if (!accName.equalsIgnoreCase(Authentication.name)) {
                        if (!accounts.get(accName).isEmpty()) {
                            Authentication.authentication.edit().putString("lasttoken", accounts.get(accName)).remove("backedCreds").commit();
                        } else {
                            ArrayList<String> tokens = new ArrayList<>(Authentication.authentication.getStringSet("tokens", new HashSet<String>()));
                            Authentication.authentication.edit().putString("lasttoken", tokens.get(keys.indexOf(accName))).remove("backedCreds").commit();
                        }
                        Authentication.isLoggedIn = true;
                        Authentication.name = accName;
                        UserSubscriptions.switchAccounts();
                        Reddit.forceRestart(MainActivity.this, true);
                    }
                }
            });
            accountList.addView(t);
        }
        header.findViewById(R.id.add).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Intent inte = new Intent(MainActivity.this, Login.class);
                MainActivity.this.startActivity(inte);
            }
        });
        header.findViewById(R.id.offline).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().putBoolean("forceoffline", true).commit();
                Reddit.forceRestart(MainActivity.this, false);
            }
        });
        headerMain = header;
        header.findViewById(R.id.multi).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_gotomultis).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (runAfterLoad == null) {
                            Intent inte = new Intent(MainActivity.this, MultiredditOverview.class);
                            inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                            MainActivity.this.startActivity(inte);
                        }
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    } else {
        header = inflater.inflate(R.layout.drawer_offline, drawerSubList, false);
        headerMain = header;
        drawerSubList.addHeaderView(header, null, false);
        hea = header.findViewById(R.id.back);
        header.findViewById(R.id.online).setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View view) {
                Reddit.appRestart.edit().remove("forceoffline").commit();
                Reddit.forceRestart(MainActivity.this, false);
            }
        });
    }
    final LinearLayout expandSettings = header.findViewById(R.id.expand_settings);
    header.findViewById(R.id.godown_settings).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (expandSettings.getVisibility() == View.GONE) {
                expand(expandSettings);
                header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_collapse));
                AnimatorUtil.flipAnimator(false, v).start();
            } else {
                collapse(expandSettings);
                header.findViewById(R.id.godown_settings).setContentDescription(getResources().getString(R.string.btn_expand));
                AnimatorUtil.flipAnimator(true, v).start();
            }
        }
    });
    {
        // Set up quick setting toggles
        final SwitchCompat toggleNightMode = expandSettings.findViewById(R.id.toggle_night_mode);
        if (SettingValues.isPro) {
            toggleNightMode.setVisibility(View.VISIBLE);
            toggleNightMode.setChecked(inNightMode);
            toggleNightMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SettingValues.forcedNightModeState = isChecked ? SettingValues.ForcedState.FORCED_ON : SettingValues.ForcedState.FORCED_OFF;
                    restartTheme();
                }
            });
        }
        final SwitchCompat toggleImmersiveMode = expandSettings.findViewById(R.id.toggle_immersive_mode);
        toggleImmersiveMode.setChecked(SettingValues.immersiveMode);
        toggleImmersiveMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.immersiveMode = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
                if (isChecked) {
                    hideDecor();
                } else {
                    showDecor();
                }
            }
        });
        final SwitchCompat toggleNSFW = expandSettings.findViewById(R.id.toggle_nsfw);
        toggleNSFW.setChecked(SettingValues.showNSFWContent);
        toggleNSFW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.showNSFWContent = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SHOW_NSFW_CONTENT, isChecked).apply();
                reloadSubs();
            }
        });
        final SwitchCompat toggleRightThumbnails = expandSettings.findViewById(R.id.toggle_right_thumbnails);
        toggleRightThumbnails.setChecked(SettingValues.switchThumb);
        toggleRightThumbnails.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.switchThumb = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_SWITCH_THUMB, isChecked).apply();
                reloadSubs();
            }
        });
        final SwitchCompat toggleReaderMode = expandSettings.findViewById(R.id.toggle_reader_mode);
        toggleReaderMode.setChecked(SettingValues.readerMode);
        toggleReaderMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                SettingValues.readerMode = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_READER_MODE, isChecked).apply();
            }
        });
    }
    header.findViewById(R.id.manage).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View view) {
            Intent i = new Intent(MainActivity.this, ManageOfflineContent.class);
            startActivity(i);
        }
    });
    if (Authentication.didOnline) {
        View support = header.findViewById(R.id.support);
        if (SettingValues.isPro) {
            support.setVisibility(View.GONE);
        } else {
            support.setOnClickListener(new OnSingleClickListener() {

                @Override
                public void onSingleClick(View view) {
                    ProUtil.proUpgradeMsg(MainActivity.this, R.string.settings_support_slide).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss()).show();
                }
            });
        }
        header.findViewById(R.id.prof).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new MaterialDialog.Builder(MainActivity.this).inputRange(3, 20).alwaysCallInputCallback().input(getString(R.string.user_enter), null, new MaterialDialog.InputCallback() {

                    @Override
                    public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                        final EditText editText = dialog.getInputEditText();
                        EditTextValidator.validateUsername(editText);
                        if (input.length() >= 3 && input.length() <= 20) {
                            dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
                        }
                    }
                }).positiveText(R.string.user_btn_goto).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Intent inte = new Intent(MainActivity.this, Profile.class);
                        // noinspection ConstantConditions
                        inte.putExtra(Profile.EXTRA_PROFILE, dialog.getInputEditText().getText().toString());
                        MainActivity.this.startActivity(inte);
                    }
                }).negativeText(R.string.btn_cancel).show();
            }
        });
    }
    header.findViewById(R.id.settings).setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            Intent i = new Intent(MainActivity.this, SettingsActivity.class);
            startActivity(i);
            // Cancel sub loading because exiting the settings will reload it anyway
            if (mAsyncGetSubreddit != null)
                mAsyncGetSubreddit.cancel(true);
            drawerLayout.closeDrawers();
        }
    });
    /*  footer.findViewById(R.id.settings).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent inte = new Intent(Overview.this, Setting.class);
                Overview.this.startActivityForResult(inte, 3);
            }
        });*/
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    final ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, drawerLayout, toolbar, R.string.btn_open, R.string.btn_close) {

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            // this disables the animation
            super.onDrawerSlide(drawerView, 0);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (drawerLayout.isDrawerOpen(GravityCompat.END)) {
                int current = pager.getCurrentItem();
                if (current == toOpenComments && toOpenComments != 0) {
                    current -= 1;
                }
                String compare = usedArray.get(current);
                if (compare.equals("random") || compare.equals("myrandom") || compare.equals("randnsfw")) {
                    if (adapter != null && adapter.getCurrentFragment() != null && ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom != null) {
                        String sub = ((SubmissionsView) adapter.getCurrentFragment()).adapter.dataSet.subredditRandom;
                        doSubSidebarNoLoad(sub);
                        doSubSidebar(sub);
                    }
                } else {
                    doSubSidebar(usedArray.get(current));
                }
            }
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            KeyboardUtil.hideKeyboard(MainActivity.this, drawerLayout.getWindowToken(), 0);
        }
    };
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
    header.findViewById(R.id.back).setBackgroundColor(Palette.getColor("alsdkfjasld"));
    accountsArea = header.findViewById(R.id.accountsarea);
    if (accountsArea != null) {
        accountsArea.setBackgroundColor(Palette.getDarkerColor("alsdkfjasld"));
    }
    setDrawerSubList();
    hideDrawerItems();
}
Also used : Arrays(java.util.Arrays) Bundle(android.os.Bundle) R(me.ccrama.redditslide.R) NonNull(androidx.annotation.NonNull) AnimatorUtil(me.ccrama.redditslide.util.AnimatorUtil) Uri(android.net.Uri) ImageView(android.widget.ImageView) PostMatch(me.ccrama.redditslide.PostMatch) ColorDrawable(android.graphics.drawable.ColorDrawable) ContentType(me.ccrama.redditslide.ContentType) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) UserRecordPaginator(net.dean.jraw.paginators.UserRecordPaginator) NeverAgainWhenClickedOnce(org.ligi.snackengage.conditions.NeverAgainWhenClickedOnce) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Manifest(android.Manifest) Handler(android.os.Handler) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) ClipboardManager(android.content.ClipboardManager) Canvas(android.graphics.Canvas) JsonNode(com.fasterxml.jackson.databind.JsonNode) ContextCompat(androidx.core.content.ContextCompat) ProUtil(me.ccrama.redditslide.util.ProUtil) Log(android.util.Log) CardView(androidx.cardview.widget.CardView) WithLimitedNumberOfTimes(org.ligi.snackengage.conditions.WithLimitedNumberOfTimes) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts) CheckForMail(me.ccrama.redditslide.Notifications.CheckForMail) KeyboardUtil(me.ccrama.redditslide.util.KeyboardUtil) IntentFilter(android.content.IntentFilter) CommentPage(me.ccrama.redditslide.Fragments.CommentPage) SidebarLayout(me.ccrama.redditslide.Views.SidebarLayout) Set(java.util.Set) DensityUtils(me.ccrama.redditslide.ForceTouch.util.DensityUtils) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Palette(me.ccrama.redditslide.Visuals.Palette) SimpleTextWatcher(me.ccrama.redditslide.util.stubs.SimpleTextWatcher) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) Executors(java.util.concurrent.Executors) CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) SortingUtil(me.ccrama.redditslide.util.SortingUtil) KVManger(com.lusfold.androidkeyvaluestore.core.KVManger) DrawerItemsDialog(me.ccrama.redditslide.Fragments.DrawerItemsDialog) DrawableUtil(me.ccrama.redditslide.util.DrawableUtil) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) BuildConfig(me.ccrama.redditslide.BuildConfig) SubmissionParser(me.ccrama.redditslide.util.SubmissionParser) AfterNumberOfOpportunities(org.ligi.snackengage.conditions.AfterNumberOfOpportunities) ViewDragHelper(androidx.customview.widget.ViewDragHelper) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) BaseSnack(org.ligi.snackengage.snacks.BaseSnack) HasSeen(me.ccrama.redditslide.HasSeen) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) Editable(android.text.Editable) AccountManager(net.dean.jraw.managers.AccountManager) ArrayList(java.util.ArrayList) MiscUtil(me.ccrama.redditslide.util.MiscUtil) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) OpenRedditLink(me.ccrama.redditslide.OpenRedditLink) MultiRedditUpdateRequest(net.dean.jraw.http.MultiRedditUpdateRequest) TimePeriod(net.dean.jraw.paginators.TimePeriod) SettingsThemeFragment(me.ccrama.redditslide.ui.settings.SettingsThemeFragment) StringUtil(me.ccrama.redditslide.util.StringUtil) FragmentManager(androidx.fragment.app.FragmentManager) SettingsSubAdapter(me.ccrama.redditslide.ui.settings.SettingsSubAdapter) Parcelable(android.os.Parcelable) FlairTemplate(net.dean.jraw.models.FlairTemplate) UserSubscriptions.modOf(me.ccrama.redditslide.UserSubscriptions.modOf) Reddit(me.ccrama.redditslide.Reddit) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Field(java.lang.reflect.Field) AutoCompleteTextView(android.widget.AutoCompleteTextView) MultiRedditManager(net.dean.jraw.managers.MultiRedditManager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) Gravity(android.view.Gravity) MySynccitUpdateTask(me.ccrama.redditslide.Synccit.MySynccitUpdateTask) SharedPreferences(android.content.SharedPreferences) IconCompat(androidx.core.graphics.drawable.IconCompat) Configuration(android.content.res.Configuration) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) LinearLayout(android.widget.LinearLayout) ToggleSwipeViewPager(me.ccrama.redditslide.Views.ToggleSwipeViewPager) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) SideArrayAdapter(me.ccrama.redditslide.Adapters.SideArrayAdapter) PackageManager(android.content.pm.PackageManager) TimeUtils(me.ccrama.redditslide.util.TimeUtils) EditTextValidator(me.ccrama.redditslide.util.EditTextValidator) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) SettingsGeneralFragment(me.ccrama.redditslide.ui.settings.SettingsGeneralFragment) Animator(android.animation.Animator) DrawableRes(androidx.annotation.DrawableRes) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Locale(java.util.Locale) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) SynccitRead(me.ccrama.redditslide.Synccit.SynccitRead) ArgbEvaluator(android.animation.ArgbEvaluator) FragmentStatePagerAdapter(androidx.fragment.app.FragmentStatePagerAdapter) AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) NetworkStateReceiver(me.ccrama.redditslide.util.NetworkStateReceiver) NotificationManager(android.app.NotificationManager) AsyncTask(android.os.AsyncTask) TabLayout(com.google.android.material.tabs.TabLayout) Authentication(me.ccrama.redditslide.Authentication) ApiException(net.dean.jraw.ApiException) ViewGroup(android.view.ViewGroup) List(java.util.List) NetworkUtil(me.ccrama.redditslide.util.NetworkUtil) TextView(android.widget.TextView) LinearInterpolator(android.view.animation.LinearInterpolator) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar) ListView(android.widget.ListView) CommentOverflow(me.ccrama.redditslide.Views.CommentOverflow) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) EditorInfo(android.view.inputmethod.EditorInfo) Snackbar(com.google.android.material.snackbar.Snackbar) RequestPermission(androidx.activity.result.contract.ActivityResultContracts.RequestPermission) LayoutUtils(me.ccrama.redditslide.util.LayoutUtils) Context(android.content.Context) SettingValues(me.ccrama.redditslide.SettingValues) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ModerationManager(net.dean.jraw.managers.ModerationManager) Submission(net.dean.jraw.models.Submission) Pair(android.util.Pair) Intent(android.content.Intent) HashMap(java.util.HashMap) Constants(me.ccrama.redditslide.Constants) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) LogUtil(me.ccrama.redditslide.util.LogUtil) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) ClipData(android.content.ClipData) HashSet(java.util.HashSet) UserRecord(net.dean.jraw.models.UserRecord) ManageOfflineContent(me.ccrama.redditslide.ui.settings.ManageOfflineContent) Build(android.os.Build) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) ExecutorService(java.util.concurrent.ExecutorService) DialogInterface(android.content.DialogInterface) RateSnack(org.ligi.snackengage.snacks.RateSnack) ViewStub(android.view.ViewStub) MultiReddit(net.dean.jraw.models.MultiReddit) SwitchCompat(androidx.appcompat.widget.SwitchCompat) CompoundButton(android.widget.CompoundButton) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) ImageFlairs(me.ccrama.redditslide.ImageFlairs) GravityCompat(androidx.core.view.GravityCompat) KVStore(com.lusfold.androidkeyvaluestore.KVStore) Point(android.graphics.Point) DialogAction(com.afollestad.materialdialogs.DialogAction) SnackEngage(org.ligi.snackengage.SnackEngage) ResolveInfo(android.content.pm.ResolveInfo) PopupMenu(androidx.appcompat.widget.PopupMenu) ImageUtil(me.ccrama.redditslide.util.ImageUtil) SettingsActivity(me.ccrama.redditslide.ui.settings.SettingsActivity) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Subreddit(net.dean.jraw.models.Subreddit) Activity(android.app.Activity) NetworkException(net.dean.jraw.http.NetworkException) Collections(java.util.Collections) LoggedInAccount(net.dean.jraw.models.LoggedInAccount) AlertDialog(androidx.appcompat.app.AlertDialog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) NonNull(androidx.annotation.NonNull) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) HashSet(java.util.HashSet) Toolbar(androidx.appcompat.widget.Toolbar) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) ManageOfflineContent(me.ccrama.redditslide.ui.settings.ManageOfflineContent) SettingsActivity(me.ccrama.redditslide.ui.settings.SettingsActivity) SwitchCompat(androidx.appcompat.widget.SwitchCompat) Set(java.util.Set) HashSet(java.util.HashSet) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) CardView(androidx.cardview.widget.CardView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) Point(android.graphics.Point) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton)

Example 9 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.

the class SettingsGeneralFragment method Bind.

/* Allow SettingsGeneral and Settings Activity classes to use the same XML functionality */
public void Bind() {
    final RelativeLayout notifLayout = context.findViewById(R.id.settings_general_notifications);
    final TextView notifCurrentView = context.findViewById(R.id.settings_general_notifications_current);
    final RelativeLayout subNotifLayout = context.findViewById(R.id.settings_general_sub_notifications);
    final TextView defaultSortingCurrentView = context.findViewById(R.id.settings_general_sorting_current);
    context.findViewById(R.id.settings_general_drawer_items).setOnClickListener(v -> new DrawerItemsDialog(new MaterialDialog.Builder(context)).show());
    {
        SwitchCompat immersiveModeSwitch = context.findViewById(R.id.settings_general_immersivemode);
        if (immersiveModeSwitch != null) {
            immersiveModeSwitch.setChecked(SettingValues.immersiveMode);
            immersiveModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
                SettingsThemeFragment.changed = true;
                SettingValues.immersiveMode = isChecked;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMMERSIVE_MODE, isChecked).apply();
            });
        }
    }
    {
        SwitchCompat highClrSpaceSwitch = context.findViewById(R.id.settings_general_high_colorspace);
        if (highClrSpaceSwitch != null) {
            highClrSpaceSwitch.setChecked(SettingValues.highColorspaceImages);
            highClrSpaceSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
                SettingsThemeFragment.changed = true;
                SettingValues.highColorspaceImages = isChecked;
                Reddit application = (Reddit) context.getApplication();
                ImageLoaderUtils.initImageLoader(application.getApplicationContext());
                application.defaultImageLoader = ImageLoaderUtils.imageLoader;
                SettingValues.prefs.edit().putBoolean(SettingValues.PREF_HIGH_COLORSPACE_IMAGES, isChecked).apply();
            });
        }
    }
    {
        SwitchCompat forceLangSwitch = context.findViewById(R.id.settings_general_forcelanguage);
        if (forceLangSwitch != null) {
            forceLangSwitch.setChecked(SettingValues.overrideLanguage);
            forceLangSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SettingsThemeFragment.changed = true;
                    SettingValues.overrideLanguage = isChecked;
                    SettingValues.prefs.edit().putBoolean(SettingValues.PREF_OVERRIDE_LANGUAGE, isChecked).apply();
                }
            });
        }
    }
    // hide fab while scrolling
    {
        SwitchCompat alwaysShowFabSwitch = context.findViewById(R.id.settings_general_always_show_fab);
        if (alwaysShowFabSwitch != null) {
            alwaysShowFabSwitch.setChecked(SettingValues.alwaysShowFAB);
            alwaysShowFabSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SettingsThemeFragment.changed = true;
                    SettingValues.alwaysShowFAB = isChecked;
                    SettingValues.prefs.edit().putBoolean(SettingValues.PREF_ALWAYS_SHOW_FAB, isChecked).apply();
                }
            });
        }
    }
    // Show image download button
    {
        SwitchCompat showDownloadBtnSwitch = context.findViewById(R.id.settings_general_show_download_button);
        if (showDownloadBtnSwitch != null) {
            showDownloadBtnSwitch.setChecked(SettingValues.imageDownloadButton);
            showDownloadBtnSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SettingValues.imageDownloadButton = isChecked;
                    SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMAGE_DOWNLOAD_BUTTON, isChecked).apply();
                }
            });
        }
    }
    {
        SwitchCompat subfolderSwitch = context.findViewById(R.id.settings_general_subfolder);
        if (subfolderSwitch != null) {
            subfolderSwitch.setChecked(SettingValues.imageSubfolders);
            subfolderSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SettingValues.imageSubfolders = isChecked;
                    SettingValues.prefs.edit().putBoolean(SettingValues.PREF_IMAGE_SUBFOLDERS, isChecked).apply();
                }
            });
        }
    }
    final RelativeLayout setSaveLocationLayout = context.findViewById(R.id.settings_general_set_save_location);
    if (setSaveLocationLayout != null) {
        setSaveLocationLayout.setOnClickListener(v -> DialogUtil.showFolderChooserDialog(context));
    }
    TextView setSaveLocationView = context.findViewById(R.id.settings_general_set_save_location_view);
    if (setSaveLocationView != null) {
        String loc = Reddit.appRestart.getString("imagelocation", context.getString(R.string.settings_image_location_unset));
        setSaveLocationView.setText(loc);
    }
    final SwitchCompat expandedMenuSwitch = context.findViewById(R.id.settings_general_expandedmenu);
    if (expandedMenuSwitch != null) {
        expandedMenuSwitch.setChecked(SettingValues.expandedToolbar);
        expandedMenuSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
            SettingValues.expandedToolbar = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_EXPANDED_TOOLBAR, isChecked).apply();
        });
    }
    final RelativeLayout viewTypeLayout = context.findViewById(R.id.settings_general_viewtype);
    if (viewTypeLayout != null) {
        viewTypeLayout.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                Intent i = new Intent(context, SettingsViewType.class);
                context.startActivity(i);
            }
        });
    }
    // FAB multi choice//
    final RelativeLayout fabLayout = context.findViewById(R.id.settings_general_fab);
    final TextView currentFabView = context.findViewById(R.id.settings_general_fab_current);
    if (currentFabView != null && fabLayout != null) {
        currentFabView.setText(SettingValues.fab ? SettingValues.fabType == FAB_DISMISS ? context.getString(R.string.fab_hide) : context.getString(R.string.fab_create) : context.getString(R.string.fab_disabled));
        fabLayout.setOnClickListener(v -> {
            PopupMenu popup = new PopupMenu(context, v);
            popup.getMenuInflater().inflate(R.menu.fab_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(item -> {
                switch(item.getItemId()) {
                    case R.id.disabled:
                        SettingValues.fab = false;
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, false).apply();
                        break;
                    case R.id.hide:
                        SettingValues.fab = true;
                        SettingValues.fabType = FAB_DISMISS;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_DISMISS).apply();
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
                        break;
                    case R.id.create:
                        SettingValues.fab = true;
                        SettingValues.fabType = FAB_POST;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_POST).apply();
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
                        break;
                    case R.id.search:
                        SettingValues.fab = true;
                        SettingValues.fabType = FAB_SEARCH;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_FAB_TYPE, FAB_SEARCH).apply();
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_FAB, true).apply();
                        break;
                }
                if (SettingValues.fab) {
                    if (SettingValues.fabType == FAB_DISMISS) {
                        currentFabView.setText(R.string.fab_hide);
                    } else if (SettingValues.fabType == FAB_POST) {
                        currentFabView.setText(R.string.fab_create);
                    } else {
                        currentFabView.setText(R.string.fab_search);
                    }
                } else {
                    currentFabView.setText(R.string.fab_disabled);
                }
                return true;
            });
            popup.show();
        });
    }
    // SettingValues.subredditSearchMethod == 1 for drawer, 2 for toolbar, 3 for both
    final TextView currentMethodTitle = context.findViewById(R.id.settings_general_subreddit_search_method_current);
    if (currentMethodTitle != null) {
        switch(SettingValues.subredditSearchMethod) {
            case SUBREDDIT_SEARCH_METHOD_DRAWER:
                currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_drawer));
                break;
            case SUBREDDIT_SEARCH_METHOD_TOOLBAR:
                currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_toolbar));
                break;
            case SUBREDDIT_SEARCH_METHOD_BOTH:
                currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_both));
                break;
        }
    }
    final RelativeLayout currentMethodLayout = context.findViewById(R.id.settings_general_subreddit_search_method);
    if (currentMethodLayout != null) {
        currentMethodLayout.setOnClickListener(v -> {
            final PopupMenu popup = new PopupMenu(SettingsGeneralFragment.this.context, v);
            popup.getMenuInflater().inflate(R.menu.subreddit_search_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(item -> {
                switch(item.getItemId()) {
                    case R.id.subreddit_search_drawer:
                        SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_DRAWER;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_DRAWER).apply();
                        searchChanged = true;
                        break;
                    case R.id.subreddit_search_toolbar:
                        SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_TOOLBAR;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_TOOLBAR).apply();
                        searchChanged = true;
                        break;
                    case R.id.subreddit_search_both:
                        SettingValues.subredditSearchMethod = SUBREDDIT_SEARCH_METHOD_BOTH;
                        SettingValues.prefs.edit().putInt(SettingValues.PREF_SUBREDDIT_SEARCH_METHOD, SUBREDDIT_SEARCH_METHOD_BOTH).apply();
                        searchChanged = true;
                        break;
                }
                switch(SettingValues.subredditSearchMethod) {
                    case SUBREDDIT_SEARCH_METHOD_DRAWER:
                        currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_drawer));
                        break;
                    case SUBREDDIT_SEARCH_METHOD_TOOLBAR:
                        currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_toolbar));
                        break;
                    case SUBREDDIT_SEARCH_METHOD_BOTH:
                        currentMethodTitle.setText(context.getString(R.string.subreddit_search_method_both));
                        break;
                }
                return true;
            });
            popup.show();
        });
    }
    final TextView currentBackButtonTitle = context.findViewById(R.id.settings_general_back_button_behavior_current);
    if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.ConfirmExit.getValue()) {
        currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_confirm_exit));
    } else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.OpenDrawer.getValue()) {
        currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_drawer));
    } else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.GotoFirst.getValue()) {
        currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_goto_first));
    } else {
        currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_default));
    }
    final RelativeLayout currentBackButtonLayout = context.findViewById(R.id.settings_general_back_button_behavior);
    currentBackButtonLayout.setOnClickListener(v -> {
        final PopupMenu popup = new PopupMenu(context, v);
        popup.getMenuInflater().inflate(R.menu.back_button_behavior_settings, popup.getMenu());
        popup.setOnMenuItemClickListener(item -> {
            switch(item.getItemId()) {
                case R.id.back_button_behavior_default:
                    SettingValues.backButtonBehavior = BackButtonBehaviorOptions.Default.getValue();
                    SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.Default.getValue()).apply();
                    break;
                case R.id.back_button_behavior_confirm_exit:
                    SettingValues.backButtonBehavior = BackButtonBehaviorOptions.ConfirmExit.getValue();
                    SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.ConfirmExit.getValue()).apply();
                    break;
                case R.id.back_button_behavior_open_drawer:
                    SettingValues.backButtonBehavior = BackButtonBehaviorOptions.OpenDrawer.getValue();
                    SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.OpenDrawer.getValue()).apply();
                    break;
                case R.id.back_button_behavior_goto_first:
                    SettingValues.backButtonBehavior = BackButtonBehaviorOptions.GotoFirst.getValue();
                    SettingValues.prefs.edit().putInt(SettingValues.PREF_BACK_BUTTON_BEHAVIOR, BackButtonBehaviorOptions.GotoFirst.getValue()).apply();
                    break;
            }
            if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.ConfirmExit.getValue()) {
                currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_confirm_exit));
            } else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.OpenDrawer.getValue()) {
                currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_drawer));
            } else if (SettingValues.backButtonBehavior == BackButtonBehaviorOptions.GotoFirst.getValue()) {
                currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_goto_first));
            } else {
                currentBackButtonTitle.setText(context.getString(R.string.back_button_behavior_default));
            }
            return true;
        });
        popup.show();
    });
    if (notifCurrentView != null && context.findViewById(R.id.settings_general_sub_notifs_current) != null) {
        if (Reddit.notificationTime > 0) {
            notifCurrentView.setText(context.getString(R.string.settings_notification_short, TimeUtils.getTimeInHoursAndMins(Reddit.notificationTime, context.getBaseContext())));
            setSubText();
        } else {
            notifCurrentView.setText(R.string.settings_notifdisabled);
            ((TextView) context.findViewById(R.id.settings_general_sub_notifs_current)).setText(R.string.settings_enable_notifs);
        }
    }
    if (Authentication.isLoggedIn) {
        if (notifLayout != null) {
            notifLayout.setOnClickListener(v -> {
                final LayoutInflater inflater = context.getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.inboxfrequency, null);
                setupNotificationSettings(dialoglayout, SettingsGeneralFragment.this.context);
            });
        }
        if (subNotifLayout != null) {
            subNotifLayout.setOnClickListener(v -> showSelectDialog());
        }
    } else {
        if (notifLayout != null) {
            notifLayout.setEnabled(false);
            notifLayout.setAlpha(0.25f);
        }
        if (subNotifLayout != null) {
            subNotifLayout.setEnabled(false);
            subNotifLayout.setAlpha(0.25f);
        }
    }
    if (defaultSortingCurrentView != null) {
        defaultSortingCurrentView.setText(SortingUtil.getSortingStrings()[SortingUtil.getSortingId("")]);
    }
    {
        if (context.findViewById(R.id.settings_general_sorting) != null) {
            context.findViewById(R.id.settings_general_sorting).setOnClickListener(v -> {
                final DialogInterface.OnClickListener l2 = (dialogInterface, i) -> {
                    switch(i) {
                        case 0:
                            SortingUtil.defaultSorting = Sorting.HOT;
                            break;
                        case 1:
                            SortingUtil.defaultSorting = Sorting.NEW;
                            break;
                        case 2:
                            SortingUtil.defaultSorting = Sorting.RISING;
                            break;
                        case 3:
                            SortingUtil.defaultSorting = Sorting.TOP;
                            askTimePeriod();
                            return;
                        case 4:
                            SortingUtil.defaultSorting = Sorting.CONTROVERSIAL;
                            askTimePeriod();
                            return;
                    }
                    SettingValues.prefs.edit().putString("defaultSorting", SortingUtil.defaultSorting.name()).apply();
                    SettingValues.defaultSorting = SortingUtil.defaultSorting;
                    if (defaultSortingCurrentView != null) {
                        defaultSortingCurrentView.setText(SortingUtil.getSortingStrings()[SortingUtil.getSortingId("")]);
                    }
                };
                // Remove the "Best" sorting option from settings because it is only supported on the frontpage.
                int skip = -1;
                List<String> sortingStrings = new ArrayList<>(Arrays.asList(SortingUtil.getSortingStrings()));
                for (int i = 0; i < sortingStrings.size(); i++) {
                    if (sortingStrings.get(i).equals(context.getString(R.string.sorting_best))) {
                        skip = i;
                        break;
                    }
                }
                if (skip != -1) {
                    sortingStrings.remove(skip);
                }
                new AlertDialog.Builder(SettingsGeneralFragment.this.context).setTitle(R.string.sorting_choose).setSingleChoiceItems(sortingStrings.toArray(new String[0]), SortingUtil.getSortingId(""), l2).show();
            });
        }
    }
    doNotifText(context);
    {
        final int i2 = SettingValues.defaultCommentSorting == CommentSort.CONFIDENCE ? 0 : SettingValues.defaultCommentSorting == CommentSort.TOP ? 1 : SettingValues.defaultCommentSorting == CommentSort.NEW ? 2 : SettingValues.defaultCommentSorting == CommentSort.CONTROVERSIAL ? 3 : SettingValues.defaultCommentSorting == CommentSort.OLD ? 4 : SettingValues.defaultCommentSorting == CommentSort.QA ? 5 : 0;
        final TextView sortingCurrentCommentView = context.findViewById(R.id.settings_general_sorting_current_comment);
        if (sortingCurrentCommentView != null) {
            sortingCurrentCommentView.setText(SortingUtil.getSortingCommentsStrings()[i2]);
        }
        if (context.findViewById(R.id.settings_general_sorting_comment) != null) {
            context.findViewById(R.id.settings_general_sorting_comment).setOnClickListener(v -> {
                final DialogInterface.OnClickListener l2 = (dialogInterface, i) -> {
                    CommentSort commentSorting = SettingValues.defaultCommentSorting;
                    switch(i) {
                        case 0:
                            commentSorting = CommentSort.CONFIDENCE;
                            break;
                        case 1:
                            commentSorting = CommentSort.TOP;
                            break;
                        case 2:
                            commentSorting = CommentSort.NEW;
                            break;
                        case 3:
                            commentSorting = CommentSort.CONTROVERSIAL;
                            break;
                        case 4:
                            commentSorting = CommentSort.OLD;
                            break;
                        case 5:
                            commentSorting = CommentSort.QA;
                            break;
                    }
                    SettingValues.prefs.edit().putString("defaultCommentSortingNew", commentSorting.name()).apply();
                    SettingValues.defaultCommentSorting = commentSorting;
                    if (sortingCurrentCommentView != null) {
                        sortingCurrentCommentView.setText(SortingUtil.getSortingCommentsStrings()[i]);
                    }
                };
                Resources res = context.getBaseContext().getResources();
                new AlertDialog.Builder(SettingsGeneralFragment.this.context).setTitle(R.string.sorting_choose).setSingleChoiceItems(new String[] { res.getString(R.string.sorting_best), res.getString(R.string.sorting_top), res.getString(R.string.sorting_new), res.getString(R.string.sorting_controversial), res.getString(R.string.sorting_old), res.getString(R.string.sorting_ama) }, i2, l2).show();
            });
        }
    }
}
Also used : Arrays(java.util.Arrays) R(me.ccrama.redditslide.R) TimeUtils(me.ccrama.redditslide.util.TimeUtils) NonNull(androidx.annotation.NonNull) FolderChooserDialogCreate(me.ccrama.redditslide.Fragments.FolderChooserDialogCreate) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) FAB_SEARCH(me.ccrama.redditslide.Constants.FAB_SEARCH) ImageLoaderUtils(me.ccrama.redditslide.util.ImageLoaderUtils) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) Sorting(net.dean.jraw.paginators.Sorting) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) CommentSort(net.dean.jraw.models.CommentSort) CheckForMail(me.ccrama.redditslide.Notifications.CheckForMail) AsyncTask(android.os.AsyncTask) Authentication(me.ccrama.redditslide.Authentication) Slider(com.rey.material.widget.Slider) NotificationJobScheduler(me.ccrama.redditslide.Notifications.NotificationJobScheduler) Palette(me.ccrama.redditslide.Visuals.Palette) BackButtonBehaviorOptions(me.ccrama.redditslide.Constants.BackButtonBehaviorOptions) List(java.util.List) TextView(android.widget.TextView) SUBREDDIT_SEARCH_METHOD_DRAWER(me.ccrama.redditslide.Constants.SUBREDDIT_SEARCH_METHOD_DRAWER) SortingUtil(me.ccrama.redditslide.util.SortingUtil) DrawerItemsDialog(me.ccrama.redditslide.Fragments.DrawerItemsDialog) RelativeLayout(android.widget.RelativeLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) SUBREDDIT_SEARCH_METHOD_BOTH(me.ccrama.redditslide.Constants.SUBREDDIT_SEARCH_METHOD_BOTH) SettingValues(me.ccrama.redditslide.SettingValues) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) Intent(android.content.Intent) HashMap(java.util.HashMap) FAB_DISMISS(me.ccrama.redditslide.Constants.FAB_DISMISS) ArrayList(java.util.ArrayList) Toast(android.widget.Toast) UserSubscriptions(me.ccrama.redditslide.UserSubscriptions) Build(android.os.Build) DialogInterface(android.content.DialogInterface) TimePeriod(net.dean.jraw.paginators.TimePeriod) StringUtil(me.ccrama.redditslide.util.StringUtil) SUBREDDIT_SEARCH_METHOD_TOOLBAR(me.ccrama.redditslide.Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR) SwitchCompat(androidx.appcompat.widget.SwitchCompat) CompoundButton(android.widget.CompoundButton) DialogUtil(me.ccrama.redditslide.util.DialogUtil) LayoutInflater(android.view.LayoutInflater) Reddit(me.ccrama.redditslide.Reddit) DialogAction(com.afollestad.materialdialogs.DialogAction) File(java.io.File) FAB_POST(me.ccrama.redditslide.Constants.FAB_POST) PopupMenu(androidx.appcompat.widget.PopupMenu) Subreddit(net.dean.jraw.models.Subreddit) Activity(android.app.Activity) FolderCallback(me.ccrama.redditslide.Fragments.FolderChooserDialogCreate.FolderCallback) Resources(android.content.res.Resources) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) DrawerItemsDialog(me.ccrama.redditslide.Fragments.DrawerItemsDialog) Reddit(me.ccrama.redditslide.Reddit) LayoutInflater(android.view.LayoutInflater) CommentSort(net.dean.jraw.models.CommentSort) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) CompoundButton(android.widget.CompoundButton) SwitchCompat(androidx.appcompat.widget.SwitchCompat) PopupMenu(androidx.appcompat.widget.PopupMenu)

Example 10 with SwitchCompat

use of androidx.appcompat.widget.SwitchCompat in project Slide by ccrama.

the class SettingsHandlingFragment method Bind.

public void Bind() {
    // todo web stuff
    SwitchCompat shortlink = context.findViewById(R.id.settings_handling_shortlink);
    SwitchCompat gif = context.findViewById(R.id.settings_handling_gif);
    SwitchCompat hqgif = context.findViewById(R.id.settings_handling_hqgif);
    SwitchCompat image = context.findViewById(R.id.settings_handling_image);
    SwitchCompat album = context.findViewById(R.id.settings_handling_album);
    SwitchCompat peek = context.findViewById(R.id.settings_handling_peek);
    shortlink.setChecked(!SettingValues.shareLongLink);
    gif.setChecked(SettingValues.gif);
    hqgif.setChecked(SettingValues.hqgif);
    image.setChecked(SettingValues.image);
    album.setChecked(SettingValues.album);
    peek.setChecked(SettingValues.peek);
    shortlink.setOnCheckedChangeListener(this);
    gif.setOnCheckedChangeListener(this);
    hqgif.setOnCheckedChangeListener(this);
    image.setOnCheckedChangeListener(this);
    album.setOnCheckedChangeListener(this);
    peek.setOnCheckedChangeListener(this);
    final SwitchCompat readerMode = context.findViewById(R.id.settings_handling_reader_mode);
    final SwitchCompat readernight = context.findViewById(R.id.settings_handling_readernight);
    final RelativeLayout handlingVideoLayout = context.findViewById(R.id.settings_handling_video);
    domainListLayout = context.findViewById(R.id.settings_handling_domainlist);
    final EditText domainListEditText = context.findViewById(R.id.settings_handling_domain_edit);
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // * Browser */
    setUpBrowserLinkHandling();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    readerMode.setChecked(SettingValues.readerMode);
    readerMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.readerMode = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_READER_MODE, SettingValues.readerMode);
        readernight.setEnabled(SettingValues.NightModeState.isEnabled() && SettingValues.readerMode);
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    readernight.setEnabled(SettingValues.NightModeState.isEnabled() && SettingValues.readerMode);
    readernight.setChecked(SettingValues.readerNight);
    readernight.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SettingValues.readerNight = isChecked;
        editSharedBooleanPreference(SettingValues.PREF_READER_NIGHT, isChecked);
    });
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if (!Reddit.videoPlugin) {
        handlingVideoLayout.setOnClickListener(v -> LinkUtil.launchMarketUri(context, R.string.youtube_plugin_package));
    } else {
        handlingVideoLayout.setVisibility(View.GONE);
    }
    /* activity_settings_handling_child.xml does not load these elements so we need to null check */
    if (domainListEditText != null & domainListLayout != null) {
        domainListEditText.setOnEditorActionListener((v, actionId, event) -> {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                SettingValues.alwaysExternal.add(domainListEditText.getText().toString().toLowerCase(Locale.ENGLISH).trim());
                domainListEditText.setText("");
                updateFilters();
            }
            return false;
        });
        updateFilters();
    }
}
Also used : EditText(android.widget.EditText) RelativeLayout(android.widget.RelativeLayout) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Aggregations

SwitchCompat (androidx.appcompat.widget.SwitchCompat)43 TextView (android.widget.TextView)23 View (android.view.View)20 CompoundButton (android.widget.CompoundButton)17 RelativeLayout (android.widget.RelativeLayout)8 LayoutInflater (android.view.LayoutInflater)7 AlertDialog (androidx.appcompat.app.AlertDialog)6 PopupMenu (androidx.appcompat.widget.PopupMenu)6 Toolbar (androidx.appcompat.widget.Toolbar)5 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)5 ArrayList (java.util.ArrayList)5 Activity (android.app.Activity)4 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)4 Uri (android.net.Uri)4 ViewGroup (android.view.ViewGroup)4 ContextCompat (androidx.core.content.ContextCompat)4 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)4 Dialog (android.app.Dialog)3 Drawable (android.graphics.drawable.Drawable)3