diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-10-30 13:20:48 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-10-30 13:20:48 +0000 |
commit | 4ab8f037f2b3da61a11b46f547615be3d2aab77f (patch) | |
tree | d589c980a6344ea15b6defd6484dd1108b5e37d2 /app/src | |
parent | efd5f618892a088fc9bc14530bbc1b80d0d9b561 (diff) | |
download | infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar.gz infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar.bz2 infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar.lz infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar.xz infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.tar.zst infinity-for-reddit-4ab8f037f2b3da61a11b46f547615be3d2aab77f.zip |
Start migrating to Material Design 3. Try optimizing image loading in PostRecyclerViewAdapter.
Diffstat (limited to '')
16 files changed, 261 insertions, 192 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index edad7ed5..60393587 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -205,7 +205,8 @@ android:label="@string/account_saved_thing_activity_label" android:parentActivityName=".activities.MainActivity" android:theme="@style/AppTheme.Slidable" /> - <activity android:name=".activities.ShareDataResolverActivity"> + <activity android:name=".activities.ShareDataResolverActivity" + android:exported="false"> <intent-filter> <action android:name="android.intent.action.SEND" /> @@ -263,7 +264,8 @@ android:label="@string/search_subreddits_activity_label" android:parentActivityName=".activities.MainActivity" android:theme="@style/AppTheme.Slidable" /> - <activity android:name=".activities.LinkResolverActivity"> + <activity android:name=".activities.LinkResolverActivity" + android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> @@ -356,7 +358,8 @@ android:name=".activities.MainActivity" android:label="@string/application_name" android:theme="@style/AppTheme.Launcher" - android:windowSoftInputMode="adjustPan"> + android:windowSoftInputMode="adjustPan" + android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> 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..cea711ae 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; @@ -44,11 +49,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 +275,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; } @@ -288,7 +297,14 @@ public abstract class BaseActivity extends AppCompatActivity { } protected void applyAppBarLayoutAndToolbarTheme(AppBarLayout appBarLayout, Toolbar toolbar) { + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar, true); + } + + protected void applyAppBarLayoutAndToolbarTheme(AppBarLayout appBarLayout, Toolbar toolbar, boolean setToolbarBackgroundColor) { appBarLayout.setBackgroundColor(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/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 0697ec04..6b5231e2 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); } @@ -356,6 +357,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); navigationView.setBackgroundColor(backgroundColor); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + collapsingToolbarLayout.setContentScrimColor(mCustomThemeWrapper.getColorPrimary()); applyTabLayoutTheme(tabLayout); bottomAppBar.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); applyFABTheme(fab); 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..a94ecbcf 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); } @@ -515,7 +517,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp 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); + } + }); + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar, false); expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor(); expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator(); expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground(); @@ -793,6 +802,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 4884ca40..51a96234 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -6,7 +6,6 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Resources; import android.net.Uri; -import android.opengl.Visibility; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -18,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; @@ -29,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; @@ -44,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; @@ -141,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) @@ -564,7 +564,14 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele 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); + } + }); + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar, false); expandedTabTextColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTextColor(); expandedTabIndicatorColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabIndicator(); expandedTabBackgroundColor = mCustomThemeWrapper.getTabLayoutWithExpandedCollapsingToolbarTabBackground(); 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..11d4145b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -455,6 +455,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 +690,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 +767,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 +780,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 +823,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 +902,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 +915,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 +946,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 +1157,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 +1272,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 +1285,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 +1297,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 +1321,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 +1333,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 +1347,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 +1359,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 +1373,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 +1385,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 +1409,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 +1421,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); @@ -1465,70 +1474,44 @@ 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); + if (mImageViewWidth > preview.getPreviewWidth()) { + imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostWithPreviewTypeViewHolder) holder).imageView); + } else { + imageRequestBuilder.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 +1520,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); + } } } } @@ -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); @@ -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) { @@ -3736,6 +3728,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie 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 +3783,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie return true; }); + errorRelativeLayout.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorRelativeLayout.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); + errorRelativeLayout.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + errorRelativeLayout.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); + return false; + } + }; } void markPostRead(Post post, boolean changePostItemColor) { @@ -3931,14 +3948,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()); } @@ -4121,6 +4138,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 +4188,31 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie } }); + errorRelativeLayout.setOnClickListener(view -> { + progressBar.setVisibility(View.VISIBLE); + errorRelativeLayout.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); + errorRelativeLayout.setVisibility(View.VISIBLE); + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + errorRelativeLayout.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; } diff --git a/app/src/main/res/layout/activity_view_subreddit_detail.xml b/app/src/main/res/layout/activity_view_subreddit_detail.xml index bdb46784..6709af9f 100644 --- a/app/src/main/res/layout/activity_view_subreddit_detail.xml +++ b/app/src/main/res/layout/activity_view_subreddit_detail.xml @@ -140,7 +140,7 @@ </RelativeLayout> - <androidx.appcompat.widget.Toolbar + <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml index 3d5501da..07600530 100644 --- a/app/src/main/res/layout/activity_view_user_detail.xml +++ b/app/src/main/res/layout/activity_view_user_detail.xml @@ -107,7 +107,7 @@ </RelativeLayout> - <androidx.appcompat.widget.Toolbar + <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar_view_user_detail_activity" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/app/src/main/res/layout/activity_view_video.xml b/app/src/main/res/layout/activity_view_video.xml index bd314ccc..cd98291d 100644 --- a/app/src/main/res/layout/activity_view_video.xml +++ b/app/src/main/res/layout/activity_view_video.xml @@ -6,6 +6,7 @@ android:id="@+id/hauler_view_view_video_activity" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="#000000" android:keepScreenOn="true" app:dragUpEnabled="true" tools:application="ml.docilealligator.infinityforreddit.activities.ViewVideoActivity"> diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 9aef7ff3..fe3656be 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -21,7 +21,7 @@ app:titleEnabled="false" app:toolbarId="@+id/toolbar"> - <androidx.appcompat.widget.Toolbar + <com.google.android.material.appbar.MaterialToolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/app/src/main/res/layout/item_post_with_preview.xml b/app/src/main/res/layout/item_post_with_preview.xml index b3ef0a9b..a6ad895c 100644 --- a/app/src/main/res/layout/item_post_with_preview.xml +++ b/app/src/main/res/layout/item_post_with_preview.xml @@ -206,7 +206,7 @@ android:fontFamily="?attr/font_family" android:visibility="gone" /> - <RelativeLayout + <FrameLayout android:id="@+id/image_wrapper_relative_layout_item_post_with_preview" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -224,7 +224,6 @@ android:layout_width="36dp" android:layout_height="36dp" android:layout_margin="16dp" - android:layout_gravity="start" android:scaleType="center" android:background="@drawable/play_button_round_background" android:visibility="gone" /> @@ -233,29 +232,20 @@ android:id="@+id/progress_bar_item_post_with_preview" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_centerInParent="true" /> + android:layout_gravity="center" /> - <RelativeLayout - android:id="@+id/load_image_error_relative_layout_item_post_with_preview" + <TextView + android:id="@+id/load_image_error_text_view_item_post_with_preview" android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_centerInParent="true" - android:visibility="gone"> - - <TextView - android:id="@+id/load_image_error_text_view_item_post_with_preview" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:drawableTop="@drawable/ic_error_outline_black_24dp" - android:layout_gravity="center" - android:gravity="center" - android:text="@string/error_loading_image_tap_to_retry" - android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" /> - - </RelativeLayout> - - </RelativeLayout> + android:layout_height="wrap_content" + android:drawableTop="@drawable/ic_error_outline_black_24dp" + android:layout_gravity="center" + android:gravity="center" + android:text="@string/error_loading_image_tap_to_retry" + android:textSize="?attr/font_default" + android:fontFamily="?attr/font_family" /> + + </FrameLayout> <ImageView android:id="@+id/image_view_no_preview_gallery_item_post_with_preview" diff --git a/app/src/main/res/values-land-v28/styles.xml b/app/src/main/res/values-land-v28/styles.xml index 037bf7e3..c3e82635 100644 --- a/app/src/main/res/values-land-v28/styles.xml +++ b/app/src/main/res/values-land-v28/styles.xml @@ -1,6 +1,6 @@ <resources> - <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> + <style name="AppTheme" parent="Theme.Material3.DayNight"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> diff --git a/app/src/main/res/values-v28/styles.xml b/app/src/main/res/values-v28/styles.xml index 80d2dd21..272e1ebf 100644 --- a/app/src/main/res/values-v28/styles.xml +++ b/app/src/main/res/values-v28/styles.xml @@ -1,7 +1,7 @@ <resources> <!-- Base application theme. --> - <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> + <style name="AppTheme" parent="Theme.Material3.DayNight"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 350b0f29..9fdc6369 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> - <style name="AppTheme" parent="Theme.MaterialComponents.DayNight"> + <style name="AppTheme" parent="Theme.Material3.DayNight"> <item name="colorPrimary">?attr/colorPrimary</item> <item name="colorPrimaryDark">?attr/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> @@ -58,7 +58,7 @@ <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.DayNight" /> - <style name="MaterialAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog"> + <style name="MaterialAlertDialogTheme" parent="ThemeOverlay.Material3.MaterialAlertDialog"> <item name="android:textSize">?attr/font_default</item> <item name="android:background">?attr/cardViewBackgroundColor</item> <item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialogTitleTextStyle @@ -78,15 +78,15 @@ </item> </style> - <style name="MaterialAlertDialogPositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog"> + <style name="MaterialAlertDialogPositiveButtonStyle" parent="Widget.Material3.Button.TextButton.Dialog"> <item name="android:textColor">@color/colorAccent</item> </style> - <style name="MaterialAlertDialogNegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog"> + <style name="MaterialAlertDialogNegativeButtonStyle" parent="Widget.Material3.Button.TextButton.Dialog"> <item name="android:textColor">?attr/primaryTextColor</item> </style> - <style name="MaterialAlertDialogTitleTextStyle" parent="MaterialAlertDialog.MaterialComponents.Title.Text"> + <style name="MaterialAlertDialogTitleTextStyle" parent="MaterialAlertDialog.Material3.Title.Text"> <item name="android:textSize">?attr/font_20</item> </style> |