浏览代码

Set icons for file actions

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父节点
当前提交
5b628f520c

+ 70 - 23
app/src/main/java/com/nextcloud/ui/fileactions/FileAction.kt

@@ -29,27 +29,74 @@ import com.owncloud.android.R
 
 // TODO get rid of id, use enum value directly
 enum class FileAction(@IdRes val id: Int, @StringRes val title: Int, @DrawableRes val icon: Int? = null) {
-    UNLOCK_FILE(R.id.action_unlock_file, R.string.unlock_file),
-    EDIT(R.id.action_edit, R.string.action_edit),
-    FAVORITE(R.id.action_favorite, R.string.favorite),
-    UNSET_FAVORITE(R.id.action_unset_favorite, R.string.unset_favorite),
-    SEE_DETAILS(R.id.action_see_details, R.string.actionbar_see_details),
-    LOCK_FILE(R.id.action_lock_file, R.string.lock_file),
-    RENAME_FILE(R.id.action_rename_file, R.string.common_rename),
-    MOVE(R.id.action_move, R.string.actionbar_move),
-    COPY(R.id.action_copy, R.string.actionbar_copy),
-    DOWNLOAD_FILE(R.id.action_download_file, R.string.filedetails_download),
-    EXPORT_FILE(R.id.action_export_file, R.string.filedetails_export),
-    STREAM_MEDIA(R.id.action_stream_media, R.string.stream),
-    SEND_SHARE_FILE(R.id.action_send_share_file, R.string.action_send_share),
-    SEND_FILE(R.id.action_send_file, R.string.common_send),
-    OPEN_FILE_WITH(R.id.action_open_file_with, R.string.actionbar_open_with),
-    SYNC_FILE(R.id.action_sync_file, R.string.filedetails_sync_file),
-    CANCEL_SYNC(R.id.action_cancel_sync, R.string.common_cancel_sync),
-    SELECT_ALL_ACTION_MENU(R.id.action_select_all_action_menu, R.string.select_all),
-    DESELECT_ALL_ACTION_MENU(R.id.action_deselect_all_action_menu, R.string.deselect_all),
-    ENCRYPTED(R.id.action_encrypted, R.string.encrypted),
-    UNSET_ENCRYPTED(R.id.action_unset_encrypted, R.string.unset_encrypted),
-    SET_AS_WALLPAPER(R.id.action_set_as_wallpaper, R.string.set_picture_as),
-    REMOVE_FILE(R.id.action_remove_file, R.string.common_remove)
+    // selection
+    SELECT_ALL(R.id.action_select_all_action_menu, R.string.select_all, R.drawable.ic_select_all),
+    SELECT_NONE(R.id.action_deselect_all_action_menu, R.string.deselect_all, R.drawable.ic_select_none),
+
+    // generic file actions
+    EDIT(R.id.action_edit, R.string.action_edit, R.drawable.ic_edit),
+    SEE_DETAILS(R.id.action_see_details, R.string.actionbar_see_details, R.drawable.ic_information_outline),
+    REMOVE_FILE(R.id.action_remove_file, R.string.common_remove, R.drawable.ic_delete),
+
+    // File moving
+    RENAME_FILE(R.id.action_rename_file, R.string.common_rename, R.drawable.ic_rename),
+    MOVE(R.id.action_move, R.string.actionbar_move, R.drawable.ic_move),
+    COPY(R.id.action_copy, R.string.actionbar_copy, R.drawable.ic_content_copy),
+
+    // favorites
+    FAVORITE(R.id.action_favorite, R.string.favorite, R.drawable.ic_star),
+    UNSET_FAVORITE(R.id.action_unset_favorite, R.string.unset_favorite, R.drawable.ic_star_outline),
+
+    // Uploads and downloads
+    DOWNLOAD_FILE(R.id.action_download_file, R.string.filedetails_download, R.drawable.ic_cloud_download),
+    SYNC_FILE(R.id.action_sync_file, R.string.filedetails_sync_file, R.drawable.ic_cloud_sync_on),
+    CANCEL_SYNC(R.id.action_cancel_sync, R.string.common_cancel_sync, R.drawable.ic_cloud_sync_off),
+
+    // File sharing
+    EXPORT_FILE(R.id.action_export_file, R.string.filedetails_export, R.drawable.ic_export),
+    SEND_SHARE_FILE(R.id.action_send_share_file, R.string.action_send_share, R.drawable.ic_share),
+    SEND_FILE(R.id.action_send_file, R.string.common_send, R.drawable.ic_share),
+    OPEN_FILE_WITH(R.id.action_open_file_with, R.string.actionbar_open_with, R.drawable.ic_external),
+    STREAM_MEDIA(R.id.action_stream_media, R.string.stream, R.drawable.ic_play_arrow),
+    SET_AS_WALLPAPER(R.id.action_set_as_wallpaper, R.string.set_picture_as, R.drawable.ic_wallpaper),
+
+    // Encryption
+    SET_ENCRYPTED(R.id.action_encrypted, R.string.encrypted, R.drawable.ic_encrypt),
+    UNSET_ENCRYPTED(R.id.action_unset_encrypted, R.string.unset_encrypted, R.drawable.ic_decrypt),
+
+    // locks
+    UNLOCK_FILE(R.id.action_unlock_file, R.string.unlock_file, R.drawable.ic_lock_open_white),
+    LOCK_FILE(R.id.action_lock_file, R.string.lock_file, R.drawable.ic_lock);
+
+    companion object {
+        /**
+         * All file actions, in the order they should be displayed
+         */
+        @JvmField
+        val SORTED_VALUES = listOf(
+            UNLOCK_FILE,
+            EDIT,
+            FAVORITE,
+            UNSET_FAVORITE,
+            SEE_DETAILS,
+            LOCK_FILE,
+            RENAME_FILE,
+            MOVE,
+            COPY,
+            DOWNLOAD_FILE,
+            EXPORT_FILE,
+            STREAM_MEDIA,
+            SEND_SHARE_FILE,
+            SEND_FILE,
+            OPEN_FILE_WITH,
+            SYNC_FILE,
+            CANCEL_SYNC,
+            SELECT_ALL,
+            SELECT_NONE,
+            SET_ENCRYPTED,
+            UNSET_ENCRYPTED,
+            SET_AS_WALLPAPER,
+            REMOVE_FILE
+        )
+    }
 }

+ 15 - 3
app/src/main/java/com/nextcloud/ui/fileactions/FileActionsBottomSheet.kt

@@ -36,6 +36,7 @@ import com.owncloud.android.databinding.FileActionsBottomSheetItemBinding
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.files.FileMenuFilter
 import com.owncloud.android.ui.activity.ComponentsGetter
+import com.owncloud.android.utils.theme.ViewThemeUtils
 import javax.inject.Inject
 
 // TODO add file name
@@ -44,7 +45,7 @@ import javax.inject.Inject
 // TODO viewModel
 // TODO drag handle
 // TODO theming
-class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
+class FileActionsBottomSheet private constructor() : BottomSheetDialogFragment(), Injectable {
 
     // TODO refactor FileMenuFilter and inject needed things into it
     lateinit var componentsGetter: ComponentsGetter
@@ -55,6 +56,9 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
     @Inject
     lateinit var currentAccountProvider: CurrentAccountProvider
 
+    @Inject
+    lateinit var viewThemeUtils: ViewThemeUtils
+
     private lateinit var binding: FileActionsBottomSheetBinding
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
@@ -75,16 +79,24 @@ class FileActionsBottomSheet : BottomSheetDialogFragment(), Injectable {
             currentAccountProvider.user
         )
             .getToHide(false)
-        FileAction.values()
+        FileAction.SORTED_VALUES
             .filter { it.id !in toHide }.forEach { action ->
                 // TODO change icon
                 val itemBinding = FileActionsBottomSheetItemBinding.inflate(inflater, binding.fileActionsList, false)
                     .apply {
-                        root.setText(action.title)
                         root.setOnClickListener {
                             clickListener.onClick(action.id)
                             dismiss()
                         }
+                        text.setText(action.title)
+                        if (action.icon != null) {
+                            val drawable =
+                                viewThemeUtils.platform.tintDrawable(
+                                    requireContext(),
+                                    resources.getDrawable(action.icon)
+                                )
+                            icon.setImageDrawable(drawable)
+                        }
                     }
                 binding.fileActionsList.addView(itemBinding.root)
             }

+ 47 - 0
app/src/main/java/com/nextcloud/utils/EditorUtils.kt

@@ -0,0 +1,47 @@
+/*
+ * Nextcloud Android client application
+ *
+ *  @author Álvaro Brey
+ *  Copyright (C) 2022 Álvaro Brey
+ *  Copyright (C) 2022 Nextcloud GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.nextcloud.utils
+
+import com.google.gson.Gson
+import com.nextcloud.client.account.User
+import com.owncloud.android.datamodel.ArbitraryDataProvider
+import com.owncloud.android.lib.common.DirectEditing
+import com.owncloud.android.lib.common.Editor
+import javax.inject.Inject
+
+class EditorUtils @Inject constructor(private val arbitraryDataProvider: ArbitraryDataProvider) {
+
+    fun getEditor(user: User?, mimeType: String?): Editor? {
+        val json = arbitraryDataProvider.getValue(user, ArbitraryDataProvider.DIRECT_EDITING)
+        if (json.isEmpty()) {
+            return null
+        }
+        val editors = Gson().fromJson(json, DirectEditing::class.java).editors.values
+        return editors.firstOrNull { mimeType in it.mimetypes }
+            ?: editors.firstOrNull { mimeType in it.optionalMimetypes }
+    }
+
+    fun isEditorAvailable(user: User?, mimeType: String?): Boolean {
+        return getEditor(user, mimeType) != null
+    }
+}

+ 8 - 0
app/src/main/res/drawable/ic_decrypt.xml

@@ -0,0 +1,8 @@
+<!-- drawable/key_minus.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M7.5 3C9.5 3 11.1 4.2 11.7 6H21V9H18V12H15V9H11.7C11.1 10.8 9.4 12 7.5 12C5 12 3 10 3 7.5S5 3 7.5 3M7.5 6C6.7 6 6 6.7 6 7.5S6.7 9 7.5 9 9 8.3 9 7.5 8.3 6 7.5 6M8 17H16V19H8V17Z" />
+</vector>

+ 8 - 0
app/src/main/res/drawable/ic_encrypt.xml

@@ -0,0 +1,8 @@
+<!-- drawable/key_plus.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M7.5 3C9.5 3 11.1 4.2 11.7 6H21V9H18V12H15V9H11.7C11.1 10.8 9.4 12 7.5 12C5 12 3 10 3 7.5S5 3 7.5 3M7.5 6C6.7 6 6 6.7 6 7.5S6.7 9 7.5 9 9 8.3 9 7.5 8.3 6 7.5 6M8 17H11V14H13V17H16V19H13V22H11V19H8V17Z" />
+</vector>

+ 8 - 0
app/src/main/res/drawable/ic_export.xml

@@ -0,0 +1,8 @@
+<!-- drawable/file_export_outline.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M14 2H6C4.9 2 4 2.9 4 4V20C4 21.1 4.9 22 6 22H18C19.1 22 20 21.1 20 20V8L14 2M18 20H6V4H13V9H18V20M16 11V18.1L13.9 16L11.1 18.8L8.3 16L11.1 13.2L8.9 11H16Z" />
+</vector>

+ 8 - 0
app/src/main/res/drawable/ic_lock.xml

@@ -0,0 +1,8 @@
+<!-- drawable/lock_outline.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M12,17C10.89,17 10,16.1 10,15C10,13.89 10.89,13 12,13A2,2 0 0,1 14,15A2,2 0 0,1 12,17M18,20V10H6V20H18M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V10C4,8.89 4.89,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z" />
+</vector>

+ 10 - 0
app/src/main/res/drawable/ic_move.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal">
+    <path
+        android:fillColor="@android:color/white"
+        android:pathData="M14 2H6C4.9 2 4 2.9 4 4V20C4 20.41 4.12 20.8 4.34 21.12C4.41 21.23 4.5 21.33 4.59 21.41C4.95 21.78 5.45 22 6 22H13.53C13 21.42 12.61 20.75 12.35 20H6V4H13V9H18V12C18.7 12 19.37 12.12 20 12.34V8L14 2M18 23L23 18.5L20 15.8L18 14V17H14V20H18V23Z" />
+</vector>

+ 10 - 0
app/src/main/res/drawable/ic_rename.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="48dp"
+    android:height="48dp"
+    android:viewportWidth="48"
+    android:viewportHeight="48"
+    android:tint="?attr/colorControlNormal">
+  <path
+      android:fillColor="@android:color/white"
+      android:pathData="M21.2,42 L28.2,35H43.5V42ZM38.2,14.7 L31.8,8.3 33.9,6.2Q34.75,5.35 36.025,5.375Q37.3,5.4 38.15,6.25L40.3,8.4Q41.15,9.25 41.15,10.5Q41.15,11.75 40.3,12.6ZM36.1,16.8 L10.9,42H4.5V35.6L29.7,10.4Z"/>
+</vector>

+ 8 - 0
app/src/main/res/drawable/ic_wallpaper.xml

@@ -0,0 +1,8 @@
+<!-- drawable/wallpaper.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+    <path android:fillColor="#000" android:pathData="M4,4H11V2H4A2,2 0 0,0 2,4V11H4V4M10,13L6,18H18L15,14L12.97,16.71L10,13M17,8.5A1.5,1.5 0 0,0 15.5,7A1.5,1.5 0 0,0 14,8.5A1.5,1.5 0 0,0 15.5,10A1.5,1.5 0 0,0 17,8.5M20,2H13V4H20V11H22V4A2,2 0 0,0 20,2M20,20H13V22H20A2,2 0 0,0 22,20V13H20V20M4,13H2V20A2,2 0 0,0 4,22H11V20H4V13Z" />
+</vector>

+ 26 - 10
app/src/main/res/layout/file_actions_bottom_sheet_item.xml

@@ -20,24 +20,40 @@
   ~
   -->
 
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/menu_upload_files"
     android:layout_width="match_parent"
     android:layout_height="@dimen/bottom_sheet_item_height"
+    android:clickable="true"
     android:background="?android:attr/selectableItemBackground"
-    android:drawablePadding="@dimen/bottom_sheet_text_start_margin"
     android:gravity="center_vertical"
-    android:clickable="true"
+    android:paddingLeft="@dimen/standard_padding"
     android:focusable="true"
     android:orientation="horizontal"
-    android:paddingLeft="@dimen/standard_padding"
     android:paddingTop="@dimen/standard_half_padding"
     android:paddingRight="@dimen/standard_padding"
     android:paddingBottom="@dimen/standard_half_padding"
-    android:textColor="@color/text_color"
-    android:textSize="@dimen/bottom_sheet_text_size"
-    app:drawableStartCompat="@drawable/ic_warning"
-    tools:text="Share file">
-    <!--TODO change drawable-->
-</TextView>
+    tools:ignore="UseCompoundDrawables">
+
+    <ImageView
+        android:id="@+id/icon"
+        android:layout_width="@dimen/iconized_single_line_item_icon_size"
+        android:layout_height="@dimen/iconized_single_line_item_icon_size"
+        android:contentDescription="@null"
+        app:tint="@color/primary"
+        tools:src="@drawable/ic_delete" />
+
+    <TextView
+        android:id="@+id/text"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:layout_marginStart="@dimen/bottom_sheet_text_start_margin"
+        android:textColor="@color/text_color"
+        android:textSize="@dimen/bottom_sheet_text_size"
+        tools:text="Delete file" />
+
+</LinearLayout>