mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +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);
|
JSONObject json = PreferenceUtil.getCachedJson(getApplicationContext(), PreferenceUtil.PREF_CACHED_USER_INFO_JSON);
|
||||||
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
||||||
|
|
||||||
// TODO Documents list page loading feedback
|
|
||||||
// TODO Fullscreen preview
|
// TODO Fullscreen preview
|
||||||
// TODO Caching preferences
|
// TODO Caching preferences
|
||||||
// TODO Edit sharing
|
// TODO Edit sharing
|
||||||
|
@ -3,6 +3,7 @@ package com.sismics.docs.fragment;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -30,11 +31,6 @@ import de.greenrobot.event.EventBus;
|
|||||||
* @author bgamard.
|
* @author bgamard.
|
||||||
*/
|
*/
|
||||||
public class DocListFragment extends Fragment {
|
public class DocListFragment extends Fragment {
|
||||||
/**
|
|
||||||
* Recycler view.
|
|
||||||
*/
|
|
||||||
private EmptyRecyclerView recyclerView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Documents adapter.
|
* Documents adapter.
|
||||||
*/
|
*/
|
||||||
@ -45,13 +41,17 @@ public class DocListFragment extends Fragment {
|
|||||||
*/
|
*/
|
||||||
private String query;
|
private String query;
|
||||||
|
|
||||||
|
// View cache
|
||||||
|
private EmptyRecyclerView recyclerView;
|
||||||
|
private SwipeRefreshLayout swipeRefreshLayout;
|
||||||
|
|
||||||
// Infinite scrolling things
|
// Infinite scrolling things
|
||||||
private boolean loading = true;
|
private boolean loading = true;
|
||||||
private int previousTotal = 0;
|
private int previousTotal = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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
|
// Configure the RecyclerView
|
||||||
recyclerView = (EmptyRecyclerView) view.findViewById(R.id.docList);
|
recyclerView = (EmptyRecyclerView) view.findViewById(R.id.docList);
|
||||||
@ -65,6 +65,19 @@ public class DocListFragment extends Fragment {
|
|||||||
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
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
|
// Document opening
|
||||||
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
|
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -139,7 +152,10 @@ public class DocListFragment extends Fragment {
|
|||||||
loading = true;
|
loading = true;
|
||||||
previousTotal = 0;
|
previousTotal = 0;
|
||||||
adapter.clearDocuments();
|
adapter.clearDocuments();
|
||||||
|
} else {
|
||||||
|
swipeRefreshLayout.setRefreshing(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerView.setEmptyView(progressBar);
|
recyclerView.setEmptyView(progressBar);
|
||||||
|
|
||||||
DocumentResource.list(getActivity(), reset ? 0 : adapter.getItemCount(), query, new JsonHttpResponseHandler() {
|
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();
|
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_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.sismics.docs.ui.view.EmptyRecyclerView
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/docList"
|
android:id="@+id/swipeRefreshLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:scrollbars="vertical">
|
|
||||||
</com.sismics.docs.ui.view.EmptyRecyclerView>
|
<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
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
|
Loading…
Reference in New Issue
Block a user