Search in sources :

Example 6 with OnSingleClickListener

use of me.ccrama.redditslide.util.OnSingleClickListener 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 7 with OnSingleClickListener

use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.

the class SubmissionAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder2, final int pos) {
    int i = pos != 0 ? pos - 1 : pos;
    if (holder2 instanceof SubmissionViewHolder) {
        final SubmissionViewHolder holder = (SubmissionViewHolder) holder2;
        final Submission submission = dataSet.posts.get(i);
        CreateCardView.colorCard(submission.getSubredditName().toLowerCase(Locale.ENGLISH), holder.itemView, subreddit, (subreddit.equals("frontpage") || subreddit.equals("mod") || subreddit.equals("friends") || (subreddit.equals("all")) || subreddit.contains(".") || subreddit.contains("+")));
        holder.itemView.setOnClickListener(new OnSingleClickListener() {

            @Override
            public void onSingleClick(View v) {
                if (Authentication.didOnline || submission.getComments() != null) {
                    holder.title.setAlpha(0.54f);
                    holder.body.setAlpha(0.54f);
                    if (context instanceof MainActivity) {
                        final MainActivity a = (MainActivity) context;
                        if (a.singleMode && a.commentPager && a.adapter instanceof MainActivity.OverviewPagerAdapterComment) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getAdapterPosition();
                                a.openingComments = submission;
                                a.toOpenComments = a.pager.getCurrentItem() + 1;
                                a.currentComment = holder.getAdapterPosition() - 1;
                                ((MainActivity.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((MainActivity.OverviewPagerAdapterComment) (a).adapter).size = a.toOpenComments + 1;
                                try {
                                    a.adapter.notifyDataSetChanged();
                                } catch (Exception ignored) {
                                }
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getAdapterPosition();
                        }
                    } else if (context instanceof SubredditView) {
                        final SubredditView a = (SubredditView) context;
                        if (a.singleMode && a.commentPager) {
                            if (a.openingComments != submission) {
                                clicked = holder2.getAdapterPosition();
                                a.openingComments = submission;
                                a.currentComment = holder.getAdapterPosition() - 1;
                                ((SubredditView.OverviewPagerAdapterComment) (a).adapter).storedFragment = (a).adapter.getCurrentFragment();
                                ((SubredditView.OverviewPagerAdapterComment) a.adapter).size = 3;
                                a.adapter.notifyDataSetChanged();
                            }
                            a.pager.postDelayed(new Runnable() {

                                @Override
                                public void run() {
                                    a.pager.setCurrentItem(a.pager.getCurrentItem() + 1, true);
                                }
                            }, 400);
                        } else {
                            Intent i2 = new Intent(context, CommentsScreen.class);
                            i2.putExtra(CommentsScreen.EXTRA_PAGE, holder2.getAdapterPosition() - 1);
                            i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, subreddit);
                            i2.putExtra("fullname", submission.getFullName());
                            context.startActivityForResult(i2, 940);
                            clicked = holder2.getAdapterPosition();
                        }
                    }
                } else {
                    if (!Reddit.appRestart.contains("offlinepopup")) {
                        new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Reddit.appRestart.edit().putString("offlinepopup", "").apply();
                            }
                        }).show();
                    } else {
                        Snackbar s = Snackbar.make(holder.itemView, R.string.cache_no_comments_found_snackbar, Snackbar.LENGTH_SHORT);
                        s.setAction(R.string.misc_more_info, new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                new AlertDialogWrapper.Builder(context).setTitle(R.string.cache_no_comments_found).setMessage(R.string.cache_no_comments_found_message).setCancelable(false).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Reddit.appRestart.edit().putString("offlinepopup", "").apply();
                                    }
                                }).show();
                            }
                        });
                        View view = s.getView();
                        TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                        tv.setTextColor(Color.WHITE);
                        s.show();
                    }
                }
            }
        });
        new PopulateSubmissionViewHolder().populateSubmissionViewHolder(holder, submission, context, false, false, dataSet.posts, listView, custom, dataSet.offline, dataSet.subreddit.toLowerCase(Locale.ENGLISH), null);
    }
    if (holder2 instanceof SubmissionFooterViewHolder) {
        Handler handler = new Handler();
        final Runnable r = new Runnable() {

            public void run() {
                notifyItemChanged(dataSet.posts.size() + // the loading spinner to replaced by nomoreposts.xml
                1);
            }
        };
        handler.post(r);
        if (holder2.itemView.findViewById(R.id.reload) != null) {
            holder2.itemView.findViewById(R.id.reload).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ((SubmissionsView) displayer).forceRefresh();
                }
            });
        }
    }
    if (holder2 instanceof SpacerViewHolder) {
        View header = (context).findViewById(R.id.header);
        int height = header.getHeight();
        if (height == 0) {
            header.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            height = header.getMeasuredHeight();
            holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
            if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
                CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
                layoutParams.setFullSpan(true);
                holder2.itemView.setLayoutParams(layoutParams);
            }
        } else {
            holder2.itemView.findViewById(R.id.height).setLayoutParams(new LinearLayout.LayoutParams(holder2.itemView.getWidth(), height));
            if (listView.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
                CatchStaggeredGridLayoutManager.LayoutParams layoutParams = new CatchStaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
                layoutParams.setFullSpan(true);
                holder2.itemView.setLayoutParams(layoutParams);
            }
        }
    }
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) DialogInterface(android.content.DialogInterface) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) TextView(android.widget.TextView) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) CommentsScreen(me.ccrama.redditslide.Activities.CommentsScreen) Submission(net.dean.jraw.models.Submission) PopulateSubmissionViewHolder(me.ccrama.redditslide.SubmissionViews.PopulateSubmissionViewHolder) Handler(android.os.Handler) Intent(android.content.Intent) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) LinearLayout(android.widget.LinearLayout) Snackbar(android.support.design.widget.Snackbar)

Example 8 with OnSingleClickListener

use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.

the class PopulateNewsViewHolder method addClickFunctions.

private static void addClickFunctions(final View base, final ContentType.Type type, final Activity contextActivity, final Submission submission, final NewsViewHolder holder, final boolean full) {
    base.setOnClickListener(new OnSingleClickListener() {

        @Override
        public void onSingleClick(View v) {
            if (NetworkUtil.isConnected(contextActivity) || (!NetworkUtil.isConnected(contextActivity) && ContentType.fullImage(type))) {
                if (SettingValues.storeHistory && !full) {
                    if (!submission.isNsfw() || SettingValues.storeNSFWHistory) {
                        HasSeen.addSeen(submission.getFullName());
                        if (contextActivity instanceof MainActivity || contextActivity instanceof MultiredditOverview || contextActivity instanceof SubredditView || contextActivity instanceof Search || contextActivity instanceof Profile) {
                            holder.title.setAlpha(0.54f);
                        }
                    }
                }
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking() || (base instanceof HeaderImageLinkView && ((HeaderImageLinkView) base).popped)) {
                    if (!PostMatch.openExternal(submission.getUrl()) || type == ContentType.Type.VIDEO) {
                        switch(type) {
                            case VID_ME:
                            case STREAMABLE:
                                if (SettingValues.video) {
                                    Intent myIntent = new Intent(contextActivity, MediaView.class);
                                    myIntent.putExtra(MediaView.SUBREDDIT, submission.getSubredditName());
                                    myIntent.putExtra(MediaView.EXTRA_URL, submission.getUrl());
                                    contextActivity.startActivity(myIntent);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case IMGUR:
                                openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
                                break;
                            case EMBEDDED:
                                if (SettingValues.video) {
                                    String data = Html.fromHtml(submission.getDataNode().get("media_embed").get("content").asText()).toString();
                                    {
                                        Intent i = new Intent(contextActivity, FullscreenVideo.class);
                                        i.putExtra(FullscreenVideo.EXTRA_HTML, data);
                                        contextActivity.startActivity(i);
                                    }
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case REDDIT:
                                openRedditContent(submission.getUrl(), contextActivity);
                                break;
                            case LINK:
                                LinkUtil.openUrl(submission.getUrl(), Palette.getColor(submission.getSubredditName()), contextActivity, holder.getAdapterPosition(), submission);
                                break;
                            case SELF:
                                if (holder != null) {
                                    OnSingleClickListener.override = true;
                                    holder.itemView.performClick();
                                }
                                break;
                            case ALBUM:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, AlbumPager.class);
                                        i.putExtra(AlbumPager.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    } else {
                                        i = new Intent(contextActivity, Album.class);
                                        i.putExtra(Album.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    }
                                    addAdaptorPosition(i, submission, holder.getAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case TUMBLR:
                                if (SettingValues.album) {
                                    Intent i;
                                    if (SettingValues.albumSwipe) {
                                        i = new Intent(contextActivity, TumblrPager.class);
                                        i.putExtra(TumblrPager.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    } else {
                                        i = new Intent(contextActivity, Tumblr.class);
                                        i.putExtra(Tumblr.SUBREDDIT, submission.getSubredditName());
                                        i.putExtra(Album.EXTRA_URL, submission.getUrl());
                                    }
                                    addAdaptorPosition(i, submission, holder.getAdapterPosition());
                                    contextActivity.startActivity(i);
                                    contextActivity.overridePendingTransition(R.anim.slideright, R.anim.fade_out);
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                            case DEVIANTART:
                            case XKCD:
                            case IMAGE:
                                openImage(type, contextActivity, submission, holder.leadImage, holder.getAdapterPosition());
                                break;
                            case GIF:
                                openGif(contextActivity, submission, holder.getAdapterPosition());
                                break;
                            case NONE:
                                if (holder != null) {
                                    holder.itemView.performClick();
                                }
                                break;
                            case VIDEO:
                                if (Reddit.videoPlugin) {
                                    try {
                                        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                        sharingIntent.setClassName("ccrama.me.slideyoutubeplugin", "ccrama.me.slideyoutubeplugin.YouTubeView");
                                        sharingIntent.putExtra("url", submission.getUrl());
                                        contextActivity.startActivity(sharingIntent);
                                    } catch (Exception e) {
                                        LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                    }
                                } else {
                                    LinkUtil.openExternally(submission.getUrl(), contextActivity);
                                }
                                break;
                        }
                    } else {
                        LinkUtil.openExternally(submission.getUrl(), contextActivity);
                    }
                }
            } else {
                if (!(contextActivity instanceof PeekViewActivity) || !((PeekViewActivity) contextActivity).isPeeking()) {
                    Snackbar s = Snackbar.make(holder.itemView, R.string.go_online_view_content, Snackbar.LENGTH_SHORT);
                    View view = s.getView();
                    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
                    tv.setTextColor(Color.WHITE);
                    s.show();
                }
            }
        }
    });
}
Also used : MultiredditOverview(me.ccrama.redditslide.Activities.MultiredditOverview) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) SubredditView(me.ccrama.redditslide.Activities.SubredditView) Intent(android.content.Intent) MainActivity(me.ccrama.redditslide.Activities.MainActivity) MediaView(me.ccrama.redditslide.Activities.MediaView) ImageView(android.widget.ImageView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) View(android.view.View) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) RecyclerView(android.support.v7.widget.RecyclerView) CreateCardView(me.ccrama.redditslide.Views.CreateCardView) Profile(me.ccrama.redditslide.Activities.Profile) MediaView(me.ccrama.redditslide.Activities.MediaView) ApiException(net.dean.jraw.ApiException) Search(me.ccrama.redditslide.Activities.Search) TextView(android.widget.TextView) PeekViewActivity(me.ccrama.redditslide.ForceTouch.PeekViewActivity) Snackbar(android.support.design.widget.Snackbar)

Example 9 with OnSingleClickListener

use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.

the class MainActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    inNightMode = SettingValues.isNight();
    disableSwipeBackLayout();
    super.onCreate(savedInstanceState);
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
        // Activity was brought to front and not created
        finish();
        return;
    }
    if (!Slide.hasStarted) {
        Slide.hasStarted = true;
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
        }
    }
    boolean first = false;
    if (Reddit.colors != null && !Reddit.colors.contains("firstStart53")) {
        new AlertDialogWrapper.Builder(this).setTitle("Content settings have moved!").setMessage("NSFW content is now disabled by default. If you are over the age of 18, to re-enable NSFW content, visit Settings > Content settings").setPositiveButton(R.string.btn_ok, null).setCancelable(false).show();
        Reddit.colors.edit().putBoolean("firstStart53", true).apply();
    }
    if (Reddit.colors != null && !Reddit.colors.contains("Tutorial")) {
        first = true;
        if (Reddit.appRestart == null) {
            Reddit.appRestart = getSharedPreferences("appRestart", 0);
        }
        Reddit.appRestart.edit().putBoolean("firststart52", true).apply();
        Intent i = new Intent(this, Tutorial.class);
        doForcePrefs();
        startActivity(i);
    } else {
        if (Authentication.didOnline && NetworkUtil.isConnected(MainActivity.this) && !checkedPopups) {
            runAfterLoad = new Runnable() {

                @Override
                public void run() {
                    runAfterLoad = null;
                    if (Authentication.isLoggedIn) {
                        new AsyncNotificationBadge().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    if (!Reddit.appRestart.getString(CheckForMail.SUBS_TO_GET, "").isEmpty()) {
                        new CheckForMail.AsyncGetSubs(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    }
                    new AsyncTask<Void, Void, Submission>() {

                        @Override
                        protected Submission doInBackground(Void... params) {
                            if (Authentication.isLoggedIn)
                                UserSubscriptions.doOnlineSyncing();
                            try {
                                SubredditPaginator p = new SubredditPaginator(Authentication.reddit, "slideforreddit");
                                p.setLimit(2);
                                ArrayList<Submission> posts = new ArrayList<>(p.next());
                                for (Submission s : posts) {
                                    String version = BuildConfig.VERSION_NAME;
                                    if (version.length() > 5) {
                                        version = version.substring(0, version.lastIndexOf("."));
                                    }
                                    if (s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Announcement") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(version)) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    } else if (BuildConfig.VERSION_NAME.contains("alpha") && s.isStickied() && s.getSubmissionFlair().getText() != null && s.getSubmissionFlair().getText().equalsIgnoreCase("Alpha") && !Reddit.appRestart.contains("announcement" + s.getFullName()) && s.getTitle().contains(BuildConfig.VERSION_NAME)) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    } else if (s.isStickied() && s.getSubmissionFlair().getText().equalsIgnoreCase("PRO") && !SettingValues.tabletUI && !Reddit.appRestart.contains("announcement" + s.getFullName())) {
                                        Reddit.appRestart.edit().putBoolean("announcement" + s.getFullName(), true).apply();
                                        return s;
                                    }
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            return null;
                        }

                        @Override
                        protected void onPostExecute(final Submission s) {
                            checkedPopups = true;
                            if (s != null) {
                                Reddit.appRestart.edit().putString("page", s.getDataNode().get("selftext_html").asText()).apply();
                                Reddit.appRestart.edit().putString("title", s.getTitle()).apply();
                                Reddit.appRestart.edit().putString("url", s.getUrl()).apply();
                                String title;
                                if (s.getTitle().toLowerCase(Locale.ENGLISH).contains("release")) {
                                    title = getString(R.string.btn_changelog);
                                } else {
                                    title = getString(R.string.btn_view);
                                }
                                Snackbar snack = Snackbar.make(pager, s.getTitle(), Snackbar.LENGTH_INDEFINITE).setAction(title, new OnSingleClickListener() {

                                    @Override
                                    public void onSingleClick(View v) {
                                        Intent i = new Intent(MainActivity.this, Announcement.class);
                                        startActivity(i);
                                    }
                                });
                                View view = snack.getView();
                                TextView tv = view.findViewById(android.support.design.R.id.snackbar_text);
                                tv.setTextColor(Color.WHITE);
                                snack.show();
                            }
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                // todo this  new AsyncStartNotifSocket().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            };
        }
    }
    if (savedInstanceState != null && !changed) {
        Authentication.isLoggedIn = savedInstanceState.getBoolean(LOGGED_IN);
        Authentication.name = savedInstanceState.getString(USERNAME, "LOGGEDOUT");
        Authentication.didOnline = savedInstanceState.getBoolean(IS_ONLINE);
    } else {
        changed = false;
    }
    if (getIntent().getBooleanExtra("EXIT", false))
        finish();
    applyColorTheme();
    setContentView(R.layout.activity_overview);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    setSupportActionBar(mToolbar);
    if (getIntent() != null && getIntent().hasExtra(EXTRA_PAGE_TO)) {
        toGoto = getIntent().getIntExtra(EXTRA_PAGE_TO, 0);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = this.getWindow();
        window.setStatusBarColor(Palette.getDarkerColor(Palette.getDarkerColor(Palette.getDefaultColor())));
    }
    mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    header = findViewById(R.id.header);
    // Gets the height of the header
    if (header != null) {
        header.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                headerHeight = header.getHeight();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    header.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                } else {
                    header.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                }
            }
        });
    }
    pager = (ToggleSwipeViewPager) findViewById(R.id.content_view);
    singleMode = SettingValues.single;
    if (singleMode) {
        commentPager = SettingValues.commentPager;
    }
    // Inflate tabs if single mode is disabled
    if (!singleMode) {
        mTabLayout = (TabLayout) ((ViewStub) findViewById(R.id.stub_tabs)).inflate();
    }
    // Disable swiping if single mode is enabled
    if (singleMode) {
        pager.setSwipingEnabled(false);
    }
    sidebarBody = (SpoilerRobotoTextView) findViewById(R.id.sidebar_text);
    sidebarOverflow = (CommentOverflow) findViewById(R.id.commentOverflow);
    if (!Reddit.appRestart.getBoolean("isRestarting", false) && Reddit.colors.contains("Tutorial")) {
        LogUtil.v("Starting main " + Authentication.name);
        Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
        Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
        UserSubscriptions.doMainActivitySubs(this);
    } else if (!first) {
        LogUtil.v("Starting main 2 " + Authentication.name);
        Authentication.isLoggedIn = Reddit.appRestart.getBoolean("loggedin", false);
        Authentication.name = Reddit.appRestart.getString("name", "LOGGEDOUT");
        Reddit.appRestart.edit().putBoolean("isRestarting", false).commit();
        Reddit.isRestarting = false;
        UserSubscriptions.doMainActivitySubs(this);
    }
    final SharedPreferences seen = getSharedPreferences("SEEN", 0);
    if (!seen.contains("isCleared") && !seen.getAll().isEmpty() || !Reddit.appRestart.contains("hasCleared")) {
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                KVManger m = KVStore.getInstance();
                Map<String, ?> values = seen.getAll();
                for (Map.Entry<String, ?> entry : values.entrySet()) {
                    if (entry.getKey().length() == 6 && entry.getValue() instanceof Boolean) {
                        m.insert(entry.getKey(), "true");
                    } else if (entry.getValue() instanceof Long) {
                        m.insert(entry.getKey(), String.valueOf(seen.getLong(entry.getKey(), 0)));
                    }
                }
                seen.edit().clear().putBoolean("isCleared", true).apply();
                if (getSharedPreferences("HIDDEN_POSTS", 0).getAll().size() != 0) {
                    getSharedPreferences("HIDDEN", 0).edit().clear().apply();
                    getSharedPreferences("HIDDEN_POSTS", 0).edit().clear().apply();
                }
                if (!Reddit.appRestart.contains("hasCleared")) {
                    SharedPreferences.Editor e = Reddit.appRestart.edit();
                    Map<String, ?> toClear = Reddit.appRestart.getAll();
                    for (Map.Entry<String, ?> entry : toClear.entrySet()) {
                        if (entry.getValue() instanceof String && ((String) entry.getValue()).length() > 300) {
                            e.remove(entry.getKey());
                        }
                    }
                    e.putBoolean("hasCleared", true);
                    e.apply();
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                dismissProgressDialog();
            }

            @Override
            protected void onPreExecute() {
                d = new MaterialDialog.Builder(MainActivity.this).title(R.string.misc_setting_up).content(R.string.misc_setting_up_message).progress(true, 100).cancelable(false).build();
                d.show();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
    if (!FDroid.isFDroid && Authentication.isLoggedIn && NetworkUtil.isConnected(MainActivity.this)) {
        // Display an snackbar that asks the user to rate the app after this
        // activity was created 6 times, never again when once clicked or with a maximum of
        // two times.
        SnackEngage.from(MainActivity.this).withSnack(new RateSnack().withConditions(new NeverAgainWhenClickedOnce(), new AfterNumberOfOpportunities(10), new WithLimitedNumberOfTimes(2)).overrideActionText(getString(R.string.misc_rate_msg)).overrideTitleText(getString(R.string.misc_rate_title)).withDuration(BaseSnack.DURATION_LONG)).build().engageWhenAppropriate();
    }
    if (SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_TOOLBAR || SettingValues.subredditSearchMethod == Constants.SUBREDDIT_SEARCH_METHOD_BOTH) {
        setupSubredditSearchToolbar();
    }
    /**
     * int for the current base theme selected.
     * 0 = Dark, 1 = Light, 2 = AMOLED, 3 = Dark blue, 4 = AMOLED with contrast, 5 = Sepia
     */
    SettingValues.currentTheme = new ColorPreferences(this).getFontStyle().getThemeType();
    networkStateReceiver = new NetworkStateReceiver();
    networkStateReceiver.addListener(this);
    try {
        this.registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
    } catch (Exception e) {
    }
}
Also used : RateSnack(org.ligi.snackengage.snacks.RateSnack) NeverAgainWhenClickedOnce(org.ligi.snackengage.conditions.NeverAgainWhenClickedOnce) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) ArrayList(java.util.ArrayList) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList) AfterNumberOfOpportunities(org.ligi.snackengage.conditions.AfterNumberOfOpportunities) SubredditPaginator(net.dean.jraw.paginators.SubredditPaginator) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) WithLimitedNumberOfTimes(org.ligi.snackengage.conditions.WithLimitedNumberOfTimes) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) ViewTreeObserver(android.view.ViewTreeObserver) Window(android.view.Window) IntentFilter(android.content.IntentFilter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Submission(net.dean.jraw.models.Submission) ColorPreferences(me.ccrama.redditslide.ColorPreferences) SharedPreferences(android.content.SharedPreferences) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) ApiException(net.dean.jraw.ApiException) ActivityNotFoundException(android.content.ActivityNotFoundException) NetworkException(net.dean.jraw.http.NetworkException) ViewStub(android.view.ViewStub) KVManger(com.lusfold.androidkeyvaluestore.core.KVManger) Map(java.util.Map) HashMap(java.util.HashMap) NetworkStateReceiver(me.ccrama.redditslide.util.NetworkStateReceiver) Snackbar(android.support.design.widget.Snackbar)

Example 10 with OnSingleClickListener

use of me.ccrama.redditslide.util.OnSingleClickListener in project Slide by ccrama.

the class MainActivity method doFriends.

public void doFriends(final List<String> friends) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (friends != null && !friends.isEmpty() && headerMain.findViewById(R.id.friends) != null) {
                headerMain.findViewById(R.id.friends).setVisibility(View.VISIBLE);
                headerMain.findViewById(R.id.friends).setOnClickListener(new OnSingleClickListener() {

                    @Override
                    public void onSingleClick(View view) {
                        new MaterialDialog.Builder(MainActivity.this).title("Friends").items(friends).itemsCallback(new MaterialDialog.ListCallback() {

                            @Override
                            public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                                Intent i = new Intent(MainActivity.this, Profile.class);
                                i.putExtra(Profile.EXTRA_PROFILE, friends.get(which));
                                startActivity(i);
                                dialog.dismiss();
                            }
                        }).show();
                    }
                });
            } else if (Authentication.isLoggedIn && headerMain.findViewById(R.id.friends) != null) {
                headerMain.findViewById(R.id.friends).setVisibility(View.GONE);
            }
        }
    });
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnSingleClickListener(me.ccrama.redditslide.util.OnSingleClickListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Aggregations

View (android.view.View)18 OnSingleClickListener (me.ccrama.redditslide.util.OnSingleClickListener)18 TextView (android.widget.TextView)17 Intent (android.content.Intent)14 AlertDialogWrapper (com.afollestad.materialdialogs.AlertDialogWrapper)13 DialogInterface (android.content.DialogInterface)12 ImageView (android.widget.ImageView)12 RecyclerView (android.support.v7.widget.RecyclerView)10 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)10 Snackbar (android.support.design.widget.Snackbar)9 LayoutInflater (android.view.LayoutInflater)9 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)9 ApiException (net.dean.jraw.ApiException)9 ArrayList (java.util.ArrayList)8 LinearLayout (android.widget.LinearLayout)7 SubredditView (me.ccrama.redditslide.Activities.SubredditView)7 Dialog (android.app.Dialog)6 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 CreateCardView (me.ccrama.redditslide.Views.CreateCardView)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5