launch a Pick PhotoVideo intent at pressing the attachment button

This commit is contained in:
tibbi 2020-04-12 12:17:06 +02:00
parent 9202e9d1b5
commit bed1d90434
1 changed files with 25 additions and 1 deletions

View File

@ -1,7 +1,9 @@
package com.simplemobiletools.smsmessenger.activities package com.simplemobiletools.smsmessenger.activities
import android.app.Activity
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Intent import android.content.Intent
import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.Telephony import android.provider.Telephony
import android.telephony.SmsManager import android.telephony.SmsManager
@ -32,6 +34,7 @@ import org.greenrobot.eventbus.ThreadMode
class ThreadActivity : SimpleActivity() { class ThreadActivity : SimpleActivity() {
private val MIN_DATE_TIME_DIFF_SECS = 300 private val MIN_DATE_TIME_DIFF_SECS = 300
private val PICK_ATTACHMENT_INTENT = 1
private var threadId = 0 private var threadId = 0
private var threadItems = ArrayList<ThreadItem>() private var threadItems = ArrayList<ThreadItem>()
@ -102,6 +105,13 @@ class ThreadActivity : SimpleActivity() {
return true return true
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == PICK_ATTACHMENT_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
addAttachment(resultData.data!!)
}
}
private fun setupAdapter() { private fun setupAdapter() {
threadItems = getThreadItems() threadItems = getThreadItems()
invalidateOptionsMenu() invalidateOptionsMenu()
@ -173,7 +183,7 @@ class ThreadActivity : SimpleActivity() {
thread_type_message.setText(intent.getStringExtra(THREAD_TEXT)) thread_type_message.setText(intent.getStringExtra(THREAD_TEXT))
thread_add_attachment.setOnClickListener { thread_add_attachment.setOnClickListener {
launchPickPhotoVideoIntent()
} }
} }
@ -272,6 +282,20 @@ class ThreadActivity : SimpleActivity() {
return items return items
} }
private fun launchPickPhotoVideoIntent() {
val mimeTypes = arrayOf("image/*", "video/*")
Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "*/*"
putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
startActivityForResult(this, PICK_ATTACHMENT_INTENT)
}
}
private fun addAttachment(uri: Uri) {
}
// show selected contacts, properly split to new lines when appropriate // show selected contacts, properly split to new lines when appropriate
// based on https://stackoverflow.com/a/13505029/1967672 // based on https://stackoverflow.com/a/13505029/1967672
private fun showSelectedContact(views: ArrayList<View>) { private fun showSelectedContact(views: ArrayList<View>) {