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

refactor/ clean up

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 3 жил өмнө
parent
commit
07885c3a18

+ 0 - 38
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -2274,44 +2274,6 @@ public class FileDataStorageManager {
         }
     }
 
-    public boolean virtualExists(VirtualFolderType type, OCFile file) {
-        Cursor cursor;
-
-        if (getContentProviderClient() != null) {
-            try {
-                cursor = getContentProviderClient().query(
-                    ProviderTableMeta.CONTENT_URI_VIRTUAL,
-                    null,
-                    ProviderTableMeta.VIRTUAL_TYPE + AND + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " =?",
-                    new String[]{String.valueOf(type), file.getRemoteId()},
-                    null
-                                                         );
-            } catch (RemoteException e) {
-                Log_OC.e(TAG, e.getMessage(), e);
-                return false;
-            }
-        } else {
-            cursor = getContentResolver().query(
-                ProviderTableMeta.CONTENT_URI_VIRTUAL,
-                null,
-                ProviderTableMeta.VIRTUAL_TYPE + AND + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " =?",
-                new String[]{String.valueOf(type), file.getRemoteId()},
-                null
-                                               );
-        }
-
-        if (cursor == null) {
-            Log_OC.e(TAG, "Couldn't determine file existence, assuming non existence");
-
-            return false;
-        } else {
-            boolean exists = cursor.moveToFirst();
-            cursor.close();
-
-            return exists;
-        }
-    }
-
     public List<OCFile> getAllGalleryItems() {
         return getGalleryItems(0, Long.MAX_VALUE);
     }

+ 1 - 2
src/main/java/com/owncloud/android/db/ProviderMeta.java

@@ -35,7 +35,7 @@ import java.util.List;
  */
 public class ProviderMeta {
     public static final String DB_NAME = "filelist";
-    public static final int DB_VERSION = 63;
+    public static final int DB_VERSION = 62;
 
     private ProviderMeta() {
         // No instance
@@ -286,7 +286,6 @@ public class ProviderMeta {
         // Columns of virtual
         public static final String VIRTUAL_TYPE = "type";
         public static final String VIRTUAL_OCFILE_ID = "ocfile_id";
-        public static final String VIRTUAL_OCFILE_REMOTE_ID = "ocfile_remote_id";
 
         // Columns of filesystem data table
         public static final String FILESYSTEM_FILE_LOCAL_PATH = "local_path";

+ 0 - 22
src/main/java/com/owncloud/android/providers/FileContentProvider.java

@@ -916,7 +916,6 @@ public class FileContentProvider extends ContentProvider {
                        + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "          // id
                        + ProviderTableMeta.VIRTUAL_TYPE + " TEXT, "                // type
                        + ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )"        // file id
-                       + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " STRING )"  // remote id
                   );
     }
 
@@ -2468,27 +2467,6 @@ public class FileContentProvider extends ContentProvider {
             if (!upgraded) {
                 Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
             }
-
-            if (oldVersion < 63 && newVersion >= 63) {
-                Log_OC.i(SQL, "Entering in the #63 add remote_id to virtuals");
-                db.beginTransaction();
-                try {
-                    db.execSQL(ALTER_TABLE + ProviderTableMeta.VIRTUAL_TABLE_NAME +
-                                   ADD_COLUMN + ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID + " TEXT ");
-
-                    // delete all virtual
-                    db.execSQL("DELETE FROM `virtual`");
-
-                    upgraded = true;
-                    db.setTransactionSuccessful();
-                } finally {
-                    db.endTransaction();
-                }
-            }
-
-            if (!upgraded) {
-                Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
-            }
         }
     }
 }

+ 1 - 5
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -857,14 +857,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         notifyDataSetChanged();
     }
 
-    // TODO split up
     public void setData(List<Object> objects,
                         ExtendedListFragment.SearchType searchType,
                         FileDataStorageManager storageManager,
                         @Nullable OCFile folder,
-                        boolean clear,
-                        long startDate,
-                        long endDate) {
+                        boolean clear) {
         if (storageManager != null && mStorageManager == null) {
             mStorageManager = storageManager;
             showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
@@ -1025,7 +1022,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 ContentValues cv = new ContentValues();
                 cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
                 cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
-                cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_REMOTE_ID, ocFile.getRemoteId());
 
                 contentValues.add(cv);
             } catch (RemoteOperationFailedException e) {

+ 37 - 42
src/main/java/com/owncloud/android/ui/asynctasks/GallerySearchTask.java

@@ -32,7 +32,6 @@ import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
 import com.owncloud.android.lib.resources.files.model.RemoteFile;
 import com.owncloud.android.lib.resources.status.OCCapability;
 import com.owncloud.android.operations.RefreshFolderOperation;
-import com.owncloud.android.ui.adapter.OCFileListAdapter;
 import com.owncloud.android.ui.fragment.ExtendedListFragment;
 import com.owncloud.android.ui.fragment.GalleryFragment;
 import com.owncloud.android.utils.FileStorageUtils;
@@ -44,7 +43,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-public class GallerySearchTask extends AsyncTask<Void, Void, RemoteOperationResult> {
+public class GallerySearchTask extends AsyncTask<Void, Void, GallerySearchTask.Result> {
 
     private final User user;
     private final WeakReference<GalleryFragment> photoFragmentWeakReference;
@@ -67,32 +66,15 @@ public class GallerySearchTask extends AsyncTask<Void, Void, RemoteOperationResu
         this.limit = limit;
     }
 
-//    @Override
-//    protected void onPreExecute() {
-//        super.onPreExecute();
-//
-//        if (photoFragmentWeakReference.get() == null) {
-//            return;
-//        }
-//        GalleryFragment photoFragment = photoFragmentWeakReference.get();
-//        // photoFragment.searchCompleted(true, lastTimeStamp);
-//    }
-
     @Override
-    protected RemoteOperationResult doInBackground(Void... voids) {
-//        try {
-//            Thread.sleep(5 * 1000);
-//        } catch (InterruptedException e) {
-//            e.printStackTrace();
-//        }
-
+    protected GallerySearchTask.Result doInBackground(Void... voids) {
         if (photoFragmentWeakReference.get() == null) {
-            return new RemoteOperationResult(new Exception("Photo fragment is null"));
+            return new Result(false, false, -1);
         }
         GalleryFragment photoFragment = photoFragmentWeakReference.get();
 
         if (isCancelled()) {
-            return new RemoteOperationResult(new Exception("Cancelled"));
+            return new Result(false, false, -1);
         } else {
             OCCapability ocCapability = storageManager.getCapability(user.getAccountName());
 
@@ -111,39 +93,40 @@ public class GallerySearchTask extends AsyncTask<Void, Void, RemoteOperationResu
                          "Start gallery search with " + new Date(startDate * 1000L) +
                              " - " + new Date(endDate * 1000L) +
                              " with limit: " + limit);
-                return searchRemoteOperation.execute(user.toPlatformAccount(), photoFragment.getContext());
+
+                RemoteOperationResult result = searchRemoteOperation.execute(user.toPlatformAccount(),
+                                                                             photoFragment.getContext());
+
+                if (result.isSuccess() && result.getData() != null && !isCancelled()) {
+                    if (result.getData() == null || result.getData().size() == 0) {
+                        photoFragment.setEmptyListMessage(ExtendedListFragment.SearchType.GALLERY_SEARCH);
+                    }
+                }
+
+                boolean emptySearch = parseMedia(startDate, endDate, result.getData());
+                long lastTimeStamp = findLastTimestamp(result.getData());
+
+                photoFragment.getAdapter().showAllGalleryItems(storageManager);
+
+                return new Result(result.isSuccess(), emptySearch, lastTimeStamp);
             } else {
-                return new RemoteOperationResult(new IllegalStateException("No context available"));
+                return new Result(false, false, -1);
             }
         }
     }
 
     @Override
-    protected void onPostExecute(RemoteOperationResult result) {
+    protected void onPostExecute(GallerySearchTask.Result result) {
         if (photoFragmentWeakReference.get() != null) {
             GalleryFragment photoFragment = photoFragmentWeakReference.get();
 
             photoFragment.setLoading(false);
 
-            OCFileListAdapter adapter = photoFragment.getAdapter();
-
-            if (result.isSuccess() && result.getData() != null && !isCancelled()) {
-                if (result.getData() == null || result.getData().size() == 0) {
-                    photoFragment.setEmptyListMessage(ExtendedListFragment.SearchType.GALLERY_SEARCH);
-                }
-            }
-
-            if (!result.isSuccess() && !isCancelled()) {
+            if (!result.success || result.emptySearch) {
                 photoFragment.setEmptyListMessage(ExtendedListFragment.SearchType.GALLERY_SEARCH);
+            } else {
+                photoFragment.searchCompleted(result.emptySearch, result.lastTimestamp);
             }
-
-            // TODO move this to backgroundThread
-            boolean emptySearch = parseMedia(startDate, endDate, result.getData());
-            long lastTimeStamp = findLastTimestamp(result.getData());
-
-            adapter.showAllGalleryItems(storageManager);
-
-            photoFragment.searchCompleted(emptySearch, lastTimeStamp);
         }
     }
 
@@ -210,4 +193,16 @@ public class GallerySearchTask extends AsyncTask<Void, Void, RemoteOperationResu
                                          Collection<OCFile> filesToRemove) {
         return filesToAdd.isEmpty() && filesToUpdate.isEmpty() && filesToRemove.isEmpty();
     }
+
+    public static class Result {
+        public boolean success;
+        public boolean emptySearch;
+        public long lastTimestamp;
+
+        public Result(boolean success, boolean emptySearch, long lastTimestamp) {
+            this.success = success;
+            this.emptySearch = emptySearch;
+            this.lastTimestamp = lastTimestamp;
+        }
+    }
 }

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

@@ -28,7 +28,6 @@ import android.view.View;
 import android.view.ViewGroup;
 
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.asynctasks.GallerySearchTask;
 import com.owncloud.android.ui.events.ChangeMenuEvent;
@@ -43,7 +42,7 @@ import androidx.recyclerview.widget.RecyclerView;
 public class GalleryFragment extends OCFileListFragment {
     private static final int MAX_ITEMS_PER_ROW = 10;
     private boolean photoSearchQueryRunning = false;
-    private AsyncTask<Void, Void, RemoteOperationResult> photoSearchTask;
+    private AsyncTask<Void, Void, GallerySearchTask.Result> photoSearchTask;
     private long startDate;
     private long endDate;
     private long daySpan = 30;
@@ -128,7 +127,6 @@ public class GalleryFragment extends OCFileListFragment {
 
     private void searchAndDisplay() {
         // first: always search from now to -30 days
-
         if (!photoSearchQueryRunning) {
             photoSearchQueryRunning = true;
 

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

@@ -1503,9 +1503,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
                          SearchType.NO_SEARCH,
                          mContainerActivity.getStorageManager(),
                          mFile,
-                         true,
-                         -1,
-                         -1);
+                         true);
 
         setFabVisible(false);
 
@@ -1563,9 +1561,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
                                              currentSearchType,
                                              storageManager,
                                              mFile,
-                                             true,
-                                             -1,
-                                             -1);
+                                             true);
                         }
 
                         final ToolbarActivity fileDisplayActivity = (ToolbarActivity) getActivity();