Browse Source

Implement shared files

Mario Danic 8 years ago
parent
commit
8b7ecc4392

+ 2 - 0
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -436,6 +436,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
             case R.id.nav_shared:
                 menuItem.setChecked(true);
                 mCheckedMenuItem = menuItem.getItemId();
+                EventBus.getDefault().post(new SearchEvent("", SearchOperation.SearchType.SHARED_SEARCH,
+                        SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR));
                 break;
             case R.id.nav_videos:
                 menuItem.setChecked(true);

+ 19 - 4
src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -50,6 +50,7 @@ import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.lib.resources.files.RemoteFile;
+import com.owncloud.android.lib.resources.shares.OCShare;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
 import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.ui.fragment.ExtendedListFragment;
@@ -463,11 +464,25 @@ public class FileListListAdapter extends BaseAdapter {
 
     public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
         mFiles = new Vector<>();
+        if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
+            ArrayList<OCShare> shares = new ArrayList<>();
+            for (int i = 0; i < objects.size(); i++) {
+                shares.add((OCShare) objects.get(i));
+            }
+            mStorageManager.saveShares(shares);
+        }
         for (int i = 0; i < objects.size(); i++) {
-            OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
-            searchForLocalFileInDefaultPath(ocFile);
-
-            mFiles.add(ocFile);
+            if (!searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
+                OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
+                searchForLocalFileInDefaultPath(ocFile);
+                mFiles.add(ocFile);
+            } else {
+                OCShare ocShare = (OCShare) objects.get(i);
+                OCFile ocFile = mStorageManager.getFileByPath(ocShare.getPath());
+                if (!mFiles.contains(ocFile)) {
+                    mFiles.add(ocFile);
+                }
+            }
         }
 
         if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&

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

@@ -1263,7 +1263,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             currentSearchType = SearchType.RECENTLY_ADDED_SEARCH;
         } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
             currentSearchType = SearchType.RECENTLY_MODIFIED_SEARCH;
-        } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_FILTER)) {
+        } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
             currentSearchType = SearchType.SHARED_FILTER;
         }
 
@@ -1322,6 +1322,9 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             } else if (event.getSearchType().equals(SearchOperation.SearchType.RECENTLY_MODIFIED_SEARCH)) {
                 setEmptyListMessage(SearchType.RECENTLY_MODIFIED_SEARCH);
                 menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SORT;
+            } else if (event.getSearchType().equals(SearchOperation.SearchType.SHARED_SEARCH)) {
+                setEmptyListMessage(SearchType.SHARED_FILTER);
+                menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_SEARCH;
             }
 
             if (!currentSearchType.equals(SearchType.FILE_SEARCH) && getActivity() != null) {

+ 1 - 0
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -589,6 +589,7 @@ public class FileOperationsHelper {
         }
     }
 
+
     public void toggleOfflineFile(OCFile file, boolean isAvailableOffline) {
         if (file.isAvailableOffline() != isAvailableOffline) {
             file.setAvailableOffline(isAvailableOffline);

+ 8 - 9
src/main/res/layout/list_item.xml

@@ -38,25 +38,24 @@
             android:paddingTop="@dimen/standard_padding"
             android:paddingRight="4dp">
 
+            <ImageView
+                android:id="@+id/thumbnail"
+                android:layout_width="32dp"
+                android:layout_height="@dimen/file_icon_size"
+                android:layout_centerInParent="true"
+                android:layout_marginLeft="8dp"
+                android:src="@drawable/ic_menu_archive" />
+
             <ImageView
                 android:id="@+id/favorite_action"
                 android:layout_width="16dp"
                 android:layout_height="16dp"
-                android:layout_gravity="top|end"
                 android:layout_alignParentTop="true"
                 android:layout_alignParentRight="true"
                 android:layout_marginRight="4dp"
                 android:src="@drawable/ic_favorite"
                 />
 
-            <ImageView
-                android:id="@+id/thumbnail"
-                android:layout_width="32dp"
-                android:layout_height="@dimen/file_icon_size"
-                android:layout_centerInParent="true"
-                android:layout_marginLeft="8dp"
-                android:src="@drawable/ic_menu_archive" />
-
 
             <ImageView
                 android:id="@+id/keptOfflineIcon"