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>
main
lenchan139 4 years ago committed by Alibek Omarov
parent 08c8aee553
commit d7ec778fd9
  1. 19
      app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt
  2. 1
      app/src/main/res/values/strings.xml

@ -132,6 +132,7 @@ class ComposeActivity : BaseActivity(),
val viewModel: ComposeViewModel by viewModels { viewModelFactory } val viewModel: ComposeViewModel by viewModels { viewModelFactory }
private var suggestFormattingSyntax: String = "text/markdown" private var suggestFormattingSyntax: String = "text/markdown"
private val maxUploadMediaNumber = 4
private var mediaCount = 0 private var mediaCount = 0
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
@ -1073,6 +1074,8 @@ class ComposeActivity : BaseActivity(),
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
} }
intent.type = "*/*" intent.type = "*/*"
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
startActivityForResult(intent, MEDIA_PICK_RESULT) startActivityForResult(intent, MEDIA_PICK_RESULT)
} }
@ -1099,7 +1102,23 @@ class ComposeActivity : BaseActivity(),
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent) super.onActivityResult(requestCode, resultCode, intent)
if (resultCode == Activity.RESULT_OK && requestCode == MEDIA_PICK_RESULT && intent != null) { if (resultCode == Activity.RESULT_OK && requestCode == MEDIA_PICK_RESULT && intent != null) {
if(intent.data != null){
// Single media, upload it and done.
pickMedia(intent.data!!) 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) { } else if (resultCode == Activity.RESULT_OK && requestCode == MEDIA_TAKE_PHOTO_RESULT) {
pickMedia(photoUploadUri!!) pickMedia(photoUploadUri!!)
} }

@ -595,6 +595,7 @@
<string name="limit_notifications">Limit timeline notifications</string> <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_posts">Hide quantitative stats on posts</string>
<string name="wellbeing_hide_stats_profile">Hide quantitative stats on profiles</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>
<string name="wellbeing_mode_notice">Some information that might affect your mental wellbeing will be hidden. This includes:\n\n <string name="wellbeing_mode_notice">Some information that might affect your mental wellbeing will be hidden. This includes:\n\n
- Favorite/Boost/Follow notifications\n - Favorite/Boost/Follow notifications\n

Loading…
Cancel
Save