Allow swipe-to-refresh on categories and updates tab.

The swipe-to-refresh from the latest tab is now also implemented
for the categories and updates tab. It was a bit weird before how
you could swipe to refresh on the first tab, which would show
"Updating repos" at the top. It would then also show the same
message on the categories tab, but you couldn't swipe-to-refresh
that tab. Additionally, several people have requested this on the
updates tab, the tab where it probably makes the most sense.

Fix #1079.
This commit is contained in:
Peter Serwylo 2017-09-28 00:44:24 +10:00
parent 8bececfa58
commit b69a26463c
4 changed files with 134 additions and 80 deletions

View File

@ -7,6 +7,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -15,6 +16,7 @@ import android.widget.FrameLayout;
import android.widget.TextView;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.CategoryProvider;
import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.views.apps.AppListActivity;
@ -54,6 +56,16 @@ class CategoriesViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
categoriesList.setLayoutManager(new LinearLayoutManager(activity));
categoriesList.setAdapter(categoryAdapter);
final SwipeRefreshLayout swipeToRefresh =
(SwipeRefreshLayout) categoriesView.findViewById(R.id.swipe_to_refresh);
swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeToRefresh.setRefreshing(false);
UpdateService.updateNow(activity);
}
});
FloatingActionButton searchFab = (FloatingActionButton) categoriesView.findViewById(R.id.btn_search);
searchFab.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -1,5 +1,6 @@
package org.fdroid.fdroid.views.updates;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -9,6 +10,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
public class UpdatesViewBinder {
@ -17,7 +19,7 @@ public class UpdatesViewBinder {
private final TextView emptyState;
private final ImageView emptyImage;
public UpdatesViewBinder(AppCompatActivity activity, FrameLayout parent) {
public UpdatesViewBinder(final AppCompatActivity activity, FrameLayout parent) {
View view = activity.getLayoutInflater().inflate(R.layout.main_tab_updates, parent, true);
adapter = new UpdatesAdapter(activity);
@ -30,6 +32,16 @@ public class UpdatesViewBinder {
emptyState = (TextView) view.findViewById(R.id.empty_state);
emptyImage = (ImageView) view.findViewById(R.id.image);
final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_to_refresh);
swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeToRefresh.setRefreshing(false);
UpdateService.updateNow(activity);
}
});
}
public void bind() {

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
@ -7,46 +7,56 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.fdroid.fdroid.views.BannerUpdatingRepos
android:id="@+id/banner_updating_repos"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteX="8dp" />
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_to_refresh">
<TextView
android:id="@+id/empty_state"
android:layout_width="0dp"
android:layout_height="0dp"
style="@style/AppListEmptyText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
android:text="@string/categories__empty_state__no_categories" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/category_list"
android:layout_width="0dp"
android:layout_height="0dp"
tools:listitem="@layout/category_item"
app:layout_constraintTop_toBottomOf="@+id/banner_updating_repos"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:scrollbars="vertical"
tools:layout_editor_absoluteX="0dp" />
<org.fdroid.fdroid.views.BannerUpdatingRepos
android:id="@+id/banner_updating_repos"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<include layout="@layout/fab_search"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin" />
<TextView
android:id="@+id/empty_state"
android:layout_width="0dp"
android:layout_height="0dp"
style="@style/AppListEmptyText"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="gone"
android:text="@string/categories__empty_state__no_categories" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/category_list"
android:layout_width="0dp"
android:layout_height="0dp"
tools:listitem="@layout/category_item"
app:layout_constraintTop_toBottomOf="@+id/banner_updating_repos"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:scrollbars="vertical"
tools:layout_editor_absoluteX="0dp" />
<include layout="@layout/fab_search"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -1,46 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/mainTabSwapBackground">
android:id="@+id/swipe_to_refresh">
<TextView
android:id="@+id/empty_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/AppListEmptyText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"
android:text="@string/empty_can_update_app_list" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/mainTabSwapBackground">
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="@drawable/no_updates_bg"
android:importantForAccessibility="no"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/empty_state"
android:tint="?attr/mainTabSwapSplashTint"
android:scaleType="fitCenter"
android:visibility="gone" />
<org.fdroid.fdroid.views.BannerUpdatingRepos
android:id="@+id/banner_updating_repos"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
tools:listitem="@layout/app_list_item"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:scrollbars="vertical" />
<TextView
android:id="@+id/empty_state"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/AppListEmptyText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner_updating_repos"
android:visibility="gone"
android:text="@string/empty_can_update_app_list" />
</android.support.constraint.ConstraintLayout>
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="@drawable/no_updates_bg"
android:importantForAccessibility="no"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/empty_state"
android:tint="?attr/mainTabSwapSplashTint"
android:scaleType="fitCenter"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
tools:listitem="@layout/app_list_item"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner_updating_repos"
app:layout_constraintBottom_toBottomOf="parent"
android:scrollbars="vertical" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>