Show an indicator in gallery post in PostRecyclerViewAdapter.

This commit is contained in:
Alex Ning 2021-07-21 13:25:40 +08:00
parent 3498989203
commit 8415ace96a
3 changed files with 27 additions and 19 deletions

View File

@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.Barrier; import androidx.constraintlayout.widget.Barrier;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet; import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import androidx.paging.PagedListAdapter; import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
@ -757,10 +758,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (holder instanceof PostWithPreviewTypeViewHolder) { } else if (holder instanceof PostWithPreviewTypeViewHolder) {
if (post.getPostType() == Post.VIDEO_TYPE) { if (post.getPostType() == Post.VIDEO_TYPE) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video)); ((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
} else if (post.getPostType() == Post.GIF_TYPE) { } else if (post.getPostType() == Post.GIF_TYPE) {
if (!mAutoplay) { if (!mAutoplay) {
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
} }
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif)); ((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
} else if (post.getPostType() == Post.IMAGE_TYPE) { } else if (post.getPostType() == Post.IMAGE_TYPE) {
@ -776,6 +779,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
} else if (post.getPostType() == Post.GALLERY_TYPE) { } else if (post.getPostType() == Post.GALLERY_TYPE) {
((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery)); ((PostWithPreviewTypeViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery));
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostWithPreviewTypeViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
} }
if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) {
@ -885,10 +890,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} else if (holder instanceof PostCard2WithPreviewViewHolder) { } else if (holder instanceof PostCard2WithPreviewViewHolder) {
if (post.getPostType() == Post.VIDEO_TYPE) { if (post.getPostType() == Post.VIDEO_TYPE) {
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video)); ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.video));
} else if (post.getPostType() == Post.GIF_TYPE) { } else if (post.getPostType() == Post.GIF_TYPE) {
if (!mAutoplay) { if (!mAutoplay) {
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
} }
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif)); ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
} else if (post.getPostType() == Post.IMAGE_TYPE) { } else if (post.getPostType() == Post.IMAGE_TYPE) {
@ -904,6 +911,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
} else if (post.getPostType() == Post.GALLERY_TYPE) { } else if (post.getPostType() == Post.GALLERY_TYPE) {
((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery)); ((PostCard2WithPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gallery));
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostCard2WithPreviewViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
} }
if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { if (post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) {
@ -1345,7 +1354,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
} else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) {
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
} else if (post.getPostType() == Post.LINK_TYPE) { } else if (post.getPostType() == Post.LINK_TYPE) {
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
@ -1360,7 +1368,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_play_circle_36dp)); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
@ -1385,7 +1393,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_play_circle_36dp)); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
@ -1410,7 +1418,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_link_post_type_indicator)); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator));
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
@ -1445,7 +1453,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(mActivity.getDrawable(R.drawable.ic_gallery_reverse_color_24dp)); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_reverse_color_24dp));
Post.Preview preview = getSuitablePreview(post.getPreviews()); Post.Preview preview = getSuitablePreview(post.getPreviews());
if (preview != null) { if (preview != null) {
@ -2786,12 +2794,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setOnClickListener(view -> { muteButton.setOnClickListener(view -> {
if (helper != null) { if (helper != null) {
if (helper.getVolume() != 0) { if (helper.getVolume() != 0) {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
helper.setVolume(0f); helper.setVolume(0f);
volume = 0f; volume = 0f;
mFragment.videoAutoplayChangeMutingOption(true); mFragment.videoAutoplayChangeMutingOption(true);
} else { } else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
helper.setVolume(1f); helper.setVolume(1f);
volume = 1f; volume = 1f;
mFragment.videoAutoplayChangeMutingOption(false); mFragment.videoAutoplayChangeMutingOption(false);
@ -2884,9 +2892,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
helper.setVolume(volume); helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE); muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) { if (volume != 0f) {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
} else { } else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
} }
break; break;
} }
@ -4005,12 +4013,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
muteButton.setOnClickListener(view -> { muteButton.setOnClickListener(view -> {
if (helper != null) { if (helper != null) {
if (helper.getVolume() != 0) { if (helper.getVolume() != 0) {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
helper.setVolume(0f); helper.setVolume(0f);
volume = 0f; volume = 0f;
mFragment.videoAutoplayChangeMutingOption(true); mFragment.videoAutoplayChangeMutingOption(true);
} else { } else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
helper.setVolume(1f); helper.setVolume(1f);
volume = 1f; volume = 1f;
mFragment.videoAutoplayChangeMutingOption(false); mFragment.videoAutoplayChangeMutingOption(false);
@ -4103,9 +4111,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
helper.setVolume(volume); helper.setVolume(volume);
muteButton.setVisibility(View.VISIBLE); muteButton.setVisibility(View.VISIBLE);
if (volume != 0f) { if (volume != 0f) {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_unmute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_unmute_white_rounded_24dp));
} else { } else {
muteButton.setImageDrawable(mActivity.getDrawable(R.drawable.ic_mute_white_rounded_24dp)); muteButton.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_mute_white_rounded_24dp));
} }
break; break;
} }

View File

@ -28,12 +28,12 @@
<ImageView <ImageView
android:id="@+id/video_or_gif_indicator_image_view_item_post_card_2_with_preview" android:id="@+id/video_or_gif_indicator_image_view_item_post_card_2_with_preview"
android:layout_width="wrap_content" android:layout_width="36dp"
android:layout_height="wrap_content" android:layout_height="36dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:layout_gravity="start" android:layout_gravity="start"
android:scaleType="center"
android:background="@drawable/play_button_round_background" android:background="@drawable/play_button_round_background"
android:src="@drawable/ic_play_circle_36dp"
android:visibility="gone" /> android:visibility="gone" />
<ProgressBar <ProgressBar

View File

@ -221,12 +221,12 @@
<ImageView <ImageView
android:id="@+id/video_or_gif_indicator_image_view_item_post_with_preview" android:id="@+id/video_or_gif_indicator_image_view_item_post_with_preview"
android:layout_width="wrap_content" android:layout_width="36dp"
android:layout_height="wrap_content" android:layout_height="36dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:layout_gravity="start" android:layout_gravity="start"
android:scaleType="center"
android:background="@drawable/play_button_round_background" android:background="@drawable/play_button_round_background"
android:src="@drawable/ic_play_circle_36dp"
android:visibility="gone" /> android:visibility="gone" />
<ProgressBar <ProgressBar