Search in sources :

Example 1 with ColorPreferences

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

the class ManageOfflineContent method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    applyColorTheme();
    setContentView(R.layout.activity_manage_history);
    setupAppBar(R.id.toolbar, R.string.manage_offline_content, true, true);
    if (!NetworkUtil.isConnected(this))
        SettingsTheme.changed = true;
    findViewById(R.id.clear_all).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean wifi = Reddit.cachedData.getBoolean("wifiOnly", false);
            String sync = Reddit.cachedData.getString("toCache", "");
            int hour = (Reddit.cachedData.getInt("hour", 0));
            int minute = (Reddit.cachedData.getInt("minute", 0));
            Reddit.cachedData.edit().clear().apply();
            Reddit.cachedData.edit().putBoolean("wifiOnly", wifi).putString("toCache", sync).putInt("hour", hour).putInt("minute", minute).apply();
            finish();
        }
    });
    if (NetworkUtil.isConnectedNoOverride(this)) {
        findViewById(R.id.sync_now).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                new CommentCacheAsync(ManageOfflineContent.this, Reddit.cachedData.getString("toCache", "").split(",")).execute();
            }
        });
    } else {
        findViewById(R.id.sync_now).setVisibility(View.GONE);
    }
    {
        SwitchCompat single = (SwitchCompat) findViewById(R.id.wifi);
        single.setChecked(Reddit.cachedData.getBoolean("wifiOnly", false));
        single.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Reddit.cachedData.edit().putBoolean("wifiOnly", isChecked).apply();
            }
        });
    }
    updateBackup();
    updateFilters();
    final List<String> commentDepths = ImmutableList.of("2", "4", "6", "8", "10");
    final String[] commentDepthArray = new String[commentDepths.size()];
    findViewById(R.id.comments_depth).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String commentDepth = SettingValues.prefs.getString(SettingValues.COMMENT_DEPTH, "2");
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
            builder.setTitle(R.string.comments_depth);
            builder.setSingleChoiceItems(commentDepths.toArray(commentDepthArray), commentDepths.indexOf(commentDepth), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SettingValues.prefs.edit().putString(SettingValues.COMMENT_DEPTH, commentDepths.get(which)).apply();
                }
            });
            builder.show();
        }
    });
    final List<String> commentCounts = ImmutableList.of("20", "40", "60", "80", "100");
    final String[] commentCountArray = new String[commentCounts.size()];
    findViewById(R.id.comments_count).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String commentCount = SettingValues.prefs.getString(SettingValues.COMMENT_COUNT, "2");
            AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(ManageOfflineContent.this);
            builder.setTitle(R.string.comments_count);
            builder.setSingleChoiceItems(commentCounts.toArray(commentCountArray), commentCounts.indexOf(commentCount), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    SettingValues.prefs.edit().putString(SettingValues.COMMENT_COUNT, commentCounts.get(which)).apply();
                }
            });
            builder.show();
        }
    });
    findViewById(R.id.autocache).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> sorted = UserSubscriptions.sort(UserSubscriptions.getSubscriptions(ManageOfflineContent.this));
            final String[] all = new String[sorted.size()];
            boolean[] checked = new boolean[all.length];
            int i = 0;
            List<String> s2 = new ArrayList<>();
            Collections.addAll(s2, Reddit.cachedData.getString("toCache", "").split(","));
            for (String s : sorted) {
                all[i] = s;
                if (s2.contains(s)) {
                    checked[i] = true;
                }
                i++;
            }
            final ArrayList<String> toCheck = new ArrayList<>();
            toCheck.addAll(s2);
            new AlertDialogWrapper.Builder(ManageOfflineContent.this).alwaysCallMultiChoiceCallback().setMultiChoiceItems(all, checked, new DialogInterface.OnMultiChoiceClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    if (!isChecked) {
                        toCheck.remove(all[which]);
                    } else {
                        toCheck.add(all[which]);
                    }
                }
            }).setTitle(R.string.multireddit_selector).setPositiveButton(getString(R.string.btn_add).toUpperCase(), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Reddit.cachedData.edit().putString("toCache", Reddit.arrayToString(toCheck)).apply();
                    updateBackup();
                }
            }).show();
        }
    });
    updateTime();
    findViewById(R.id.autocache_time_touch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final TimePickerDialog d = new TimePickerDialog(ManageOfflineContent.this);
            d.hour(Reddit.cachedData.getInt("hour", 0));
            d.minute(Reddit.cachedData.getInt("minute", 0));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                d.applyStyle(new ColorPreferences(ManageOfflineContent.this).getFontStyle().getBaseId());
            d.positiveAction("SET");
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = getTheme();
            theme.resolveAttribute(R.attr.activity_background, typedValue, true);
            int color = typedValue.data;
            d.backgroundColor(color);
            d.actionTextColor(getResources().getColor(new ColorPreferences(ManageOfflineContent.this).getFontStyle().getColor()));
            d.positiveActionClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Reddit.cachedData.edit().putInt("hour", d.getHour()).putInt("minute", d.getMinute()).commit();
                    Reddit.autoCache = new AutoCacheScheduler(ManageOfflineContent.this);
                    Reddit.autoCache.start(getApplicationContext());
                    updateTime();
                    d.dismiss();
                }
            });
            theme.resolveAttribute(R.attr.fontColor, typedValue, true);
            int color2 = typedValue.data;
            d.setTitle(getString(R.string.choose_sync_time));
            d.titleColor(color2);
            d.show();
        }
    });
}
Also used : AutoCacheScheduler(me.ccrama.redditslide.Autocache.AutoCacheScheduler) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TypedValue(android.util.TypedValue) CommentCacheAsync(me.ccrama.redditslide.CommentCacheAsync) ColorPreferences(me.ccrama.redditslide.ColorPreferences) TimePickerDialog(com.rey.material.app.TimePickerDialog) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 2 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 3 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 4 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 5 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)8 DialogInterface (android.content.DialogInterface)6 TextView (android.widget.TextView)6 View (android.view.View)5 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)5 ArrayList (java.util.ArrayList)5 RecyclerView (android.support.v7.widget.RecyclerView)4 SwitchCompat (android.support.v7.widget.SwitchCompat)3 SubredditView (me.ccrama.redditslide.Activities.SubredditView)3 Dialog (android.app.Dialog)2 LayoutInflater (android.view.LayoutInflater)2 CompoundButton (android.widget.CompoundButton)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 Subreddit (net.dean.jraw.models.Subreddit)2 LineColorPicker (uz.shift.colorpicker.LineColorPicker)2 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1