浏览代码

Merge pull request #662 from tobiasKaminsky/fileCount

File count
jabarros 10 年之前
父节点
当前提交
0a0c808e3b

+ 18 - 0
res/layout/list_footer.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="56dp"
+    android:layout_gravity="center_horizontal"
+    android:gravity="center_horizontal"
+    android:orientation="vertical"
+    android:showDividers="none" >
+
+    <TextView
+        android:id="@+id/footerText"
+        android:layout_width="match_parent"
+        android:layout_height="56dp"
+        android:layout_gravity="center"
+        android:gravity="center"
+        android:textColor="@color/setup_text_hint" />
+
+</LinearLayout> 

+ 7 - 5
res/layout/list_fragment.xml

@@ -25,16 +25,18 @@
     <android.support.v4.widget.SwipeRefreshLayout
         android:id="@+id/swipe_refresh_files"
         android:layout_width="match_parent"
-        android:layout_height="match_parent" >
-
+        android:layout_height="match_parent" 
+        android:layout_weight="1"
+        android:footerDividersEnabled="false" > 
+        
         <com.owncloud.android.ui.ExtendedListView
             android:id="@+id/list_root"
             android:layout_width="match_parent"
             android:layout_height="match_parent" />
-        
+            
     </android.support.v4.widget.SwipeRefreshLayout>
-
-    <android.support.v4.widget.SwipeRefreshLayout
+    	
+    	<android.support.v4.widget.SwipeRefreshLayout
         android:id="@+id/swipe_refresh_files_emptyView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"

+ 4 - 0
res/values/strings.xml

@@ -66,6 +66,10 @@
     <string name="file_list_empty">Nothing in here. Upload something!</string>
     <string name="file_list_loading">Loading...</string>
     <string name="local_file_list_empty">There are no files in this folder.</string>
+    <string name="file_list_folder">folder</string>
+    <string name="file_list_folders">folders</string>
+    <string name="file_list_file">file</string>
+    <string name="file_list_files">files</string>
     <string name="filedetails_select_file">Tap on a file to display additional information.</string>
     <string name="filedetails_size">Size:</string>
     <string name="filedetails_type">Type:</string>

+ 23 - 19
src/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -38,14 +38,14 @@ import com.owncloud.android.ui.ExtendedListView;
 import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
 
 /**
- *  TODO extending SherlockListFragment instead of SherlockFragment 
+ * TODO extending SherlockListFragment instead of SherlockFragment
  */
 public class ExtendedListFragment extends SherlockFragment 
 implements OnItemClickListener, OnEnforceableRefreshListener {
-    
+
     private static final String TAG = ExtendedListFragment.class.getSimpleName();
 
-    private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION"; 
+    private static final String KEY_SAVED_LIST_POSITION = "SAVED_LIST_POSITION";
     private static final String KEY_INDEXES = "INDEXES";
     private static final String KEY_FIRST_POSITIONS= "FIRST_POSITIONS";
     private static final String KEY_TOPS = "TOPS";
@@ -53,7 +53,7 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
     private static final String KEY_EMPTY_LIST_MESSAGE = "EMPTY_LIST_MESSAGE";
 
     protected ExtendedListView mList;
-    
+
     private SwipeRefreshLayout mRefreshLayout;
     private SwipeRefreshLayout mRefreshEmptyLayout;
     private TextView mEmptyListMessage;
@@ -72,18 +72,22 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
         mList.invalidate();
     }
 
+    public void setFooterView(View footer) {
+        mList.addFooterView(footer, null, false);
+        mList.invalidate();
+    }
+
     public ListView getListView() {
         return mList;
     }
-    
-    
+
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         Log_OC.e(TAG, "onCreateView");
-        
+
         View v = inflater.inflate(R.layout.list_fragment, null);
         mEmptyListMessage = (TextView) v.findViewById(R.id.empty_list_view);
-        mList = (ExtendedListView)(v.findViewById(R.id.list_root));
+        mList = (ExtendedListView) (v.findViewById(R.id.list_root));
         mList.setOnItemClickListener(this);
 
         mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
@@ -93,7 +97,7 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
             int referencePosition = savedInstanceState.getInt(KEY_SAVED_LIST_POSITION);
             setReferencePosition(referencePosition);
         }
-        
+
         // Pull down refresh
         mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files);
         mRefreshEmptyLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files_emptyView);
@@ -106,7 +110,6 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
         return v;
     }
 
-    
     /**
      * {@inheritDoc}
      */
@@ -142,14 +145,16 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
         savedInstanceState.putString(KEY_EMPTY_LIST_MESSAGE, getEmptyViewText());
     }
 
-    
     /**
-     * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
-     * the device is turned to other position. 
+     * Calculates the position of the item that will be used as a reference to
+     * reposition the visible items in the list when the device is turned to
+     * other position.
      * 
-     * THe current policy is take as a reference the visible item in the center of the screen.  
+     * THe current policy is take as a reference the visible item in the center
+     * of the screen.
      * 
-     * @return      The position in the list of the visible item in the center of the screen.
+     * @return The position in the list of the visible item in the center of the
+     *         screen.
      */
     protected int getReferencePosition() {
         if (mList != null) {
@@ -159,11 +164,11 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
         }
     }
 
-    
     /**
      * Sets the visible part of the list from the reference position.
      * 
-     * @param   position    Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
+     * @param position Reference position previously returned by
+     *            {@link LocalFileListFragment#getReferencePosition()}
      */
     protected void setReferencePosition(int position) {
         if (mList != null) {
@@ -227,7 +232,7 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
     
     @Override
     public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
-        // to be @overriden  
+        // to be @overriden
     }
 
     @Override
@@ -240,7 +245,6 @@ implements OnItemClickListener, OnEnforceableRefreshListener {
             mOnRefreshListener.onRefresh();
         }
     }
-    
     public void setOnRefreshListener(OnEnforceableRefreshListener listener) {
         mOnRefreshListener = listener;
     }

+ 57 - 6
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -18,8 +18,10 @@
 package com.owncloud.android.ui.fragment;
 
 import java.io.File;
+import java.util.Vector;
 
 import android.app.Activity;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.support.v4.widget.SwipeRefreshLayout;
@@ -29,6 +31,8 @@ import android.view.MenuItem;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.TextView;
+import android.view.LayoutInflater;
 
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -70,6 +74,7 @@ public class OCFileListFragment extends ExtendedListFragment {
    
     private OCFile mFile = null;
     private FileListListAdapter mAdapter;
+    private View mFooterView;
     
     private OCFile mTargetFile;
 
@@ -112,24 +117,28 @@ public class OCFileListFragment extends ExtendedListFragment {
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         Log_OC.e(TAG, "onActivityCreated() start");
-        
+
         if (savedInstanceState != null) {
             mFile = savedInstanceState.getParcelable(KEY_FILE);
         }
-        
+
+        mFooterView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
+                        R.layout.list_footer, null, false);
+        setFooterView(mFooterView);
+
         Bundle args = getArguments();
         boolean justFolders = (args == null) ? false : args.getBoolean(ARG_JUST_FOLDERS, false); 
         mAdapter = new FileListListAdapter(
                 justFolders,
                 getSherlockActivity(), 
                 mContainerActivity
-        );
+                );
         setListAdapter(mAdapter);
-        
+
         registerForContextMenu(getListView());
         getListView().setOnCreateContextMenuListener(this);
-  }
-    
+    }
+
     /**
      * Saves the current listed folder.
      */
@@ -384,9 +393,51 @@ public class OCFileListFragment extends ExtendedListFragment {
                 mList.setSelectionFromTop(0, 0);
             }
             mFile = directory;
+            
+            // Update Footer
+            TextView footerText = (TextView) mFooterView.findViewById(R.id.footerText);
+            Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
+            footerText.setText(generateFooterText(directory));
+            Log_OC.d("footer", String.valueOf(System.currentTimeMillis()));
         }
     }
     
+    private String generateFooterText(OCFile directory) {
+        Integer files = 0;
+        Integer folders = 0;
+
+        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
+        Vector<OCFile> mFiles = storageManager.getFolderContent(mFile);
+
+        for (OCFile ocFile : mFiles) {
+            if (ocFile.isFolder()) {
+                folders++;
+            } else {
+                files++;
+            }
+        }
+
+        String output = "";
+       
+        if (files > 0){
+            if (files == 1) {
+                output = output + files.toString() + " " + getResources().getString(R.string.file_list_file);
+            } else {
+                output = output + files.toString() + " " + getResources().getString(R.string.file_list_files);
+            }
+        }
+        if (folders > 0 && files > 0){
+            output = output + ", ";
+        }
+        if (folders == 1) {
+            output = output + folders.toString() + " " + getResources().getString(R.string.file_list_folder);
+        } else if (folders > 1) {
+            output = output + folders.toString() + " " + getResources().getString(R.string.file_list_folders);
+        }
+        
+        return output;
+    }
+    
     public void sortByName(boolean descending) {
         mAdapter.setSortOrder(FileListListAdapter.SORT_NAME, descending);
     }