Re-added paged feed button

This commit is contained in:
ByteHamster 2020-03-17 14:23:16 +01:00
parent 8d2a188eda
commit 7db3da273a
3 changed files with 59 additions and 46 deletions

View File

@ -87,7 +87,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
private static final String ARGUMENT_FEED_ID = "argument.de.danoeh.antennapod.feed_id";
private FeedItemListAdapter adapter;
private MoreContentListFooterUtil listFooter;
private MoreContentListFooterUtil nextPageLoader;
private ProgressBar progressBar;
private RecyclerView recyclerView;
@ -179,6 +179,33 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
}
};
appBar.addOnOffsetChangedListener(iconTintManager);
nextPageLoader = new MoreContentListFooterUtil(root.findViewById(R.id.more_content_list_footer));
nextPageLoader.setClickListener(() -> {
if (feed != null) {
try {
DBTasks.loadNextPageOfFeed(getActivity(), feed, false);
} catch (DownloadRequestException e) {
e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage());
}
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int deltaX, int deltaY) {
super.onScrolled(recyclerView, deltaX, deltaY);
int visibleEpisodeCount = recyclerView.getChildCount();
int totalEpisodeCount = recyclerView.getLayoutManager().getItemCount();
int firstVisibleEpisode = layoutManager.findFirstVisibleItemPosition();
boolean isAtBottom = (totalEpisodeCount - visibleEpisodeCount) <= (firstVisibleEpisode + 3);
boolean hasMorePages = feed != null && feed.isPaged() && feed.getNextPageLink() != null;
nextPageLoader.getRoot().setVisibility((isAtBottom && hasMorePages) ? View.VISIBLE : View.GONE);
}
});
EventBus.getDefault().register(this);
loadItems();
return root;
@ -193,7 +220,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
disposable.dispose();
}
adapter = null;
listFooter = null;
}
private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = new MenuItemUtils.UpdateRefreshMenuItemChecker() {
@ -390,9 +416,10 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
if (isUpdatingFeed != updateRefreshMenuItemChecker.isRefreshing()) {
getActivity().supportInvalidateOptionsMenu();
}
if (listFooter != null) {
listFooter.setLoadingState(DownloadRequester.getInstance().isDownloadingFeeds());
if (!DownloadRequester.getInstance().isDownloadingFeeds()) {
nextPageLoader.getRoot().setVisibility(View.GONE);
}
nextPageLoader.setLoadingState(DownloadRequester.getInstance().isDownloadingFeeds());
}
private void displayList() {
@ -402,7 +429,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
}
if (adapter == null) {
recyclerView.setAdapter(null);
setupFooterView();
adapter = new FeedItemListAdapter((MainActivity) getActivity());
recyclerView.setAdapter(adapter);
}
@ -411,10 +437,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
adapter.updateItems(feed.getItems());
getActivity().supportInvalidateOptionsMenu();
/*if (feed != null && feed.getNextPageLink() == null && listFooter != null) {
listView.removeFooterView(listFooter.getRoot());
}*/
updateProgressBarVisibility();
}
private void refreshHeaderView() {
@ -496,31 +519,6 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
.into(imgvCover);
}
private void setupFooterView() {
if (recyclerView == null || feed == null) {
Log.e(TAG, "Unable to setup listview: recyclerView = null or feed = null");
return;
}
if (feed.isPaged() && feed.getNextPageLink() != null) {
LayoutInflater inflater = (LayoutInflater)
getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View footer = inflater.inflate(R.layout.more_content_list_footer, null, false);
//adapter.setFooterView(footer);
listFooter = new MoreContentListFooterUtil(footer);
listFooter.setClickListener(() -> {
if (feed != null) {
try {
DBTasks.loadNextPageOfFeed(getActivity(), feed, false);
} catch (DownloadRequestException e) {
e.printStackTrace();
DownloadRequestErrorDialogCreator.newRequestErrorDialog(getActivity(), e.getMessage());
}
}
});
}
}
private void loadItems() {
if (disposable != null) {
disposable.dispose();

View File

@ -59,4 +59,11 @@
android:indeterminateOnly="true"
android:visibility="gone"/>
<include
layout="@layout/more_content_list_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="gone"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -1,28 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:id="@+id/more_content_list_footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground">
android:layout_height="wrap_content"
android:foreground="?attr/selectableItemBackground"
android:background="?android:attr/windowBackground"
android:gravity="center"
android:padding="8dp">
<ImageView
android:id="@+id/imgExpand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center"
android:layout_margin="16dp"
android:contentDescription="@string/load_next_page_label"
app:srcCompat="?attr/ic_load_more" />
<ProgressBar
android:id="@+id/progBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:layout_width="16dp"
android:layout_height="16dp"
android:indeterminateOnly="true"
android:visibility="gone" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/load_next_page_label"
android:textColor="?android:attr/textColorPrimary"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"/>
</LinearLayout>