Search in sources :

Example 36 with ColorPreferences

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

the class NewsActivity method setDataSet.

public void setDataSet(List<String> data) {
    if (data != null && !data.isEmpty()) {
        usedArray = new CaseInsensitiveArrayList(data);
        if (adapter == null) {
            adapter = new OverviewPagerAdapter(getSupportFragmentManager());
        } else {
            adapter.notifyDataSetChanged();
        }
        pager.setAdapter(adapter);
        pager.setOffscreenPageLimit(1);
        if (toGoto == -1) {
            toGoto = 0;
        }
        if (toGoto >= usedArray.size()) {
            toGoto -= 1;
        }
        shouldLoad = usedArray.get(toGoto);
        selectedSub = (usedArray.get(toGoto));
        themeSystemBars(usedArray.get(toGoto));
        final String USEDARRAY_0 = usedArray.get(0);
        mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(NewsActivity.this).getColor(USEDARRAY_0));
        pager.setCurrentItem(toGoto);
        mTabLayout.setupWithViewPager(pager);
        if (mTabLayout != null) {
            mTabLayout.setupWithViewPager(pager);
            scrollToTabAfterLayout(toGoto);
        }
        setToolbarClick();
    } else if (NetworkUtil.isConnected(this)) {
        UserSubscriptions.doNewsSubs(this);
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) CaseInsensitiveArrayList(me.ccrama.redditslide.CaseInsensitiveArrayList)

Example 37 with ColorPreferences

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

the class Profile method onCreate.

@Override
public void onCreate(Bundle savedInstance) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstance);
    name = getIntent().getExtras().getString(EXTRA_PROFILE, "");
    setShareUrl("https://reddit.com/u/" + name);
    applyColorTheme();
    setContentView(R.layout.activity_profile);
    setupUserAppBar(R.id.toolbar, name, true, name);
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    profSort = Sorting.HOT;
    profTime = TimePeriod.ALL;
    findViewById(R.id.header).setBackgroundColor(Palette.getColorUser(name));
    tabs = (TabLayout) findViewById(R.id.sliding_tabs);
    tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabs.setSelectedTabIndicatorColor(new ColorPreferences(Profile.this).getColor("no sub"));
    pager = (ViewPager) findViewById(R.id.content_view);
    if (name.equals(Authentication.name))
        setDataSet(new String[] { getString(R.string.profile_overview), getString(R.string.profile_comments), getString(R.string.profile_submitted), getString(R.string.profile_gilded), getString(R.string.profile_upvoted), getString(R.string.profile_downvoted), getString(R.string.profile_saved), getString(R.string.profile_hidden), getString(R.string.profile_history) });
    else
        setDataSet(new String[] { getString(R.string.profile_overview), getString(R.string.profile_comments), getString(R.string.profile_submitted), getString(R.string.profile_gilded) });
    new getProfile().execute(name);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 6) {
                isSavedView = true;
            } else {
                isSavedView = false;
            }
            findViewById(R.id.header).animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
            if (sortItem != null) {
                if (position < 3) {
                    sortItem.setVisible(true);
                } else {
                    sortItem.setVisible(false);
                }
            }
            if (categoryItem != null && Authentication.me != null && Authentication.me.hasGold()) {
                if (position == 6) {
                    categoryItem.setVisible(true);
                } else {
                    categoryItem.setVisible(false);
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    if (getIntent().hasExtra(EXTRA_SAVED) && name.equals(Authentication.name)) {
        pager.setCurrentItem(6);
    }
    if (getIntent().hasExtra(EXTRA_COMMENT) && name.equals(Authentication.name)) {
        pager.setCurrentItem(1);
    }
    if (getIntent().hasExtra(EXTRA_SUBMIT) && name.equals(Authentication.name)) {
        pager.setCurrentItem(2);
    }
    if (getIntent().hasExtra(EXTRA_HISTORY) && name.equals(Authentication.name)) {
        pager.setCurrentItem(8);
    }
    if (getIntent().hasExtra(EXTRA_UPVOTE) && name.equals(Authentication.name)) {
        pager.setCurrentItem(4);
    }
    if (pager.getCurrentItem() == 6) {
        isSavedView = true;
    } else {
        isSavedView = false;
    }
    if (pager.getCurrentItem() != 0) {
        scrollToTabAfterLayout(pager.getCurrentItem());
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) ViewPager(android.support.v4.view.ViewPager)

Example 38 with ColorPreferences

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

the class Search method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    overrideSwipeFromAnywhere();
    super.onCreate(savedInstanceState);
    applyColorTheme("");
    setContentView(R.layout.activity_search);
    where = getIntent().getExtras().getString(EXTRA_TERM, "");
    if (getIntent().hasExtra(EXTRA_MULTIREDDIT)) {
        multireddit = true;
        subreddit = getIntent().getExtras().getString(EXTRA_MULTIREDDIT);
    } else {
        if (getIntent().hasExtra(EXTRA_AUTHOR)) {
            where = where + "&author=" + getIntent().getExtras().getString(EXTRA_AUTHOR);
        }
        if (getIntent().hasExtra(EXTRA_NSFW)) {
            where = where + "&nsfw=" + (getIntent().getExtras().getBoolean(EXTRA_NSFW) ? "yes" : "no");
        }
        if (getIntent().hasExtra(EXTRA_SELF)) {
            where = where + "&selftext=" + (getIntent().getExtras().getBoolean(EXTRA_SELF) ? "yes" : "no");
        }
        if (getIntent().hasExtra(EXTRA_SITE)) {
            where = where + "&site=" + getIntent().getExtras().getString(EXTRA_SITE);
        }
        if (getIntent().hasExtra(EXTRA_URL)) {
            where = where + "&url=" + getIntent().getExtras().getString(EXTRA_URL);
        }
        subreddit = getIntent().getExtras().getString(EXTRA_SUBREDDIT, "");
    }
    where = StringEscapeUtils.unescapeHtml4(where);
    setupSubredditAppBar(R.id.toolbar, "Search", true, subreddit.toLowerCase(Locale.ENGLISH));
    time = TimePeriod.ALL;
    getSupportActionBar().setTitle(Html.fromHtml(where));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // it won't be, trust me
    assert mToolbar != null;
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Simulate a system's "Back" button functionality.
            onBackPressed();
        }
    });
    mToolbar.setPopupTheme(new ColorPreferences(this).getFontStyle().getBaseId());
    // When the .name() is returned for both of the ENUMs, it will be in all caps.
    // So, make it lowercase, then capitalize the first letter of each.
    getSupportActionBar().setSubtitle(StringUtils.capitalize(Reddit.search.name().toLowerCase(Locale.ENGLISH)) + " › " + StringUtils.capitalize(time.name().toLowerCase(Locale.ENGLISH)));
    rv = ((RecyclerView) findViewById(R.id.vertical_content));
    final RecyclerView.LayoutManager mLayoutManager;
    mLayoutManager = createLayoutManager(getNumColumns(getResources().getConfiguration().orientation, Search.this));
    rv.setLayoutManager(mLayoutManager);
    rv.addOnScrollListener(new ToolbarScrollHideHandler(mToolbar, findViewById(R.id.header)) {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            visibleItemCount = rv.getLayoutManager().getChildCount();
            totalItemCount = rv.getLayoutManager().getItemCount();
            if (rv.getLayoutManager() instanceof PreCachingLayoutManager) {
                pastVisiblesItems = ((PreCachingLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
            } else {
                int[] firstVisibleItems = null;
                firstVisibleItems = ((CatchStaggeredGridLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPositions(firstVisibleItems);
                if (firstVisibleItems != null && firstVisibleItems.length > 0) {
                    pastVisiblesItems = firstVisibleItems[0];
                }
            }
            if (!posts.loading && (visibleItemCount + pastVisiblesItems) + 5 >= totalItemCount && !posts.nomore) {
                posts.loading = true;
                posts.loadMore(adapter, subreddit, where, false, multireddit, time);
            }
        }
    });
    final SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.activity_main_swipe_refresh_layout);
    mSwipeRefreshLayout.setColorSchemeColors(Palette.getColors(subreddit, this));
    // If we use 'findViewById(R.id.header).getMeasuredHeight()', 0 is always returned.
    // So, we estimate the height of the header in dp.
    mSwipeRefreshLayout.setProgressViewOffset(false, Constants.SINGLE_HEADER_VIEW_OFFSET - Constants.PTR_OFFSET_TOP, Constants.SINGLE_HEADER_VIEW_OFFSET + Constants.PTR_OFFSET_BOTTOM);
    mSwipeRefreshLayout.post(new Runnable() {

        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
    posts = new SubredditSearchPosts(subreddit, where.toLowerCase(Locale.ENGLISH), this);
    adapter = new ContributionAdapter(this, posts, rv);
    rv.setAdapter(adapter);
    posts.bindAdapter(adapter, mSwipeRefreshLayout);
    // TODO catch errors
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            posts.loadMore(adapter, subreddit, where, true, multireddit, time);
        // TODO catch errors
        }
    });
}
Also used : CatchStaggeredGridLayoutManager(me.ccrama.redditslide.Views.CatchStaggeredGridLayoutManager) ColorPreferences(me.ccrama.redditslide.ColorPreferences) SubredditSearchPosts(me.ccrama.redditslide.Adapters.SubredditSearchPosts) PreCachingLayoutManager(me.ccrama.redditslide.Views.PreCachingLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ContributionAdapter(me.ccrama.redditslide.Adapters.ContributionAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ToolbarScrollHideHandler(me.ccrama.redditslide.handler.ToolbarScrollHideHandler)

Example 39 with ColorPreferences

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

the class SettingsSubAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    View convertView = holder.itemView;
    final TextView t = ((TextView) convertView.findViewById(R.id.name));
    t.setText(objects.get(position));
    final String subreddit = objects.get(position);
    convertView.findViewById(R.id.color).setBackgroundResource(R.drawable.circle);
    convertView.findViewById(R.id.color).getBackground().setColorFilter(Palette.getColor(subreddit), PorterDuff.Mode.MULTIPLY);
    final String DELETE_SUB_SETTINGS_TITLE = (subreddit.contains("/m/")) ? subreddit : ("/r/" + subreddit);
    convertView.findViewById(R.id.remove).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialogWrapper.Builder(context).setTitle(context.getString(R.string.settings_delete_sub_settings, DELETE_SUB_SETTINGS_TITLE)).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Palette.removeColor(subreddit);
                    // Remove layout settings
                    SettingValues.prefs.edit().remove(Reddit.PREF_LAYOUT + subreddit).apply();
                    // Remove accent / font color settings
                    new ColorPreferences(context).removeFontStyle(subreddit);
                    SettingValues.resetPicsEnabled(subreddit);
                    SettingValues.resetSelftextEnabled(subreddit);
                    dialog.dismiss();
                    objects.remove(subreddit);
                    notifyDataSetChanged();
                }
            }).setNegativeButton(R.string.btn_no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    dialog.dismiss();
                }
            }).show();
        }
    });
    convertView.findViewById(R.id.edit).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            prepareAndShowSubEditor(subreddit);
        }
    });
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) SubredditView(me.ccrama.redditslide.Activities.SubredditView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 40 with ColorPreferences

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

the class SettingsSubAdapter method showSubThemeEditor.

/**
 * Displays the subreddit color chooser
 * It is possible to color multiple subreddits at the same time
 *
 * @param subreddits   Subreddits as an array
 * @param context      Context for getting colors
 * @param dialoglayout The subchooser layout (R.layout.colorsub)
 */
public static void showSubThemeEditor(final ArrayList<String> subreddits, final Activity context, View dialoglayout) {
    if (subreddits.isEmpty()) {
        return;
    }
    final boolean multipleSubs = (subreddits.size() > 1);
    boolean isAlternateLayout;
    int currentColor;
    int currentAccentColor;
    final ColorPreferences colorPrefs = new ColorPreferences(context);
    final String subreddit = multipleSubs ? null : subreddits.get(0);
    final SwitchCompat bigPics = (SwitchCompat) dialoglayout.findViewById(R.id.bigpics);
    final SwitchCompat selftext = (SwitchCompat) dialoglayout.findViewById(R.id.selftext);
    // Selected multiple subreddits
    if (multipleSubs) {
        // Check if all selected subs have the same settings
        int previousSubColor = 0;
        int previousSubAccent = 0;
        bigPics.setChecked(SettingValues.bigPicEnabled);
        selftext.setChecked(SettingValues.cardText);
        boolean sameMainColor = true;
        boolean sameAccentColor = true;
        for (String sub : subreddits) {
            int currentSubColor = Palette.getColor(sub);
            int currentSubAccent = colorPrefs.getColor("");
            if (previousSubColor != 0 && previousSubAccent != 0) {
                if (currentSubColor != previousSubColor) {
                    sameMainColor = false;
                } else if (currentSubAccent != previousSubAccent) {
                    sameAccentColor = false;
                }
            }
            if (!sameMainColor && !sameAccentColor) {
                break;
            }
            previousSubAccent = currentSubAccent;
            previousSubColor = currentSubColor;
        }
        currentColor = Palette.getDefaultColor();
        currentAccentColor = colorPrefs.getColor("");
        isAlternateLayout = false;
        // If all selected subs have the same settings, display them
        if (sameMainColor) {
            currentColor = previousSubColor;
        }
        if (sameAccentColor) {
            currentAccentColor = previousSubAccent;
        }
    } else {
        // Is only one selected sub
        currentColor = Palette.getColor(subreddit);
        isAlternateLayout = SettingValues.prefs.contains(Reddit.PREF_LAYOUT + subreddit);
        currentAccentColor = colorPrefs.getColor(subreddit);
        bigPics.setChecked(SettingValues.isPicsEnabled(subreddit));
        selftext.setChecked(SettingValues.isSelftextEnabled(subreddit));
    }
    AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context);
    final TextView title = (TextView) dialoglayout.findViewById(R.id.title);
    title.setBackgroundColor(currentColor);
    if (multipleSubs) {
        String titleString = "";
        for (String sub : subreddits) {
            // if the subreddit is the frontpage, don't put "/r/" in front of it
            if (sub.equals("frontpage")) {
                titleString += sub + ", ";
            } else {
                if (sub.contains("/m/")) {
                    titleString += sub + ", ";
                } else {
                    titleString += "/r/" + sub + ", ";
                }
            }
        }
        titleString = titleString.substring(0, titleString.length() - 2);
        title.setMaxLines(3);
        title.setText(titleString);
    } else {
        if (subreddit.contains("/m/")) {
            title.setText(subreddit);
        } else {
            // if the subreddit is the frontpage, don't put "/r/" in front of it
            title.setText(((subreddit.equals("frontpage")) ? "frontpage" : "/r/" + subreddit));
        }
    }
    {
        // Primary color pickers
        final LineColorPicker colorPickerPrimary = (LineColorPicker) dialoglayout.findViewById(R.id.picker);
        // shades of primary colors
        final LineColorPicker colorPickerPrimaryShades = (LineColorPicker) dialoglayout.findViewById(R.id.picker2);
        colorPickerPrimary.setColors(ColorPreferences.getBaseColors(context));
        // Iterate through all colors and check if it matches the current color of the sub, then select it
        for (int i : colorPickerPrimary.getColors()) {
            for (int i2 : ColorPreferences.getColors(context, i)) {
                if (i2 == currentColor) {
                    colorPickerPrimary.setSelectedColor(i);
                    colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, i));
                    colorPickerPrimaryShades.setSelectedColor(i2);
                    break;
                }
            }
        }
        // Base color changed
        colorPickerPrimary.setOnColorChangedListener(new OnColorChangedListener() {

            @Override
            public void onColorChanged(int c) {
                // Show variations of the base color
                colorPickerPrimaryShades.setColors(ColorPreferences.getColors(context, c));
                colorPickerPrimaryShades.setSelectedColor(c);
            }
        });
        colorPickerPrimaryShades.setOnColorChangedListener(new OnColorChangedListener() {

            @Override
            public void onColorChanged(int i) {
                if (context instanceof MainActivity) {
                    ((MainActivity) context).updateColor(colorPickerPrimaryShades.getColor(), subreddit);
                }
                title.setBackgroundColor(colorPickerPrimaryShades.getColor());
            }
        });
        {
        /* TODO   TextView dialogButton = (TextView) dialoglayout.findViewById(R.id.reset);

                            // if button is clicked, close the custom dialog
                            dialogButton.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Palette.removeColor(subreddit);
                                    hea.setBackgroundColor(Palette.getDefaultColor());
                                    findViewById(R.id.header).setBackgroundColor(Palette.getDefaultColor());
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                        Window window = getWindow();
                                        window.setStatusBarColor(Palette.getDarkerColor(Palette.getDefaultColor()));
                                        context.setTaskDescription(new ActivityManager.TaskDescription(subreddit, ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_launcher)).getBitmap(), colorPicker2.getColor()));

                                    }
                                    title.setBackgroundColor(Palette.getDefaultColor());


                                    int cx = center.getWidth() / 2;
                                    int cy = center.getHeight() / 2;

                                    int initialRadius = body.getWidth();
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                                        Animator anim =
                                                ViewAnimationUtils.createCircularReveal(body, cx, cy, initialRadius, 0);

                                        anim.addListener(new AnimatorListenerAdapter() {
                                            @Override
                                            public void onAnimationEnd(Animator animation) {
                                                super.onAnimationEnd(animation);
                                                body.setVisibility(View.GONE);
                                            }
                                        });
                                        anim.start();

                                    } else {
                                        body.setVisibility(View.GONE);

                                    }

                                }
                            });*/
        }
        // Accent color picker
        final LineColorPicker colorPickerAcc = (LineColorPicker) dialoglayout.findViewById(R.id.picker3);
        {
            // Get all possible accent colors (for day theme)
            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(context, type.getColor());
                    i++;
                }
                colorPickerAcc.setColors(arrs);
                colorPickerAcc.setSelectedColor(currentAccentColor);
            }
        }
        builder.setView(dialoglayout);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (context instanceof MainActivity) {
                    ((MainActivity) context).updateColor(Palette.getColor(subreddit), subreddit);
                }
            }
        }).setNeutralButton(R.string.btn_reset, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                String subTitles = "";
                if (multipleSubs) {
                    for (String sub : subreddits) {
                        // if the subreddit is the frontpage, don't put "/r/" in front of it
                        if (sub.equals("frontpage")) {
                            subTitles += sub + ", ";
                        } else {
                            subTitles += "/r/" + sub + ", ";
                        }
                    }
                    subTitles = subTitles.substring(0, subTitles.length() - 2);
                } else {
                    // if the subreddit is the frontpage, don't put "/r/" in front of it
                    subTitles = (subreddit.equals("frontpage") ? "frontpage" : "/r/" + subreddit);
                }
                String titleStart = context.getString(R.string.settings_delete_sub_settings, subTitles);
                titleStart = titleStart.replace("/r//r/", "/r/");
                if (titleStart.contains("/r/frontpage")) {
                    titleStart = titleStart.replace("/r/frontpage", "frontpage");
                }
                new AlertDialogWrapper.Builder(context).setTitle(titleStart).setPositiveButton(R.string.btn_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        for (String sub : subreddits) {
                            Palette.removeColor(sub);
                            // Remove layout settings
                            SettingValues.prefs.edit().remove(Reddit.PREF_LAYOUT + sub).apply();
                            // Remove accent / font color settings
                            new ColorPreferences(context).removeFontStyle(sub);
                            SettingValues.resetPicsEnabled(sub);
                            SettingValues.resetSelftextEnabled(sub);
                        }
                        if (context instanceof MainActivity) {
                            ((MainActivity) context).reloadSubs();
                        } else if (context instanceof SettingsSubreddit) {
                            ((SettingsSubreddit) context).reloadSubList();
                        } else if (context instanceof SubredditView) {
                            ((SubredditView) context).restartTheme();
                        }
                    }
                }).setNegativeButton(R.string.btn_no, null).show();
            }
        }).setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                final int newPrimaryColor = colorPickerPrimaryShades.getColor();
                final int newAccentColor = colorPickerAcc.getColor();
                for (String sub : subreddits) {
                    // Set main color
                    if (bigPics.isChecked() != SettingValues.isPicsEnabled(sub)) {
                        SettingValues.setPicsEnabled(sub, bigPics.isChecked());
                    }
                    if (selftext.isChecked() != SettingValues.isSelftextEnabled(sub)) {
                        SettingValues.setSelftextEnabled(sub, selftext.isChecked());
                    }
                    // Only do set colors if either subreddit theme color has changed
                    if (Palette.getColor(sub) != newPrimaryColor || Palette.getDarkerColor(sub) != newAccentColor) {
                        if (newPrimaryColor != Palette.getDefaultColor()) {
                            Palette.setColor(sub, newPrimaryColor);
                        } else {
                            Palette.removeColor(sub);
                        }
                        // Set accent color
                        ColorPreferences.Theme t = null;
                        // Do not save accent color if it matches the default accent color
                        if (newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyle().getColor()) || newAccentColor != ContextCompat.getColor(context, colorPrefs.getFontStyleSubreddit(sub).getColor())) {
                            LogUtil.v("Accent colors not equal");
                            int back = new ColorPreferences(context).getFontStyle().getThemeType();
                            for (ColorPreferences.Theme type : ColorPreferences.Theme.values()) {
                                if (ContextCompat.getColor(context, type.getColor()) == newAccentColor && back == type.getThemeType()) {
                                    t = type;
                                    LogUtil.v("Setting accent color to " + t.getTitle());
                                    break;
                                }
                            }
                        } else {
                            new ColorPreferences(context).removeFontStyle(sub);
                        }
                        if (t != null) {
                            colorPrefs.setFontStyle(t, sub);
                        }
                    }
                    // Set layout
                    SettingValues.prefs.edit().putBoolean(Reddit.PREF_LAYOUT + sub, true).apply();
                }
                // Only refresh stuff if the user changed something
                if (Palette.getColor(subreddit) != newPrimaryColor || Palette.getDarkerColor(subreddit) != newAccentColor) {
                    if (context instanceof MainActivity) {
                        ((MainActivity) context).reloadSubs();
                    } else if (context instanceof SettingsSubreddit) {
                        ((SettingsSubreddit) context).reloadSubList();
                    } else if (context instanceof SubredditView) {
                        ((SubredditView) context).restartTheme();
                    }
                }
            }
        }).show();
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.ColorPreferences) DialogInterface(android.content.DialogInterface) SubredditView(me.ccrama.redditslide.Activities.SubredditView) MainActivity(me.ccrama.redditslide.Activities.MainActivity) LineColorPicker(uz.shift.colorpicker.LineColorPicker) AlertDialogWrapper(com.afollestad.materialdialogs.AlertDialogWrapper) OnColorChangedListener(uz.shift.colorpicker.OnColorChangedListener) SettingsSubreddit(me.ccrama.redditslide.Activities.SettingsSubreddit) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

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