Search in sources :

Example 21 with ColorPreferences

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

the class BaseActivity method applyColorTheme.

/**
 * Applies the activity's base color theme based on the theme of a specific subreddit. Should be
 * called before inflating any layouts.
 *
 * @param subreddit The subreddit to base the theme on
 */
protected void applyColorTheme(String subreddit) {
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getThemeSubreddit(subreddit), true);
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences)

Example 22 with ColorPreferences

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

the class MainActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final String subreddit = usedArray.get(Reddit.currentPosition);
    switch(item.getItemId()) {
        case R.id.filter:
            filterContent(shouldLoad);
            return true;
        case R.id.sidebar:
            if (!subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.contains(".") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
                drawerLayout.openDrawer(GravityCompat.END);
            } else {
                Toast.makeText(this, R.string.sidebar_notfound, Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.night:
            {
                LayoutInflater inflater = getLayoutInflater();
                final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
                final TextView title = dialoglayout.findViewById(R.id.title);
                title.setBackgroundColor(Palette.getDefaultColor());
                final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setView(dialoglayout);
                final Dialog d = builder.show();
                back = new ColorPreferences(MainActivity.this).getFontStyle().getThemeType();
                if (SettingValues.isNight()) {
                    dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
                }
                for (final Pair<Integer, Integer> pair : ColorPreferences.themePairList) {
                    dialoglayout.findViewById(pair.first).setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            String[] names = new ColorPreferences(MainActivity.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() == pair.second) {
                                    back = theme.getThemeType();
                                    new ColorPreferences(MainActivity.this).setFontStyle(theme);
                                    d.dismiss();
                                    restartTheme();
                                    break;
                                }
                            }
                        }
                    });
                }
            }
            return true;
        case R.id.action_refresh:
            if (adapter != null && adapter.getCurrentFragment() != null) {
                ((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
            }
            return true;
        case R.id.action_sort:
            if (subreddit.equalsIgnoreCase("friends")) {
                Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
                LayoutUtils.showSnackbar(s);
            } else {
                openPopup();
            }
            return true;
        case R.id.search:
            MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {

                @Override
                public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
                    term = charSequence.toString();
                }
            });
            // Add "search current sub" if it is not frontpage/all/random
            if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.contains(".") && !subreddit.contains("/m/") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equalsIgnoreCase("myrandom") && !subreddit.equalsIgnoreCase("randnsfw")) {
                builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
                        Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
                        startActivity(i);
                    }
                });
                builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            } else {
                builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {

                    @Override
                    public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
                        Intent i = new Intent(MainActivity.this, Search.class);
                        i.putExtra(Search.EXTRA_TERM, term);
                        startActivity(i);
                    }
                });
            }
            builder.show();
            return true;
        case R.id.save:
            saveOffline(((SubmissionsView) adapter.getCurrentFragment()).posts.posts, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
            return true;
        case R.id.hide_posts:
            ((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
            return true;
        case R.id.share:
            Reddit.defaultShareText("Slide for Reddit", "https://play.google.com/store/apps/details?id=me.ccrama.redditslide", MainActivity.this);
            return true;
        case R.id.submit:
            {
                Intent i = new Intent(MainActivity.this, Submit.class);
                i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
                startActivity(i);
            }
            return true;
        case R.id.gallery:
            if (SettingValues.isPro) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Gallery.class);
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_gallerymode_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
                if (SettingValues.previews > 0) {
                    b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), (dialog, which) -> {
                        SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                        SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                        List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                        if (posts != null && !posts.isEmpty()) {
                            Intent i2 = new Intent(MainActivity.this, Gallery.class);
                            i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                            i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                            startActivity(i2);
                        }
                    });
                }
                b.show();
            }
            return true;
        case R.id.action_shadowbox:
            if (SettingValues.isPro) {
                List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                if (posts != null && !posts.isEmpty()) {
                    Intent i2 = new Intent(this, Shadowbox.class);
                    i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                    i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                    i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                    startActivity(i2);
                }
            } else {
                final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_shadowbox_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
                if (SettingValues.previews > 0) {
                    b.setNeutralButton("Preview (" + SettingValues.previews + ")", (dialog, which) -> {
                        SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
                        SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
                        List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
                        if (posts != null && !posts.isEmpty()) {
                            Intent i2 = new Intent(MainActivity.this, Shadowbox.class);
                            i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
                            i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
                            i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
                            startActivity(i2);
                        }
                    });
                }
                b.show();
            }
            return true;
        default:
            return false;
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DrawerItemsDialog(me.ccrama.redditslide.Fragments.DrawerItemsDialog) Dialog(android.app.Dialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AlertDialog(androidx.appcompat.app.AlertDialog) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) TextView(android.widget.TextView) Pair(android.util.Pair) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) Submission(net.dean.jraw.models.Submission) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) CardView(androidx.cardview.widget.CardView) AutoCompleteTextView(android.widget.AutoCompleteTextView) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) DialogAction(com.afollestad.materialdialogs.DialogAction) LayoutInflater(android.view.LayoutInflater) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 23 with ColorPreferences

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

the class MainActivity method doPageSelectedComments.

public void doPageSelectedComments(int position) {
    pager.setSwipeLeftOnly(false);
    header.animate().translationY(0).setInterpolator(new LinearInterpolator()).setDuration(180);
    Reddit.currentPosition = position;
    if (position + 1 != currentComment) {
        doSubSidebarNoLoad(usedArray.get(position));
    }
    SubmissionsView page = (SubmissionsView) adapter.getCurrentFragment();
    if (page != null && page.adapter != null) {
        SubredditPosts p = page.adapter.dataSet;
        if (p.offline && p.cached != null) {
            Toast.makeText(MainActivity.this, getString(R.string.offline_last_update, TimeUtils.getTimeAgo(p.cached.time, MainActivity.this)), Toast.LENGTH_LONG).show();
        }
    }
    if (hea != null) {
        hea.setBackgroundColor(Palette.getColor(usedArray.get(position)));
        if (accountsArea != null) {
            accountsArea.setBackgroundColor(Palette.getDarkerColor(usedArray.get(position)));
        }
    }
    header.setBackgroundColor(Palette.getColor(usedArray.get(position)));
    themeSystemBars(usedArray.get(position));
    setRecentBar(usedArray.get(position));
    if (SettingValues.single) {
        getSupportActionBar().setTitle(usedArray.get(position));
    } else {
        if (mTabLayout != null) {
            mTabLayout.setSelectedTabIndicatorColor(new ColorPreferences(MainActivity.this).getColor(usedArray.get(position)));
        }
    }
    selectedSub = usedArray.get(position);
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) LinearInterpolator(android.view.animation.LinearInterpolator) SubmissionsView(me.ccrama.redditslide.Fragments.SubmissionsView) SubredditPosts(me.ccrama.redditslide.Adapters.SubredditPosts)

Example 24 with ColorPreferences

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

the class Announcement method setViews.

private void setViews(String rawHTML, String subredditName, SpoilerRobotoTextView firstTextView, CommentOverflow commentOverflow) {
    if (rawHTML.isEmpty()) {
        return;
    }
    List<String> blocks = SubmissionParser.getBlocks(rawHTML);
    int startIndex = 0;
    // the <div class="md"> case is when the body contains a table or code block first
    if (!blocks.get(0).equals("<div class=\"md\">")) {
        firstTextView.setVisibility(View.VISIBLE);
        firstTextView.setTextHtml(blocks.get(0), subredditName);
        firstTextView.setLinkTextColor(new ColorPreferences(this).getColor(subredditName));
        startIndex = 1;
    } else {
        firstTextView.setText("");
        firstTextView.setVisibility(View.GONE);
    }
    if (blocks.size() > 1) {
        if (startIndex == 0) {
            commentOverflow.setViews(blocks, subredditName);
        } else {
            commentOverflow.setViews(blocks.subList(startIndex, blocks.size()), subredditName);
        }
        SidebarLayout sidebar = (SidebarLayout) findViewById(R.id.submission_dialog_drawerLayout);
        for (int i = 0; i < commentOverflow.getChildCount(); i++) {
            View maybeScrollable = commentOverflow.getChildAt(i);
            if (maybeScrollable instanceof HorizontalScrollView) {
                sidebar.addScrollable(maybeScrollable);
            }
        }
    } else {
        commentOverflow.removeAllViews();
    }
}
Also used : ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences) SidebarLayout(me.ccrama.redditslide.Views.SidebarLayout) SpoilerRobotoTextView(me.ccrama.redditslide.SpoilerRobotoTextView) HorizontalScrollView(android.widget.HorizontalScrollView) TitleTextView(me.ccrama.redditslide.Views.TitleTextView) View(android.view.View) HorizontalScrollView(android.widget.HorizontalScrollView)

Example 25 with ColorPreferences

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

the class BaseActivity method applyColorTheme.

/**
 * Applies the activity's base color theme. Should be called before inflating any layouts.
 */
protected void applyColorTheme() {
    getTheme().applyStyle(new FontPreferences(this).getCommentFontStyle().getResId(), true);
    getTheme().applyStyle(new FontPreferences(this).getPostFontStyle().getResId(), true);
    getTheme().applyStyle(new ColorPreferences(this).getFontStyle().getBaseId(), true);
}
Also used : FontPreferences(me.ccrama.redditslide.Visuals.FontPreferences) ColorPreferences(me.ccrama.redditslide.Visuals.ColorPreferences)

Aggregations

ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)55 View (android.view.View)25 TextView (android.widget.TextView)21 Intent (android.content.Intent)18 AlertDialog (androidx.appcompat.app.AlertDialog)15 ArrayList (java.util.ArrayList)15 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)13 Context (android.content.Context)12 LayoutInflater (android.view.LayoutInflater)12 ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)12 RecyclerView (androidx.recyclerview.widget.RecyclerView)11 SubmissionsView (me.ccrama.redditslide.Fragments.SubmissionsView)11 ImageView (android.widget.ImageView)10 HorizontalScrollView (android.widget.HorizontalScrollView)9 ViewPager (androidx.viewpager.widget.ViewPager)9 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)9 Snackbar (com.google.android.material.snackbar.Snackbar)8 LinearInterpolator (android.view.animation.LinearInterpolator)7 Dialog (android.app.Dialog)6 AutoCompleteTextView (android.widget.AutoCompleteTextView)6