allow opening a file as different type with "Open as"
This commit is contained in:
parent
ba983ffc42
commit
f69228be71
|
@ -13,22 +13,20 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
import com.simplemobiletools.commons.dialogs.*
|
||||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
|
||||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
|
||||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
|
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
|
||||||
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
|
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.commons.views.FastScroller
|
import com.simplemobiletools.commons.views.FastScroller
|
||||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
import com.simplemobiletools.filemanager.dialogs.CompressAsDialog
|
||||||
import com.simplemobiletools.filemanager.extensions.*
|
import com.simplemobiletools.filemanager.extensions.*
|
||||||
import com.simplemobiletools.filemanager.helpers.RootHelpers
|
import com.simplemobiletools.filemanager.helpers.*
|
||||||
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
|
import com.simplemobiletools.filemanager.interfaces.ItemOperationsListener
|
||||||
import com.stericson.RootTools.RootTools
|
import com.stericson.RootTools.RootTools
|
||||||
import kotlinx.android.synthetic.main.list_item.view.*
|
import kotlinx.android.synthetic.main.list_item.view.*
|
||||||
|
@ -65,6 +63,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||||
findItem(R.id.cab_confirm_selection).isVisible = isPickMultipleIntent
|
findItem(R.id.cab_confirm_selection).isVisible = isPickMultipleIntent
|
||||||
findItem(R.id.cab_copy_path).isVisible = isOneItemSelected()
|
findItem(R.id.cab_copy_path).isVisible = isOneItemSelected()
|
||||||
findItem(R.id.cab_open_with).isVisible = isOneFileSelected()
|
findItem(R.id.cab_open_with).isVisible = isOneFileSelected()
|
||||||
|
findItem(R.id.cab_open_as).isVisible = isOneFileSelected()
|
||||||
findItem(R.id.cab_set_as).isVisible = isOneFileSelected()
|
findItem(R.id.cab_set_as).isVisible = isOneFileSelected()
|
||||||
|
|
||||||
checkHideBtnVisibility(this)
|
checkHideBtnVisibility(this)
|
||||||
|
@ -92,7 +91,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||||
R.id.cab_copy_path -> copyPath()
|
R.id.cab_copy_path -> copyPath()
|
||||||
R.id.cab_set_as -> setAs()
|
R.id.cab_set_as -> setAs()
|
||||||
R.id.cab_open_with -> openWith()
|
R.id.cab_open_with -> openWith()
|
||||||
R.id.cab_open_as -> openAsText()
|
R.id.cab_open_as -> openAs()
|
||||||
R.id.cab_copy_to -> copyMoveTo(true)
|
R.id.cab_copy_to -> copyMoveTo(true)
|
||||||
R.id.cab_move_to -> copyMoveTo(false)
|
R.id.cab_move_to -> copyMoveTo(false)
|
||||||
R.id.cab_compress -> compressSelection()
|
R.id.cab_compress -> compressSelection()
|
||||||
|
@ -224,8 +223,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
|
||||||
activity.tryOpenPathIntent(getSelectedMedia().first().path, true)
|
activity.tryOpenPathIntent(getSelectedMedia().first().path, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openAsText() {
|
private fun openAs() {
|
||||||
activity.tryOpenPathIntent(getSelectedMedia().first().path, false, true)
|
val res = activity.resources
|
||||||
|
val items = arrayListOf(
|
||||||
|
RadioItem(OPEN_AS_TEXT, res.getString(R.string.text_file)),
|
||||||
|
RadioItem(OPEN_AS_IMAGE, res.getString(R.string.image_file)),
|
||||||
|
RadioItem(OPEN_AS_AUDIO, res.getString(R.string.audio_file)),
|
||||||
|
RadioItem(OPEN_AS_VIDEO, res.getString(R.string.video_file)),
|
||||||
|
RadioItem(OPEN_AS_OTHER, res.getString(R.string.other_file)))
|
||||||
|
|
||||||
|
RadioGroupDialog(activity, items) {
|
||||||
|
activity.tryOpenPathIntent(getSelectedMedia().first().path, false, it as Int)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyMoveTo(isCopyOperation: Boolean) {
|
private fun copyMoveTo(isCopyOperation: Boolean) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import com.simplemobiletools.filemanager.BuildConfig
|
import com.simplemobiletools.filemanager.BuildConfig
|
||||||
|
import com.simplemobiletools.filemanager.helpers.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ fun Activity.sharePaths(paths: ArrayList<String>) {
|
||||||
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
sharePathsIntent(paths, BuildConfig.APPLICATION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, openAsText: Boolean = false) {
|
fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, openAsType: Int = OPEN_AS_DEFAULT) {
|
||||||
if (!forceChooser && path.endsWith(".apk", true)) {
|
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))
|
||||||
|
@ -35,13 +36,21 @@ fun Activity.tryOpenPathIntent(path: String, forceChooser: Boolean, openAsText:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
openPath(path, forceChooser, openAsText)
|
openPath(path, forceChooser, openAsType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.openPath(path: String, forceChooser: Boolean, openAsText: Boolean = false) {
|
fun Activity.openPath(path: String, forceChooser: Boolean, openAsType: Int = OPEN_AS_DEFAULT) {
|
||||||
val mimeType = if (openAsText) "text/plain" else ""
|
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID, getMimeType(openAsType))
|
||||||
openPathIntent(path, forceChooser, BuildConfig.APPLICATION_ID, mimeType)
|
}
|
||||||
|
|
||||||
|
private fun getMimeType(type: Int) = when (type) {
|
||||||
|
OPEN_AS_DEFAULT -> ""
|
||||||
|
OPEN_AS_TEXT -> "text/*"
|
||||||
|
OPEN_AS_IMAGE -> "image/*"
|
||||||
|
OPEN_AS_AUDIO -> "audio/*"
|
||||||
|
OPEN_AS_VIDEO -> "video/*"
|
||||||
|
else -> "*/*"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.setAs(path: String) {
|
fun Activity.setAs(path: String) {
|
||||||
|
|
|
@ -10,3 +10,11 @@ const val SORT_FOLDER_PREFIX = "sort_folder_"
|
||||||
const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
|
const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
|
||||||
const val IS_ROOT_AVAILABLE = "is_root_available"
|
const val IS_ROOT_AVAILABLE = "is_root_available"
|
||||||
const val ENABLE_ROOT_ACCESS = "enable_root_access"
|
const val ENABLE_ROOT_ACCESS = "enable_root_access"
|
||||||
|
|
||||||
|
// open as
|
||||||
|
const val OPEN_AS_DEFAULT = 0
|
||||||
|
const val OPEN_AS_TEXT = 1
|
||||||
|
const val OPEN_AS_IMAGE = 2
|
||||||
|
const val OPEN_AS_AUDIO = 3
|
||||||
|
const val OPEN_AS_VIDEO = 4
|
||||||
|
const val OPEN_AS_OTHER = 5
|
||||||
|
|
Loading…
Reference in New Issue