From f7a630c1d81cb0d06be11aa2d17592cba62d2cd4 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 | 20 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 20 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 e9615d33f..5306e57ae 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 @@ -110,6 +110,7 @@ class ComposeActivity : BaseActivity(), private var composeOptions: ComposeOptions? = null private val viewModel: ComposeViewModel by viewModels { viewModelFactory } + private val maxUploadMediaNumber = 4 private var mediaCount = 0 public override fun onCreate(savedInstanceState: Bundle?) { @@ -807,6 +808,7 @@ class ComposeActivity : BaseActivity(), val mimeTypes = arrayOf("image/*", "video/*", "audio/*") intent.type = "*/*" intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) startActivityForResult(intent, MEDIA_PICK_RESULT) } @@ -833,7 +835,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 85cd7cce5..87d63df5b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -591,5 +591,6 @@ Limit timeline notifications Hide quantitative stats on posts Hide quantitative stats on profiles + You cannot upload more than %1$d media attachments.