From 17df9d41ca298a86203da9a5f097109229cd58f7 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Wed, 10 Nov 2021 15:37:11 +0300 Subject: Fix bottom url menu not being themed accordingly Use linkify for in-gallery caption url --- .../infinityforreddit/activities/BaseActivity.java | 11 ++++++++++ .../activities/ViewRedditGalleryActivity.java | 4 +++- .../adapters/PostDetailRecyclerViewAdapter.java | 3 +++ .../adapters/PostRecyclerViewAdapter.java | 3 +++ .../ViewRedditGalleryImageOrGifFragment.java | 24 +++++++++++++--------- 5 files changed, 34 insertions(+), 11 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 13f40f63..636e4615 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -59,6 +59,7 @@ public abstract class BaseActivity extends AppCompatActivity { private int systemVisibilityToolbarExpanded = 0; private int systemVisibilityToolbarCollapsed = 0; private CustomThemeWrapper customThemeWrapper; + private int appliedTheme; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -98,15 +99,18 @@ public abstract class BaseActivity extends AppCompatActivity { AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Normal, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); + setAppliedTheme(R.style.Theme_Normal); break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + setAppliedTheme(R.style.Theme_Normal_NormalDark); } break; case 2: @@ -117,14 +121,17 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Normal, true); + setAppliedTheme(R.style.Theme_Normal); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.LIGHT); } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.AMOLED); + setAppliedTheme(R.style.Theme_Normal_AmoledDark); } else { getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); customThemeWrapper.setThemeType(CustomThemeSharedPreferencesUtils.DARK); + setAppliedTheme(R.style.Theme_Normal_NormalDark); } } } @@ -227,6 +234,8 @@ public abstract class BaseActivity extends AppCompatActivity { return systemVisibilityToolbarCollapsed; } + public int getAppliedTheme() { return appliedTheme; } + public boolean isImmersiveInterface() { return immersiveInterface; } @@ -297,6 +306,8 @@ public abstract class BaseActivity extends AppCompatActivity { isImmersiveInterfaceApplicable = false; } + public void setAppliedTheme(int appliedStyle) { this.appliedTheme = appliedStyle; } + protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) { applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 8b477c34..3c016a2c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -48,6 +48,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA public static final String EXTRA_REDDIT_GALLERY = "ERG"; public static final String EXTRA_SUBREDDIT_NAME = "ESN"; + public static final String EXTRA_APPLIED_THEME = "EAS"; @BindView(R.id.hauler_view_view_reddit_gallery_activity) HaulerView haulerView; @@ -69,7 +70,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(R.style.Theme_Normal, true); + int theme = getIntent().getIntExtra(EXTRA_APPLIED_THEME, R.style.Theme_Normal); + getTheme().applyStyle(theme <= 0 ? R.style.Theme_Normal : theme, true); getTheme().applyStyle(FontStyle.valueOf(sharedPreferences .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 9857e421..dba26de7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -87,6 +87,7 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; +import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CommentActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; @@ -2268,6 +2269,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { - UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); - Bundle bundle = new Bundle(); - bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, captionUrl); - urlMenuBottomSheetFragment.setArguments(bundle); - urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); - return true; - }); - - captionUrlTextView.setVisibility(View.VISIBLE); captionUrlTextView.setText(captionUrl); + if (!activity.isDestroyed() && !activity.isFinishing()) { + BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, captionUrlTextView).setOnLinkLongClickListener((textView, url) -> { + UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url); + urlMenuBottomSheetFragment.setArguments(bundle); + urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); + return true; + }); + } + captionUrlTextView.setVisibility(View.VISIBLE); } } -- cgit v1.2.3