From d7ec778fd947c58704dd9b33d61bdbbec97504b2 Mon Sep 17 00:00:00 2001 From: lenchan139 Date: Thu, 31 Dec 2020 00:36:00 +0800 Subject: [PATCH] multiple media upload support (#2029) * multiple media upload support * multiple media upload support * multiple media upload support * remove typing * Update app/src/main/res/values/strings.xml Co-authored-by: Konrad Pozniak * remove magic number on string.xml and add to activity. Co-authored-by: Konrad Pozniak --- .../components/compose/ComposeActivity.kt | 21 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index be1a3490..f43be81d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -132,6 +132,7 @@ class ComposeActivity : BaseActivity(), val viewModel: ComposeViewModel by viewModels { viewModelFactory } private var suggestFormattingSyntax: String = "text/markdown" + private val maxUploadMediaNumber = 4 private var mediaCount = 0 public override fun onCreate(savedInstanceState: Bundle?) { @@ -1073,6 +1074,8 @@ class ComposeActivity : BaseActivity(), intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) } intent.type = "*/*" + intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) startActivityForResult(intent, MEDIA_PICK_RESULT) } @@ -1099,7 +1102,23 @@ class ComposeActivity : BaseActivity(), override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { super.onActivityResult(requestCode, resultCode, intent) if (resultCode == Activity.RESULT_OK && requestCode == MEDIA_PICK_RESULT && intent != null) { - pickMedia(intent.data!!) + if(intent.data != null){ + // Single media, upload it and done. + pickMedia(intent.data!!) + }else if(intent.clipData != null){ + val clipData = intent.clipData!! + val count = clipData.itemCount + if(mediaCount + count > maxUploadMediaNumber){ + // check if exist media + upcoming media > 4, then prob error message. + Toast.makeText(this, getString(R.string.error_upload_max_media_reached, maxUploadMediaNumber), Toast.LENGTH_SHORT).show() + }else{ + // if not grater then 4, upload all multiple media. + for (i in 0 until count) { + val imageUri = clipData.getItemAt(i).getUri() + pickMedia(imageUri) + } + } + } } else if (resultCode == Activity.RESULT_OK && requestCode == MEDIA_TAKE_PHOTO_RESULT) { pickMedia(photoUploadUri!!) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de5a8e9b..ae573e39 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -595,6 +595,7 @@ Limit timeline notifications Hide quantitative stats on posts Hide quantitative stats on profiles + You cannot upload more than %1$d media attachments. Some information that might affect your mental wellbeing will be hidden. This includes:\n\n - Favorite/Boost/Follow notifications\n