mirror of
https://github.com/sismics/docs.git
synced 2024-12-22 19:33:47 +01:00
Android: swipe refresh on documents list
This commit is contained in:
parent
1d08508e51
commit
824e37b8ea
@ -20,7 +20,6 @@ public class MainApplication extends Application {
|
||||
JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON);
|
||||
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
||||
|
||||
// TODO Documents list page loading feedback
|
||||
// TODO Fullscreen preview
|
||||
// TODO Caching preferences
|
||||
// TODO Edit sharing
|
||||
|
@ -3,6 +3,7 @@ package com.sismics.docs.fragment;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -30,11 +31,6 @@ import de.greenrobot.event.EventBus;
|
||||
* @author bgamard.
|
||||
*/
|
||||
public class DocListFragment extends Fragment {
|
||||
/**
|
||||
* Recycler view.
|
||||
*/
|
||||
private EmptyRecyclerView recyclerView;
|
||||
|
||||
/**
|
||||
* Documents adapter.
|
||||
*/
|
||||
@ -45,13 +41,17 @@ public class DocListFragment extends Fragment {
|
||||
*/
|
||||
private String query;
|
||||
|
||||
// View cache
|
||||
private EmptyRecyclerView recyclerView;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
// Infinite scrolling things
|
||||
private boolean loading = true;
|
||||
private int previousTotal = 0;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.doc_list_fragment, container, false);
|
||||
final View view = inflater.inflate(R.layout.doc_list_fragment, container, false);
|
||||
|
||||
// Configure the RecyclerView
|
||||
recyclerView = (EmptyRecyclerView) view.findViewById(R.id.docList);
|
||||
@ -65,6 +65,19 @@ public class DocListFragment extends Fragment {
|
||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
// Configure the swipe refresh layout
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
|
||||
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
|
||||
android.R.color.holo_green_light,
|
||||
android.R.color.holo_orange_light,
|
||||
android.R.color.holo_red_light);
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
loadDocuments(view, true);
|
||||
}
|
||||
});
|
||||
|
||||
// Document opening
|
||||
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
|
||||
@Override
|
||||
@ -139,7 +152,10 @@ public class DocListFragment extends Fragment {
|
||||
loading = true;
|
||||
previousTotal = 0;
|
||||
adapter.clearDocuments();
|
||||
} else {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
}
|
||||
|
||||
recyclerView.setEmptyView(progressBar);
|
||||
|
||||
DocumentResource.list(getActivity(), reset ? 0 : adapter.getItemCount(), query, new JsonHttpResponseHandler() {
|
||||
@ -160,6 +176,11 @@ public class DocListFragment extends Fragment {
|
||||
Toast.makeText(getActivity(), R.string.error_loading_documents, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,19 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.sismics.docs.ui.view.EmptyRecyclerView
|
||||
android:id="@+id/docList"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeRefreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical">
|
||||
</com.sismics.docs.ui.view.EmptyRecyclerView>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.sismics.docs.ui.view.EmptyRecyclerView
|
||||
android:id="@+id/docList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical">
|
||||
</com.sismics.docs.ui.view.EmptyRecyclerView>
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
|
Loading…
Reference in New Issue
Block a user