Sfoglia il codice sorgente

Implement favorites

Mario Danic 8 anni fa
parent
commit
6bdb618014

+ 42 - 9
src/main/java/com/owncloud/android/files/FileMenuFilter.java

@@ -229,20 +229,35 @@ public class FileMenuFilter {
             toShow.add(R.id.action_send_file);
         }
 
-        // FAVORITES
+        // Kept available offline
+        if (!allFiles() || synchronizing || allKeptAvailableOffline()) {
+            toHide.add(R.id.action_keep_files_offline);
+        } else {
+            toShow.add(R.id.action_keep_files_offline);
+        }
+
+        // Not kept available offline
+        if (!allFiles() || synchronizing || allNotKeptAvailableOffline()) {
+            toHide.add(R.id.action_unset_keep_files_offline);
+        } else {
+            toShow.add(R.id.action_unset_keep_files_offline);
+        }
+
+        // Favorite
         if (!allFiles() || synchronizing || allFavorites()) {
-            toHide.add(R.id.action_favorite_file);
+            toHide.add(R.id.action_favorite);
         } else {
-            toShow.add(R.id.action_favorite_file);
+            toShow.add(R.id.action_favorite);
         }
 
-        // UNFAVORITES
-        if (!allFiles() || synchronizing || allUnfavorites()) {
-            toHide.add(R.id.action_unfavorite_file);
+        // Unfavorite
+        if (!allFiles() || synchronizing || allNotFavorites()) {
+            toHide.add(R.id.action_unset_favorite);
         } else {
-            toShow.add(R.id.action_unfavorite_file);
+            toShow.add(R.id.action_unset_favorite);
         }
 
+
     }
 
     private boolean anyFileSynchronizing() {
@@ -320,7 +335,7 @@ public class FileMenuFilter {
         return false;
     }
 
-    private boolean allFavorites() {
+    private boolean allKeptAvailableOffline() {
         for(OCFile file: mFiles) {
             if(!file.isAvailableOffline()) {
                 return false;
@@ -329,7 +344,25 @@ public class FileMenuFilter {
         return true;
     }
 
-    private boolean allUnfavorites() {
+    private boolean allFavorites() {
+        for(OCFile file: mFiles) {
+            if(!file.getIsFavorite()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean allNotFavorites() {
+        for(OCFile file: mFiles) {
+            if(file.getIsFavorite()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean allNotKeptAvailableOffline() {
         for(OCFile file: mFiles) {
             if(file.isAvailableOffline()) {
                 return false;

+ 15 - 8
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -219,6 +219,21 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
             item.setEnabled(false);
         }
 
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_unset_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+
         Boolean dualPane = getResources().getBoolean(R.bool.large_land_layout);
 
         item = menu.findItem(R.id.action_switch_view);
@@ -285,14 +300,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
                 }
                 return true;
             }
-            case R.id.action_favorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), true);
-                return true;
-            }
-            case R.id.action_unfavorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), false);
-                return true;
-            }
             default:
                 return super.onOptionsItemSelected(item);
         }

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

@@ -879,14 +879,22 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
                 ((FileDisplayActivity) mContainerActivity).cancelTransference(checkedFiles);
                 return true;
             }
-            case R.id.action_favorite_file: {
+            case R.id.action_keep_files_offline: {
                 mContainerActivity.getFileOperationsHelper().toogleOfflineFiles(checkedFiles, true);
                 return true;
             }
-            case R.id.action_unfavorite_file: {
+            case R.id.action_unset_keep_files_offline: {
                 mContainerActivity.getFileOperationsHelper().toogleOfflineFiles(checkedFiles, false);
                 return true;
             }
+            case R.id.action_favorite: {
+                mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, true);
+                return true;
+            }
+            case R.id.action_unset_favorite: {
+                mContainerActivity.getFileOperationsHelper().toggleFavoriteFiles(checkedFiles, false);
+                return true;
+            }
             case R.id.action_move: {
                 Intent action = new Intent(getActivity(), FolderPickerActivity.class);
                 action.putParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES, checkedFiles);

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

@@ -49,6 +49,9 @@ import com.owncloud.android.services.observer.FileObserverService;
 import com.owncloud.android.ui.activity.FileActivity;
 import com.owncloud.android.ui.activity.ShareActivity;
 import com.owncloud.android.ui.dialog.ShareLinkToDialog;
+import com.owncloud.android.ui.events.FavoriteEvent;
+
+import org.greenrobot.eventbus.EventBus;
 
 import java.io.BufferedReader;
 import java.io.FileInputStream;
@@ -60,6 +63,9 @@ import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import static com.owncloud.android.R.drawable.file;
+import static com.owncloud.android.R.layout.files;
+
 /**
  *
  */
@@ -546,6 +552,28 @@ public class FileOperationsHelper {
         }
     }
 
+    public void toggleFavoriteFiles(Collection<OCFile> files, boolean shouldBeFavorite) {
+        List<OCFile> alreadyRightStateList = new ArrayList<>();
+        for(OCFile file : files) {
+            if(file.getIsFavorite() == shouldBeFavorite) {
+                alreadyRightStateList.add(file);
+            }
+        }
+
+        files.removeAll(alreadyRightStateList);
+
+        for (OCFile file: files) {
+            toggleFavoriteFile(file, shouldBeFavorite);
+        }
+    }
+
+    public void toggleFavoriteFile(OCFile file, boolean shouldBeFavorite) {
+        if(file.getIsFavorite() != shouldBeFavorite) {
+            EventBus.getDefault().post(new FavoriteEvent(file.getRemotePath(), shouldBeFavorite, file.getRemoteId()));
+        }
+    }
+
+
     public void toogleOfflineFiles(Collection<OCFile> files, boolean isAvailableOffline){
         List<OCFile> alreadyRightStateList = new ArrayList<>();
         for(OCFile file : files) {

+ 14 - 8
src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -280,6 +280,20 @@ public class PreviewImageFragment extends FileFragment {
             item.setEnabled(false);
         }
 
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_unset_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
     }
 
 
@@ -314,14 +328,6 @@ public class PreviewImageFragment extends FileFragment {
                 mContainerActivity.getFileOperationsHelper().syncFile(getFile());
                 return true;
             }
-            case R.id.action_favorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), true);
-                return true;
-            }
-            case R.id.action_unfavorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), false);
-                return true;
-            }
             default:
                 return super.onOptionsItemSelected(item);
         }

+ 15 - 8
src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -344,6 +344,21 @@ public class PreviewMediaFragment extends FileFragment implements
             item.setVisible(false);
             item.setEnabled(false);
         }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_unset_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
     }
 
 
@@ -378,14 +393,6 @@ public class PreviewMediaFragment extends FileFragment implements
                 mContainerActivity.getFileOperationsHelper().syncFile(getFile());
                 return true;
             }
-            case R.id.action_favorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), true);
-                return true;
-            }
-            case R.id.action_unfavorite_file:{
-                mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), false);
-                return true;
-            }
             default:
                 return super.onOptionsItemSelected(item);
         }

+ 15 - 0
src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -331,6 +331,21 @@ public class PreviewTextFragment extends FileFragment {
             item.setVisible(false);
             item.setEnabled(false);
         }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
+        // additional restriction for this fragment
+        item = menu.findItem(R.id.action_unset_favorite);
+        if (item != null) {
+            item.setVisible(false);
+            item.setEnabled(false);
+        }
+
     }
 
     /**

+ 14 - 2
src/main/res/menu/file_actions_menu.xml

@@ -93,19 +93,31 @@
         android:showAsAction="never"
         android:orderInCategory="1" />
     <item
-        android:id="@+id/action_favorite_file"
+        android:id="@+id/action_keep_files_offline"
         android:title="@string/favorite"
         android:icon="@drawable/ic_action_set_available_offline_white"
         app:showAsAction="never"
         android:showAsAction="never"
         android:orderInCategory="1" />
     <item
-        android:id="@+id/action_unfavorite_file"
+        android:id="@+id/action_unset_keep_files_offline"
         android:title="@string/unfavorite"
         android:icon="@drawable/ic_action_unset_available_offline_white"
         app:showAsAction="never"
         android:showAsAction="never"
         android:orderInCategory="1" />
+    <item
+        android:id="@+id/action_favorite"
+        android:title="@string/favorite_real"
+        app:showAsAction="never"
+        android:showAsAction="never"
+        android:orderInCategory="1" />
+    <item
+        android:id="@+id/action_unset_favorite"
+        android:title="@string/unset_favorite_real"
+        app:showAsAction="never"
+        android:showAsAction="never"
+        android:orderInCategory="1" />
     <item
         android:id="@+id/action_see_details"
         android:title="@string/actionbar_see_details"

+ 2 - 0
src/main/res/values/strings.xml

@@ -270,6 +270,8 @@
     
     <string name="favorite">Set as available offline</string>
     <string name="unfavorite">Unset as available offline</string>
+    <string name="favorite_real">Set as favorite</string>
+    <string name="unset_favorite_real">Unset favorite</string>
     <string name="common_rename">Rename</string>
     <string name="common_remove">Remove</string>
     <string name="confirmation_remove_file_alert">"Do you really want to remove %1$s?"</string>