aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-04-02 14:15:47 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-04-02 14:15:47 +0000
commit9690c5eeaca4bf1317af2c792c48ee859060eefe (patch)
treef8cfbcdd150ceb9734a03c55d725a40728dc4c04 /app/src/main/java/ml/docilealligator/infinityforreddit
parent5f7ac4349f1e0c0b7e44d49f3edb9469a428dc7c (diff)
downloadinfinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar.gz
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar.bz2
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar.lz
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar.xz
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.tar.zst
infinity-for-reddit-9690c5eeaca4bf1317af2c792c48ee859060eefe.zip
Add an activity for theme preview.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java448
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewCommentsFragment.java93
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java149
6 files changed, 701 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
index 07730b0c..0853700b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.Activity;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
@@ -189,6 +190,12 @@ public class CustomizeThemeActivity extends BaseActivity {
case android.R.id.home:
finish();
return true;
+ case R.id.action_preview_customize_theme_activity:
+ Intent intent = new Intent(this, ThemePreviewActivity.class);
+ intent.putParcelableArrayListExtra(ThemePreviewActivity.EXTRA_CUSTOM_THEME_SETTINGS_ITEMS, customThemeSettingsItems);
+ startActivity(intent);
+
+ return true;
case R.id.action_save_customize_theme_activity:
if (adapter != null) {
themeName = adapter.getThemeName();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java
new file mode 100644
index 00000000..d701cfa6
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java
@@ -0,0 +1,448 @@
+package ml.docilealligator.infinityforreddit.Activity;
+
+import android.content.SharedPreferences;
+import android.content.res.ColorStateList;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.TypedValue;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.app.AppCompatDelegate;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentPagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.google.android.material.bottomappbar.BottomAppBar;
+import com.google.android.material.chip.Chip;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.tabs.TabLayout;
+
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
+import ml.docilealligator.infinityforreddit.ContentFontStyle;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeSettingsItem;
+import ml.docilealligator.infinityforreddit.FontStyle;
+import ml.docilealligator.infinityforreddit.Fragment.ThemePreviewCommentsFragment;
+import ml.docilealligator.infinityforreddit.Fragment.ThemePreviewPostsFragment;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.TitleFontStyle;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
+
+public class ThemePreviewActivity extends AppCompatActivity {
+
+ public static final String EXTRA_CUSTOM_THEME_SETTINGS_ITEMS = "ECTSI";
+
+ @BindView(R.id.coordinator_layout_theme_preview_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.view_pager_theme_preview_activity)
+ ViewPager viewPager;
+ @BindView(R.id.appbar_layout_theme_preview_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.collapsing_toolbar_layout_theme_preview_activity)
+ CollapsingToolbarLayout collapsingToolbarLayout;
+ @BindView(R.id.toolbar_linear_layout_theme_preview_activity)
+ LinearLayout linearLayout;
+ @BindView(R.id.subreddit_name_text_view_theme_preview_activity)
+ TextView subredditNameTextView;
+ @BindView(R.id.user_name_text_view_theme_preview_activity)
+ TextView usernameTextView;
+ @BindView(R.id.subscribe_subreddit_chip_theme_preview_activity)
+ Chip subscribeSubredditChip;
+ @BindView(R.id.primary_text_text_view_theme_preview_activity)
+ TextView primaryTextView;
+ @BindView(R.id.secondary_text_text_view_theme_preview_activity)
+ TextView secondaryTextView;
+ @BindView(R.id.toolbar)
+ Toolbar toolbar;
+ @BindView(R.id.tab_layout_theme_preview_activity)
+ TabLayout tabLayout;
+ @BindView(R.id.bottom_navigation_theme_preview_activity)
+ BottomAppBar bottomNavigationView;
+ @BindView(R.id.linear_layout_bottom_app_bar_theme_preview_activity)
+ LinearLayout linearLayoutBottomAppBar;
+ @BindView(R.id.subscriptions_bottom_app_bar_theme_preview_activity)
+ ImageView subscriptionsBottomAppBar;
+ @BindView(R.id.multi_reddit_bottom_app_bar_theme_preview_activity)
+ ImageView multiRedditBottomAppBar;
+ @BindView(R.id.message_bottom_app_bar_theme_preview_activity)
+ ImageView messageBottomAppBar;
+ @BindView(R.id.profile_bottom_app_bar_theme_preview_activity)
+ ImageView profileBottomAppBar;
+ @BindView(R.id.fab_theme_preview_activity)
+ FloatingActionButton fab;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ private ArrayList<CustomThemeSettingsItem> customThemeSettingsItems;
+ private CustomTheme customTheme;
+ private int expandedTabTextColor;
+ private int expandedTabBackgroundColor;
+ private int expandedTabIndicatorColor;
+ private int collapsedTabTextColor;
+ private int collapsedTabBackgroundColor;
+ private int collapsedTabIndicatorColor;
+ private int unsubscribedColor;
+ private int subscribedColor;
+ private int systemVisibilityToolbarExpanded = 0;
+ private int systemVisibilityToolbarCollapsed = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ customThemeSettingsItems = getIntent().getParcelableArrayListExtra(EXTRA_CUSTOM_THEME_SETTINGS_ITEMS);
+ customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, "ThemePreview");
+
+ boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
+ int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
+ switch (systemThemeType) {
+ case 0:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
+ getTheme().applyStyle(R.style.Theme_Normal, true);
+ break;
+ case 1:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
+ if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
+ getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
+ } else {
+ getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
+ }
+ break;
+ case 2:
+ if (systemDefault) {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
+ }
+ if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) {
+ getTheme().applyStyle(R.style.Theme_Normal, true);
+ } else {
+ if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) {
+ getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true);
+ } else {
+ getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true);
+ }
+ }
+ }
+
+ boolean immersiveInterface = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
+ mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true);
+ boolean changeStatusBarIconColor = false;
+ if (immersiveInterface) {
+ changeStatusBarIconColor = customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface;
+ }
+ boolean isLightStatusbar = customTheme.isLightStatusBar;
+ Window window = getWindow();
+ View decorView = window.getDecorView();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ boolean isLightNavBar = customTheme.isLightNavBar;
+ if (isLightStatusbar) {
+ if (isLightNavBar) {
+ systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
+ if (changeStatusBarIconColor) {
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
+ } else {
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
+ }
+ } else {
+ systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ if (!changeStatusBarIconColor) {
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ }
+ }
+ } else {
+ if (isLightNavBar) {
+ systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
+ if (changeStatusBarIconColor) {
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
+ }
+ } else {
+ if (changeStatusBarIconColor) {
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ }
+ }
+ }
+ decorView.setSystemUiVisibility(systemVisibilityToolbarExpanded);
+ window.setNavigationBarColor(customTheme.navBarColor);
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (isLightStatusbar) {
+ decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ systemVisibilityToolbarExpanded = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ systemVisibilityToolbarCollapsed = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
+ }
+ }
+
+ getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(TitleFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY, TitleFontStyle.Normal.name())).getResId(), true);
+
+ getTheme().applyStyle(ContentFontStyle.valueOf(mSharedPreferences
+ .getString(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY, ContentFontStyle.Normal.name())).getResId(), true);
+
+ setContentView(R.layout.activity_theme_preview);
+
+ ButterKnife.bind(this);
+ applyCustomTheme();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ if (immersiveInterface) {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+
+ Resources resources = getResources();
+ int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+ if (navBarResourceId > 0) {
+ int navBarHeight = resources.getDimensionPixelSize(navBarResourceId);
+ if (navBarHeight > 0) {
+ CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
+ params.bottomMargin = navBarHeight;
+ fab.setLayoutParams(params);
+ linearLayoutBottomAppBar.setPadding(0,
+ (int) (6 * getResources().getDisplayMetrics().density), 0, navBarHeight);
+ }
+ }
+ }
+
+ if (changeStatusBarIconColor) {
+ appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
+ @Override
+ public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) {
+ if (state == State.COLLAPSED) {
+ decorView.setSystemUiVisibility(systemVisibilityToolbarCollapsed);
+ tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor);
+ tabLayout.setBackgroundColor(collapsedTabBackgroundColor);
+ } else if (state == State.EXPANDED) {
+ decorView.setSystemUiVisibility(systemVisibilityToolbarExpanded);
+ tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor);
+ tabLayout.setBackgroundColor(expandedTabBackgroundColor);
+ }
+ }
+ });
+ } else {
+ appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
+ @Override
+ public void onStateChanged(AppBarLayout appBarLayout, AppBarStateChangeListener.State state) {
+ if (state == State.COLLAPSED) {
+ tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor);
+ tabLayout.setBackgroundColor(collapsedTabBackgroundColor);
+ } else if (state == State.EXPANDED) {
+ tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor);
+ tabLayout.setBackgroundColor(expandedTabBackgroundColor);
+ }
+ }
+ });
+ }
+ } else {
+ appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
+ @Override
+ public void onStateChanged(AppBarLayout appBarLayout, State state) {
+ if (state == State.EXPANDED) {
+ tabLayout.setTabTextColors(expandedTabTextColor, expandedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(expandedTabIndicatorColor);
+ tabLayout.setBackgroundColor(expandedTabBackgroundColor);
+ } else if (state == State.COLLAPSED) {
+ tabLayout.setTabTextColors(collapsedTabTextColor, collapsedTabTextColor);
+ tabLayout.setSelectedTabIndicatorColor(collapsedTabIndicatorColor);
+ tabLayout.setBackgroundColor(collapsedTabBackgroundColor);
+ }
+ }
+ });
+ }
+
+ adjustToolbar(toolbar);
+ setSupportActionBar(toolbar);
+
+ subscribeSubredditChip.setOnClickListener(view -> {
+ if (subscribeSubredditChip.getText().equals(getResources().getString(R.string.subscribe))) {
+ subscribeSubredditChip.setText(R.string.unsubscribe);
+ subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
+ } else {
+ subscribeSubredditChip.setText(R.string.subscribe);
+ subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
+ }
+ });
+
+ SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
+ viewPager.setAdapter(sectionsPagerAdapter);
+ viewPager.setOffscreenPageLimit(2);
+ tabLayout.setupWithViewPager(viewPager);
+ }
+
+ private void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(customTheme.backgroundColor);
+ collapsingToolbarLayout.setContentScrimColor(customTheme.colorPrimary);
+ subscribeSubredditChip.setTextColor(customTheme.chipTextColor);
+ subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(customTheme.unsubscribed));
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ expandedTabTextColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor;
+ expandedTabIndicatorColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator;
+ expandedTabBackgroundColor = customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground;
+ collapsedTabTextColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor;
+ collapsedTabIndicatorColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator;
+ collapsedTabBackgroundColor = customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground;
+ linearLayout.setBackgroundColor(customTheme.backgroundColor);
+ subredditNameTextView.setTextColor(customTheme.subreddit);
+ usernameTextView.setTextColor(customTheme.username);
+ subscribeSubredditChip.setTextColor(customTheme.chipTextColor);
+ primaryTextView.setTextColor(customTheme.primaryTextColor);
+ secondaryTextView.setTextColor(customTheme.secondaryTextColor);
+ bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(customTheme.backgroundColor));
+ int primaryIconColor = customTheme.primaryIconColor;
+ subscriptionsBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ multiRedditBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ messageBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ profileBottomAppBar.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ applyTabLayoutTheme(tabLayout);
+ applyFABTheme(fab);
+ unsubscribedColor = customTheme.unsubscribed;
+ subscribedColor = customTheme.subscribed;
+ }
+
+ protected void applyAppBarLayoutAndToolbarTheme(AppBarLayout appBarLayout, Toolbar toolbar) {
+ appBarLayout.setBackgroundColor(customTheme.colorPrimary);
+ toolbar.setTitleTextColor(customTheme.toolbarPrimaryTextAndIconColor);
+ if (toolbar.getNavigationIcon() != null) {
+ toolbar.getNavigationIcon().setColorFilter(customTheme.toolbarPrimaryTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ }
+ if (toolbar.getOverflowIcon() != null) {
+ toolbar.getOverflowIcon().setColorFilter(customTheme.toolbarPrimaryTextAndIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ }
+ }
+
+ private void adjustToolbar(Toolbar toolbar) {
+ int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
+ if (statusBarResourceId > 0) {
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
+ int statusBarHeight = getResources().getDimensionPixelSize(statusBarResourceId);
+ params.topMargin = statusBarHeight;
+ toolbar.setLayoutParams(params);
+ TypedValue tv = new TypedValue();
+ if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
+ {
+ int dp16 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
+ linearLayout.setPadding(dp16,
+ TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics()) + statusBarHeight,
+ dp16, 0);
+ }
+ }
+ }
+
+ protected void applyTabLayoutTheme(TabLayout tabLayout) {
+ int toolbarAndTabBackgroundColor = customTheme.colorPrimary;
+ tabLayout.setBackgroundColor(toolbarAndTabBackgroundColor);
+ tabLayout.setSelectedTabIndicatorColor(customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator);
+ tabLayout.setTabTextColors(customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor,
+ customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor);
+ }
+
+ protected void applyFABTheme(FloatingActionButton fab) {
+ fab.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimaryLightTheme));
+ fab.setImageTintList(ColorStateList.valueOf(customTheme.fabIconColor));
+ Drawable myFabSrc = getResources().getDrawable(R.drawable.ic_add_day_night_24dp);
+ if (myFabSrc.getConstantState() != null) {
+ Drawable willBeWhite = myFabSrc.getConstantState().newDrawable();
+ willBeWhite.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
+ fab.setImageDrawable(willBeWhite);
+ }
+ }
+
+ public CustomTheme getCustomTheme() {
+ return customTheme;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return false;
+ }
+
+ private class SectionsPagerAdapter extends FragmentPagerAdapter {
+ private ThemePreviewPostsFragment themePreviewPostsFragment;
+ private ThemePreviewCommentsFragment themePreviewCommentsFragment;
+
+ SectionsPagerAdapter(FragmentManager fm) {
+ super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
+ }
+
+ @NonNull
+ @Override
+ public Fragment getItem(int position) {
+ if (position == 0) {
+ return new ThemePreviewPostsFragment();
+ }
+ return new ThemePreviewCommentsFragment();
+ }
+
+ @Override
+ public int getCount() {
+ return 2;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ switch (position) {
+ case 0:
+ return "Posts";
+ case 1:
+ return "Comments";
+ }
+ return null;
+ }
+
+ @NonNull
+ @Override
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
+ Fragment fragment = (Fragment) super.instantiateItem(container, position);
+ switch (position) {
+ case 0:
+ themePreviewPostsFragment = (ThemePreviewPostsFragment) fragment;
+ break;
+ case 1:
+ themePreviewCommentsFragment = (ThemePreviewCommentsFragment) fragment;
+ }
+ return fragment;
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index b34ce856..34f38542 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -97,7 +97,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
CoordinatorLayout coordinatorLayout;
@BindView(R.id.view_pager_view_subreddit_detail_activity)
ViewPager viewPager;
- @BindView(R.id.appbar_layout_view_subreddit_detail)
+ @BindView(R.id.appbar_layout_view_subreddit_detail_activity)
AppBarLayout appBarLayout;
@BindView(R.id.collapsing_toolbar_layout_view_subreddit_detail_activity)
CollapsingToolbarLayout collapsingToolbarLayout;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index bdc69bcd..3a8fd8bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -28,6 +28,7 @@ import ml.docilealligator.infinityforreddit.Activity.SettingsActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubscribedThingListingActivity;
+import ml.docilealligator.infinityforreddit.Activity.ThemePreviewActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewGIFActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewImageActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewMessageActivity;
@@ -152,4 +153,6 @@ public interface AppComponent {
void inject(SidebarFragment sidebarFragment);
void inject(AdvancedPreferenceFragment advancedPreferenceFragment);
+
+ void inject(ThemePreviewActivity themePreviewActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewCommentsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewCommentsFragment.java
new file mode 100644
index 00000000..4a194579
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewCommentsFragment.java
@@ -0,0 +1,93 @@
+package ml.docilealligator.infinityforreddit.Fragment;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.core.widget.NestedScrollView;
+import androidx.fragment.app.Fragment;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Activity.ThemePreviewActivity;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class ThemePreviewCommentsFragment extends Fragment {
+
+ @BindView(R.id.linear_layout_theme_preview_comments_fragment)
+ LinearLayout linearLayout;
+ @BindView(R.id.vertical_block_theme_preview_comments_fragment)
+ View verticalBlock;
+ @BindView(R.id.author_type_image_view_theme_preview_comments_fragment)
+ ImageView authorTypeImageView;
+ @BindView(R.id.author_text_view_theme_preview_comments_fragment)
+ TextView authorTextView;
+ @BindView(R.id.author_flair_text_view_theme_preview_comments_fragment)
+ TextView flairTextView;
+ @BindView(R.id.comment_time_text_view_theme_preview_comments_fragment)
+ TextView commentTimeTextView;
+ @BindView(R.id.comment_markdown_view_theme_preview_comments_fragment)
+ TextView contentTextView;
+ @BindView(R.id.up_vote_button_theme_preview_comments_fragment)
+ ImageView upvoteButton;
+ @BindView(R.id.score_text_view_theme_preview_comments_fragment)
+ TextView scoreTextView;
+ @BindView(R.id.down_vote_button_theme_preview_comments_fragment)
+ ImageView downvoteButton;
+ @BindView(R.id.more_button_theme_preview_comments_fragment)
+ ImageView moreButton;
+ @BindView(R.id.expand_button_theme_preview_comments_fragment)
+ ImageView expandButton;
+ @BindView(R.id.save_button_theme_preview_comments_fragment)
+ ImageView saveButton;
+ @BindView(R.id.reply_button_theme_preview_comments_fragment)
+ ImageView replyButton;
+ @BindView(R.id.divider_theme_preview_comments_fragment)
+ View divider;
+ private ThemePreviewActivity activity;
+
+ public ThemePreviewCommentsFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_theme_preview_comments, container, false);
+ ButterKnife.bind(this, rootView);
+
+ CustomTheme customTheme = activity.getCustomTheme();
+ linearLayout.setBackgroundColor(customTheme.commentBackgroundColor);
+ authorTypeImageView.setColorFilter(customTheme.moderator, android.graphics.PorterDuff.Mode.SRC_IN);
+ authorTextView.setTextColor(customTheme.moderator);
+ commentTimeTextView.setTextColor(customTheme.secondaryTextColor);
+ contentTextView.setTextColor(customTheme.commentColor);
+ flairTextView.setTextColor(customTheme.authorFlairTextColor);
+ divider.setBackgroundColor(customTheme.dividerColor);
+ upvoteButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ scoreTextView.setTextColor(customTheme.commentIconAndInfoColor);
+ downvoteButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ moreButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ expandButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ saveButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ replyButton.setColorFilter(customTheme.commentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (ThemePreviewActivity) context;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java
new file mode 100644
index 00000000..e8963f92
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java
@@ -0,0 +1,149 @@
+package ml.docilealligator.infinityforreddit.Fragment;
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.cardview.widget.CardView;
+import androidx.core.graphics.drawable.DrawableCompat;
+import androidx.core.widget.NestedScrollView;
+import androidx.fragment.app.Fragment;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.RequestOptions;
+import com.libRG.CustomTextView;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import ml.docilealligator.infinityforreddit.Activity.ThemePreviewActivity;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
+import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView;
+import ml.docilealligator.infinityforreddit.R;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class ThemePreviewPostsFragment extends Fragment {
+
+ @BindView(R.id.card_view_theme_preview_posts_fragment)
+ CardView cardView;
+ @BindView(R.id.icon_gif_image_view_theme_preview_posts_fragment)
+ AspectRatioGifImageView iconImageView;
+ @BindView(R.id.subreddit_name_text_view_theme_preview_posts_fragment)
+ TextView subredditNameTextView;
+ @BindView(R.id.user_text_view_theme_preview_posts_fragment)
+ TextView usernameTextView;
+ @BindView(R.id.stickied_post_image_view_theme_preview_posts_fragment)
+ ImageView stickiedPostImageView;
+ @BindView(R.id.post_time_text_view_best_theme_preview_posts_fragment)
+ TextView postTimeTextView;
+ @BindView(R.id.title_text_view_best_theme_preview_posts_fragment)
+ TextView titleTextView;
+ @BindView(R.id.content_text_view_theme_preview_posts_fragment)
+ TextView contentTextView;
+ @BindView(R.id.type_text_view_theme_preview_posts_fragment)
+ CustomTextView typeTextView;
+ @BindView(R.id.spoiler_custom_text_view_theme_preview_posts_fragment)
+ CustomTextView spoilerTextView;
+ @BindView(R.id.nsfw_text_view_theme_preview_posts_fragment)
+ CustomTextView nsfwTextView;
+ @BindView(R.id.flair_custom_text_view_theme_preview_posts_fragment)
+ CustomTextView flairTextView;
+ @BindView(R.id.archived_image_view_theme_preview_posts_fragment)
+ ImageView archivedImageView;
+ @BindView(R.id.locked_image_view_theme_preview_posts_fragment)
+ ImageView lockedImageView;
+ @BindView(R.id.crosspost_image_view_theme_preview_posts_fragment)
+ ImageView crosspostImageView;
+ @BindView(R.id.link_text_view_theme_preview_posts_fragment)
+ TextView linkTextView;
+ @BindView(R.id.progress_bar_theme_preview_posts_fragment)
+ ProgressBar progressBar;
+ @BindView(R.id.image_view_no_preview_link_theme_preview_posts_fragment)
+ ImageView noPreviewLinkImageView;
+ @BindView(R.id.plus_button_theme_preview_posts_fragment)
+ ImageView upvoteButton;
+ @BindView(R.id.score_text_view_theme_preview_posts_fragment)
+ TextView scoreTextView;
+ @BindView(R.id.minus_button_theme_preview_posts_fragment)
+ ImageView downvoteButton;
+ @BindView(R.id.comments_count_theme_preview_posts_fragment)
+ TextView commentsCountTextView;
+ @BindView(R.id.save_button_theme_preview_posts_fragment)
+ ImageView saveButton;
+ @BindView(R.id.share_button_theme_preview_posts_fragment)
+ ImageView shareButton;
+ private ThemePreviewActivity activity;
+
+ public ThemePreviewPostsFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_theme_preview_posts, container, false);
+ ButterKnife.bind(this, rootView);
+
+ CustomTheme customTheme = activity.getCustomTheme();
+
+ cardView.setBackgroundTintList(ColorStateList.valueOf(customTheme.cardViewBackgroundColor));
+ Glide.with(this).load(R.drawable.subreddit_default_icon)
+ .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
+ .into(iconImageView);
+ subredditNameTextView.setTextColor(customTheme.subreddit);
+ usernameTextView.setTextColor(customTheme.username);
+ postTimeTextView.setTextColor(customTheme.secondaryTextColor);
+ titleTextView.setTextColor(customTheme.postTitleColor);
+ contentTextView.setTextColor(customTheme.postContentColor);
+ stickiedPostImageView.setColorFilter(customTheme.stickiedPostIconTint, PorterDuff.Mode.SRC_IN);
+ typeTextView.setBackgroundColor(customTheme.postTypeBackgroundColor);
+ typeTextView.setBorderColor(customTheme.postTypeBackgroundColor);
+ typeTextView.setTextColor(customTheme.postTypeTextColor);
+ spoilerTextView.setBackgroundColor(customTheme.spoilerBackgroundColor);
+ spoilerTextView.setBorderColor(customTheme.spoilerBackgroundColor);
+ spoilerTextView.setTextColor(customTheme.spoilerTextColor);
+ nsfwTextView.setBackgroundColor(customTheme.nsfwBackgroundColor);
+ nsfwTextView.setBorderColor(customTheme.nsfwBackgroundColor);
+ nsfwTextView.setTextColor(customTheme.nsfwTextColor);
+ flairTextView.setBackgroundColor(customTheme.flairBackgroundColor);
+ flairTextView.setBorderColor(customTheme.flairBackgroundColor);
+ flairTextView.setTextColor(customTheme.flairTextColor);
+ archivedImageView.setColorFilter(customTheme.archivedTint, PorterDuff.Mode.SRC_IN);
+ lockedImageView.setColorFilter(customTheme.lockedIconTint, PorterDuff.Mode.SRC_IN);
+ crosspostImageView.setColorFilter(customTheme.crosspostIconTint, PorterDuff.Mode.SRC_IN);
+ linkTextView.setTextColor(customTheme.secondaryTextColor);
+ progressBar.setIndeterminateTintList(ColorStateList.valueOf(customTheme.colorAccent));
+ noPreviewLinkImageView.setBackgroundColor(customTheme.noPreviewLinkBackgroundColor);
+ upvoteButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ scoreTextView.setTextColor(customTheme.postIconAndInfoColor);
+ downvoteButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ commentsCountTextView.setTextColor(customTheme.postIconAndInfoColor);
+ Drawable commentIcon = activity.getDrawable(R.drawable.ic_comment_grey_24dp);
+ if (commentIcon != null) {
+ DrawableCompat.setTint(commentIcon, customTheme.postIconAndInfoColor);
+ }
+ commentsCountTextView.setCompoundDrawablesWithIntrinsicBounds(commentIcon, null, null, null);
+ saveButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+ shareButton.setColorFilter(customTheme.postIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (ThemePreviewActivity) context;
+ }
+}