mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-10 15:33:17 +01:00
Added saving MMS (#106)
This commit is contained in:
parent
95fbe59ac8
commit
f2a25b46dd
@ -52,10 +52,13 @@ import kotlinx.android.synthetic.main.item_selected_contact.view.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class ThreadActivity : SimpleActivity() {
|
||||
private val MIN_DATE_TIME_DIFF_SECS = 300
|
||||
private val PICK_ATTACHMENT_INTENT = 1
|
||||
private val PICK_SAVE_FILE_INTENT = 11
|
||||
|
||||
private var threadId = 0L
|
||||
private var currentSIMCardIndex = 0
|
||||
@ -69,6 +72,7 @@ class ThreadActivity : SimpleActivity() {
|
||||
private val availableSIMCards = ArrayList<SIMCard>()
|
||||
private var attachmentSelections = mutableMapOf<String, AttachmentSelection>()
|
||||
private val imageCompressor by lazy { ImageCompressor(this) }
|
||||
private var lastAttachmentUri: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -171,6 +175,24 @@ class ThreadActivity : SimpleActivity() {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == PICK_ATTACHMENT_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||
addAttachment(resultData.data!!)
|
||||
} else if (requestCode == PICK_SAVE_FILE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||
val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
||||
applicationContext.contentResolver.takePersistableUriPermission(resultData.data!!, takeFlags)
|
||||
var inputStream: InputStream? = null
|
||||
var outputStream: OutputStream? = null
|
||||
try {
|
||||
inputStream = contentResolver.openInputStream(Uri.parse(lastAttachmentUri))
|
||||
outputStream = contentResolver.openOutputStream(Uri.parse(resultData.dataString!!), "rwt")
|
||||
inputStream!!.copyTo(outputStream!!)
|
||||
outputStream.flush()
|
||||
toast(R.string.file_saved)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
} finally {
|
||||
inputStream?.close()
|
||||
outputStream?.close()
|
||||
}
|
||||
lastAttachmentUri = null
|
||||
}
|
||||
}
|
||||
|
||||
@ -872,6 +894,16 @@ class ThreadActivity : SimpleActivity() {
|
||||
return participants
|
||||
}
|
||||
|
||||
fun saveMMS(mimeType: String, path: String) {
|
||||
lastAttachmentUri = path
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
|
||||
type = mimeType
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(Intent.EXTRA_TITLE, path.split("/").last())
|
||||
startActivityForResult(this, PICK_SAVE_FILE_INTENT)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Subscribe(threadMode = ThreadMode.ASYNC)
|
||||
fun refreshMessages(event: Events.RefreshMessages) {
|
||||
|
@ -30,6 +30,7 @@ import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||
import com.simplemobiletools.smsmessenger.dialogs.SelectTextDialog
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteMessage
|
||||
import com.simplemobiletools.smsmessenger.extensions.updateLastConversationMessage
|
||||
@ -62,10 +63,13 @@ class ThreadAdapter(
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {
|
||||
val isOneItemSelected = isOneItemSelected()
|
||||
val selectedItem = getSelectedItems().firstOrNull() as? Message
|
||||
val hasText = selectedItem?.body != null && selectedItem.body != ""
|
||||
menu.apply {
|
||||
findItem(R.id.cab_copy_to_clipboard).isVisible = isOneItemSelected
|
||||
findItem(R.id.cab_share).isVisible = isOneItemSelected
|
||||
findItem(R.id.cab_select_text).isVisible = isOneItemSelected
|
||||
findItem(R.id.cab_copy_to_clipboard).isVisible = isOneItemSelected && hasText
|
||||
findItem(R.id.cab_save_as).isVisible = isOneItemSelected && selectedItem?.attachment?.attachments?.size == 1
|
||||
findItem(R.id.cab_share).isVisible = isOneItemSelected && hasText
|
||||
findItem(R.id.cab_select_text).isVisible = isOneItemSelected && hasText
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,6 +80,7 @@ class ThreadAdapter(
|
||||
|
||||
when (id) {
|
||||
R.id.cab_copy_to_clipboard -> copyToClipboard()
|
||||
R.id.cab_save_as -> saveAs()
|
||||
R.id.cab_share -> shareText()
|
||||
R.id.cab_select_text -> selectText()
|
||||
R.id.cab_delete -> askConfirmDelete()
|
||||
@ -142,6 +147,12 @@ class ThreadAdapter(
|
||||
activity.copyToClipboard(firstItem.body)
|
||||
}
|
||||
|
||||
private fun saveAs() {
|
||||
val firstItem = getSelectedItems().firstOrNull() as? Message ?: return
|
||||
val attachment = firstItem.attachment?.attachments?.first() ?: return
|
||||
(activity as ThreadActivity).saveMMS(attachment.mimetype, attachment.uriString)
|
||||
}
|
||||
|
||||
private fun shareText() {
|
||||
val firstItem = getSelectedItems().firstOrNull() as? Message ?: return
|
||||
activity.shareTextIntent(firstItem.body)
|
||||
|
@ -6,6 +6,11 @@
|
||||
android:icon="@drawable/ic_copy_vector"
|
||||
android:title="@string/copy_to_clipboard"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/cab_save_as"
|
||||
android:icon="@drawable/ic_save_vector"
|
||||
android:title="@string/save_as"
|
||||
app:showAsAction="always" />
|
||||
<item
|
||||
android:id="@+id/cab_share"
|
||||
android:icon="@drawable/ic_share_vector"
|
||||
|
Loading…
Reference in New Issue
Block a user