Add support for sending all types of files
This commit is contained in:
parent
8d75d5b133
commit
23643d3198
26 changed files with 1234 additions and 459 deletions
|
|
@ -4,10 +4,12 @@ import android.app.Activity
|
|||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.commons.extensions.getMimeType
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import java.util.*
|
||||
|
||||
fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
|
||||
hideKeyboard()
|
||||
|
|
@ -24,3 +26,25 @@ fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.launchViewIntent(uri: Uri, mimetype: String, filename: String) {
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
setDataAndType(uri, mimetype.lowercase(Locale.getDefault()))
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
try {
|
||||
hideKeyboard()
|
||||
startActivity(this)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
val newMimetype = filename.getMimeType()
|
||||
if (newMimetype.isNotEmpty() && mimetype != newMimetype) {
|
||||
launchViewIntent(uri, newMimetype, filename)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -335,6 +335,7 @@ fun Context.getMmsAttachment(id: Long, getImageResolutions: Boolean): MessageAtt
|
|||
val attachment = Attachment(partId, id, Uri.withAppendedPath(uri, partId.toString()).toString(), mimetype, 0, 0, attachmentName)
|
||||
messageAttachment.attachments.add(attachment)
|
||||
} else {
|
||||
// todo: fix filename parsing, xml is shown some sometimes
|
||||
val text = cursor.getStringValue(Mms.Part.TEXT)
|
||||
val cutName = text.substringAfter("ref src=\"").substringBefore("\"")
|
||||
if (cutName.isNotEmpty()) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.simplemobiletools.smsmessenger.extensions
|
||||
|
||||
import android.animation.ObjectAnimator
|
||||
import android.view.View
|
||||
import androidx.core.animation.doOnStart
|
||||
import androidx.core.view.isVisible
|
||||
|
||||
fun View.showWithAnimation(duration: Long = 250L) {
|
||||
if (!isVisible) {
|
||||
ObjectAnimator.ofFloat(
|
||||
this, "alpha", 0f, 1f
|
||||
).apply {
|
||||
this.duration = duration
|
||||
doOnStart { visibility = View.VISIBLE }
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue