Эх сурвалжийг харах

Merge pull request #526 from owncloud/pull_down_refresh

Pull down to refresh in list of files.
David A. Velasco 11 жил өмнө
parent
commit
edb8c54e3f

+ 12 - 6
res/layout/list_fragment.xml

@@ -23,13 +23,19 @@
 	android:layout_weight="1"
 	android:orientation="vertical" >
 
-	<com.owncloud.android.ui.ExtendedListView
-        android:id="@+id/list_root"
+    <android.support.v4.widget.SwipeRefreshLayout
+        android:id="@+id/swipe_refresh_files"
         android:layout_width="match_parent"
-        android:layout_height="0dip"
-        android:layout_weight="1" 
-	/>
-    
+        android:layout_height="match_parent" >
+
+        <com.owncloud.android.ui.ExtendedListView
+            android:id="@+id/list_root"
+            android:layout_width="match_parent"
+            android:layout_height="0dip"
+            android:layout_weight="1" />
+        
+    </android.support.v4.widget.SwipeRefreshLayout>
+
     <TextView
     	android:id="@+id/empty_list_view"
         android:layout_width="match_parent"

+ 1 - 0
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -922,6 +922,7 @@ FileFragment.ContainerActivity, OnNavigationListener, OnSslUntrustedCertListener
                         removeStickyBroadcast(intent);
                         Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
                         setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
+                        
                 }
                 
                 if (synchResult != null) {

+ 49 - 2
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -25,6 +25,7 @@ import com.owncloud.android.utils.Log_OC;
 
 
 import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -36,7 +37,7 @@ import android.widget.ListView;
 /**
  *  TODO extending SherlockListFragment instead of SherlockFragment 
  */
-public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener {
+public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener{
     
     private static final String TAG = ExtendedListFragment.class.getSimpleName();
 
@@ -44,6 +45,8 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
 
     protected ExtendedListView mList;
     
+    private SwipeRefreshLayout mRefreshLayout;
+    
     public void setListAdapter(ListAdapter listAdapter) {
         mList.setAdapter(listAdapter);
         mList.invalidate();
@@ -58,6 +61,7 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         Log_OC.e(TAG, "onCreateView");
         //mList = new ExtendedListView(getActivity());
+        
         View v = inflater.inflate(R.layout.list_fragment, null);
         mList = (ExtendedListView)(v.findViewById(R.id.list_root));
         mList.setOnItemClickListener(this);
@@ -70,6 +74,14 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
             setReferencePosition(referencePosition);
         }
         
+        // Pull down refresh
+        mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files);
+        // Colors in animations: background
+        mRefreshLayout.setColorScheme(R.color.background_color, R.color.background_color, 
+                 R.color.background_color, R.color.background_color);
+        
+        mRefreshLayout.setOnRefreshListener(this);
+        
         return v;
     }
 
@@ -111,9 +123,44 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
     }
 
     @Override
-    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
+    public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
         // to be @overriden  
     }
 
+    @Override
+    public void onRefresh() {
+        // to be @overriden  
+        mRefreshLayout.setRefreshing(false);
+    }
+
+    /**
+     * Enables swipe gesture
+     */
+    public void enableSwipe() {
+        mRefreshLayout.setEnabled(true);
+    }
+ 
+    /**
+     * Disables swipe gesture. It prevents manual gestures but keeps the option you show
+     * refreshing programmatically.
+     */
+    public void disableSwipe() {
+        mRefreshLayout.setEnabled(false);
+    }
+    
+    /**
+     * It shows the SwipeRefreshLayout progress
+     */
+    public void showSwipeProgress() {
+        mRefreshLayout.setRefreshing(true);
+    }
+ 
+    /**
+     * It shows the SwipeRefreshLayout progress
+     */
+    public void hideSwipeProgress() {
+        mRefreshLayout.setRefreshing(false);
+    }
+ 
     
 }

+ 1 - 0
src/com/owncloud/android/ui/fragment/LocalFileListFragment.java

@@ -77,6 +77,7 @@ public class LocalFileListFragment extends ExtendedListFragment {
         Log_OC.i(TAG, "onCreateView() start");
         View v = super.onCreateView(inflater, container, savedInstanceState);
         getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+        disableSwipe(); // Disable pull refresh
         Log_OC.i(TAG, "onCreateView() end");
         return v;
     }    

+ 15 - 0
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -106,6 +106,7 @@ public class OCFileListFragment extends ExtendedListFragment {
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         Log_OC.e(TAG, "onActivityCreated() start");
+        
         mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity); 
                 
         if (savedInstanceState != null) {
@@ -432,5 +433,19 @@ public class OCFileListFragment extends ExtendedListFragment {
             mFile = directory;
         }
     }
+
+
+    @Override
+    public void onRefresh() {
+        super.onRefresh();
+        
+        if (mFile != null) {
+            listDirectory(mFile);
+            
+            ((FileDisplayActivity)mContainerActivity).startSyncFolderOperation(mFile);
+        }
+    }
+    
+    
     
 }

BIN
third_party/android-support-library/android-support-v4.jar