mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-06 14:44:53 +01:00
Remove code related to NetworkState in PostRecyclerViewAdapter.
This commit is contained in:
parent
a725f7eb3a
commit
a239eec17c
@ -73,7 +73,6 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
|
|||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
|
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
|
||||||
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
|
||||||
import ml.docilealligator.infinityforreddit.NetworkState;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.SaveThing;
|
import ml.docilealligator.infinityforreddit.SaveThing;
|
||||||
import ml.docilealligator.infinityforreddit.VoteThing;
|
import ml.docilealligator.infinityforreddit.VoteThing;
|
||||||
@ -111,8 +110,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 6;
|
private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 6;
|
||||||
private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 7;
|
private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 7;
|
||||||
private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 8;
|
private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 8;
|
||||||
private static final int VIEW_TYPE_ERROR = 9;
|
|
||||||
private static final int VIEW_TYPE_LOADING = 10;
|
|
||||||
|
|
||||||
private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() {
|
private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() {
|
||||||
@Override
|
@Override
|
||||||
@ -209,7 +206,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
private boolean mHideTheNumberOfVotes;
|
private boolean mHideTheNumberOfVotes;
|
||||||
private boolean mHideTheNumberOfComments;
|
private boolean mHideTheNumberOfComments;
|
||||||
private Drawable mCommentIcon;
|
private Drawable mCommentIcon;
|
||||||
private NetworkState networkState;
|
|
||||||
private ExoCreator mExoCreator;
|
private ExoCreator mExoCreator;
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
|
|
||||||
@ -342,14 +338,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
// Reached at the end
|
|
||||||
if (hasExtraRow() && position == getItemCount() - 1) {
|
|
||||||
if (networkState.getStatus() == NetworkState.Status.LOADING) {
|
|
||||||
return VIEW_TYPE_LOADING;
|
|
||||||
} else {
|
|
||||||
return VIEW_TYPE_ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_CARD) {
|
if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_CARD) {
|
||||||
Post post = getItem(position);
|
Post post = getItem(position);
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
@ -433,7 +421,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
return VIEW_TYPE_POST_CARD_2_TEXT_TYPE;
|
return VIEW_TYPE_POST_CARD_2_TEXT_TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
@ -459,12 +446,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
return new PostCard2VideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_video_autoplay, parent, false));
|
return new PostCard2VideoAutoplayViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_video_autoplay, parent, false));
|
||||||
} else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE) {
|
} else if (viewType == VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE) {
|
||||||
return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false));
|
return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false));
|
||||||
} else if (viewType == VIEW_TYPE_POST_CARD_2_TEXT_TYPE) {
|
|
||||||
return new PostCard2TextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_text, parent, false));
|
|
||||||
} else if (viewType == VIEW_TYPE_ERROR) {
|
|
||||||
return new ErrorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_error, parent, false));
|
|
||||||
} else {
|
} else {
|
||||||
return new LoadingViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_footer_loading, parent, false));
|
//VIEW_TYPE_POST_CARD_2_TEXT_TYPE
|
||||||
|
return new PostCard2TextTypeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_text, parent, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1679,14 +1663,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
shareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), shareLinkBottomSheetFragment.getTag());
|
shareLinkBottomSheetFragment.show(mActivity.getSupportFragmentManager(), shareLinkBottomSheetFragment.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
if (hasExtraRow()) {
|
|
||||||
return super.getItemCount() + 1;
|
|
||||||
}
|
|
||||||
return super.getItemCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Post getItemByPosition(int position) {
|
public Post getItemByPosition(int position) {
|
||||||
if (position >= 0 && super.getItemCount() > position) {
|
if (position >= 0 && super.getItemCount() > position) {
|
||||||
@ -1755,34 +1731,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasExtraRow() {
|
|
||||||
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNetworkState(NetworkState newNetworkState) {
|
|
||||||
NetworkState previousState = this.networkState;
|
|
||||||
boolean previousExtraRow = hasExtraRow();
|
|
||||||
this.networkState = newNetworkState;
|
|
||||||
boolean newExtraRow = hasExtraRow();
|
|
||||||
if (previousExtraRow != newExtraRow) {
|
|
||||||
if (previousExtraRow) {
|
|
||||||
notifyItemRemoved(getItemCount() - 1);
|
|
||||||
} else {
|
|
||||||
notifyItemInserted(super.getItemCount());
|
|
||||||
}
|
|
||||||
} else if (newExtraRow && !previousState.equals(newNetworkState)) {
|
|
||||||
notifyItemChanged(getItemCount() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeFooter() {
|
|
||||||
if (hasExtraRow()) {
|
|
||||||
notifyItemRemoved(getItemCount() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
networkState = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutoplay(boolean autoplay) {
|
public void setAutoplay(boolean autoplay) {
|
||||||
mAutoplay = autoplay;
|
mAutoplay = autoplay;
|
||||||
}
|
}
|
||||||
@ -4372,33 +4320,4 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
divider.setBackgroundColor(mDividerColor);
|
divider.setBackgroundColor(mDividerColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ErrorViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
@BindView(R.id.error_text_view_item_footer_error)
|
|
||||||
TextView errorTextView;
|
|
||||||
@BindView(R.id.retry_button_item_footer_error)
|
|
||||||
Button retryButton;
|
|
||||||
|
|
||||||
ErrorViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
ButterKnife.bind(this, itemView);
|
|
||||||
errorTextView.setText(R.string.load_more_posts_error);
|
|
||||||
errorTextView.setTextColor(mSecondaryTextColor);
|
|
||||||
retryButton.setOnClickListener(view -> mCallback.retryLoadingMore());
|
|
||||||
retryButton.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme));
|
|
||||||
retryButton.setTextColor(mButtonTextColor);
|
|
||||||
itemView.setOnClickListener(view -> retryButton.performClick());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class LoadingViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
@BindView(R.id.progress_bar_item_footer_loading)
|
|
||||||
ProgressBar progressBar;
|
|
||||||
|
|
||||||
LoadingViewHolder(@NonNull View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
ButterKnife.bind(this, itemView);
|
|
||||||
progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
private boolean isLazyModePaused = false;
|
private boolean isLazyModePaused = false;
|
||||||
private boolean hasPost = false;
|
private boolean hasPost = false;
|
||||||
private boolean isShown = false;
|
private boolean isShown = false;
|
||||||
private boolean isInitialRefreshingStarted = false;
|
|
||||||
private boolean savePostFeedScrolledPosition;
|
private boolean savePostFeedScrolledPosition;
|
||||||
private boolean rememberMutingOptionInPostFeed;
|
private boolean rememberMutingOptionInPostFeed;
|
||||||
private Boolean masterMutingOption;
|
private Boolean masterMutingOption;
|
||||||
@ -1184,7 +1183,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
mAdapter.addLoadStateListener(combinedLoadStates -> {
|
mAdapter.addLoadStateListener(combinedLoadStates -> {
|
||||||
LoadState refreshLoadState = combinedLoadStates.getRefresh();
|
LoadState refreshLoadState = combinedLoadStates.getRefresh();
|
||||||
LoadState appendLoadState = combinedLoadStates.getAppend();
|
|
||||||
|
|
||||||
mSwipeRefreshLayout.setRefreshing(refreshLoadState instanceof LoadState.Loading);
|
mSwipeRefreshLayout.setRefreshing(refreshLoadState instanceof LoadState.Loading);
|
||||||
if (refreshLoadState instanceof LoadState.NotLoading) {
|
if (refreshLoadState instanceof LoadState.NotLoading) {
|
||||||
@ -1205,35 +1203,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(mCustomThemeWrapper, R.string.load_more_posts_error,
|
mPostRecyclerView.setAdapter(mAdapter.withLoadStateFooter(new Paging3LoadingStateAdapter(mCustomThemeWrapper, R.string.load_more_posts_error,
|
||||||
view -> mAdapter.retry())));
|
view -> mAdapter.retry())));
|
||||||
|
|
||||||
/*mPostViewModel.hasPost().observe(getViewLifecycleOwner(), hasPost -> {
|
|
||||||
this.hasPost = hasPost;
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
|
||||||
if (hasPost) {
|
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
if (isInLazyMode) {
|
|
||||||
stopLazyMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
mFetchPostInfoLinearLayout.setOnClickListener(null);
|
|
||||||
showErrorView(R.string.no_posts);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mPostViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
|
|
||||||
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
|
||||||
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
|
||||||
mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh());
|
|
||||||
showErrorView(R.string.load_posts_error);
|
|
||||||
} else {
|
|
||||||
mSwipeRefreshLayout.setRefreshing(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mPostViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState));*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSortType(SortType sortType) {
|
public void changeSortType(SortType sortType) {
|
||||||
@ -1278,7 +1247,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
mGlide.clear(mFetchPostInfoImageView);
|
mGlide.clear(mFetchPostInfoImageView);
|
||||||
}
|
}
|
||||||
mAdapter.removeFooter();
|
|
||||||
hasPost = false;
|
hasPost = false;
|
||||||
if (isInLazyMode) {
|
if (isInLazyMode) {
|
||||||
stopLazyMode();
|
stopLazyMode();
|
||||||
@ -1356,7 +1324,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mAdapter.removeFooter();
|
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
hasPost = false;
|
hasPost = false;
|
||||||
if (isInLazyMode) {
|
if (isInLazyMode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user