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 <connyduck@users.noreply.github.com> * remove magic number on string.xml and add to activity. Co-authored-by: Konrad Pozniak <connyduck@users.noreply.github.com>
This commit is contained in:
parent
8b9ddca7bd
commit
f7a630c1d8
|
@ -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) {
|
||||
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!!)
|
||||
}
|
||||
|
|
|
@ -591,5 +591,6 @@
|
|||
<string name="limit_notifications">Limit timeline notifications</string>
|
||||
<string name="wellbeing_hide_stats_posts">Hide quantitative stats on posts</string>
|
||||
<string name="wellbeing_hide_stats_profile">Hide quantitative stats on profiles</string>
|
||||
<string name="error_upload_max_media_reached">You cannot upload more than %1$d media attachments.</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue