From 9690c5eeaca4bf1317af2c792c48ee859060eefe Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 2 Apr 2020 22:15:47 +0800 Subject: Add an activity for theme preview. --- app/src/main/AndroidManifest.xml | 11 +- .../Activity/CustomizeThemeActivity.java | 7 + .../Activity/ThemePreviewActivity.java | 448 +++++++++++++++++++++ .../Activity/ViewSubredditDetailActivity.java | 2 +- .../infinityforreddit/AppComponent.java | 3 + .../Fragment/ThemePreviewCommentsFragment.java | 93 +++++ .../Fragment/ThemePreviewPostsFragment.java | 149 +++++++ app/src/main/res/drawable/ic_preview_24dp.xml | 9 + app/src/main/res/layout/activity_theme_preview.xml | 204 ++++++++++ .../res/layout/activity_view_subreddit_detail.xml | 2 +- .../res/layout/fragment_theme_preview_comments.xml | 220 ++++++++++ .../res/layout/fragment_theme_preview_posts.xml | 321 +++++++++++++++ app/src/main/res/menu/customize_theme_activity.xml | 9 +- app/src/main/res/values/strings.xml | 13 + 14 files changed, 1485 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ThemePreviewActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewCommentsFragment.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/ThemePreviewPostsFragment.java create mode 100644 app/src/main/res/drawable/ic_preview_24dp.xml create mode 100644 app/src/main/res/layout/activity_theme_preview.xml create mode 100644 app/src/main/res/layout/fragment_theme_preview_comments.xml create mode 100644 app/src/main/res/layout/fragment_theme_preview_posts.xml (limited to 'app/src') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c18183cc..d2738240 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,7 +21,12 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:replace="android:label"> - + @@ -266,9 +271,9 @@ android:theme="@style/AppTheme.ActionBar.Transparent" /> + android:theme="@style/AppTheme.ActionBar.Transparent" /> 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; + } +} diff --git a/app/src/main/res/drawable/ic_preview_24dp.xml b/app/src/main/res/drawable/ic_preview_24dp.xml new file mode 100644 index 00000000..4153950d --- /dev/null +++ b/app/src/main/res/drawable/ic_preview_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_theme_preview.xml b/app/src/main/res/layout/activity_theme_preview.xml new file mode 100644 index 00000000..0fbc028b --- /dev/null +++ b/app/src/main/res/layout/activity_theme_preview.xml @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml index 837df600..f7b2ee50 100644 --- a/app/src/main/res/layout/activity_view_subreddit_detail.xml +++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml @@ -15,7 +15,7 @@ app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_theme_preview_posts.xml b/app/src/main/res/layout/fragment_theme_preview_posts.xml new file mode 100644 index 00000000..4b4f7cb0 --- /dev/null +++ b/app/src/main/res/layout/fragment_theme_preview_posts.xml @@ -0,0 +1,321 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/customize_theme_activity.xml b/app/src/main/res/menu/customize_theme_activity.xml index 0e363e0f..b48416ae 100644 --- a/app/src/main/res/menu/customize_theme_activity.xml +++ b/app/src/main/res/menu/customize_theme_activity.xml @@ -2,9 +2,16 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc00e0f6..e87d9a60 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,6 +22,7 @@ Custom Themes Customize Theme Create Theme + Theme Preview Open navigation drawer Close navigation drawer @@ -658,5 +659,17 @@ Delete all themes successful Reset all settings successful + Theme Preview + u/Hostilenemy + r/Infinity_For_Reddit + Primary Text + Secondary Text + This is a post + This gravity joke is getting a bit old, but I fall for it every time. + POST + Flair + x4 + Author Flair + I got my girlfriend a “Get better soon” card.\nShe\'s not ill or anything, but she could definitely get better. -- cgit v1.2.3