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

FileListListAdapter is a SimpleCursorAdapter

masensio 11 жил өмнө
parent
commit
44dae87d2f

+ 68 - 44
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -610,6 +610,30 @@ public class FileDataStorageManager {
     }
     
     
+    public Cursor getContent(long parentId) {
+        Uri req_uri = Uri.withAppendedPath(
+                ProviderTableMeta.CONTENT_URI_DIR,
+                String.valueOf(parentId));
+        Cursor c = null;
+
+        if (getContentProviderClient() != null) {
+            try {
+                c = getContentProviderClient().query(req_uri, null, 
+                        ProviderTableMeta.FILE_PARENT + "=?" ,
+                        new String[] { String.valueOf(parentId)}, null);
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, e.getMessage());
+                return c;
+            }
+        } else {
+            c = getContentResolver().query(req_uri, null, 
+                    ProviderTableMeta.FILE_PARENT + "=?" ,
+                    new String[] { String.valueOf(parentId)}, null);
+        }
+        
+        return c;
+    }
+    
     private OCFile createRootDir() {
         OCFile file = new OCFile(OCFile.ROOT_PATH);
         file.setMimetype("DIR");
@@ -674,31 +698,31 @@ public class FileDataStorageManager {
         return c;
     }
     
-    private Cursor getShareCursorForValue(String key, String value) {
-        Cursor c = null;
-        if (getContentResolver() != null) {
-            c = getContentResolver()
-                    .query(ProviderTableMeta.CONTENT_URI_SHARE,
-                            null,
-                            key + "=? AND "
-                                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
-                                    + "=?",
-                                    new String[] { value, mAccount.name }, null);
-        } else {
-            try {
-                c = getContentProviderClient().query(
-                        ProviderTableMeta.CONTENT_URI_SHARE,
-                        null,
-                        key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
-                        + "=?", new String[] { value, mAccount.name },
-                        null);
-            } catch (RemoteException e) {
-                Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
-                c = null;
-            }
-        }
-        return c;
-    }
+//    private Cursor getShareCursorForValue(String key, String value) {
+//        Cursor c = null;
+//        if (getContentResolver() != null) {
+//            c = getContentResolver()
+//                    .query(ProviderTableMeta.CONTENT_URI_SHARE,
+//                            null,
+//                            key + "=? AND "
+//                                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
+//                                    + "=?",
+//                                    new String[] { value, mAccount.name }, null);
+//        } else {
+//            try {
+//                c = getContentProviderClient().query(
+//                        ProviderTableMeta.CONTENT_URI_SHARE,
+//                        null,
+//                        key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
+//                        + "=?", new String[] { value, mAccount.name },
+//                        null);
+//            } catch (RemoteException e) {
+//                Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
+//                c = null;
+//            }
+//        }
+//        return c;
+//    }
 
     private OCFile createFileInstance(Cursor c) {
         OCFile file = null;
@@ -838,25 +862,25 @@ public class FileDataStorageManager {
         return overriden;
     }
 
-    private OCShare getShareById(long id) {
-        Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
-        OCShare share = null;
-        if (c.moveToFirst()) {
-            share = createShareInstance(c);
-        }
-        c.close();
-        return share;
-    }
-
-    private OCShare getShareByRemoteId(long remoteId) {
-        Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId));
-        OCShare share = null;
-        if (c.moveToFirst()) {
-            share = createShareInstance(c);
-        }
-        c.close();
-        return share;
-    }
+//    private OCShare getShareById(long id) {
+//        Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
+//        OCShare share = null;
+//        if (c.moveToFirst()) {
+//            share = createShareInstance(c);
+//        }
+//        c.close();
+//        return share;
+//    }
+//
+//    private OCShare getShareByRemoteId(long remoteId) {
+//        Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, String.valueOf(remoteId));
+//        OCShare share = null;
+//        if (c.moveToFirst()) {
+//            share = createShareInstance(c);
+//        }
+//        c.close();
+//        return share;
+//    }
 
     public OCShare getFirstShareByPathAndType(String path, ShareType type) {
         Cursor c = null;

+ 29 - 5
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -19,10 +19,12 @@ package com.owncloud.android.ui.adapter;
 
 import android.accounts.Account;
 import android.content.Context;
+import android.database.Cursor;
+import android.support.v4.widget.SimpleCursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.BaseAdapter;
+//import android.widget.BaseAdapter;
 import android.widget.ImageView;
 import android.widget.ListAdapter;
 import android.widget.ListView;
@@ -35,6 +37,7 @@ import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.ProviderMeta;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.ui.activity.TransferServiceGetter;
@@ -48,18 +51,39 @@ import com.owncloud.android.utils.DisplayUtils;
  * @author Bartek Przybylski
  * 
  */
-public class FileListListAdapter extends BaseAdapter implements ListAdapter {
+public class FileListListAdapter extends SimpleCursorAdapter /*BaseAdapter*/ implements ListAdapter {
+
     private Context mContext;
-    private OCFile mFile = null;
+    private static OCFile mFile = null;
     private Vector<OCFile> mFiles = null;
-    private FileDataStorageManager mStorageManager;
+    private static FileDataStorageManager mStorageManager;
     private Account mAccount;
     private TransferServiceGetter mTransferServiceGetter;
+    private static String[] cursorFrom = { ProviderMeta.ProviderTableMeta.FILE_NAME,
+        ProviderMeta.ProviderTableMeta.FILE_MODIFIED, 
+        ProviderMeta.ProviderTableMeta.FILE_CONTENT_LENGTH
+        }; 
+    private static int[] cursorTo  = { R.id.Filename, 
+        R.id.last_mod, 
+        R.id.file_size
+    };
+
+    public FileListListAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
+        super(context, layout, c, from, to, flags);
+        // TODO Auto-generated constructor stub
+    }
     
-    public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {
+    public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter, OCFile file) {
+        super(context,
+                R.layout.list_item, 
+                file == null ? null : mStorageManager.getContent(file.getParentId()),
+                cursorFrom,
+                cursorTo, 
+                0);
         mContext = context;
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
         mTransferServiceGetter = transferServiceGetter;
+        mFile = file;
     }
 
     @Override

+ 3 - 1
src/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -108,7 +108,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         Log_OC.e(TAG, "onActivityCreated() start");
-        mAdapter = new FileListListAdapter(getActivity(), mContainerActivity);
+
         if (savedInstanceState != null) {
             mFile = savedInstanceState.getParcelable(EXTRA_FILE);
             mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES);
@@ -124,6 +124,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             
         }
         
+        mAdapter = new FileListListAdapter(getActivity(), mContainerActivity, mFile);
+        
         setListAdapter(mAdapter);
         
         registerForContextMenu(getListView());