Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6000e15e authored by tibbi's avatar tibbi
Browse files

run some activity intents on background threads, no code change

parent 0a3ec16e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.4.15'
        propVersionName = '3.5.0'
        kotlin_version = '1.2.10'
        support_libs = '27.0.2'
    }
+95 −83
Original line number Diff line number Diff line
@@ -126,6 +126,7 @@ fun Activity.isShowingSAFDialog(file: File, treeUri: String, requestCode: Int):
fun Activity.launchViewIntent(id: Int) = launchViewIntent(resources.getString(id))

fun Activity.launchViewIntent(url: String) {
    Thread {
        Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
            if (resolveActivity(packageManager) != null) {
                startActivity(this)
@@ -133,9 +134,11 @@ fun Activity.launchViewIntent(url: String) {
                toast(R.string.no_app_found)
            }
        }
    }.start()
}

fun Activity.shareUri(uri: Uri, applicationId: String) {
    Thread {
        val newUri = ensurePublicUri(uri, applicationId)
        Intent().apply {
            action = Intent.ACTION_SEND
@@ -148,9 +151,11 @@ fun Activity.shareUri(uri: Uri, applicationId: String) {
                toast(R.string.no_app_found)
            }
        }
    }.start()
}

fun Activity.shareUris(uris: ArrayList<Uri>, applicationId: String) {
    Thread {
        if (uris.size == 1) {
            shareUri(uris.first(), applicationId)
        } else {
@@ -176,9 +181,11 @@ fun Activity.shareUris(uris: ArrayList<Uri>, applicationId: String) {
                }
            }
        }
    }.start()
}

fun Activity.setAs(uri: Uri, applicationId: String) {
    Thread {
        val newUri = ensurePublicUri(uri, applicationId)
        Intent().apply {
            action = Intent.ACTION_ATTACH_DATA
@@ -192,9 +199,11 @@ fun Activity.setAs(uri: Uri, applicationId: String) {
                toast(R.string.no_app_found)
            }
        }
    }.start()
}

fun Activity.openEditor(uri: Uri, applicationId: String) {
    Thread {
        val newUri = ensurePublicUri(uri, applicationId)
        Intent().apply {
            action = Intent.ACTION_EDIT
@@ -208,14 +217,16 @@ fun Activity.openEditor(uri: Uri, applicationId: String) {
                toast(R.string.no_app_found)
            }
        }
    }.start()
}

fun Activity.openFile(uri: Uri, forceChooser: Boolean, applicationId: String) {
    Thread {
        val newUri = try {
            ensurePublicUri(uri, applicationId)
        } catch (e: Exception) {
            showErrorToast(e)
        return
            return@Thread
        }
        val mimeType = getUriMimeType(uri, newUri)
        Intent().apply {
@@ -238,6 +249,7 @@ fun Activity.openFile(uri: Uri, forceChooser: Boolean, applicationId: String) {
                }
            }
        }
    }.start()
}

fun Activity.getUriMimeType(oldUri: Uri, newUri: Uri): String {