浏览代码

further centralize mimetype definitions

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 2 年之前
父节点
当前提交
dd129b4e6c

+ 2 - 1
app/src/main/java/com/nextcloud/talk/activities/FullScreenImageActivity.kt

@@ -37,6 +37,7 @@ import com.nextcloud.talk.BuildConfig
 import com.nextcloud.talk.R
 import com.nextcloud.talk.databinding.ActivityFullScreenImageBinding
 import com.nextcloud.talk.utils.BitmapShrinker
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX_GENERIC
 import pl.droidsonroids.gif.GifDrawable
 import java.io.File
 
@@ -64,7 +65,7 @@ class FullScreenImageActivity : AppCompatActivity() {
             val shareIntent: Intent = Intent().apply {
                 action = Intent.ACTION_SEND
                 putExtra(Intent.EXTRA_STREAM, shareUri)
-                type = "image/*"
+                type = IMAGE_PREFIX_GENERIC
                 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
             }
             startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))

+ 2 - 1
app/src/main/java/com/nextcloud/talk/activities/FullScreenMediaActivity.kt

@@ -38,6 +38,7 @@ import com.nextcloud.talk.BuildConfig
 import com.nextcloud.talk.R
 import com.nextcloud.talk.application.NextcloudTalkApplication
 import com.nextcloud.talk.databinding.ActivityFullScreenMediaBinding
+import com.nextcloud.talk.utils.Mimetype.VIDEO_PREFIX_GENERIC
 import java.io.File
 
 @AutoInjector(NextcloudTalkApplication::class)
@@ -66,7 +67,7 @@ class FullScreenMediaActivity : AppCompatActivity(), Player.Listener {
             val shareIntent: Intent = Intent().apply {
                 action = Intent.ACTION_SEND
                 putExtra(Intent.EXTRA_STREAM, shareUri)
-                type = "video/*"
+                type = VIDEO_PREFIX_GENERIC
                 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
             }
             startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))

+ 2 - 1
app/src/main/java/com/nextcloud/talk/activities/FullScreenTextViewerActivity.kt

@@ -35,6 +35,7 @@ import com.nextcloud.talk.R
 import com.nextcloud.talk.application.NextcloudTalkApplication
 import com.nextcloud.talk.databinding.ActivityFullScreenTextBinding
 import com.nextcloud.talk.utils.DisplayUtils
+import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX_GENERIC
 import io.noties.markwon.Markwon
 import java.io.File
 
@@ -63,7 +64,7 @@ class FullScreenTextViewerActivity : AppCompatActivity() {
             val shareIntent: Intent = Intent().apply {
                 action = Intent.ACTION_SEND
                 putExtra(Intent.EXTRA_STREAM, shareUri)
-                type = "text/*"
+                type = TEXT_PREFIX_GENERIC
                 addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
             }
             startActivity(Intent.createChooser(shareIntent, resources.getText(R.string.send_to)))

+ 1 - 1
app/src/main/java/com/nextcloud/talk/components/filebrowser/models/BrowserFile.kt

@@ -36,7 +36,7 @@ import com.nextcloud.talk.components.filebrowser.models.properties.NCPreview
 import com.nextcloud.talk.components.filebrowser.models.properties.OCFavorite
 import com.nextcloud.talk.components.filebrowser.models.properties.OCId
 import com.nextcloud.talk.components.filebrowser.models.properties.OCSize
-import com.nextcloud.talk.utils.Mimetype.Companion.FOLDER
+import com.nextcloud.talk.utils.Mimetype.FOLDER
 import kotlinx.android.parcel.Parcelize
 import java.io.File
 

+ 1 - 1
app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFolderListingOperation.kt

@@ -44,7 +44,7 @@ import com.nextcloud.talk.dagger.modules.RestModule.MagicAuthenticator
 import com.nextcloud.talk.models.database.UserEntity
 import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem
 import com.nextcloud.talk.utils.ApiUtils
-import com.nextcloud.talk.utils.Mimetype.Companion.FOLDER
+import com.nextcloud.talk.utils.Mimetype.FOLDER
 import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
 import okhttp3.OkHttpClient
 import java.io.File

+ 3 - 1
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -147,6 +147,8 @@ import io.reactivex.disposables.Disposable;
 import io.reactivex.schedulers.Schedulers;
 import retrofit2.HttpException;
 
+import static com.nextcloud.talk.utils.Mimetype.TEXT_PLAIN;
+
 @AutoInjector(NextcloudTalkApplication.class)
 public class ConversationsListController extends BaseController implements FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, ConversationMenuInterface {
 
@@ -1099,7 +1101,7 @@ public class ConversationsListController extends BaseController implements Flexi
                 || Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
                 try {
                     String mimeType = intent.getType();
-                    if ("text/plain".equals(mimeType) && (intent.getStringExtra(Intent.EXTRA_TEXT) != null)) {
+                    if (TEXT_PLAIN.equals(mimeType) && (intent.getStringExtra(Intent.EXTRA_TEXT) != null)) {
                         // Share from Google Chrome sets text/plain MIME type, but also provides a content:// URI
                         // with a *screenshot* of the current page in getClipData().
                         // Here we assume that when sharing a web page the user would prefer to send the URL

+ 8 - 3
app/src/main/java/com/nextcloud/talk/controllers/ProfileController.kt

@@ -71,7 +71,9 @@ import com.nextcloud.talk.ui.dialog.ScopeDialog
 import com.nextcloud.talk.utils.ApiUtils
 import com.nextcloud.talk.utils.DisplayUtils
 import com.nextcloud.talk.utils.FileUtils
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_PREFIX
+import com.nextcloud.talk.utils.Mimetype.IMAGE_JPG
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX_GENERIC
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MIME_TYPE_FILTER
 import com.nextcloud.talk.utils.database.user.UserUtils
 import io.reactivex.Observer
@@ -566,10 +568,13 @@ class ProfileController : NewBaseController(R.layout.controller_profile) {
     private fun uploadAvatar(file: File?) {
         val builder = MultipartBody.Builder()
         builder.setType(MultipartBody.FORM)
-        builder.addFormDataPart("files[]", file!!.name, RequestBody.create("image/*".toMediaTypeOrNull(), file))
+        builder.addFormDataPart(
+            "files[]", file!!.name,
+            RequestBody.create(IMAGE_PREFIX_GENERIC.toMediaTypeOrNull(), file)
+        )
         val filePart: MultipartBody.Part = MultipartBody.Part.createFormData(
             "files[]", file.name,
-            RequestBody.create("image/jpg".toMediaTypeOrNull(), file)
+            RequestBody.create(IMAGE_JPG.toMediaTypeOrNull(), file)
         )
 
         // upload file

+ 1 - 1
app/src/main/java/com/nextcloud/talk/remotefilebrowser/adapters/RemoteFileBrowserItemsListViewHolder.kt

@@ -37,7 +37,7 @@ import com.nextcloud.talk.utils.ApiUtils
 import com.nextcloud.talk.utils.DateUtils.getLocalDateTimeStringFromTimestamp
 import com.nextcloud.talk.utils.DisplayUtils
 import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType
-import com.nextcloud.talk.utils.Mimetype.Companion.FOLDER
+import com.nextcloud.talk.utils.Mimetype.FOLDER
 
 @AutoInjector(NextcloudTalkApplication::class)
 class RemoteFileBrowserItemsListViewHolder(

+ 1 - 1
app/src/main/java/com/nextcloud/talk/remotefilebrowser/viewmodels/RemoteFileBrowserItemsViewModel.kt

@@ -29,7 +29,7 @@ import androidx.lifecycle.ViewModel
 import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem
 import com.nextcloud.talk.remotefilebrowser.repositories.RemoteFileBrowserItemsRepository
 import com.nextcloud.talk.utils.FileSortOrder
-import com.nextcloud.talk.utils.Mimetype.Companion.FOLDER
+import com.nextcloud.talk.utils.Mimetype.FOLDER
 import com.nextcloud.talk.utils.preferences.AppPreferences
 import io.reactivex.Observer
 import io.reactivex.android.schedulers.AndroidSchedulers

+ 2 - 1
app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt

@@ -57,6 +57,7 @@ import com.nextcloud.talk.jobs.LeaveConversationWorker
 import com.nextcloud.talk.models.database.CapabilitiesUtil
 import com.nextcloud.talk.models.database.UserEntity
 import com.nextcloud.talk.models.json.conversations.Conversation
+import com.nextcloud.talk.utils.Mimetype.TEXT_PLAIN
 import com.nextcloud.talk.utils.ShareUtils
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_OPERATION_CODE
@@ -242,7 +243,7 @@ class ConversationsListBottomDialog(
         binding.conversationOperationShareLink.setOnClickListener {
             val sendIntent: Intent = Intent().apply {
                 action = Intent.ACTION_SEND
-                type = "text/plain"
+                type = TEXT_PLAIN
                 putExtra(
                     Intent.EXTRA_SUBJECT,
                     String.format(

+ 5 - 6
app/src/main/java/com/nextcloud/talk/utils/DrawableUtils.kt

@@ -21,12 +21,11 @@
 package com.nextcloud.talk.utils
 
 import com.nextcloud.talk.R
-import com.nextcloud.talk.utils.Mimetype.Companion.AUDIO_PREFIX
-import com.nextcloud.talk.utils.Mimetype.Companion.FOLDER
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_PREFIX
-import com.nextcloud.talk.utils.Mimetype.Companion.TEXT_PREFIX
-import com.nextcloud.talk.utils.Mimetype.Companion.VIDEO_PREFIX
-import java.util.HashMap
+import com.nextcloud.talk.utils.Mimetype.AUDIO_PREFIX
+import com.nextcloud.talk.utils.Mimetype.FOLDER
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PREFIX
+import com.nextcloud.talk.utils.Mimetype.TEXT_PREFIX
+import com.nextcloud.talk.utils.Mimetype.VIDEO_PREFIX
 
 object DrawableUtils {
 

+ 36 - 24
app/src/main/java/com/nextcloud/talk/utils/FileViewerUtils.kt

@@ -47,20 +47,28 @@ import com.nextcloud.talk.models.database.CapabilitiesUtil
 import com.nextcloud.talk.models.database.UserEntity
 import com.nextcloud.talk.models.json.chat.ChatMessage
 import com.nextcloud.talk.utils.AccountUtils.canWeOpenFilesApp
-import com.nextcloud.talk.utils.Mimetype.Companion.AUDIO_PREFIX
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_GIF
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_JPEG
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_PNG
+import com.nextcloud.talk.utils.Mimetype.AUDIO_MPEG
+import com.nextcloud.talk.utils.Mimetype.AUDIO_OGG
+import com.nextcloud.talk.utils.Mimetype.AUDIO_PREFIX
+import com.nextcloud.talk.utils.Mimetype.AUDIO_WAV
+import com.nextcloud.talk.utils.Mimetype.IMAGE_GIF
+import com.nextcloud.talk.utils.Mimetype.IMAGE_JPEG
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PNG
+import com.nextcloud.talk.utils.Mimetype.TEXT_MARKDOWN
+import com.nextcloud.talk.utils.Mimetype.TEXT_PLAIN
+import com.nextcloud.talk.utils.Mimetype.VIDEO_MP4
+import com.nextcloud.talk.utils.Mimetype.VIDEO_OGG
+import com.nextcloud.talk.utils.Mimetype.VIDEO_QUICKTIME
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ACCOUNT
 import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_ID
 import java.io.File
 import java.util.concurrent.ExecutionException
 
 /*
-Usage of this class forces us to do things at one location which should be separated in a activity and view model.
-
-Example:
-  - SharedItemsViewHolder
+ * Usage of this class forces us to do things at one location which should be separated in a activity and view model.
+ *
+ * Example:
+ *   - SharedItemsViewHolder
  */
 class FileViewerUtils(private val context: Context, private val userEntity: UserEntity) {
 
@@ -147,19 +155,19 @@ class FileViewerUtils(private val context: Context, private val userEntity: User
     private fun openFileByMimetype(filename: String, mimetype: String?) {
         if (mimetype != null) {
             when (mimetype) {
-                "audio/mpeg",
-                "audio/wav",
-                "audio/ogg",
-                "video/mp4",
-                "video/quicktime",
-                "video/ogg"
+                AUDIO_MPEG,
+                AUDIO_WAV,
+                AUDIO_OGG,
+                VIDEO_MP4,
+                VIDEO_QUICKTIME,
+                VIDEO_OGG
                 -> openMediaView(filename, mimetype)
                 IMAGE_PNG,
                 IMAGE_JPEG,
                 IMAGE_GIF
                 -> openImageView(filename, mimetype)
-                "text/markdown",
-                "text/plain"
+                TEXT_MARKDOWN,
+                TEXT_PLAIN
                 -> openTextView(filename, mimetype)
                 else
                 -> openFileByExternalApp(filename, mimetype)
@@ -253,12 +261,17 @@ class FileViewerUtils(private val context: Context, private val userEntity: User
 
     fun isSupportedForInternalViewer(mimetype: String?): Boolean {
         return when (mimetype) {
-            IMAGE_PNG, IMAGE_JPEG,
-            IMAGE_GIF, "audio/mpeg",
-            "audio/wav", "audio/ogg",
-            "video/mp4", "video/quicktime",
-            "video/ogg", "text/markdown",
-            "text/plain" -> true
+            IMAGE_PNG,
+            IMAGE_JPEG,
+            IMAGE_GIF,
+            AUDIO_MPEG,
+            AUDIO_WAV,
+            AUDIO_OGG,
+            VIDEO_MP4,
+            VIDEO_QUICKTIME,
+            VIDEO_OGG,
+            TEXT_MARKDOWN,
+            TEXT_PLAIN -> true
             else -> false
         }
     }
@@ -268,7 +281,7 @@ class FileViewerUtils(private val context: Context, private val userEntity: User
     }
 
     private fun isMarkdown(mimetype: String): Boolean {
-        return "text/markdown" == mimetype
+        return TEXT_MARKDOWN == mimetype
     }
 
     private fun isAudioOnly(mimetype: String): Boolean {
@@ -420,6 +433,5 @@ class FileViewerUtils(private val context: Context, private val userEntity: User
 
     companion object {
         private val TAG = FileViewerUtils::class.simpleName
-        const val KEY_ID = "id"
     }
 }

+ 3 - 3
app/src/main/java/com/nextcloud/talk/utils/ImageEmojiEditText.kt

@@ -29,9 +29,9 @@ import android.view.inputmethod.InputConnection
 import androidx.core.view.inputmethod.EditorInfoCompat
 import androidx.core.view.inputmethod.InputConnectionCompat
 import androidx.emoji.widget.EmojiEditText
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_GIF
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_JPEG
-import com.nextcloud.talk.utils.Mimetype.Companion.IMAGE_PNG
+import com.nextcloud.talk.utils.Mimetype.IMAGE_GIF
+import com.nextcloud.talk.utils.Mimetype.IMAGE_JPEG
+import com.nextcloud.talk.utils.Mimetype.IMAGE_PNG
 
 /*
 Subclass of EmojiEditText with support for image keyboards - primarily for GIF handling. ;-)

+ 1 - 1
app/src/main/java/com/nextcloud/talk/utils/LoggingUtils.kt

@@ -52,7 +52,7 @@ object LoggingUtils {
         // val mailto = "android@nextcloud.com"
         // emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mailto))
         // emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs")
-        // emailIntent.type = "text/plain"
+        // emailIntent.type = TEXT_PLAIN
         // emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
         // val uri: Uri
         //

+ 27 - 13
app/src/main/java/com/nextcloud/talk/utils/Mimetype.kt

@@ -20,17 +20,31 @@
 
 package com.nextcloud.talk.utils
 
-class Mimetype {
-    companion object {
-        const val IMAGE_PREFIX = "image/"
-        const val VIDEO_PREFIX = "video/"
-        const val TEXT_PREFIX = "text/"
-        const val AUDIO_PREFIX = "audio"
-
-        const val FOLDER = "inode/directory"
-
-        const val IMAGE_PNG = "image/png"
-        const val IMAGE_JPEG = "image/jpeg"
-        const val IMAGE_GIF = "image/gif"
-    }
+object Mimetype {
+    const val IMAGE_PREFIX = "image/"
+    const val VIDEO_PREFIX = "video/"
+    const val TEXT_PREFIX = "text/"
+    const val AUDIO_PREFIX = "audio"
+
+    const val IMAGE_PREFIX_GENERIC = "image/*"
+    const val VIDEO_PREFIX_GENERIC = "video/*"
+    const val TEXT_PREFIX_GENERIC = "text/*"
+
+    const val FOLDER = "inode/directory"
+
+    const val IMAGE_PNG = "image/png"
+    const val IMAGE_JPEG = "image/jpeg"
+    const val IMAGE_JPG = "image/jpg"
+    const val IMAGE_GIF = "image/gif"
+
+    const val VIDEO_MP4 = "video/mp4"
+    const val VIDEO_QUICKTIME = "video/quicktime"
+    const val VIDEO_OGG = "video/ogg"
+
+    const val TEXT_MARKDOWN = "text/markdown"
+    const val TEXT_PLAIN = "text/plain"
+
+    const val AUDIO_MPEG = "audio/mpeg"
+    const val AUDIO_WAV = "audio/wav"
+    const val AUDIO_OGG = "audio/ogg"
 }