diff options
Diffstat (limited to 'app/src/main/java')
51 files changed, 349 insertions, 224 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java index 2bd6a247..69c20f34 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java @@ -50,10 +50,10 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @BindView(R.id.coordinator_layout_account_posts_activity) CoordinatorLayout coordinatorLayout; - @BindView(R.id.collapsing_toolbar_layout_account_posts_activity) - CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_account_posts_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_account_posts_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_account_posts_activity) Toolbar toolbar; @Inject @@ -160,7 +160,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } private void initializeFragment() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java index bbdb74f0..6254f97d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountSavedThingActivity.java @@ -59,10 +59,10 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT @BindView(R.id.coordinator_layout_account_saved_thing_activity) CoordinatorLayout coordinatorLayout; - @BindView(R.id.collapsing_toolbar_layout_account_saved_thing_activity) - CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_account_saved_thing_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_account_saved_thing_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_account_saved_thing_activity) Toolbar toolbar; @BindView(R.id.tab_layout_tab_layout_account_saved_thing_activity_activity) @@ -167,7 +167,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyTabLayoutTheme(tabLayout); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java index f0e753b7..403f3567 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AnonymousSubscriptionsActivity.java @@ -13,6 +13,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import javax.inject.Inject; @@ -32,6 +33,8 @@ public class AnonymousSubscriptionsActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_anonymous_subscriptions_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_anonymous_subscriptions_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_anonymous_subscriptions_activity) Toolbar toolbar; @Inject @@ -99,7 +102,7 @@ public class AnonymousSubscriptionsActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override 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 12e565c4..13f40f63 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -1,5 +1,10 @@ package ml.docilealligator.infinityforreddit.activities; +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; + import android.annotation.SuppressLint; import android.content.SharedPreferences; import android.content.res.ColorStateList; @@ -25,6 +30,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.widget.ViewPager2; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; @@ -44,11 +50,6 @@ import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils; 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 abstract class BaseActivity extends AppCompatActivity { private boolean immersiveInterface; private boolean changeStatusBarIconColor; @@ -275,6 +276,15 @@ public abstract class BaseActivity extends AppCompatActivity { return 0; } + public int getStatusBarHeight() { + int result = 0; + int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + result = getResources().getDimensionPixelSize(resourceId); + } + return result; + } + protected void setTransparentStatusBarAfterToolbarCollapsed() { this.transparentStatusBarAfterToolbarCollapsed = true; } @@ -287,8 +297,18 @@ public abstract class BaseActivity extends AppCompatActivity { isImmersiveInterfaceApplicable = false; } - protected void applyAppBarLayoutAndToolbarTheme(AppBarLayout appBarLayout, Toolbar toolbar) { + protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar) { + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, true); + } + + protected void applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(AppBarLayout appBarLayout, @Nullable CollapsingToolbarLayout collapsingToolbarLayout, Toolbar toolbar, boolean setToolbarBackgroundColor) { appBarLayout.setBackgroundColor(customThemeWrapper.getColorPrimary()); + if (collapsingToolbarLayout != null) { + collapsingToolbarLayout.setContentScrimColor(customThemeWrapper.getColorPrimary()); + } + if (setToolbarBackgroundColor) { + toolbar.setBackgroundColor(customThemeWrapper.getColorPrimary()); + } toolbar.setTitleTextColor(customThemeWrapper.getToolbarPrimaryTextAndIconColor()); toolbar.setSubtitleTextColor(customThemeWrapper.getToolbarSecondaryTextColor()); if (toolbar.getNavigationIcon() != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java index a244fafe..1f85f362 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -310,7 +310,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); commentParentMarkwonView.setTextColor(mCustomThemeWrapper.getCommentColor()); divider.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); commentEditText.setTextColor(mCustomThemeWrapper.getCommentColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java index c586c1da..9ae956f9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -19,6 +19,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.snackbar.Snackbar; import com.r0adkll.slidr.Slidr; @@ -47,6 +48,8 @@ public class CreateMultiRedditActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_create_multi_reddit_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_create_multi_reddit_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_create_multi_reddit_activity) Toolbar toolbar; @BindView(R.id.multi_reddit_name_edit_text_create_multi_reddit_activity) @@ -220,7 +223,7 @@ public class CreateMultiRedditActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); nameEditText.setTextColor(primaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java index 144898bb..8ab69a4d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomThemeListingActivity.java @@ -22,6 +22,7 @@ import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -62,6 +63,8 @@ public class CustomThemeListingActivity extends BaseActivity implements CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_customize_theme_listing_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_customize_theme_listing_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_customize_theme_listing_activity) Toolbar toolbar; @BindView(R.id.recycler_view_customize_theme_listing_activity) @@ -152,7 +155,7 @@ public class CustomThemeListingActivity extends BaseActivity implements @Override protected void applyCustomTheme() { - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java index 37194312..8603c808 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java @@ -395,7 +395,7 @@ public class CustomizePostFilterActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); int primaryIconColor = mCustomThemeWrapper.getPrimaryIconColor(); Drawable cursorDrawable = Utils.getTintedDrawable(this, R.drawable.edit_text_cursor, primaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java index cadaa8d5..58dd009b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java @@ -15,6 +15,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; @@ -56,6 +57,8 @@ public class CustomizeThemeActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_customize_theme_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_customize_theme_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_customize_theme_activity) Toolbar toolbar; @BindView(R.id.recycler_view_customize_theme_activity) @@ -253,6 +256,6 @@ public class CustomizeThemeActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index e46f581b..4f4b81ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -183,7 +183,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); contentEditText.setTextColor(mCustomThemeWrapper.getCommentColor()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index eb559f1c..1ff1b157 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -21,6 +21,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.snackbar.Snackbar; import com.r0adkll.slidr.Slidr; @@ -51,6 +52,8 @@ public class EditMultiRedditActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_edit_multi_reddit_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_edit_multi_reddit_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_edit_multi_reddit_activity) Toolbar toolbar; @BindView(R.id.progress_bar_edit_multi_reddit_activity) @@ -272,7 +275,7 @@ public class EditMultiRedditActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); progressBar.setIndeterminateTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorAccent())); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 21e1418d..0d22d9b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -192,7 +192,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); titleTextView.setTextColor(mCustomThemeWrapper.getPostTitleColor()); divider.setBackgroundColor(mCustomThemeWrapper.getPostTitleColor()); contentEditText.setTextColor(mCustomThemeWrapper.getPostContentColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 175ff228..3c0dd8e3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -256,7 +256,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyFABTheme(fab); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 9eb9fb86..dca5b75b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -25,6 +25,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.model.SlidrInterface; @@ -68,6 +69,8 @@ public class FullMarkdownActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_comment_full_markdown_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_comment_full_markdown_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_comment_full_markdown_activity) Toolbar toolbar; @BindView(R.id.content_markdown_view_comment_full_markdown_activity) @@ -277,7 +280,7 @@ public class FullMarkdownActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java index 98e1b604..50db35d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/GiveAwardActivity.java @@ -189,6 +189,6 @@ public class GiveAwardActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java index 2437103f..203ded9e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/InboxActivity.java @@ -73,10 +73,10 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf @BindView(R.id.coordinator_layout_inbox_activity) CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.collapsing_toolbar_layout_inbox_activity) - CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_inbox_activity) AppBarLayout mAppBarLayout; + @BindView(R.id.collapsing_toolbar_layout_inbox_activity) + CollapsingToolbarLayout mCollapsingToolbarLayout; @BindView(R.id.toolbar_inbox_activity) Toolbar mToolbar; @BindView(R.id.tab_layout_inbox_activity) @@ -238,7 +238,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf @Override protected void applyCustomTheme() { mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 8bdc0528..cef2a207 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -281,7 +281,7 @@ public class LoginActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); twoFAInfoTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); Drawable infoDrawable = Utils.getTintedDrawable(this, R.drawable.ic_info_preference_24dp, mCustomThemeWrapper.getPrimaryIconColor()); twoFAInfoTextView.setCompoundDrawablesWithIntrinsicBounds(infoDrawable, null, null, null); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 0697ec04..30d134fe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -31,7 +31,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AppCompatDelegate; -import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.app.ActivityCompat; import androidx.core.view.GravityCompat; @@ -52,6 +51,7 @@ import androidx.work.WorkManager; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -160,7 +160,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar) - Toolbar toolbar; + MaterialToolbar toolbar; @BindView(R.id.nav_drawer_recycler_view_main_activity) RecyclerView navDrawerRecyclerView; @BindView(R.id.tab_layout_main_activity) @@ -269,9 +269,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb drawer.setStatusBarBackgroundColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { drawer.setFitsSystemWindows(false); - drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + getWindow().setDecorFitsSystemWindows(false); + /*drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);*/ } else { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } @@ -355,7 +356,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); navigationView.setBackgroundColor(backgroundColor); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyTabLayoutTheme(tabLayout); bottomAppBar.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); applyFABTheme(fab); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java index 7b1596f8..d4f7dd07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java @@ -18,6 +18,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; @@ -55,6 +56,8 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_multireddit_selection_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_multireddit_selection_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_multireddit_selection_activity) Toolbar toolbar; @Inject @@ -142,7 +145,7 @@ public class MultiredditSelectionActivity extends BaseActivity implements Activi @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } private void bindView(boolean initializeFragment) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java index d8c89639..44a6f62d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterPreferenceActivity.java @@ -12,6 +12,7 @@ import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; @@ -43,6 +44,8 @@ public class PostFilterPreferenceActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_post_filter_preference_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_post_filter_preference_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_post_filter_preference_activity) Toolbar toolbar; @BindView(R.id.recycler_view_post_filter_preference_activity) @@ -207,7 +210,7 @@ public class PostFilterPreferenceActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java index 350584db..e24a47b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostFilterUsageListingActivity.java @@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.textfield.TextInputEditText; @@ -47,6 +48,8 @@ public class PostFilterUsageListingActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_post_filter_application_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_post_filter_application_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_post_filter_application_activity) Toolbar toolbar; @BindView(R.id.recycler_view_post_filter_application_activity) @@ -209,6 +212,6 @@ public class PostFilterUsageListingActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } }
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index 8edb4516..3dcb726e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -407,7 +407,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index acf5034d..cf6c7664 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -388,7 +388,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 8ce97d55..eecefa75 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -362,7 +362,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index a03f7355..5336051c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -386,7 +386,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index a7fb97d8..f80b5e94 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -399,7 +399,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java index 4b8f9b38..f00c9eb3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ReportActivity.java @@ -196,6 +196,6 @@ public class ReportActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java index ca687cf1..75e01121 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java @@ -18,6 +18,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; @@ -49,6 +50,8 @@ public class RulesActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_rules_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_rules_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_rules_activity) Toolbar toolbar; @BindView(R.id.progress_bar_rules_activity) @@ -154,7 +157,7 @@ public class RulesActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); progressBar.setIndeterminateTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorAccent())); errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index 6daffcce..b98fb205 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -349,7 +349,7 @@ public class SearchActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); simpleSearchView.setSearchBackground(new ColorDrawable(mCustomThemeWrapper.getColorPrimary())); int toolbarPrimaryTextAndIconColorColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(); simpleSearchView.setIconsColor(toolbarPrimaryTextAndIconColorColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 4dca5fc6..95a98aa9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -28,6 +28,7 @@ import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; @@ -95,6 +96,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_search_result_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_search_result_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_search_result_activity) Toolbar toolbar; @BindView(R.id.tab_layout_search_result_activity) @@ -230,7 +233,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java index ae115534..4cd3390e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java @@ -23,7 +23,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; -import java.util.List; import javax.inject.Inject; import javax.inject.Named; @@ -36,7 +35,6 @@ import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment; -import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface { @@ -143,7 +141,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); } public void getSelectedSubreddit(String name, String iconUrl) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java index 58db6bc7..c0cab347 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java @@ -140,7 +140,7 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); } public void getSelectedUser(String name, String iconUrl) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java index f9a7460e..3b4252dd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectUserFlairActivity.java @@ -223,7 +223,7 @@ public class SelectUserFlairActivity extends BaseActivity implements ActivityToo @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java index 38502fd4..9df207b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java @@ -14,6 +14,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.r0adkll.slidr.Slidr; @@ -45,6 +46,8 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_selected_subreddits_and_users_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_selected_subreddits_and_users_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_selected_subreddits_and_users_activity) Toolbar toolbar; @BindView(R.id.recycler_view_selected_subreddits_and_users_activity) @@ -187,7 +190,7 @@ public class SelectedSubredditsAndUsersActivity extends BaseActivity implements @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyFABTheme(fab); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java index 216dd2ae..abfe7810 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SendPrivateMessageActivity.java @@ -174,7 +174,7 @@ public class SendPrivateMessageActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); usernameEditText.setTextColor(primaryTextColor); subjectEditText.setTextColor(primaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java index b4a70c30..067e44a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java @@ -13,6 +13,7 @@ import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -46,6 +47,8 @@ public class SettingsActivity extends BaseActivity implements @BindView(R.id.appbar_layout_settings_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_settings_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_settings_activity) Toolbar toolbar; private String mAccountName; @@ -126,7 +129,7 @@ public class SettingsActivity extends BaseActivity implements @Override protected void applyCustomTheme() { - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java index b5ac9689..dd3b0d89 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java @@ -391,7 +391,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java index 344f00dd..91da0e06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditMultiselectionActivity.java @@ -24,6 +24,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import java.util.ArrayList; @@ -54,6 +55,8 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act CoordinatorLayout mCoordinatorLayout; @BindView(R.id.appbar_layout_subreddits_multiselection_activity) AppBarLayout mAppBarLayout; + @BindView(R.id.collapsing_toolbar_layout_subscribed_subreddits_multiselection_activity) + CollapsingToolbarLayout mCollapsingToolbarLayout; @BindView(R.id.toolbar_subscribed_subreddits_multiselection_activity) Toolbar mToolbar; @BindView(R.id.swipe_refresh_layout_subscribed_subscribed_subreddits_multiselection_activity) @@ -226,7 +229,7 @@ public class SubredditMultiselectionActivity extends BaseActivity implements Act @Override protected void applyCustomTheme() { mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar); mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java index 3db45c00..3578a32b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java @@ -19,6 +19,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import org.greenrobot.eventbus.EventBus; @@ -62,6 +63,8 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_subreddit_selection_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_subreddit_selection_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_subreddit_selection_activity) Toolbar toolbar; @Inject @@ -153,7 +156,7 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } private void bindView(boolean initializeFragment) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java index de5438e1..dde51105 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubscribedThingListingActivity.java @@ -21,6 +21,7 @@ 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.dialog.MaterialAlertDialogBuilder; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; @@ -74,6 +75,8 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_subscribed_thing_listing_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_subscribed_thing_listing_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_subscribed_thing_listing_activity) Toolbar toolbar; @BindView(R.id.tab_layout_subscribed_thing_listing_activity) @@ -178,7 +181,7 @@ public class SubscribedThingListingActivity extends BaseActivity implements Acti @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java index 7f0282f3..7057b1ad 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java @@ -64,10 +64,10 @@ public class TrendingActivity extends BaseActivity { @BindView(R.id.coordinator_layout_trending_activity) CoordinatorLayout coordinatorLayout; - @BindView(R.id.collapsing_toolbar_layout_trending_activity) - CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_trending_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_trending_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_trending_activity) Toolbar toolbar; @BindView(R.id.swipe_refresh_layout_trending_activity) @@ -326,7 +326,7 @@ public class TrendingActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); errorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 012742d4..33561073 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -298,7 +298,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index ae3538b1..494d062c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -31,6 +31,7 @@ import com.evernote.android.state.State; import com.github.piasy.biv.BigImageViewer; import com.github.piasy.biv.loader.glide.GlideImageLoader; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.card.MaterialCardView; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; @@ -88,6 +89,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele CoordinatorLayout mCoordinatorLayout; @BindView(R.id.appbar_layout_view_post_detail_activity) AppBarLayout mAppBarLayout; + @BindView(R.id.collapsing_toolbar_layout_view_post_detail_activity) + CollapsingToolbarLayout mCollapsingToolbarLayout; @BindView(R.id.toolbar_view_post_detail_activity) Toolbar mToolbar; @BindView(R.id.view_pager_2_view_post_detail_activity) @@ -276,7 +279,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele @Override protected void applyCustomTheme() { mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, mCollapsingToolbarLayout, mToolbar); applyFABTheme(fab); searchPanelMaterialCardView.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimary())); int searchPanelTextAndIconColor = mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java index ad09e76e..f56bf406 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPrivateMessagesActivity.java @@ -290,7 +290,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit @Override protected void applyCustomTheme() { mLinearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(mAppBarLayout, null, mToolbar); mDivider.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); mEditText.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); mSecondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 41fd582d..9ea9f5de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -16,6 +16,7 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -27,7 +28,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -42,6 +42,7 @@ import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.chip.Chip; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -149,7 +150,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @BindView(R.id.toolbar_linear_layout_view_subreddit_detail_activity) LinearLayout linearLayout; @BindView(R.id.toolbar) - Toolbar toolbar; + MaterialToolbar toolbar; @BindView(R.id.tab_layout_view_subreddit_detail_activity) TabLayout tabLayout; @BindView(R.id.banner_image_view_view_subreddit_detail_activity) @@ -268,9 +269,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp if (isImmersiveInterface()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + /*coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);*/ + getWindow().setDecorFitsSystemWindows(false); } else { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } @@ -514,8 +516,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - collapsingToolbarLayout.setContentScrimColor(mCustomThemeWrapper.getColorPrimary()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + appBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + collapsingToolbarLayout.setScrimVisibleHeightTrigger(toolbar.getHeight() + tabLayout.getHeight() + getStatusBarHeight() * 2); + appBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, false); expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor(); expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator(); expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground(); @@ -793,6 +801,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp option1BottomAppBar.setOnClickListener(view -> { bottomAppBarOptionAction(option1); + //Toast.makeText(this, "s " + collapsingToolbarLayout.getScrimVisibleHeightTrigger(), Toast.LENGTH_SHORT).show(); }); option2BottomAppBar.setOnClickListener(view -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 14586b0e..dfc40140 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -17,6 +17,7 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -28,7 +29,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -43,6 +43,7 @@ import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.bottomappbar.BottomAppBar; import com.google.android.material.chip.Chip; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -140,7 +141,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @BindView(R.id.appbar_layout_view_user_detail) AppBarLayout appBarLayout; @BindView(R.id.toolbar_view_user_detail_activity) - Toolbar toolbar; + MaterialToolbar toolbar; @BindView(R.id.toolbar_linear_layout_view_user_detail_activity) LinearLayout linearLayout; @BindView(R.id.tab_layout_view_user_detail_activity) @@ -562,8 +563,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - collapsingToolbarLayout.setContentScrimColor(mCustomThemeWrapper.getColorPrimary()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + appBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + collapsingToolbarLayout.setScrimVisibleHeightTrigger(toolbar.getHeight() + tabLayout.getHeight() + getStatusBarHeight() * 2); + appBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar, false); expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor(); expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator(); expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java index 8945e758..8c18718c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WebViewActivity.java @@ -109,7 +109,7 @@ public class WebViewActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); Drawable closeIcon = Utils.getTintedDrawable(this, R.drawable.ic_close_black_24dp, mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor()); toolbar.setNavigationIcon(closeIcon); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 372d3c6f..c5e9d35c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -27,6 +27,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.model.SlidrInterface; @@ -78,6 +79,8 @@ public class WikiActivity extends BaseActivity { CoordinatorLayout coordinatorLayout; @BindView(R.id.appbar_layout_comment_wiki_activity) AppBarLayout appBarLayout; + @BindView(R.id.collapsing_toolbar_layout_wiki_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.toolbar_comment_wiki_activity) Toolbar toolbar; @BindView(R.id.swipe_refresh_layout_wiki_activity) @@ -356,7 +359,7 @@ public class WikiActivity extends BaseActivity { @Override protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground()); swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); mFetchWikiInfoTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); 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 d083a0bc..789ce798 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -680,7 +680,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler } ((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f); - if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfyOrRedgifsVideoSuccess()) { + if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrRedgifsVideoSuccess()) { ((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() { @Override public void success(String webm, String mp4) { @@ -1670,14 +1670,14 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler if (mPost.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); - if (mPost.isLoadGfyOrRedgifsVideoSuccess()) { + if (mPost.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(mPost.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); } } else if (mPost.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId()); - if (mPost.isLoadGfyOrRedgifsVideoSuccess()) { + if (mPost.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(mPost.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 7556cba0..464a4ab1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -39,6 +39,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; +import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestOptions; @@ -455,6 +456,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (holder instanceof PostBaseViewHolder) { Post post = getItem(position); if (post != null) { + ((PostBaseViewHolder) holder).post = post; ((PostBaseViewHolder) holder).currentPosition = position; if (post.isRead()) { if (((PostBaseViewHolder) holder).itemViewIsNotCardView) { @@ -689,7 +691,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostVideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); } - if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) { + if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrRedgifsVideoSuccess()) { ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() { @Override public void success(String webm, String mp4) { @@ -766,6 +768,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else { Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostWithPreviewTypeViewHolder) holder).preview = preview; if (preview != null) { ((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE); if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { @@ -778,7 +781,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostWithPreviewTypeViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE); if (post.getPostType() == Post.VIDEO_TYPE) { @@ -821,7 +824,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCard2VideoAutoplayViewHolder) holder).setVolume(mFragment.getMasterMutingOption() ? 0f : 1f); } - if (post.isGfycat() || post.isRedgifs() && !post.isLoadGfyOrRedgifsVideoSuccess()) { + if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrRedgifsVideoSuccess()) { ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() { @Override public void success(String webm, String mp4) { @@ -900,6 +903,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else { Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostCard2WithPreviewViewHolder) holder).preview = preview; if (preview != null) { ((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.VISIBLE); if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { @@ -912,7 +916,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCard2WithPreviewViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); @@ -943,6 +947,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (holder instanceof PostCompactBaseViewHolder) { Post post = getItem(position); if (post != null) { + ((PostCompactBaseViewHolder) holder).post = post; ((PostCompactBaseViewHolder) holder).currentPosition = position; if (post.isRead()) { holder.itemView.setBackgroundColor(mReadPostCardViewBackgroundColor); @@ -1153,13 +1158,12 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostCompactBaseViewHolder) holder).noPreviewPostImageFrameLayout.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).noPreviewPostImageView.setImageResource(R.drawable.ic_gallery_24dp); } - ArrayList<Post.Preview> previews = post.getPreviews(); - if (previews != null && !previews.isEmpty()) { + if (post.getPreviews() != null && !post.getPreviews().isEmpty()) { if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) { ((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE); } - loadImage(holder, post, previews.get(0)); + loadImage(holder); } } @@ -1269,6 +1273,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (holder instanceof PostGalleryViewHolder) { Post post = getItem(position); if (post != null) { + ((PostGalleryViewHolder) holder).post = post; ((PostGalleryViewHolder) holder).currentPosition = position; if (post.isRead()) { holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor)); @@ -1281,6 +1286,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { int height = (int) (400 * mScale); @@ -1292,7 +1298,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); if (post.getPostType() == Post.VIDEO_TYPE) { @@ -1316,6 +1322,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { int height = (int) (400 * mScale); @@ -1327,7 +1334,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); @@ -1341,6 +1348,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp)); Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { int height = (int) (400 * mScale); @@ -1352,7 +1360,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); @@ -1366,6 +1374,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator)); Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { int height = (int) (400 * mScale); @@ -1377,7 +1386,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); @@ -1401,6 +1410,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp)); Post.Preview preview = getSuitablePreview(post.getPreviews()); + ((PostGalleryViewHolder) holder).preview = preview; if (preview != null) { if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { int height = (int) (400 * mScale); @@ -1412,7 +1422,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ((PostGalleryViewHolder) holder).imageView .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); } - loadImage(holder, post, preview); + loadImage(holder); } else { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); @@ -1435,29 +1445,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie previewIndex = 0; } preview = previews.get(previewIndex); - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { for (int i = previews.size() - 1; i >= 1; i--) { preview = previews.get(i); if (mImageViewWidth >= preview.getPreviewWidth()) { - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { return preview; } } else { int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight(); - if (mImageViewWidth * height <= 10_000_000) { + if (mImageViewWidth * height <= 5_000_000) { + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); return preview; } } } } - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { int divisor = 2; do { preview.setPreviewWidth(preview.getPreviewWidth() / divisor); preview.setPreviewHeight(preview.getPreviewHeight() / divisor); divisor *= 2; - } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000); + } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000); } return preview; } @@ -1465,70 +1477,40 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return null; } - private void loadImage(final RecyclerView.ViewHolder holder, final Post post, @NonNull Post.Preview preview) { + private void loadImage(final RecyclerView.ViewHolder holder) { if (holder instanceof PostWithPreviewTypeViewHolder) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); - } else { - url = preview.getPreviewUrl(); - } - RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostWithPreviewTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostWithPreviewTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - ((PostWithPreviewTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; + Post post = ((PostWithPreviewTypeViewHolder) holder).post; + Post.Preview preview = ((PostWithPreviewTypeViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); } - }); + RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostWithPreviewTypeViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostWithPreviewTypeViewHolder) holder).imageView); + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostWithPreviewTypeViewHolder) holder).imageView); } else { - imageRequestBuilder.into(((PostWithPreviewTypeViewHolder) holder).imageView); + imageRequestBuilder.diskCacheStrategy(DiskCacheStrategy.NONE).override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostWithPreviewTypeViewHolder) holder).imageView); } } } else if (holder instanceof PostCompactBaseViewHolder) { + Post post = ((PostCompactBaseViewHolder) holder).post; String postCompactThumbnailPreviewUrl; ArrayList<Post.Preview> previews = post.getPreviews(); if (previews != null && !previews.isEmpty()) { if (previews.size() >= 2) { postCompactThumbnailPreviewUrl = previews.get(1).getPreviewUrl(); } else { - postCompactThumbnailPreviewUrl = preview.getPreviewUrl(); + postCompactThumbnailPreviewUrl = previews.get(0).getPreviewUrl(); } RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(postCompactThumbnailPreviewUrl) - .error(R.drawable.ic_error_outline_black_24dp).listener(new RequestListener<Drawable>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; - } - }); + .error(R.drawable.ic_error_outline_black_24dp).listener(((PostCompactBaseViewHolder) holder).requestListener); if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || post.isSpoiler() && mNeedBlurSpoiler) { imageRequestBuilder .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView); @@ -1537,81 +1519,51 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } } } else if (holder instanceof PostGalleryViewHolder) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); - } else { - url = preview.getPreviewUrl(); - } - RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostGalleryViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - ((PostGalleryViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; + Post post = ((PostGalleryViewHolder) holder).post; + Post.Preview preview = ((PostGalleryViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); } - }); + RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostGalleryViewHolder) holder).requestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostGalleryViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostGalleryViewHolder) holder).imageView); + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostGalleryViewHolder) holder).imageView); } else { - imageRequestBuilder.into(((PostGalleryViewHolder) holder).imageView); + if (mImageViewWidth > preview.getPreviewWidth()) { + imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostGalleryViewHolder) holder).imageView); + } else { + imageRequestBuilder.into(((PostGalleryViewHolder) holder).imageView); + } } } } else if (holder instanceof PostCard2WithPreviewViewHolder) { - String url; - boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; - if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { - url = post.getUrl(); - } else { - url = preview.getPreviewUrl(); - } - RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> { - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE); - ((PostCard2WithPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - loadImage(holder, post, preview); - }); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { - ((PostCard2WithPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); - return false; + Post post = ((PostCard2WithPreviewViewHolder) holder).post; + Post.Preview preview = ((PostCard2WithPreviewViewHolder) holder).preview; + if (preview != null) { + String url; + boolean blurImage = (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler; + if (post.getPostType() == Post.GIF_TYPE && mAutoplay && !blurImage) { + url = post.getUrl(); + } else { + url = preview.getPreviewUrl(); } - }); + RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostCard2WithPreviewViewHolder) holder).requestListener); - if (blurImage) { - imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) - .into(((PostCard2WithPreviewViewHolder) holder).imageView); - } else { - if (mImageViewWidth > preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostCard2WithPreviewViewHolder) holder).imageView); + if (blurImage) { + imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) + .into(((PostCard2WithPreviewViewHolder) holder).imageView); } else { - imageRequestBuilder.into(((PostCard2WithPreviewViewHolder) holder).imageView); + if (mImageViewWidth > preview.getPreviewWidth()) { + imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostCard2WithPreviewViewHolder) holder).imageView); + } else { + imageRequestBuilder.into(((PostCard2WithPreviewViewHolder) holder).imageView); + } } } } @@ -1787,6 +1739,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else { holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor)); } + mGlide.clear(((PostBaseViewHolder) holder).iconGifImageView); ((PostBaseViewHolder) holder).titleTextView.setTextColor(mPostTitleColor); if (holder instanceof PostVideoAutoplayViewHolder) { ((PostVideoAutoplayViewHolder) holder).mediaUri = null; @@ -1801,7 +1754,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (holder instanceof PostWithPreviewTypeViewHolder) { mGlide.clear(((PostWithPreviewTypeViewHolder) holder).imageView); ((PostWithPreviewTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.GONE); - ((PostWithPreviewTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostWithPreviewTypeViewHolder) holder).errorTextView.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); @@ -1823,7 +1776,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } else if (holder instanceof PostCard2WithPreviewViewHolder) { mGlide.clear(((PostCard2WithPreviewViewHolder) holder).imageView); ((PostCard2WithPreviewViewHolder) holder).imageView.setVisibility(View.GONE); - ((PostCard2WithPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostCard2WithPreviewViewHolder) holder).errorTextView.setVisibility(View.GONE); ((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); ((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE); ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); @@ -1894,7 +1847,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie mGlide.clear(((PostGalleryViewHolder) holder).imageView); ((PostGalleryViewHolder) holder).imageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.GONE); - ((PostGalleryViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE); + ((PostGalleryViewHolder) holder).errorTextView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.GONE); } @@ -2045,6 +1998,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie TextView commentsCountTextView; ImageView saveButton; ImageView shareButton; + Post post; + Post.Preview preview; boolean itemViewIsNotCardView = false; int currentPosition; @@ -2706,14 +2661,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (post.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfyOrRedgifsVideoSuccess()) { + if (post.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); } } else if (post.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfyOrRedgifsVideoSuccess()) { + if (post.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); } @@ -2871,13 +2826,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie @BindView(R.id.video_or_gif_indicator_image_view_item_post_with_preview) ImageView videoOrGifIndicatorImageView; @BindView(R.id.image_wrapper_relative_layout_item_post_with_preview) - RelativeLayout imageWrapperRelativeLayout; + FrameLayout imageWrapperRelativeLayout; @BindView(R.id.progress_bar_item_post_with_preview) ProgressBar progressBar; @BindView(R.id.image_view_item_post_with_preview) AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_post_with_preview) - RelativeLayout errorRelativeLayout; @BindView(R.id.load_image_error_text_view_item_post_with_preview) TextView errorTextView; @BindView(R.id.image_view_no_preview_gallery_item_post_with_preview) @@ -2896,6 +2849,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView saveButton; @BindView(R.id.share_button_item_post_with_preview) ImageView shareButton; + RequestListener<Drawable> glideRequestListener; PostWithPreviewTypeViewHolder(View itemView) { super(itemView); @@ -2943,9 +2897,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + errorTextView.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorTextView.setVisibility(View.GONE); + loadImage(this); + }); + noPreviewLinkImageView.setOnClickListener(view -> { imageView.performClick(); }); + + glideRequestListener = new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + errorTextView.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + errorTextView.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return false; + } + }; } } @@ -3056,6 +3032,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView saveButton; ImageView shareButton; View divider; + RequestListener<Drawable> requestListener; + Post post; int currentPosition; @@ -3552,6 +3530,20 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie shareLink(post); } }); + + requestListener = new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + return false; + } + }; } void markPostRead(Post post, boolean changePostItemColor) { @@ -3728,14 +3720,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView videoOrGifIndicatorImageView; @BindView(R.id.image_view_item_post_gallery) AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_post_gallery) - RelativeLayout errorRelativeLayout; @BindView(R.id.load_image_error_text_view_item_gallery) TextView errorTextView; @BindView(R.id.image_view_no_preview_item_post_gallery) ImageView noPreviewImageView; @BindView(R.id.title_text_view_item_post_gallery) TextView titleTextView; + RequestListener<Drawable> requestListener; + Post post; + Post.Preview preview; int currentPosition; @@ -3788,9 +3781,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return true; }); + errorTextView.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorTextView.setVisibility(View.GONE); + loadImage(this); + }); + noPreviewImageView.setOnClickListener(view -> { itemView.performClick(); }); + + requestListener = new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + errorTextView.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + errorTextView.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return false; + } + }; } void markPostRead(Post post, boolean changePostItemColor) { @@ -3931,14 +3946,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie if (post.isGfycat()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfyOrRedgifsVideoSuccess()) { + if (post.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); } } else if (post.isRedgifs()) { intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS); intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId()); - if (post.isLoadGfyOrRedgifsVideoSuccess()) { + if (post.isLoadGfycatOrRedgifsVideoSuccess()) { intent.setData(Uri.parse(post.getVideoUrl())); intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl()); } @@ -4099,8 +4114,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ProgressBar progressBar; @BindView(R.id.image_view_item_post_card_2_with_preview) AspectRatioGifImageView imageView; - @BindView(R.id.load_image_error_relative_layout_item_post_card_2_with_preview) - RelativeLayout errorRelativeLayout; @BindView(R.id.load_image_error_text_view_item_post_card_2_with_preview) TextView errorTextView; @BindView(R.id.image_view_no_preview_gallery_item_post_card_2_with_preview) @@ -4121,6 +4134,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie ImageView shareButton; @BindView(R.id.divider_item_post_card_2_with_preview) View divider; + RequestListener<Drawable> requestListener; PostCard2WithPreviewViewHolder(@NonNull View itemView) { super(itemView); @@ -4170,9 +4184,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + errorTextView.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorTextView.setVisibility(View.GONE); + loadImage(this); + }); + noPreviewImageView.setOnClickListener(view -> { imageView.performClick(); }); + + requestListener = new RequestListener<>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + progressBar.setVisibility(View.GONE); + errorTextView.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + errorTextView.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return false; + } + }; } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index d814fb86..6a0173c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -337,7 +337,7 @@ public class Post implements Parcelable { this.isRedgifs = isRedgifs; } - public boolean isLoadGfyOrRedgifsVideoSuccess() { + public boolean isLoadGfycatOrRedgifsVideoSuccess() { return loadGfyOrRedgifsVideoSuccess; } |