Add swipe-down-to-refresh-repos on main overview screen.

Happy to discuss whether this is a good idea or not, but right now
there is no way to update repositories so often you are left with
an empty first screen.

This doesn't worry about state management (e.g. remembering
whether we are refreshing or not and showing this when we resume the
activity). Instead, it listens for the refresh listener, and when
triggered it will set the refreshing state to not refreshing. For now
the notification can act as the feedback that something is happening.
This commit is contained in:
Peter Serwylo 2017-02-21 11:37:06 +11:00
parent 26b9e09f2f
commit 34e176539b
2 changed files with 26 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import android.os.Bundle;
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.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -12,6 +13,7 @@ import android.view.View;
import android.widget.FrameLayout;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.views.whatsnew.WhatsNewAdapter;
@ -28,7 +30,7 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
private static RecyclerView.ItemDecoration appListDecorator;
WhatsNewViewBinder(AppCompatActivity activity, FrameLayout parent) {
WhatsNewViewBinder(final AppCompatActivity activity, FrameLayout parent) {
this.activity = activity;
View whatsNewView = activity.getLayoutInflater().inflate(R.layout.main_tab_whats_new, parent, true);
@ -57,6 +59,15 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
appList.addItemDecoration(appListDecorator);
final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) whatsNewView.findViewById(R.id.swipe_to_refresh);
swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeToRefresh.setRefreshing(false);
UpdateService.updateNow(activity);
}
});
activity.getSupportLoaderManager().initLoader(LOADER_ID, null, this);
}

View File

@ -6,14 +6,21 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/app_list"
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/app_card_normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scrollbars="vertical" />
android:id="@+id/swipe_to_refresh">
<android.support.v7.widget.RecyclerView
android:id="@+id/app_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/app_card_normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>