mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-08-18 11:03:26 +00:00
Hide toolbar icons in PostRecyclerViewAdapter when item width drops below threshold.
This commit is contained in:
@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@ -281,6 +280,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
private boolean canPlayVideo = true;
|
private boolean canPlayVideo = true;
|
||||||
private RecyclerView.RecycledViewPool mGalleryRecycledViewPool;
|
private RecyclerView.RecycledViewPool mGalleryRecycledViewPool;
|
||||||
private MultiPlayPlayerSelector multiPlayPlayerSelector;
|
private MultiPlayPlayerSelector multiPlayPlayerSelector;
|
||||||
|
private int itemWidth;
|
||||||
|
|
||||||
// postHistorySharedPreferences will be null when being used in HistoryPostFragment.
|
// postHistorySharedPreferences will be null when being used in HistoryPostFragment.
|
||||||
public PostRecyclerViewAdapter(BaseActivity activity, PostFragmentBase fragment, RedditDataRoomDatabase redditDataRoomDatabase,
|
public PostRecyclerViewAdapter(BaseActivity activity, PostFragmentBase fragment, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
@ -1190,6 +1190,48 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
|
|
||||||
mCallback.currentlyBindItem(holder.getBindingAdapterPosition());
|
mCallback.currentlyBindItem(holder.getBindingAdapterPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (itemWidth < 250) {
|
||||||
|
if (((PostViewHolder) holder).commentsCountButton != null) {
|
||||||
|
((PostViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).saveButton != null) {
|
||||||
|
((PostViewHolder) holder).saveButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).shareButton != null) {
|
||||||
|
((PostViewHolder) holder).shareButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
} else if (itemWidth < 316) {
|
||||||
|
if (((PostViewHolder) holder).commentsCountButton != null) {
|
||||||
|
((PostViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).saveButton != null) {
|
||||||
|
((PostViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).shareButton != null) {
|
||||||
|
((PostViewHolder) holder).shareButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
} else if (itemWidth < 420) {
|
||||||
|
if (((PostViewHolder) holder).commentsCountButton != null) {
|
||||||
|
((PostViewHolder) holder).commentsCountButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).saveButton != null) {
|
||||||
|
((PostViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).shareButton != null) {
|
||||||
|
((PostViewHolder) holder).shareButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (((PostViewHolder) holder).commentsCountButton != null) {
|
||||||
|
((PostViewHolder) holder).commentsCountButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).saveButton != null) {
|
||||||
|
((PostViewHolder) holder).saveButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
if (((PostViewHolder) holder).shareButton != null) {
|
||||||
|
((PostViewHolder) holder).shareButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (holder instanceof PostGalleryViewHolder) {
|
} else if (holder instanceof PostGalleryViewHolder) {
|
||||||
Post post = getItem(position);
|
Post post = getItem(position);
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
@ -1971,6 +2013,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
this.canPlayVideo = canPlayVideo;
|
this.canPlayVideo = canPlayVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void provideItemWidth(int width) {
|
||||||
|
itemWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract class PostViewHolder extends RecyclerView.ViewHolder {
|
public abstract class PostViewHolder extends RecyclerView.ViewHolder {
|
||||||
AspectRatioGifImageView iconGifImageView;
|
AspectRatioGifImageView iconGifImageView;
|
||||||
ImageView stickiedPostImageView;
|
ImageView stickiedPostImageView;
|
||||||
|
|||||||
@ -154,6 +154,8 @@ public abstract class PostFragmentBase extends Fragment {
|
|||||||
protected AdjustableTouchSlopItemTouchHelper touchHelper;
|
protected AdjustableTouchSlopItemTouchHelper touchHelper;
|
||||||
private boolean shouldSwipeBack;
|
private boolean shouldSwipeBack;
|
||||||
protected final Map<String, String> subredditOrUserIcons = new HashMap<>();
|
protected final Map<String, String> subredditOrUserIcons = new HashMap<>();
|
||||||
|
private View.OnLayoutChangeListener onLayoutChangeListener;
|
||||||
|
private int recyclerViewWidth;
|
||||||
|
|
||||||
public PostFragmentBase() {
|
public PostFragmentBase() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@ -322,6 +324,26 @@ public abstract class PostFragmentBase extends Fragment {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onLayoutChangeListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
|
||||||
|
int width = right - left;
|
||||||
|
if (recyclerViewWidth == width) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
recyclerViewWidth = width;
|
||||||
|
PostRecyclerViewAdapter adapter = getPostAdapter();
|
||||||
|
if (adapter != null) {
|
||||||
|
if (mStaggeredGridLayoutManager != null) {
|
||||||
|
width /= mStaggeredGridLayoutManager.getSpanCount();
|
||||||
|
}
|
||||||
|
int finalWidth = width;
|
||||||
|
v.post(() -> {
|
||||||
|
adapter.provideItemWidth(Utils.convertPxToDp(finalWidth, mActivity));
|
||||||
|
refreshAdapter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
getPostRecyclerView().addOnLayoutChangeListener(onLayoutChangeListener);
|
||||||
|
|
||||||
SharedPreferencesLiveDataKt.stringLiveData(mSharedPreferences, SharedPreferencesUtils.LONG_PRESS_POST_NON_MEDIA_AREA, SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS).observe(getViewLifecycleOwner(), s -> {
|
SharedPreferencesLiveDataKt.stringLiveData(mSharedPreferences, SharedPreferencesUtils.LONG_PRESS_POST_NON_MEDIA_AREA, SharedPreferencesUtils.LONG_PRESS_POST_VALUE_SHOW_POST_OPTIONS).observe(getViewLifecycleOwner(), s -> {
|
||||||
if (getPostAdapter() != null) {
|
if (getPostAdapter() != null) {
|
||||||
getPostAdapter().setLongPressPostNonMediaAreaAction(s);
|
getPostAdapter().setLongPressPostNonMediaAreaAction(s);
|
||||||
@ -355,6 +377,15 @@ public abstract class PostFragmentBase extends Fragment {
|
|||||||
ViewCompat.requestApplyInsets(view);
|
ViewCompat.requestApplyInsets(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
if (onLayoutChangeListener != null) {
|
||||||
|
getPostRecyclerView().removeOnLayoutChangeListener(onLayoutChangeListener);
|
||||||
|
onLayoutChangeListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
|
|||||||
@ -462,6 +462,11 @@ public final class Utils {
|
|||||||
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int convertPxToDp(int px, Context context) {
|
||||||
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||||
|
return Math.round(px / (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Drawable getTintedDrawable(Context context, int drawableId, int color) {
|
public static Drawable getTintedDrawable(Context context, int drawableId, int color) {
|
||||||
final Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
|
final Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
|
||||||
|
|||||||
Reference in New Issue
Block a user