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);
}
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;
}
}
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);
}
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();
}
}
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);
}
Aggregations