Merge branch 'develop' into refactor_update_filelist_from_database
authormasensio <masensio@solidgear.es>
Mon, 5 May 2014 06:48:19 +0000 (08:48 +0200)
committermasensio <masensio@solidgear.es>
Mon, 5 May 2014 06:48:19 +0000 (08:48 +0200)
15 files changed:
owncloud-android-library
src/com/owncloud/android/datamodel/FileDataStorageManager.java
src/com/owncloud/android/datamodel/FileListCursorLoader.java [new file with mode: 0644]
src/com/owncloud/android/providers/FileContentProvider.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java
src/com/owncloud/android/ui/activity/UploadFilesActivity.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/ui/dialog/ConfirmationDialogFragment.java [new file with mode: 0644]
src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java [deleted file]
src/com/owncloud/android/ui/fragment/FileDetailFragment.java
src/com/owncloud/android/ui/fragment/OCFileListFragment.java
src/com/owncloud/android/ui/preview/FileDownloadFragment.java
src/com/owncloud/android/ui/preview/PreviewImageActivity.java
src/com/owncloud/android/ui/preview/PreviewImageFragment.java
src/com/owncloud/android/ui/preview/PreviewMediaFragment.java

index 796189a..2157723 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 796189a04d5af05448993054a988658080128b20
+Subproject commit 2157723124a15dffb0a142c25e4ca706558acc48
index f132d96..39b1959 100644 (file)
@@ -33,7 +33,6 @@ import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
 
-
 import android.accounts.Account;
 import android.content.ContentProviderClient;
 import android.content.ContentProviderOperation;
@@ -610,6 +609,35 @@ public class FileDataStorageManager {
     }
     
     
+    public Cursor getContent(long parentId) {
+        Log_OC.d(TAG, "getContent start");
+        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);
+            
+            //Log_OC.d(TAG, "getContent Uri " + req_uri);
+            //c.setNotificationUri(getContentResolver(), req_uri);
+        }
+        
+        Log_OC.d(TAG, "getContent end");
+        return c;
+    }
+    
     private OCFile createRootDir() {
         OCFile file = new OCFile(OCFile.ROOT_PATH);
         file.setMimetype("DIR");
@@ -674,33 +702,33 @@ 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) {
+    public OCFile createFileInstance(Cursor c) {
         OCFile file = null;
         if (c != null) {
             file = new OCFile(c.getString(c
@@ -838,25 +866,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;
@@ -1301,4 +1329,5 @@ public class FileDataStorageManager {
             */
         //}
     }
+    
 }
diff --git a/src/com/owncloud/android/datamodel/FileListCursorLoader.java b/src/com/owncloud/android/datamodel/FileListCursorLoader.java
new file mode 100644 (file)
index 0000000..20039ee
--- /dev/null
@@ -0,0 +1,76 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012-2014 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.datamodel;
+
+import com.owncloud.android.utils.Log_OC;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.support.v4.content.CursorLoader;
+
+/**
+ * CursorLoader for FileList
+ * 
+ * @author masensio
+ *
+ */
+public class FileListCursorLoader extends CursorLoader {
+
+    private static final String TAG = CursorLoader.class.getSimpleName();
+    
+    private long mParentId;
+    private FileDataStorageManager mStorageManager;
+    
+    public FileListCursorLoader(Context context) {
+        super(context);
+        // TODO Auto-generated constructor stub
+    }
+
+    public FileListCursorLoader(Context context, Uri uri, String[] projection, String selection,
+            String[] selectionArgs, String sortOrder) {
+        super(context, uri, projection, selection, selectionArgs, sortOrder);
+        // TODO Auto-generated constructor stub
+    }
+    
+    public FileListCursorLoader(Context context, FileDataStorageManager storageManager) {
+        super(context);
+        mStorageManager = storageManager;
+    }
+    
+    public void setParentId(long parentId) {
+        mParentId = parentId;
+    }
+    public long getParentId(){
+        return mParentId;
+    }
+    
+    public void setStorageManager(FileDataStorageManager storageManager) {
+        mStorageManager = storageManager;
+    }
+    
+    @Override
+    public Cursor loadInBackground() {
+        Log_OC.d(TAG, "loadInBackgroud");
+        Cursor cursor = null;
+        if (mStorageManager != null) {
+            cursor = mStorageManager.getContent(mParentId);
+        }
+        return cursor;
+    }
+}
\ No newline at end of file
index 54e67a2..f76ae94 100644 (file)
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import com.owncloud.android.R;
 import com.owncloud.android.db.ProviderMeta;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
+import com.owncloud.android.lib.resources.files.FileUtils;
 import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.utils.Log_OC;
 
@@ -99,6 +100,8 @@ public class FileContentProvider extends ContentProvider {
     private static final int DIRECTORY = 2;
     private static final int ROOT_DIRECTORY = 3;
     private static final int SHARES = 4;
+
+    private static final String TAG = FileContentProvider.class.getSimpleName();
     
     // Projection for ocshares table
     private static HashMap<String, String> mOCSharesProjectionMap;
@@ -139,20 +142,57 @@ public class FileContentProvider extends ContentProvider {
     
     @Override
     public int delete(Uri uri, String where, String[] whereArgs) {
-        //Log_OC.d(TAG, "Deleting " + uri + " at provider " + this);
+        Log_OC.d(TAG, "Deleting " + uri + " at provider " + this);
         int count = 0;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
+        
+        // Get parentId to notify the change
+        long parentId = getParentId(uri);
+        
+        // Delete action
         try {
             count = delete(db, uri, where, whereArgs);
             db.setTransactionSuccessful();
         } finally {
             db.endTransaction();
         }
+        Log_OC.d(TAG, "Uri " + uri);
         getContext().getContentResolver().notifyChange(uri, null);
+        
+        // Notify the change to the parent folder
+        notifyChangeToParentUri(parentId);
         return count;
     }
     
+    private long getParentId(Uri uri) {
+        long parentId = -1;
+        
+        if (mUriMatcher.match(uri) == SINGLE_FILE || mUriMatcher.match(uri) == DIRECTORY) {
+            String fileId = uri.toString().substring(uri.toString().lastIndexOf(FileUtils.PATH_SEPARATOR) + 1);
+            Uri selectFileUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, fileId);
+            String[] fileProjection = new String[] { ProviderTableMeta.FILE_PARENT };
+            Cursor fileCursor = query(selectFileUri, fileProjection, null, null, null);
+            
+            if (fileCursor != null  && fileCursor.moveToFirst()) {
+                parentId = fileCursor.getLong(fileCursor.getColumnIndex(ProviderTableMeta.FILE_PARENT));
+            }
+            fileCursor.close();
+        }
+        Log_OC.d(TAG, "getParentId = " + parentId);
+        return parentId;
+    }
+    
+    private void notifyChangeToParentUri(long parentId) {
+        if (parentId != -1) {
+            Uri parentUri = Uri.withAppendedPath(
+                    ProviderTableMeta.CONTENT_URI_DIR, 
+                    String.valueOf(parentId));
+            Log_OC.d(TAG, "ParentUri " + parentUri);
+            getContext().getContentResolver().notifyChange(parentUri, null);
+        }
+    }
+    
     private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
         int count = 0;
         switch (mUriMatcher.match(uri)) {
@@ -250,9 +290,12 @@ public class FileContentProvider extends ContentProvider {
     @Override
     public Uri insert(Uri uri, ContentValues values) {
         //Log_OC.d(TAG, "Inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
+        Log_OC.d(TAG, "Uri " + uri);
         Uri newUri = null;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
+        
+        // Insert action
         try {
             newUri = insert(db, uri, values);
             db.setTransactionSuccessful();
@@ -260,6 +303,12 @@ public class FileContentProvider extends ContentProvider {
             db.endTransaction();
         }
         getContext().getContentResolver().notifyChange(newUri, null);
+        
+        // Get parentId to notify the change
+        long parentId = getParentId(newUri);
+        // Notify the change to the parent folder
+        notifyChangeToParentUri(parentId);
+        
         return newUri;
     }
     
@@ -414,6 +463,7 @@ public class FileContentProvider extends ContentProvider {
         // DB case_sensitive
         db.execSQL("PRAGMA case_sensitive_like = true");
         Cursor c = sqlQuery.query(db, projection, selection, selectionArgs, null, null, order);
+        Log_OC.d(TAG, "setting notification URI: " + uri);
         c.setNotificationUri(getContext().getContentResolver(), uri);
         return c;
     }
@@ -421,7 +471,8 @@ public class FileContentProvider extends ContentProvider {
     @Override
     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         
-        //Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
+        Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
+        Log_OC.d(TAG, "Uri " + uri);
         int count = 0;
         SQLiteDatabase db = mDbHelper.getWritableDatabase();
         db.beginTransaction();
@@ -432,6 +483,12 @@ public class FileContentProvider extends ContentProvider {
             db.endTransaction();
         }
         getContext().getContentResolver().notifyChange(uri, null);
+        
+     // Get parentId to notify the change
+        long parentId = getParentId(uri);
+        // Notify the change to the parent folder
+        notifyChangeToParentUri(parentId);
+        
         return count;
     }
     
index f6136ed..c594717 100644 (file)
@@ -215,7 +215,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     protected void onStart() {
         super.onStart();
         getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId());
+        /*
         refeshListOfFilesFragment();
+        */
     }
 
     @Override
@@ -416,12 +418,14 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         updateNavigationElementsInActionBar(null);
     }
 
+    /* TODO WIP COMMENT 
     protected void refeshListOfFilesFragment() {
         OCFileListFragment fileListFragment = getListOfFilesFragment();
         if (fileListFragment != null) { 
             fileListFragment.listDirectory();
         }
     }
+    */
 
     protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
         FileFragment secondFragment = getSecondFragment();
@@ -940,13 +944,15 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                                 cleanSecondFragment();
                                 currentFile = currentDir;
                             }
-                        
+
+                            /* TODO WIP COMMENT 
                             if (synchFolderRemotePath != null && currentDir.getRemotePath().equals(synchFolderRemotePath)) {
                                 OCFileListFragment fileListFragment = getListOfFilesFragment();
                                 if (fileListFragment != null) {
                                     fileListFragment.listDirectory(currentDir);
                                 }
                             }
+                            */
                             setFile(currentFile);
                         }
                         
@@ -999,7 +1005,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             OCFile currentDir = getCurrentDir();
             boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) && (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
             if (sameAccount && isDescendant) {
+                /*
                 refeshListOfFilesFragment();
+                */
             }
         }
 
@@ -1020,7 +1028,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
             boolean isDescendant = isDescendant(downloadedRemotePath);
 
             if (sameAccount && isDescendant) {
+                /* TODO WIP COMMENT 
                 refeshListOfFilesFragment();
+                */
                 refreshSecondFragment(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
             }
 
@@ -1069,7 +1079,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 if (getAccount() != null && account.name.equals(getAccount().name)
                         && getStorageManager() != null
                         ) {
+                    /*
                     refeshListOfFilesFragment();
+                    */
                 }
                 if ((getSharesResult != null) &&
                         RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(getSharesResult.getCode())) {
@@ -1224,10 +1236,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     /**
      * {@inheritDoc}
      */
+    
     @Override
     public void onFileStateChanged() {
+        /* TODO WIP COMMENT 
         refeshListOfFilesFragment();
         updateNavigationElementsInActionBar(getSecondFragment().getFile());
+        */
     }
 
 
@@ -1362,7 +1377,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) {
         if (result.isSuccess()) {
             refreshShowDetails();
+            /* TODO WIP COMMENT 
             refeshListOfFilesFragment();
+            */
         }
     }
 
@@ -1370,10 +1387,14 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
         if (result.isSuccess()) {
             refreshShowDetails();
+            /*
             refeshListOfFilesFragment();
+            */
         } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
             cleanSecondFragment();
+            /*
             refeshListOfFilesFragment();
+            */
         }
     }
     
@@ -1413,7 +1434,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 cleanSecondFragment();
             }
             if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
+                /*
                 refeshListOfFilesFragment();
+                */
             }
 
         } else {
@@ -1435,7 +1458,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     private void onCreateFolderOperationFinish(CreateFolderOperation operation, RemoteOperationResult result) {
         if (result.isSuccess()) {
             dismissLoadingDialog();
+            /* TODO WIP COMMENT 
             refeshListOfFilesFragment();
+            */
 
         } else {
             dismissLoadingDialog();
@@ -1472,7 +1497,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
                 }
             }
             if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())) {
+                /*
                 refeshListOfFilesFragment();
+                */
             }
 
         } else {
@@ -1509,7 +1536,9 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
         } else {
             if (operation.transferWasRequested()) {
+                /*
                 refeshListOfFilesFragment();
+                */
                 onTransferStateChanged(syncedFile, true, true);
 
             } else {
index 8b4a41d..db0802b 100644 (file)
@@ -36,10 +36,10 @@ import com.actionbarsherlock.app.ActionBar;
 import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
 import com.actionbarsherlock.view.MenuItem;
 import com.owncloud.android.R;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
-import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
 import com.owncloud.android.ui.fragment.LocalFileListFragment;
-import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
index 11449af..7af4832 100644 (file)
@@ -19,18 +19,17 @@ package com.owncloud.android.ui.adapter;
 \r
 import android.accounts.Account;\r
 import android.content.Context;\r
+import android.database.Cursor;\r
+import android.support.v4.widget.CursorAdapter;\r
 import android.view.LayoutInflater;\r
 import android.view.View;\r
 import android.view.ViewGroup;\r
-import android.widget.BaseAdapter;\r
 import android.widget.ImageView;\r
 import android.widget.ListAdapter;\r
 import android.widget.ListView;\r
 import android.widget.TextView;\r
 \r
 \r
-import java.util.Vector;\r
-\r
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.AccountUtils;\r
 import com.owncloud.android.datamodel.FileDataStorageManager;\r
@@ -39,6 +38,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
 import com.owncloud.android.ui.activity.TransferServiceGetter;\r
 import com.owncloud.android.utils.DisplayUtils;\r
+import com.owncloud.android.utils.Log_OC;\r
 \r
 \r
 /**\r
@@ -48,20 +48,36 @@ import com.owncloud.android.utils.DisplayUtils;
  * @author Bartek Przybylski\r
  * \r
  */\r
-public class FileListListAdapter extends BaseAdapter implements ListAdapter {\r
+public class FileListListAdapter extends CursorAdapter implements ListAdapter {\r
+\r
+    private static final String TAG = FileListListAdapter.class.getSimpleName();\r
+    \r
     private Context mContext;\r
-    private OCFile mFile = null;\r
-    private Vector<OCFile> mFiles = null;\r
     private FileDataStorageManager mStorageManager;\r
     private Account mAccount;\r
     private TransferServiceGetter mTransferServiceGetter;\r
     \r
+\r
     public FileListListAdapter(Context context, TransferServiceGetter transferServiceGetter) {\r
+        super(context, null, FLAG_AUTO_REQUERY);\r
         mContext = context;\r
         mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
         mTransferServiceGetter = transferServiceGetter;\r
     }\r
 \r
+    public void setStorageManager(FileDataStorageManager storageManager) {\r
+        mStorageManager = storageManager;\r
+    }\r
+    \r
+    @Override\r
+    protected void onContentChanged() {\r
+        Log_OC.d(TAG, "onContentChanged() start");\r
+        super.onContentChanged();\r
+        \r
+        notifyDataSetChanged();\r
+        Log_OC.d(TAG, "onContentChanged() end");\r
+    }\r
+    /*\r
     @Override\r
     public boolean areAllItemsEnabled() {\r
         return true;\r
@@ -95,91 +111,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     public int getItemViewType(int position) {\r
         return 0;\r
     }\r
-\r
-    @Override\r
-    public View getView(int position, View convertView, ViewGroup parent) {\r
-        View view = convertView;\r
-        if (view == null) {\r
-            LayoutInflater inflator = (LayoutInflater) mContext\r
-                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
-            view = inflator.inflate(R.layout.list_item, null);\r
-        }\r
     \r
-        if (mFiles != null && mFiles.size() > position) {\r
-            OCFile file = mFiles.get(position);\r
-            TextView fileName = (TextView) view.findViewById(R.id.Filename);\r
-            String name = file.getFileName();\r
-\r
-            fileName.setText(name);\r
-            ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);\r
-            fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));\r
-            ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);\r
-            FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();\r
-            FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
-            if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
-                localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {\r
-                localStateView.setImageResource(R.drawable.uploading_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else if (file.isDown()) {\r
-                localStateView.setImageResource(R.drawable.local_file_indicator);\r
-                localStateView.setVisibility(View.VISIBLE);\r
-            } else {\r
-                localStateView.setVisibility(View.INVISIBLE);\r
-            }\r
-            \r
-            TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
-            TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
-            ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
-            \r
-            if (!file.isFolder()) {\r
-                fileSizeV.setVisibility(View.VISIBLE);\r
-                fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
-                lastModV.setVisibility(View.VISIBLE);\r
-                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
-                // this if-else is needed even thoe fav icon is visible by default\r
-                // because android reuses views in listview\r
-                if (!file.keepInSync()) {\r
-                    view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
-                } else {\r
-                    view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);\r
-                }\r
-                \r
-                ListView parentList = (ListView)parent;\r
-                if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { \r
-                    checkBoxV.setVisibility(View.GONE);\r
-                } else {\r
-                    if (parentList.isItemChecked(position)) {\r
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);\r
-                    } else {\r
-                        checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);\r
-                    }\r
-                    checkBoxV.setVisibility(View.VISIBLE);\r
-                }\r
-                \r
-            } \r
-            else {\r
-                \r
-                fileSizeV.setVisibility(View.INVISIBLE);\r
-                //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
-                lastModV.setVisibility(View.VISIBLE);\r
-                lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
-                checkBoxV.setVisibility(View.GONE);\r
-                view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
-            }\r
-            \r
-            ImageView shareIconV = (ImageView) view.findViewById(R.id.shareIcon);\r
-            if (file.isShareByLink()) {\r
-                shareIconV.setVisibility(View.VISIBLE);\r
-            } else {\r
-                shareIconV.setVisibility(View.INVISIBLE);\r
-            }\r
-        }\r
-\r
-        return view;\r
-    }\r
-\r
     @Override\r
     public int getViewTypeCount() {\r
         return 1;\r
@@ -194,24 +126,124 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
     public boolean isEmpty() {\r
         return (mFiles == null || mFiles.isEmpty());\r
     }\r
+    */\r
+\r
+//    /**\r
+//     * Change the adapted directory for a new one\r
+//     * @param folder                    New file to adapt. Can be NULL, meaning "no content to adapt".\r
+//     * @param updatedStorageManager     Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)\r
+//     */\r
+//    public void swapDirectory(OCFile folder, FileDataStorageManager updatedStorageManager) {\r
+//        if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {\r
+//            mStorageManager = updatedStorageManager;\r
+//            mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
+//        }\r
+//        Cursor newCursor = null; \r
+//        if (mStorageManager != null) {\r
+//            //mFiles = mStorageManager.getFolderContent(mFile);\r
+//            newCursor = mStorageManager.getContent(folder.getFileId());\r
+//            Uri uri = Uri.withAppendedPath(\r
+//                    ProviderTableMeta.CONTENT_URI_DIR, \r
+//                    String.valueOf(folder.getFileId()));\r
+//            Log_OC.d(TAG, "swapDirectory Uri " + uri);\r
+//            newCursor.setNotificationUri(mContext.getContentResolver(), uri);\r
+//            \r
+//        }\r
+//        Cursor oldCursor = swapCursor(newCursor);\r
+//        if (oldCursor != null){\r
+//            oldCursor.close();\r
+//        }\r
+//        notifyDataSetChanged();\r
+//    }\r
 \r
-    /**\r
-     * Change the adapted directory for a new one\r
-     * @param directory                 New file to adapt. Can be NULL, meaning "no content to adapt".\r
-     * @param updatedStorageManager     Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)\r
-     */\r
-    public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager) {\r
-        mFile = directory;\r
-        if (updatedStorageManager != null && updatedStorageManager != mStorageManager) {\r
-            mStorageManager = updatedStorageManager;\r
-            mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);\r
+    @Override\r
+    public void bindView(View view, Context context, Cursor cursor) {\r
+        //Log_OC.d(TAG, "bindView start");\r
+        \r
+        OCFile file = mStorageManager.createFileInstance(cursor);\r
+        \r
+        TextView fileName = (TextView) view.findViewById(R.id.Filename);\r
+        String name = file.getFileName();\r
+\r
+        fileName.setText(name);\r
+        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);\r
+        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));\r
+        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);\r
+        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();\r
+        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();\r
+        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {\r
+            localStateView.setImageResource(R.drawable.downloading_file_indicator);\r
+            localStateView.setVisibility(View.VISIBLE);\r
+        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {\r
+            localStateView.setImageResource(R.drawable.uploading_file_indicator);\r
+            localStateView.setVisibility(View.VISIBLE);\r
+        } else if (file.isDown()) {\r
+            localStateView.setImageResource(R.drawable.local_file_indicator);\r
+            localStateView.setVisibility(View.VISIBLE);\r
+        } else {\r
+            localStateView.setVisibility(View.INVISIBLE);\r
         }\r
-        if (mStorageManager != null) {\r
-            mFiles = mStorageManager.getFolderContent(mFile);\r
+        \r
+        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);\r
+        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);\r
+        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
+        \r
+        if (!file.isFolder()) {\r
+            fileSizeV.setVisibility(View.VISIBLE);\r
+            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
+            lastModV.setVisibility(View.VISIBLE);\r
+            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
+            // this if-else is needed even thoe fav icon is visible by default\r
+            // because android reuses views in listview\r
+            if (!file.keepInSync()) {\r
+                view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
+            } else {\r
+                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);\r
+            }\r
+            \r
+        } \r
+        else {\r
+            \r
+            fileSizeV.setVisibility(View.INVISIBLE);\r
+            //fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));\r
+            lastModV.setVisibility(View.VISIBLE);\r
+            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));\r
+            checkBoxV.setVisibility(View.GONE);\r
+            view.findViewById(R.id.imageView3).setVisibility(View.GONE);\r
+        }\r
+        \r
+        ImageView shareIconV = (ImageView) view.findViewById(R.id.shareIcon);\r
+        if (file.isShareByLink()) {\r
+            shareIconV.setVisibility(View.VISIBLE);\r
         } else {\r
-            mFiles = null;\r
+            shareIconV.setVisibility(View.INVISIBLE);\r
         }\r
-        notifyDataSetChanged();\r
+        //}\r
+        //Log_OC.d(TAG, "bindView end");\r
+    }\r
+\r
+    @Override\r
+    public View newView(Context context, Cursor cursor, ViewGroup parent) {\r
+        //Log_OC.d(TAG, "newView start");\r
+        LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
+        View view = inflator.inflate(R.layout.list_item, null);\r
+        \r
+        // TODO check activity to upload\r
+        ListView parentList = (ListView) parent;\r
+        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);\r
+        if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) { \r
+            checkBoxV.setVisibility(View.GONE);\r
+        } else {\r
+            /*if (parentList.isItemChecked(position)) {\r
+                checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);\r
+            } else {\r
+                checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);\r
+            }*/\r
+            checkBoxV.setVisibility(View.VISIBLE);\r
+        }\r
+        //Log_OC.d(TAG, "newView end");\r
+        return view;\r
+      \r
     }\r
     \r
 }\r
diff --git a/src/com/owncloud/android/ui/dialog/ConfirmationDialogFragment.java b/src/com/owncloud/android/ui/dialog/ConfirmationDialogFragment.java
new file mode 100644 (file)
index 0000000..52c1ac4
--- /dev/null
@@ -0,0 +1,126 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012 Bartek Przybylski
+ *   Copyright (C) 2012-2013 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.ui.dialog;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+
+import com.actionbarsherlock.app.SherlockDialogFragment;
+import com.owncloud.android.utils.Log_OC;
+
+
+public class ConfirmationDialogFragment extends SherlockDialogFragment {
+
+    public final static String ARG_CONF_RESOURCE_ID = "resource_id";
+    public final static String ARG_CONF_ARGUMENTS = "string_array";
+    
+    public final static String ARG_POSITIVE_BTN_RES = "positive_btn_res";
+    public final static String ARG_NEUTRAL_BTN_RES = "neutral_btn_res";
+    public final static String ARG_NEGATIVE_BTN_RES = "negative_btn_res";
+    
+    public static final String FTAG_CONFIRMATION = "CONFIRMATION_FRAGMENT";
+
+    private ConfirmationDialogFragmentListener mListener;
+    
+    /**
+     * Public factory method to create new ConfirmationDialogFragment instances.
+     * 
+     * @param string_id         Resource id for a message to show in the dialog.
+     * @param arguments         Arguments to complete the message, if it's a format string.
+     * @param posBtn            Resource id for the text of the positive button.
+     * @param neuBtn            Resource id for the text of the neutral button.
+     * @param negBtn            Resource id for the text of the negative button.
+     * @return                  Dialog ready to show.
+     */
+    public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments, int posBtn, int neuBtn, int negBtn) {
+        ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
+        Bundle args = new Bundle();
+        args.putInt(ARG_CONF_RESOURCE_ID, string_id);
+        args.putStringArray(ARG_CONF_ARGUMENTS, arguments);
+        args.putInt(ARG_POSITIVE_BTN_RES, posBtn);
+        args.putInt(ARG_NEUTRAL_BTN_RES, neuBtn);
+        args.putInt(ARG_NEGATIVE_BTN_RES, negBtn);
+        frag.setArguments(args);
+        return frag;
+    }
+    
+    public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener) {
+        mListener = listener;
+    }
+
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+        Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS);
+        int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1);
+        int posBtn = getArguments().getInt(ARG_POSITIVE_BTN_RES, -1);
+        int neuBtn = getArguments().getInt(ARG_NEUTRAL_BTN_RES, -1);
+        int negBtn = getArguments().getInt(ARG_NEGATIVE_BTN_RES, -1);
+        
+        if (confirmationTarget == null || resourceId == -1) {
+            Log_OC.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
+            return null;
+        }
+
+        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+            .setIcon(android.R.drawable.ic_dialog_alert)
+            .setMessage(String.format(getString(resourceId), confirmationTarget))
+            .setTitle(android.R.string.dialog_alert_title);
+        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
+            builder.setIconAttribute(android.R.attr.alertDialogIcon);
+        }
+        
+        if (posBtn != -1)
+            builder.setPositiveButton(posBtn,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int whichButton) {
+                            mListener.onConfirmation(getTag()); 
+                            dialog.dismiss();
+                        }
+                    });
+        if (neuBtn != -1)
+            builder.setNeutralButton(neuBtn,
+                    new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int whichButton) {
+                            mListener.onNeutral(getTag()); 
+                            dialog.dismiss();
+                        }
+                    });
+        if (negBtn != -1)
+            builder.setNegativeButton(negBtn,
+                    new DialogInterface.OnClickListener() {
+                        @Override
+                        public void onClick(DialogInterface dialog, int which) {
+                            mListener.onCancel(getTag());
+                            dialog.dismiss();
+                        }
+                    });
+      return builder.create();
+    }
+    
+    
+    public interface ConfirmationDialogFragmentListener {
+        public void onConfirmation(String callerTag);
+        public void onNeutral(String callerTag);
+        public void onCancel(String callerTag);
+    }
+    
+}
+
diff --git a/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java b/src/com/owncloud/android/ui/fragment/ConfirmationDialogFragment.java
deleted file mode 100644 (file)
index bb9adbe..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012 Bartek Przybylski
- *   Copyright (C) 2012-2013 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.ui.fragment;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-
-import com.actionbarsherlock.app.SherlockDialogFragment;
-import com.owncloud.android.utils.Log_OC;
-
-
-public class ConfirmationDialogFragment extends SherlockDialogFragment {
-
-    public final static String ARG_CONF_RESOURCE_ID = "resource_id";
-    public final static String ARG_CONF_ARGUMENTS = "string_array";
-    
-    public final static String ARG_POSITIVE_BTN_RES = "positive_btn_res";
-    public final static String ARG_NEUTRAL_BTN_RES = "neutral_btn_res";
-    public final static String ARG_NEGATIVE_BTN_RES = "negative_btn_res";
-    
-    public static final String FTAG_CONFIRMATION = "CONFIRMATION_FRAGMENT";
-
-    private ConfirmationDialogFragmentListener mListener;
-    
-    /**
-     * Public factory method to create new ConfirmationDialogFragment instances.
-     * 
-     * @param string_id         Resource id for a message to show in the dialog.
-     * @param arguments         Arguments to complete the message, if it's a format string.
-     * @param posBtn            Resource id for the text of the positive button.
-     * @param neuBtn            Resource id for the text of the neutral button.
-     * @param negBtn            Resource id for the text of the negative button.
-     * @return                  Dialog ready to show.
-     */
-    public static ConfirmationDialogFragment newInstance(int string_id, String[] arguments, int posBtn, int neuBtn, int negBtn) {
-        ConfirmationDialogFragment frag = new ConfirmationDialogFragment();
-        Bundle args = new Bundle();
-        args.putInt(ARG_CONF_RESOURCE_ID, string_id);
-        args.putStringArray(ARG_CONF_ARGUMENTS, arguments);
-        args.putInt(ARG_POSITIVE_BTN_RES, posBtn);
-        args.putInt(ARG_NEUTRAL_BTN_RES, neuBtn);
-        args.putInt(ARG_NEGATIVE_BTN_RES, negBtn);
-        frag.setArguments(args);
-        return frag;
-    }
-    
-    public void setOnConfirmationListener(ConfirmationDialogFragmentListener listener) {
-        mListener = listener;
-    }
-
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        Object[] confirmationTarget = getArguments().getStringArray(ARG_CONF_ARGUMENTS);
-        int resourceId = getArguments().getInt(ARG_CONF_RESOURCE_ID, -1);
-        int posBtn = getArguments().getInt(ARG_POSITIVE_BTN_RES, -1);
-        int neuBtn = getArguments().getInt(ARG_NEUTRAL_BTN_RES, -1);
-        int negBtn = getArguments().getInt(ARG_NEGATIVE_BTN_RES, -1);
-        
-        if (confirmationTarget == null || resourceId == -1) {
-            Log_OC.wtf(getTag(), "Calling confirmation dialog without resource or arguments");
-            return null;
-        }
-
-        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
-            .setIcon(android.R.drawable.ic_dialog_alert)
-            .setMessage(String.format(getString(resourceId), confirmationTarget))
-            .setTitle(android.R.string.dialog_alert_title);
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
-            builder.setIconAttribute(android.R.attr.alertDialogIcon);
-        }
-        
-        if (posBtn != -1)
-            builder.setPositiveButton(posBtn,
-                    new DialogInterface.OnClickListener() {
-                        public void onClick(DialogInterface dialog, int whichButton) {
-                            mListener.onConfirmation(getTag()); 
-                            dialog.dismiss();
-                        }
-                    });
-        if (neuBtn != -1)
-            builder.setNeutralButton(neuBtn,
-                    new DialogInterface.OnClickListener() {
-                        public void onClick(DialogInterface dialog, int whichButton) {
-                            mListener.onNeutral(getTag()); 
-                            dialog.dismiss();
-                        }
-                    });
-        if (negBtn != -1)
-            builder.setNegativeButton(negBtn,
-                    new DialogInterface.OnClickListener() {
-                        @Override
-                        public void onClick(DialogInterface dialog, int which) {
-                            mListener.onCancel(getTag());
-                            dialog.dismiss();
-                        }
-                    });
-      return builder.create();
-    }
-    
-    
-    public interface ConfirmationDialogFragmentListener {
-        public void onConfirmation(String callerTag);
-        public void onNeutral(String callerTag);
-        public void onCancel(String callerTag);
-    }
-    
-}
-
index dc8c9f6..33fef5e 100644 (file)
@@ -61,6 +61,7 @@ import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.dialog.EditNameDialog;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
@@ -83,7 +84,6 @@ public class FileDetailFragment extends FileFragment implements
     private int mLayout;
     private View mView;
     private Account mAccount;
-    private FileDataStorageManager mStorageManager;
     
     private UploadFinishReceiver mUploadFinishReceiver;
     public ProgressListener mProgressListener;
@@ -103,7 +103,6 @@ public class FileDetailFragment extends FileFragment implements
     public FileDetailFragment() {
         super();
         mAccount = null;
-        mStorageManager = null;
         mLayout = R.layout.file_details_empty;
         mProgressListener = null;
     }
@@ -119,7 +118,6 @@ public class FileDetailFragment extends FileFragment implements
     public FileDetailFragment(OCFile fileToDetail, Account ocAccount) {
         super(fileToDetail);
         mAccount = ocAccount;
-        mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment 
         mLayout = R.layout.file_details_empty;
         mProgressListener = null;
     }
@@ -185,8 +183,8 @@ public class FileDetailFragment extends FileFragment implements
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
         if (mAccount != null) {
-            mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
-            OCFile file = mStorageManager.getFileByPath(getFile().getRemotePath());
+            OCFile file = ((FileActivity)getActivity()).getStorageManager().
+                    getFileByPath(getFile().getRemotePath());
             if (file != null) {
                 setFile(file);
             }
@@ -361,17 +359,17 @@ public class FileDetailFragment extends FileFragment implements
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.action_share_file: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                FileActivity activity = (FileActivity) getSherlockActivity();
                 activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity);
                 return true;
             }
             case R.id.action_unshare_file: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                FileActivity activity = (FileActivity) getSherlockActivity();
                 activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
                 return true;
             }
             case R.id.action_open_file_with: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                FileActivity activity = (FileActivity) getSherlockActivity();
                 activity.getFileOperationsHelper().openFile(getFile(), activity);
                 return true;
             }
@@ -428,7 +426,7 @@ public class FileDetailFragment extends FileFragment implements
         CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
         OCFile file = getFile();
         file.setKeepInSync(cb.isChecked());
-        mStorageManager.saveFile(file);
+        ((FileActivity)getActivity()).getStorageManager().saveFile(file);
         
         /// register the OCFile instance in the observer service to monitor local updates;
         /// if necessary, the file is download 
@@ -494,11 +492,17 @@ public class FileDetailFragment extends FileFragment implements
             }
             
         } else {
-            mLastRemoteOperation = new SynchronizeFileOperation(file, null, mStorageManager, mAccount, true, getActivity());
+            mLastRemoteOperation = new SynchronizeFileOperation(
+                    file, 
+                    null, 
+                    ((FileActivity)getActivity()).getStorageManager(), 
+                    mAccount, 
+                    true, 
+                    getActivity());
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
             // update ui 
-            ((FileDisplayActivity) getActivity()).showLoadingDialog();
+            ((FileActivity) getActivity()).showLoadingDialog();
             
         }
     }
@@ -507,13 +511,15 @@ public class FileDetailFragment extends FileFragment implements
     public void onConfirmation(String callerTag) {
         OCFile file = getFile();
         if (callerTag.equals(FTAG_CONFIRMATION)) {
-            if (mStorageManager.getFileById(file.getFileId()) != null) {
+            FileDataStorageManager storageManager =
+                    ((FileActivity)getActivity()).getStorageManager();
+            if (storageManager.getFileById(file.getFileId()) != null) {
                 mLastRemoteOperation = new RemoveFileOperation( file, 
                                                                 true, 
-                                                                mStorageManager);
+                                                                storageManager);
                 mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
                                 
-                ((FileDisplayActivity) getActivity()).showLoadingDialog();
+                ((FileActivity) getActivity()).showLoadingDialog();
             }
         }
     }
@@ -521,7 +527,7 @@ public class FileDetailFragment extends FileFragment implements
     @Override
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
-        mStorageManager.removeFile(file, false, true);    // TODO perform in background task / new thread
+        ((FileActivity)getActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         if (file.getStoragePath() != null) {
             file.setStoragePath(null);
             updateFileDetails(file, mAccount);
@@ -551,11 +557,12 @@ public class FileDetailFragment extends FileFragment implements
      */
     public void updateFileDetails(OCFile file, Account ocAccount) {
         setFile(file);
+        FileDataStorageManager storageManager = ((FileActivity)getActivity()).getStorageManager();
         if (ocAccount != null && ( 
-                mStorageManager == null || 
+                storageManager == null || 
                 (mAccount != null && !mAccount.equals(ocAccount))
            )) {
-            mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
+            storageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
         }
         mAccount = ocAccount;
         updateFileDetails(false, false);
@@ -577,9 +584,10 @@ public class FileDetailFragment extends FileFragment implements
     public void updateFileDetails(boolean transferring, boolean refresh) {
 
         if (readyToShow()) {
-            
-            if (refresh && mStorageManager != null) {
-                setFile(mStorageManager.getFileByPath(getFile().getRemotePath()));
+            FileDataStorageManager storageManager = 
+                    ((FileActivity)getActivity()).getStorageManager();
+            if (refresh && storageManager != null) {
+                setFile(storageManager.getFileByPath(getFile().getRemotePath()));
             }
             OCFile file = getFile();
             
@@ -779,7 +787,7 @@ public class FileDetailFragment extends FileFragment implements
                 if (getFile().getRemotePath().equals(uploadRemotePath) ||
                     renamedInUpload) {
                     if (uploadWasFine) {
-                        setFile(mStorageManager.getFileByPath(uploadRemotePath));
+                        setFile(((FileActivity)getActivity()).getStorageManager().getFileByPath(uploadRemotePath));
                     }
                     if (renamedInUpload) {
                         String newName = (new File(uploadRemotePath)).getName();
@@ -809,7 +817,7 @@ public class FileDetailFragment extends FileFragment implements
                                                             newFilename, 
                                                             new FileDataStorageManager(mAccount, getActivity().getContentResolver()));
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
-            ((FileDisplayActivity) getActivity()).showLoadingDialog();
+            ((FileActivity) getActivity()).showLoadingDialog();
         }
     }
     
@@ -834,7 +842,7 @@ public class FileDetailFragment extends FileFragment implements
     
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
+        ((FileActivity) getActivity()).dismissLoadingDialog();
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
@@ -850,11 +858,13 @@ public class FileDetailFragment extends FileFragment implements
     }
     
     private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
-        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
+        ((FileActivity) getActivity()).dismissLoadingDialog();
         
         if (result.isSuccess()) {
             updateFileDetails(((RenameFileOperation)operation).getFile(), mAccount);
+            /* TODO WIP COMMENT 
             mContainerActivity.onFileStateChanged();
+            */
             
         } else {
             if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
@@ -875,7 +885,7 @@ public class FileDetailFragment extends FileFragment implements
     }
     
     private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation, RemoteOperationResult result) {
-        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
+        ((FileActivity) getActivity()).dismissLoadingDialog();
         OCFile file = getFile();
         if (!result.isSuccess()) {
             if (result.getCode() == ResultCode.SYNC_CONFLICT) {
@@ -896,8 +906,10 @@ public class FileDetailFragment extends FileFragment implements
         } else {
             if (operation.transferWasRequested()) {
                 setButtonsForTransferring();
+                /* TODO WIP COMMENT 
                 mContainerActivity.onFileStateChanged();    // this is not working; FileDownloader won't do NOTHING at all until this method finishes, so 
                                                             // checking the service to see if the file is downloading results in FALSE
+                 */
             } else {
                 Toast msg = Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG); 
                 msg.show();
index 95847ba..d6e2e16 100644 (file)
@@ -24,7 +24,9 @@ import java.util.List;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.FileListCursorLoader;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
@@ -32,20 +34,27 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.operations.RenameFileOperation;
 import com.owncloud.android.operations.SynchronizeFileOperation;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.ui.activity.FileActivity;
+import com.owncloud.android.ui.ExtendedListView;
 import com.owncloud.android.ui.activity.TransferServiceGetter;
 import com.owncloud.android.ui.adapter.FileListListAdapter;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.dialog.EditNameDialog;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
 import com.owncloud.android.ui.dialog.EditNameDialog.EditNameDialogListener;
-import com.owncloud.android.ui.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.ui.preview.PreviewMediaFragment;
 import com.owncloud.android.utils.Log_OC;
 
 import android.accounts.Account;
 import android.app.Activity;
+import android.database.Cursor;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
+import android.support.v4.app.LoaderManager;
+import android.support.v4.app.LoaderManager.LoaderCallbacks;
+import android.support.v4.content.Loader;
 import android.view.ContextMenu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
@@ -59,7 +68,9 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
  * @author Bartek Przybylski
  * 
  */
-public class OCFileListFragment extends ExtendedListFragment implements EditNameDialogListener, ConfirmationDialogFragmentListener {
+public class OCFileListFragment extends ExtendedListFragment 
+        implements EditNameDialogListener, ConfirmationDialogFragmentListener, 
+        LoaderCallbacks<Cursor>{
     
     private static final String TAG = OCFileListFragment.class.getSimpleName();
 
@@ -71,10 +82,14 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     private static final String KEY_TOPS = "TOPS";
     private static final String KEY_HEIGHT_CELL = "HEIGHT_CELL";
     
+    private static final int LOADER_ID = 0;
+    
     private OCFileListFragment.ContainerActivity mContainerActivity;
     
     private OCFile mFile = null;
     private FileListListAdapter mAdapter;
+    private LoaderManager mLoaderManager;
+    private FileListCursorLoader  mCursorLoader;
     
     private Handler mHandler;
     private OCFile mTargetFile;
@@ -108,7 +123,10 @@ 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);
+        
+        mAdapter = new FileListListAdapter(getSherlockActivity(), mContainerActivity); 
+        mLoaderManager = getLoaderManager();
+                
         if (savedInstanceState != null) {
             mFile = savedInstanceState.getParcelable(EXTRA_FILE);
             mIndexes = savedInstanceState.getIntegerArrayList(KEY_INDEXES);
@@ -124,12 +142,16 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             
         }
         
+        // Initialize loaderManager and makes it active
+        mLoaderManager.initLoader(LOADER_ID, null, this);
+        
         setListAdapter(mAdapter);
         
         registerForContextMenu(getListView());
-        getListView().setOnCreateContextMenuListener(this);        
+        getListView().setOnCreateContextMenuListener(this);
         
         mHandler = new Handler();
+        
 
     }
     
@@ -159,7 +181,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         int moveCount = 0;
         
         if(mFile != null){
-            FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
+            FileDataStorageManager storageManager = 
+                    ((FileActivity)getSherlockActivity()).getStorageManager();
             
             String parentPath = null;
             if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
@@ -205,20 +228,21 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             
             int top = mTops.remove(mTops.size() - 1);
             
-            mList.setSelectionFromTop(firstPosition, top);
+            ExtendedListView list = (ExtendedListView) getListView();
+            list.setSelectionFromTop(firstPosition, top);
             
             // Move the scroll if the selection is not visible
             int indexPosition = mHeightCell*index;
-            int height = mList.getHeight();
+            int height = list.getHeight();
             
             if (indexPosition > height) {
                 if (android.os.Build.VERSION.SDK_INT >= 11)
                 {
-                    mList.smoothScrollToPosition(index); 
+                    list.smoothScrollToPosition(index); 
                 }
                 else if (android.os.Build.VERSION.SDK_INT >= 8)
                 {
-                    mList.setSelectionFromTop(index, 0);
+                    list.setSelectionFromTop(index, 0);
                 }
                 
             }
@@ -232,10 +256,12 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         
         mIndexes.add(index);
         
-        int firstPosition = mList.getFirstVisiblePosition();
+        ExtendedListView list = (ExtendedListView) getListView();
+        
+        int firstPosition = list.getFirstVisiblePosition();
         mFirstPositions.add(firstPosition);
         
-        View view = mList.getChildAt(0);
+        View view = list.getChildAt(0);
         int top = (view == null) ? 0 : view.getTop() ;
 
         mTops.add(top);
@@ -246,7 +272,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     
     @Override
     public void onItemClick(AdapterView<?> l, View v, int position, long id) {
-        OCFile file = (OCFile) mAdapter.getItem(position);
+        OCFile file = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+                (Cursor) mAdapter.getItem(position));
         if (file != null) {
             if (file.isFolder()) { 
                 // update state and view of this fragment
@@ -266,7 +293,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                         // media preview
                         mContainerActivity.startMediaPreview(file, 0, true);
                     } else {
-                        FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                        FileActivity activity = (FileActivity) getSherlockActivity();
                         activity.getFileOperationsHelper().openFile(file, activity);
                     }
                     
@@ -289,10 +316,11 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     @Override
     public void onCreateContextMenu (ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
         super.onCreateContextMenu(menu, v, menuInfo);
-        MenuInflater inflater = getActivity().getMenuInflater();
+        MenuInflater inflater = getSherlockActivity().getMenuInflater();
         inflater.inflate(R.menu.file_actions_menu, menu);
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
-        OCFile targetFile = (OCFile) mAdapter.getItem(info.position);
+        OCFile targetFile = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+                (Cursor) mAdapter.getItem(info.position));
         List<Integer> toHide = new ArrayList<Integer>();    
         List<Integer> toDisable = new ArrayList<Integer>();  
         
@@ -306,8 +334,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             toHide.add(R.id.action_sync_file);
             toHide.add(R.id.action_see_details);
             toHide.add(R.id.action_send_file);
-            if (    mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile) ||
-                    mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)           ) {
+            if (    mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile) ||
+                    mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)           ) {
                 toDisable.add(R.id.action_rename_file);
                 toDisable.add(R.id.action_remove_file);
                 
@@ -327,12 +355,12 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             } else {
                 toHide.add(R.id.action_sync_file);
             }
-            if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
+            if ( mContainerActivity.getFileDownloaderBinder().isDownloading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
                 toHide.add(R.id.action_cancel_upload);
                 toDisable.add(R.id.action_rename_file);
                 toDisable.add(R.id.action_remove_file);
                     
-            } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getActivity()), targetFile)) {
+            } else if ( mContainerActivity.getFileUploaderBinder().isUploading(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), targetFile)) {
                 toHide.add(R.id.action_cancel_download);
                 toDisable.add(R.id.action_rename_file);
                 toDisable.add(R.id.action_remove_file);
@@ -377,15 +405,16 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     @Override
     public boolean onContextItemSelected (MenuItem item) {
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();        
-        mTargetFile = (OCFile) mAdapter.getItem(info.position);
+        mTargetFile = ((FileActivity)getSherlockActivity()).getStorageManager().createFileInstance(
+                (Cursor) mAdapter.getItem(info.position));
         switch (item.getItemId()) {                
             case R.id.action_share_file: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                FileActivity activity = (FileActivity) getSherlockActivity();
                 activity.getFileOperationsHelper().shareFileWithLink(mTargetFile, activity);
                 return true;
             }
             case R.id.action_unshare_file: {
-                FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                FileActivity activity = (FileActivity) getSherlockActivity();
                 activity.getFileOperationsHelper().unshareFileWithLink(mTargetFile, activity);
                 return true;
             }
@@ -421,14 +450,20 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             }
             case R.id.action_sync_file: {
                 Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
-                RemoteOperation operation = new SynchronizeFileOperation(mTargetFile, null, mContainerActivity.getStorageManager(), account, true, getSherlockActivity());
+                RemoteOperation operation = new SynchronizeFileOperation(
+                        mTargetFile, 
+                        null, 
+                        ((FileActivity)getSherlockActivity()).getStorageManager(), 
+                        account, 
+                        true, 
+                        getSherlockActivity());
                 operation.execute(account, getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-                ((FileDisplayActivity) getSherlockActivity()).showLoadingDialog();
+                ((FileActivity) getSherlockActivity()).showLoadingDialog();
                 return true;
             }
             case R.id.action_cancel_download: {
                 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
-                Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+                Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
                 if (downloaderBinder != null && downloaderBinder.isDownloading(account, mTargetFile)) {
                     downloaderBinder.cancel(account, mTargetFile);
                     listDirectory();
@@ -438,7 +473,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
             }
             case R.id.action_cancel_upload: {
                 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
-                Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
+                Account account = AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity());
                 if (uploaderBinder != null && uploaderBinder.isUploading(account, mTargetFile)) {
                     uploaderBinder.cancel(account, mTargetFile);
                     listDirectory();
@@ -447,7 +482,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 return true;
             }
             case R.id.action_see_details: {
-                ((FileFragment.ContainerActivity)getActivity()).showDetails(mTargetFile);
+                ((FileFragment.ContainerActivity)getSherlockActivity()).showDetails(mTargetFile);
                 return true;
             }
             case R.id.action_send_file: {
@@ -458,7 +493,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                     
                 } else {
                 
-                    FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity();
+                    FileActivity activity = (FileActivity) getSherlockActivity();
                     activity.getFileOperationsHelper().sendDownloadedFile(mTargetFile, activity);
                 }
                 return true;
@@ -493,7 +528,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
      * @param directory File to be listed
      */
     public void listDirectory(OCFile directory) {
-        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
+        FileDataStorageManager storageManager = ((FileActivity)getSherlockActivity()).getStorageManager();
         if (storageManager != null) {
 
             // Check input parameters for null
@@ -513,15 +548,45 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
                 directory = storageManager.getFileById(directory.getParentId());
             }
 
-            mAdapter.swapDirectory(directory, storageManager);
+            swapDirectory(directory.getFileId(), storageManager);
+            
             if (mFile == null || !mFile.equals(directory)) {
-                mList.setSelectionFromTop(0, 0);
+                ((ExtendedListView) getListView()).setSelectionFromTop(0, 0);
             }
             mFile = directory;
         }
     }
     
     
+    /**
+     * Change the adapted directory for a new one
+     * @param folder                    New file to adapt. Can be NULL, meaning "no content to adapt".
+     * @param updatedStorageManager     Optional updated storage manager; used to replace mStorageManager if is different (and not NULL)
+     */
+    public void swapDirectory(long parentId, FileDataStorageManager updatedStorageManager) {
+        FileDataStorageManager storageManager = null;
+        if (updatedStorageManager != null && updatedStorageManager != storageManager) {
+            storageManager = updatedStorageManager;
+        }
+        Cursor newCursor = null; 
+        if (storageManager != null) {
+            mAdapter.setStorageManager(storageManager);
+            mCursorLoader.setParentId(parentId);
+            newCursor = mCursorLoader.loadInBackground();//storageManager.getContent(folder.getFileId());
+            Uri uri = Uri.withAppendedPath(
+                    ProviderTableMeta.CONTENT_URI_DIR, 
+                    String.valueOf(parentId));
+            Log_OC.d(TAG, "swapDirectory Uri " + uri);
+            //newCursor.setNotificationUri(getSherlockActivity().getContentResolver(), uri);
+            
+        }
+        Cursor oldCursor = mAdapter.swapCursor(newCursor);
+        if (oldCursor != null){
+            oldCursor.close();
+        }
+        mAdapter.notifyDataSetChanged();
+    }
+    
     
     /**
      * Interface to implement by any Activity that includes some instance of FileListFragment
@@ -546,12 +611,6 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         public void startSyncFolderOperation(OCFile folder);
 
         /**
-         * Getter for the current DataStorageManager in the container activity
-         */
-        public FileDataStorageManager getStorageManager();
-        
-        
-        /**
          * Callback method invoked when a the 'transfer state' of a file changes.
          * 
          * This happens when a download or upload is started or ended for a file.
@@ -568,7 +627,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
          */
         public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading);
 
-        void startDownloadForSending(OCFile file);
+        public void startDownloadForSending(OCFile file);
         
     }
     
@@ -578,12 +637,14 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         if (dialog.getResult()) {
             String newFilename = dialog.getNewFilename();
             Log_OC.d(TAG, "name edit dialog dismissed with new name " + newFilename);
-            RemoteOperation operation = new RenameFileOperation(mTargetFile, 
-                                                                AccountUtils.getCurrentOwnCloudAccount(getActivity()), 
-                                                                newFilename, 
-                                                                mContainerActivity.getStorageManager());
+            RemoteOperation operation = 
+                    new RenameFileOperation(
+                            mTargetFile, 
+                            AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), 
+                            newFilename, 
+                            ((FileActivity)getSherlockActivity()).getStorageManager());
             operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
-            ((FileDisplayActivity) getActivity()).showLoadingDialog();
+            ((FileActivity) getSherlockActivity()).showLoadingDialog();
         }
     }
 
@@ -591,20 +652,22 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
     @Override
     public void onConfirmation(String callerTag) {
         if (callerTag.equals(FileDetailFragment.FTAG_CONFIRMATION)) {
-            if (mContainerActivity.getStorageManager().getFileById(mTargetFile.getFileId()) != null) {
+            FileDataStorageManager storageManager = 
+                    ((FileActivity)getSherlockActivity()).getStorageManager();
+            if (storageManager.getFileById(mTargetFile.getFileId()) != null) {
                 RemoteOperation operation = new RemoveFileOperation( mTargetFile, 
                                                                     true, 
-                                                                    mContainerActivity.getStorageManager());
+                                                                    storageManager);
                 operation.execute(AccountUtils.getCurrentOwnCloudAccount(getSherlockActivity()), getSherlockActivity(), mContainerActivity, mHandler, getSherlockActivity());
                 
-                ((FileDisplayActivity) getActivity()).showLoadingDialog();
+                ((FileActivity) getSherlockActivity()).showLoadingDialog();
             }
         }
     }
     
     @Override
     public void onNeutral(String callerTag) {
-        mContainerActivity.getStorageManager().removeFile(mTargetFile, false, true);    // TODO perform in background task / new thread
+        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(mTargetFile, false, true);    // TODO perform in background task / new thread
         listDirectory();
         mContainerActivity.onTransferStateChanged(mTargetFile, false, false);
     }
@@ -614,5 +677,70 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName
         Log_OC.d(TAG, "REMOVAL CANCELED");
     }
 
+    /***
+     *  LoaderManager.LoaderCallbacks<Cursor>
+     */
+    
+    /**
+     * Instantiate and return a new Loader for the given ID. This is where the cursor is created.
+     */
+    @Override
+    public Loader<Cursor> onCreateLoader(int id, Bundle bundle) {
+        Log_OC.d(TAG, "onCreateLoader start");
+        mCursorLoader = new FileListCursorLoader((FileActivity)getSherlockActivity(), 
+                ((FileActivity)getSherlockActivity()).getStorageManager());
+        if (mFile != null) {
+            mCursorLoader.setParentId(mFile.getFileId());
+        } else {
+            mCursorLoader.setParentId(1);
+        }
+        Log_OC.d(TAG, "onCreateLoader end");
+        return mCursorLoader;
+    }
+
+
+    /**
+     * Called when a previously created loader has finished its load. Here, you can start using the cursor.
+     */
+    @Override
+    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
+        Log_OC.d(TAG, "onLoadFinished start");
+        
+        FileDataStorageManager storageManager = ((FileActivity)getSherlockActivity()).getStorageManager();
+        if (storageManager != null)  {
+            mCursorLoader.setStorageManager(storageManager);
+            if (mFile != null) {
+                mCursorLoader.setParentId(mFile.getFileId());
+            } else {
+                mCursorLoader.setParentId(1);
+            }
+            mAdapter.swapCursor(mCursorLoader.loadInBackground());
+        }
+        
+//        if(mAdapter != null && cursor != null)
+//            mAdapter.swapCursor(cursor); //swap the new cursor in.
+//        else
+//            Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
+        
+        Log_OC.d(TAG, "onLoadFinished end");
+    }
+
+
+    /**
+     *  Called when a previously created loader is being reset, thus making its data unavailable. 
+     *  It is being reset in order to create a new cursor to query different data. 
+     *  This is called when the last Cursor provided to onLoadFinished() above is about to be closed. 
+     *  We need to make sure we are no longer using it.
+     */
+    @Override
+    public void onLoaderReset(Loader<Cursor> loader) {
+        Log_OC.d(TAG, "onLoadReset start");
+        if(mAdapter != null)
+            mAdapter.swapCursor(null);
+        else
+            Log_OC.d(TAG,"OnLoadFinished: mAdapter is null");
+        Log_OC.d(TAG, "onLoadReset end");
+    }
+
 
 }
index c8fd2d2..5bbc534 100644 (file)
@@ -154,18 +154,6 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
     }
     
     
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void onActivityCreated(Bundle savedInstanceState) {
-        super.onActivityCreated(savedInstanceState);
-        if (mAccount != null) {
-            //mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());;
-        }
-    }
-        
-
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
index d7cc36d..12b5cce 100644 (file)
@@ -26,9 +26,6 @@ import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentManager;
-import android.support.v4.app.FragmentTransaction;
 import android.support.v4.view.ViewPager;
 import android.view.MotionEvent;
 import android.view.View;
@@ -54,7 +51,6 @@ import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.PinCodeActivity;
-import com.owncloud.android.ui.dialog.LoadingDialog;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.Log_OC;
@@ -74,8 +70,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     public static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
     private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
     
-    private static final String DIALOG_WAIT_TAG = "DIALOG_WAIT";
-    
     private ViewPager mViewPager; 
     private PreviewImagePagerAdapter mPreviewImagePagerAdapter;    
     
@@ -292,29 +286,6 @@ public class PreviewImageActivity extends FileActivity implements FileFragment.C
     }
     
     /**
-     * Show loading dialog 
-     */
-    public void showLoadingDialog() {
-        // Construct dialog
-        LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment));
-        FragmentManager fm = getSupportFragmentManager();
-        FragmentTransaction ft = fm.beginTransaction();
-        loading.show(ft, DIALOG_WAIT_TAG);
-        
-    }
-    
-    /**
-     * Dismiss loading dialog
-     */
-    public void dismissLoadingDialog(){
-        Fragment frag = getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_TAG);
-      if (frag != null) {
-          LoadingDialog loading = (LoadingDialog) frag;
-            loading.dismiss();
-        }
-    }
-    
-    /**
      * {@inheritDoc}
      */
     @Override
index 3a374e0..70ffa79 100644 (file)
@@ -58,7 +58,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.Log_OC;
 
@@ -79,7 +79,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
 
     private View mView;
     private Account mAccount;
-    private FileDataStorageManager mStorageManager;
     private ImageView mImageView;
     private TextView mMessageView;
     private ProgressBar mProgressWheel;
@@ -106,7 +105,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     public PreviewImageFragment(OCFile fileToDetail, Account ocAccount, boolean ignoreFirstSavedState) {
         super(fileToDetail);
         mAccount = ocAccount;
-        mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment
         mIgnoreFirstSavedState = ignoreFirstSavedState;
     }
     
@@ -121,7 +119,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     public PreviewImageFragment() {
         super();
         mAccount = null;
-        mStorageManager = null;
         mIgnoreFirstSavedState = false;
     }
     
@@ -173,7 +170,6 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
-        mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
         if (savedInstanceState != null) {
             if (!mIgnoreFirstSavedState) {
                 OCFile file = (OCFile)savedInstanceState.getParcelable(PreviewImageFragment.EXTRA_FILE);
@@ -181,8 +177,8 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
                 
                 // Update the file
                 if (mAccount!= null) {
-                    mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
-                    OCFile updatedFile = mStorageManager.getFileByPath(file.getRemotePath());
+                    OCFile updatedFile = ((FileActivity)getSherlockActivity()).
+                            getStorageManager().getFileByPath(file.getRemotePath());
                     if (updatedFile != null) {
                         setFile(updatedFile);
                     } else {
@@ -433,13 +429,15 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
      */
     @Override
     public void onConfirmation(String callerTag) {
-        if (mStorageManager.getFileById(getFile().getFileId()) != null) {   // check that the file is still there;
+        FileDataStorageManager storageManager = 
+                ((FileActivity)getSherlockActivity()).getStorageManager();
+        if (storageManager.getFileById(getFile().getFileId()) != null) {   // check that the file is still there;
             mLastRemoteOperation = new RemoveFileOperation( getFile(),      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
                                                             true, 
-                                                            mStorageManager);
+                                                            storageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            ((PreviewImageActivity) getActivity()).showLoadingDialog();
+            ((FileActivity) getActivity()).showLoadingDialog();
         }
     }
     
@@ -450,7 +448,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     @Override
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
-        mStorageManager.removeFile(file, false, true);    // TODO perform in background task / new thread
+        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         finish();
     }
     
@@ -657,7 +655,7 @@ public class PreviewImageFragment extends FileFragment implements   OnRemoteOper
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((PreviewImageActivity) getActivity()).dismissLoadingDialog();
+        ((FileActivity) getActivity()).dismissLoadingDialog();
         
         if (result.isSuccess()) {
             Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
index 7fa399a..02c4e2d 100644 (file)
@@ -63,8 +63,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.operations.RemoveFileOperation;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
-import com.owncloud.android.ui.fragment.ConfirmationDialogFragment;
+import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
 import com.owncloud.android.utils.Log_OC;
 
@@ -89,7 +88,6 @@ public class PreviewMediaFragment extends FileFragment implements
 
     private View mView;
     private Account mAccount;
-    private FileDataStorageManager mStorageManager;
     private ImageView mImagePreview;
     private VideoView mVideoPreview;
     private int mSavedPlaybackPosition;
@@ -119,7 +117,6 @@ public class PreviewMediaFragment extends FileFragment implements
         super(fileToDetail);
         mAccount = ocAccount;
         mSavedPlaybackPosition = startPlaybackPosition;
-        mStorageManager = null; // we need a context to init this; the container activity is not available yet at this moment 
         mAutoplay = autoplay;
     }
     
@@ -135,7 +132,6 @@ public class PreviewMediaFragment extends FileFragment implements
         super();
         mAccount = null;
         mSavedPlaybackPosition = 0;
-        mStorageManager = null;
         mAutoplay = true;
     }
     
@@ -194,7 +190,6 @@ public class PreviewMediaFragment extends FileFragment implements
         super.onActivityCreated(savedInstanceState);
         Log_OC.e(TAG, "onActivityCreated");
 
-        mStorageManager = new FileDataStorageManager(mAccount, getActivity().getApplicationContext().getContentResolver());
         if (savedInstanceState != null) {
             setFile((OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE));
             mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT);
@@ -378,27 +373,27 @@ public class PreviewMediaFragment extends FileFragment implements
     
     private void unshareFileWithLink() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity());
+        FileActivity activity = (FileActivity)getSherlockActivity();
         activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity);
     }
     
     private void shareFileWithLink() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity());
+        FileActivity activity = (FileActivity)getSherlockActivity();
         activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity);
         
     }
 
     private void sendFile() {
         stopPreview(false);
-        FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity());
+        FileActivity activity = (FileActivity)getSherlockActivity();
         activity.getFileOperationsHelper().sendDownloadedFile(getFile(), activity);
         
     }
 
     private void seeDetails() {
         stopPreview(false);
-        ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());        
+        ((FileFragment.ContainerActivity)getSherlockActivity()).showDetails(getFile());        
     }
 
 
@@ -481,8 +476,8 @@ public class PreviewMediaFragment extends FileFragment implements
         @Override
         public boolean onError(MediaPlayer mp, int what, int extra) {
             if (mVideoPreview.getWindowToken() != null) {
-                String message = MediaService.getMessageForMediaError(getActivity(), what, extra);
-                new AlertDialog.Builder(getActivity())
+                String message = MediaService.getMessageForMediaError(getSherlockActivity(), what, extra);
+                new AlertDialog.Builder(getSherlockActivity())
                         .setMessage(message)
                         .setPositiveButton(android.R.string.VideoView_error_button,
                                 new DialogInterface.OnClickListener() {
@@ -529,7 +524,7 @@ public class PreviewMediaFragment extends FileFragment implements
             if (mMediaServiceBinder != null && mMediaController != null) {
                 mMediaServiceBinder.unregisterMediaController(mMediaController);
             }
-            getActivity().unbindService(mMediaServiceConnection);
+            getSherlockActivity().unbindService(mMediaServiceConnection);
             mMediaServiceConnection = null;
             mMediaServiceBinder = null;
         }
@@ -546,7 +541,7 @@ public class PreviewMediaFragment extends FileFragment implements
 
     
     private void startFullScreenVideo() {
-        Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
+        Intent i = new Intent(getSherlockActivity(), PreviewVideoActivity.class);
         i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
         i.putExtra(FileActivity.EXTRA_FILE, getFile());
         i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
@@ -591,7 +586,7 @@ public class PreviewMediaFragment extends FileFragment implements
         if (mMediaServiceConnection == null) {
             mMediaServiceConnection = new MediaServiceConnection();
         }
-        getActivity().bindService(  new Intent(getActivity(), 
+        getSherlockActivity().bindService(  new Intent(getSherlockActivity(), 
                                     MediaService.class),
                                     mMediaServiceConnection, 
                                     Context.BIND_AUTO_CREATE);
@@ -603,8 +598,8 @@ public class PreviewMediaFragment extends FileFragment implements
 
         @Override
         public void onServiceConnected(ComponentName component, IBinder service) {
-            if (getActivity() != null) {
-                if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
+            if (getSherlockActivity() != null) {
+                if (component.equals(new ComponentName(getSherlockActivity(), MediaService.class))) {
                     Log_OC.d(TAG, "Media service connected");
                     mMediaServiceBinder = (MediaServiceBinder) service;
                     if (mMediaServiceBinder != null) {
@@ -631,12 +626,12 @@ public class PreviewMediaFragment extends FileFragment implements
 
         @Override
         public void onServiceDisconnected(ComponentName component) {
-            if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
+            if (component.equals(new ComponentName(getSherlockActivity(), MediaService.class))) {
                 Log_OC.e(TAG, "Media service suddenly disconnected");
                 if (mMediaController != null) {
                     mMediaController.setMediaPlayer(null);
                 } else {
-                    Toast.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getSherlockActivity(), "No media controller to release when disconnected from media service", Toast.LENGTH_SHORT).show();
                 }
                 mMediaServiceBinder = null;
                 mMediaServiceConnection = null;
@@ -694,7 +689,7 @@ public class PreviewMediaFragment extends FileFragment implements
                 
             } finally {
                 if (toastIt) {
-                    Toast.makeText(getActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
+                    Toast.makeText(getSherlockActivity(), "There is no application to handle file " + file.getFileName(), Toast.LENGTH_SHORT).show();
                 }
             }
             
@@ -726,14 +721,16 @@ public class PreviewMediaFragment extends FileFragment implements
     @Override
     public void onConfirmation(String callerTag) {
         OCFile file = getFile();
-        if (mStorageManager.getFileById(file.getFileId()) != null) {   // check that the file is still there;
+        FileDataStorageManager storageManager = 
+                ((FileActivity)getSherlockActivity()).getStorageManager();
+        if (storageManager.getFileById(file.getFileId()) != null) {   // check that the file is still there;
             stopPreview(true);
             mLastRemoteOperation = new RemoveFileOperation( file,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
                                                             true, 
-                                                            mStorageManager);
+                                                            storageManager);
             mLastRemoteOperation.execute(mAccount, getSherlockActivity(), this, mHandler, getSherlockActivity());
             
-            ((FileDisplayActivity) getActivity()).showLoadingDialog();
+            ((FileActivity) getSherlockActivity()).showLoadingDialog();
         }
     }
     
@@ -745,7 +742,7 @@ public class PreviewMediaFragment extends FileFragment implements
     public void onNeutral(String callerTag) {
         OCFile file = getFile();
         stopPreview(true);
-        mStorageManager.removeFile(file, false, true);    // TODO perform in background task / new thread
+        ((FileActivity)getSherlockActivity()).getStorageManager().removeFile(file, false, true);    // TODO perform in background task / new thread
         finish();
     }
     
@@ -781,14 +778,14 @@ public class PreviewMediaFragment extends FileFragment implements
     }
     
     private void onRemoveFileOperationFinish(RemoveFileOperation operation, RemoteOperationResult result) {
-        ((FileDisplayActivity) getActivity()).dismissLoadingDialog();
+        ((FileActivity) getSherlockActivity()).dismissLoadingDialog();
         if (result.isSuccess()) {
-            Toast msg = Toast.makeText(getActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
+            Toast msg = Toast.makeText(getSherlockActivity().getApplicationContext(), R.string.remove_success_msg, Toast.LENGTH_LONG);
             msg.show();
             finish();
                 
         } else {
-            Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
+            Toast msg = Toast.makeText(getSherlockActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG); 
             msg.show();
             if (result.isSslRecoverableException()) {
                 // TODO show the SSL warning dialog
@@ -812,7 +809,7 @@ public class PreviewMediaFragment extends FileFragment implements
      * Finishes the preview
      */
     private void finish() {
-        getActivity().onBackPressed();
+        getSherlockActivity().onBackPressed();
     }