mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-06-05 22:09:15 +02:00
simplify Open as Plain Text, move the helper function in Commons
This commit is contained in:
@@ -45,7 +45,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.4.8'
|
implementation 'com.simplemobiletools:commons:4.4.9'
|
||||||
|
|
||||||
implementation files('../libs/RootTools.jar')
|
implementation files('../libs/RootTools.jar')
|
||||||
|
|
||||||
|
@@ -15,41 +15,8 @@ fun Activity.sharePaths(paths: ArrayList<String>) {
|
|||||||
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, asText: Boolean = false) {
|
fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, openAsText: Boolean = false) {
|
||||||
if (asText) {
|
if (!forceChooser && path.endsWith(".apk", true)) {
|
||||||
|
|
||||||
//TODO: Improve
|
|
||||||
|
|
||||||
val uri = if (isNougatPlus()) {
|
|
||||||
FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", File(path))
|
|
||||||
} else {
|
|
||||||
Uri.fromFile(File(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent().apply {
|
|
||||||
action = Intent.ACTION_VIEW
|
|
||||||
|
|
||||||
val mimeType = "text/plain"
|
|
||||||
setDataAndType(uri, mimeType)
|
|
||||||
|
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
||||||
|
|
||||||
if (resolveActivity(packageManager) != null) {
|
|
||||||
val chooser = Intent.createChooser(this, getString(R.string.open_with))
|
|
||||||
try {
|
|
||||||
startActivity(if (forceChooser) chooser else this)
|
|
||||||
} catch (e: NullPointerException) {
|
|
||||||
showErrorToast(e)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!tryGenericMimeType(this, mimeType, uri)) {
|
|
||||||
toast(R.string.no_app_found)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!forceChooser && path.endsWith(".apk", true)) {
|
|
||||||
val uri = if (isNougatPlus()) {
|
val uri = if (isNougatPlus()) {
|
||||||
FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", File(path))
|
FileProvider.getUriForFile(this, "${BuildConfig.APPLICATION_ID}.provider", File(path))
|
||||||
} else {
|
} else {
|
||||||
@@ -67,12 +34,13 @@ fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, asText: Bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
openPath(path, forceChooser)
|
openPath(path, forceChooser, openAsText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.openPath(path: String, forceChooser: Boolean) {
|
fun Activity.openPath(path: String, forceChooser: Boolean, openAsText: Boolean = false) {
|
||||||
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID)
|
val mimeType = if (openAsText) "text/plain" else ""
|
||||||
|
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID, mimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.setAs(path: String) {
|
fun Activity.setAs(path: String) {
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<string name="go_to_home_folder">Ísť do domovského priečinka</string>
|
<string name="go_to_home_folder">Ísť do domovského priečinka</string>
|
||||||
<string name="set_as_home_folder">Nastaviť ako domovský priečinok</string>
|
<string name="set_as_home_folder">Nastaviť ako domovský priečinok</string>
|
||||||
<string name="home_folder_updated">Domovský priečinok bol nastavený</string>
|
<string name="home_folder_updated">Domovský priečinok bol nastavený</string>
|
||||||
<string name="open_as_text">Open as Plain Text</string>
|
<string name="open_as_text">Otvoriť ako textový súbor</string>
|
||||||
<string name="copy_path">Kopírovať cestu do schránky</string>
|
<string name="copy_path">Kopírovať cestu do schránky</string>
|
||||||
<string name="path_copied">Cesta skopírovaná</string>
|
<string name="path_copied">Cesta skopírovaná</string>
|
||||||
<string name="select_audio_file">Prosím zvoľte audio súbor</string>
|
<string name="select_audio_file">Prosím zvoľte audio súbor</string>
|
||||||
|
Reference in New Issue
Block a user