Search in sources :

Example 16 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SettingsSubreddit method reloadSubList.

public void reloadSubList() {
    changedSubs.clear();
    List<String> allSubs = UserSubscriptions.sort(UserSubscriptions.getAllUserSubreddits(this));
    // Check which subreddits are different
    ColorPreferences colorPrefs = new ColorPreferences(SettingsSubreddit.this);
    int defaultFont = colorPrefs.getFontStyle().getColor();
    for (String s : allSubs) {
        if (Palette.getColor(s) != Palette.getDefaultColor() || SettingValues.prefs.contains(Reddit.PREF_LAYOUT + s) || colorPrefs.getFontStyleSubreddit(s).getColor() != defaultFont || SettingValues.prefs.contains("picsenabled" + s.toLowerCase(Locale.ENGLISH))) {
            changedSubs.add(s);
        }
    }
    mSettingsSubAdapter = new SettingsSubAdapter(this, changedSubs);
    recycler.setAdapter(mSettingsSubAdapter);
    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.post_floating_action_button);
    recycler.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy <= 0 && fab.getId() != 0) {
                fab.show();
            } else {
                fab.hide();
            }
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
        }
    });
    fab.show();
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) SettingsSubAdapter(me.ccrama.redditslide.Adapters.SettingsSubAdapter)

Example 17 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SettingsTheme method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_settings_theme);
    setupAppBar(R.id.toolbar, R.string.title_edit_theme, true, true);
    back = new ColorPreferences(SettingsTheme.this).getFontStyle().getThemeType();
    findViewById(R.id.accent).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.chooseaccent, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            final LineColorPicker colorPicker = (LineColorPicker) dialoglayout.findViewById(R.id.picker3);
            int[] arrs = new int[ColorPreferences.getNumColorsFromThemeType(0)];
            int i = 0;
            for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                if (type.getThemeType() == 0) {
                    arrs[i] = ContextCompat.getColor(SettingsTheme.this, type.getColor());
                    i++;
                }
            }
            colorPicker.setColors(arrs);
            colorPicker.setSelectedColor(ContextCompat.getColor(SettingsTheme.this, new ColorPreferences(SettingsTheme.this).getFontStyle().getColor()));
            dialoglayout.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    int color = colorPicker.getColor();
                    ColorPreferences.Theme t = null;
                    for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                        if (ContextCompat.getColor(SettingsTheme.this, type.getColor()) == color && back == type.getThemeType()) {
                            t = type;
                            LogUtil.v("Setting to " + t.getTitle());
                            break;
                        }
                    }
                    new ColorPreferences(SettingsTheme.this).setFontStyle(t);
                    Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(i);
                    overridePendingTransition(0, 0);
                    finish();
                    overridePendingTransition(0, 0);
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    findViewById(R.id.theme).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            if (SettingValues.isNight()) {
                dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
            }
            dialoglayout.findViewById(R.id.black).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 2) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.light).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 1) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.pixel).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 7) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.dark).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 0) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.blacklighter).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 4) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.deep).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 8) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.sepia).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 5) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.red).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 6) {
                            back = theme.getThemeType();
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            dialoglayout.findViewById(R.id.blue).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    SettingsTheme.changed = true;
                    String[] names = new ColorPreferences(SettingsTheme.this).getFontStyle().getTitle().split("_");
                    String name = names[names.length - 1];
                    final String newName = name.replace("(", "");
                    for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
                        if (theme.toString().contains(newName) && theme.getThemeType() == 3) {
                            new ColorPreferences(SettingsTheme.this).setFontStyle(theme);
                            back = theme.getThemeType();
                            Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                            startActivity(i);
                            overridePendingTransition(0, 0);
                            finish();
                            overridePendingTransition(0, 0);
                            break;
                        }
                    }
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    findViewById(R.id.main).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            LayoutInflater inflater = getLayoutInflater();
            final View dialoglayout = inflater.inflate(R.layout.choosemain, null);
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
            final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
            title.setBackgroundColor(Palette.getDefaultColor());
            final LineColorPicker colorPicker = (LineColorPicker) dialoglayout.findViewById(R.id.picker);
            final LineColorPicker colorPicker2 = (LineColorPicker) dialoglayout.findViewById(R.id.picker2);
            colorPicker.setColors(ColorPreferences.getBaseColors(SettingsTheme.this));
            int currentColor = Palette.getDefaultColor();
            for (int i : colorPicker.getColors()) {
                for (int i2 : ColorPreferences.getColors(getBaseContext(), i)) {
                    if (i2 == currentColor) {
                        colorPicker.setSelectedColor(i);
                        colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), i));
                        colorPicker2.setSelectedColor(i2);
                        break;
                    }
                }
            }
            colorPicker.setOnColorChangedListener(new OnColorChangedListener() {

                @Override
                public void onColorChanged(int c) {
                    SettingsTheme.changed = true;
                    colorPicker2.setColors(ColorPreferences.getColors(getBaseContext(), c));
                    colorPicker2.setSelectedColor(c);
                }
            });
            colorPicker2.setOnColorChangedListener(new OnColorChangedListener() {

                @Override
                public void onColorChanged(int i) {
                    SettingsTheme.changed = true;
                    title.setBackgroundColor(colorPicker2.getColor());
                    if (mToolbar != null)
                        mToolbar.setBackgroundColor(colorPicker2.getColor());
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        Window window = getWindow();
                        window.setStatusBarColor(Palette.getDarkerColor(colorPicker2.getColor()));
                    }
                    setRecentBar(getString(R.string.title_theme_settings), colorPicker2.getColor());
                }
            });
            dialoglayout.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (SettingValues.colorIcon) {
                        getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                        getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, colorPicker2.getColor())), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
                    }
                    Reddit.colors.edit().putInt("DEFAULTCOLOR", colorPicker2.getColor()).apply();
                    Intent i = new Intent(SettingsTheme.this, SettingsTheme.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(i);
                    overridePendingTransition(0, 0);
                    finish();
                    overridePendingTransition(0, 0);
                }
            });
            builder.setView(dialoglayout);
            builder.show();
        }
    });
    // Color tinting mode
    final SwitchCompat s2 = (SwitchCompat) findViewById(R.id.tint_everywhere);
    ((TextView) findViewById(R.id.tint_current)).setText(SettingValues.colorBack ? (SettingValues.colorSubName ? getString(R.string.subreddit_name_tint) : getString(R.string.card_background_tint)) : getString(R.string.misc_none));
    boolean enabled = !((TextView) findViewById(R.id.tint_current)).getText().equals(getString(R.string.misc_none));
    findViewById(R.id.dotint).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SettingsTheme.this, v);
            popup.getMenuInflater().inflate(R.menu.color_tinting_mode_settings, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.none:
                            SettingValues.colorBack = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, false).apply();
                            break;
                        case R.id.background:
                            SettingValues.colorBack = true;
                            SettingValues.colorSubName = false;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_SUB_NAME, false).apply();
                            break;
                        case R.id.name:
                            SettingValues.colorBack = true;
                            SettingValues.colorSubName = true;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_BACK, true).apply();
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_SUB_NAME, true).apply();
                            break;
                    }
                    ((TextView) findViewById(R.id.tint_current)).setText(SettingValues.colorBack ? (SettingValues.colorSubName ? getString(R.string.subreddit_name_tint) : getString(R.string.card_background_tint)) : getString(R.string.misc_none));
                    boolean enabled = !((TextView) findViewById(R.id.tint_current)).getText().equals(getString(R.string.misc_none));
                    s2.setEnabled(enabled);
                    s2.setChecked(SettingValues.colorEverywhere);
                    s2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            SettingValues.colorEverywhere = isChecked;
                            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_EVERYWHERE, isChecked).apply();
                        }
                    });
                    return true;
                }
            });
            popup.show();
        }
    });
    s2.setEnabled(enabled);
    s2.setChecked(SettingValues.colorEverywhere);
    s2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.colorEverywhere = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_EVERYWHERE, isChecked).apply();
        }
    });
    final SwitchCompat colorNavbarSwitch = (SwitchCompat) findViewById(R.id.color_navigation_bar);
    colorNavbarSwitch.setChecked(SettingValues.colorNavBar);
    colorNavbarSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingsTheme.changed = true;
            SettingValues.colorNavBar = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_NAV_BAR, isChecked).apply();
            themeSystemBars("");
            if (!isChecked) {
                getWindow().setNavigationBarColor(Color.TRANSPARENT);
            }
        }
    });
    final SwitchCompat colorIcon = (SwitchCompat) findViewById(R.id.color_icon);
    colorIcon.setChecked(SettingValues.colorIcon);
    colorIcon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingValues.colorIcon = isChecked;
            SettingValues.prefs.edit().putBoolean(SettingValues.PREF_COLOR_ICON, isChecked).apply();
            if (isChecked) {
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, Slide.class.getPackage().getName() + ".Slide"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            } else {
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, ColorPreferences.getIconName(SettingsTheme.this, Reddit.colors.getInt("DEFAULTCOLOR", 0))), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
                getPackageManager().setComponentEnabledSetting(new ComponentName(SettingsTheme.this, Slide.class.getPackage().getName() + ".Slide"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            }
        }
    });
    LinearLayout nightMode = (LinearLayout) findViewById(R.id.night);
    assert nightMode != null;
    nightMode.setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View view) {
            if (SettingValues.tabletUI) {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.nightmode, null);
                final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(SettingsTheme.this);
                final Dialog dialog = builder.setView(dialoglayout).create();
                dialog.show();
                dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                    // todo save
                    }
                });
                SwitchCompat s = (SwitchCompat) dialog.findViewById(R.id.enabled);
                s.setChecked(SettingValues.nightMode);
                s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        SettingValues.nightMode = isChecked;
                        SettingValues.prefs.edit().putBoolean(SettingValues.PREF_NIGHT_MODE, isChecked).apply();
                        SettingsTheme.changed = true;
                    }
                });
                switch(SettingValues.nightTheme) {
                    case 0:
                        ((RadioButton) dialoglayout.findViewById(R.id.dark)).setChecked(true);
                        break;
                    case 2:
                        ((RadioButton) dialoglayout.findViewById(R.id.amoled)).setChecked(true);
                        break;
                    case 3:
                        ((RadioButton) dialoglayout.findViewById(R.id.blue)).setChecked(true);
                        break;
                    case 6:
                        ((RadioButton) dialoglayout.findViewById(R.id.red)).setChecked(true);
                        break;
                    case 4:
                        ((RadioButton) dialoglayout.findViewById(R.id.amoled_contrast)).setChecked(true);
                        break;
                    default:
                        ((RadioButton) dialoglayout.findViewById(R.id.dark)).setChecked(true);
                        break;
                }
                ((RadioButton) dialoglayout.findViewById(R.id.dark)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 0;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 0).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.amoled)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 2;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 2).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.red)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 6;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 6).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.blue)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 3;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 3).apply();
                        }
                    }
                });
                ((RadioButton) dialoglayout.findViewById(R.id.amoled_contrast)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            SettingsTheme.changed = true;
                            SettingValues.nightTheme = 4;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_THEME, 4).apply();
                        }
                    }
                });
                {
                    final List<String> timesStart = new ArrayList<String>() {

                        {
                            add("6pm");
                            add("7pm");
                            add("8pm");
                            add("9pm");
                            add("10pm");
                            add("11pm");
                        }
                    };
                    final Spinner startSpinner = (Spinner) dialoglayout.findViewById(R.id.start_spinner);
                    final ArrayAdapter<String> startAdapter = new ArrayAdapter<>(SettingsTheme.this, android.R.layout.simple_spinner_item, timesStart);
                    startAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    startSpinner.setAdapter(startAdapter);
                    // set the currently selected pref
                    startSpinner.setSelection(startAdapter.getPosition(Integer.toString(SettingValues.nightStart).concat("pm")));
                    startSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            // get the time, but remove the "pm" from the string when parsing
                            final int time = Integer.parseInt(((String) startSpinner.getItemAtPosition(position)).replaceAll("pm", ""));
                            SettingValues.nightStart = time;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_START, time).apply();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });
                }
                {
                    final List<String> timesEnd = new ArrayList<String>() {

                        {
                            add("12am");
                            add("1am");
                            add("2am");
                            add("3am");
                            add("4am");
                            add("5am");
                            add("6am");
                            add("7am");
                            add("8am");
                            add("9am");
                            add("10am");
                        }
                    };
                    final Spinner endSpinner = (Spinner) dialoglayout.findViewById(R.id.end_spinner);
                    final ArrayAdapter<String> endAdapter = new ArrayAdapter<>(SettingsTheme.this, android.R.layout.simple_spinner_item, timesEnd);
                    endAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    endSpinner.setAdapter(endAdapter);
                    // set the currently selected pref
                    endSpinner.setSelection(endAdapter.getPosition(Integer.toString(SettingValues.nightEnd).concat("am")));
                    endSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            // get the time, but remove the "am" from the string when parsing
                            final int time = Integer.parseInt(((String) endSpinner.getItemAtPosition(position)).replaceAll("am", ""));
                            SettingValues.nightEnd = time;
                            SettingValues.prefs.edit().putInt(SettingValues.PREF_NIGHT_END, time).apply();
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });
                }
                {
                    Button okayButton = (Button) dialoglayout.findViewById(R.id.ok);
                    okayButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                }
            } else {
                new AlertDialogWrapper.Builder(SettingsTheme.this).setTitle(R.string.general_nighttheme_ispro).setMessage(R.string.pro_upgrade_msg).setPositiveButton(R.string.btn_yes_exclaim, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=me.ccrama.slideforreddittabletuiunlock")));
                        } catch (android.content.ActivityNotFoundException anfe) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=me.ccrama.slideforreddittabletuiunlock")));
                        }
                    }
                }).setNegativeButton(R.string.btn_no_danks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                }).show();
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) RadioButton(android.widget.RadioButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Dialog(android.app.Dialog) TextView(android.widget.TextView) ComponentName(android.content.ComponentName) Window(android.view.Window) ColorPreferences(me.ccrama.redditslide.ColorPreferences) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LineColorPicker(uz.shift.colorpicker.LineColorPicker) OnColorChangedListener(uz.shift.colorpicker.OnColorChangedListener) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) LinearLayout(android.widget.LinearLayout) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat) PopupMenu(android.support.v7.widget.PopupMenu)

Example 18 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SetupWidget method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
    super.onCreate(savedInstanceState);
    assignAppWidgetId();
    doShortcut();
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.ColorPreferences)

Example 19 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class SettingsSubAdapter method prepareAndShowSubEditor.

private void prepareAndShowSubEditor(String subreddit) {
    int style = new ColorPreferences(context).getThemeSubreddit(subreddit);
    final Context contextThemeWrapper = new ContextThemeWrapper(context, style);
    LayoutInflater localInflater = context.getLayoutInflater().cloneInContext(contextThemeWrapper);
    final View dialoglayout = localInflater.inflate(R.layout.colorsub, null);
    ArrayList<String> arrayList = new ArrayList<>();
    arrayList.add(subreddit);
    showSubThemeEditor(arrayList, context, dialoglayout);
}
Also used : Context(android.content.Context) ColorPreferences(me.ccrama.redditslide.ColorPreferences) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 20 with ColorPreferences

use of me.ccrama.redditslide.ColorPreferences in project Slide by ccrama.

the class ReorderSubreddits method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_sort);
    setupAppBar(R.id.toolbar, R.string.settings_manage_subscriptions, false, true);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    isSubscribed = new HashMap<>();
    if (Authentication.isLoggedIn) {
        new AsyncTask<Void, Void, Void>() {

            boolean success = true;

            @Override
            protected Void doInBackground(Void... params) {
                ArrayList<Subreddit> subs = new ArrayList<>();
                UserSubredditsPaginator p = new UserSubredditsPaginator(Authentication.reddit, "subscriber");
                try {
                    while (p.hasNext()) {
                        subs.addAll(p.next());
                    }
                } catch (Exception e) {
                    success = false;
                    return null;
                }
                for (Subreddit s : subs) {
                    isSubscribed.put(s.getDisplayName().toLowerCase(Locale.ENGLISH), true);
                }
                if (UserSubscriptions.multireddits == null) {
                    UserSubscriptions.loadMultireddits();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                if (success) {
                    d.dismiss();
                    doShowSubs();
                } else {
                    new AlertDialogWrapper.Builder(ReorderSubreddits.this).setTitle(R.string.err_title).setMessage(R.string.misc_please_try_again_soon).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    }).show();
                }
            }

            Dialog d;

            @Override
            protected void onPreExecute() {
                d = new MaterialDialog.Builder(ReorderSubreddits.this).progress(true, 100).content(R.string.misc_please_wait).title(R.string.reorder_loading_title).cancelable(false).show();
            }
        }.execute();
    } else {
        doShowSubs();
    }
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) ArrayList(java.util.ArrayList) UserSubredditsPaginator(net.dean.jraw.paginators.UserSubredditsPaginator) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) MultiSubreddit(net.dean.jraw.models.MultiSubreddit) Subreddit(net.dean.jraw.models.Subreddit)

Aggregations

ColorPreferences (me.ccrama.redditslide.ColorPreferences)50 View (android.view.View)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)16 DialogInterface (android.content.DialogInterface)14 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)14 ArrayList (java.util.ArrayList)14 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)13 LayoutInflater (android.view.LayoutInflater)12 RecyclerView (android.support.v7.widget.RecyclerView)10 ImageView (android.widget.ImageView)10 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)10 Context (android.content.Context)9 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)9 HorizontalScrollView (android.widget.HorizontalScrollView)9 Snackbar (android.support.design.widget.Snackbar)8 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)8 CaseInsensitiveArrayList (me.ccrama.redditslide.CaseInsensitiveArrayList)8 LinearInterpolator (android.view.animation.LinearInterpolator)7 Dialog (android.app.Dialog)6