Add "Open as" option in explorer menu

This commit is contained in:
Matéo Duparc 2021-10-19 11:24:20 +02:00
parent c858d556d5
commit 5349d40da9
Signed by untrusted user: hardcoresushi
GPG Key ID: 007F84120107191E
7 changed files with 52 additions and 30 deletions

View File

@ -149,6 +149,26 @@ open class BaseExplorerActivity : BaseActivity() {
ExternalProvider.open(this, gocryptfsVolume, fullPath)
}
private fun showOpenAsDialog(path: String) {
val adapter = OpenAsDialogAdapter(this, usf_open)
ColoredAlertDialogBuilder(this)
.setSingleChoiceItems(adapter, -1) { dialog, which ->
when (adapter.getItem(which)) {
"image" -> startFileViewer(ImageViewer::class.java, path)
"video" -> startFileViewer(VideoPlayer::class.java, path)
"audio" -> startFileViewer(AudioPlayer::class.java, path)
"text" -> startFileViewer(TextEditor::class.java, path)
"external" -> if (usf_open) {
openWithExternalApp(path)
}
}
dialog.dismiss()
}
.setTitle(getString(R.string.open_as) + ':')
.setNegativeButton(R.string.cancel, null)
.show()
}
protected open fun onExplorerItemClick(position: Int) {
val wasSelecting = explorerAdapter.selectedItems.isNotEmpty()
explorerAdapter.onItemClick(position)
@ -174,25 +194,7 @@ open class BaseExplorerActivity : BaseActivity() {
isAudio(fullPath) -> {
startFileViewer(AudioPlayer::class.java, fullPath)
}
else -> {
val adapter = OpenAsDialogAdapter(this, usf_open)
ColoredAlertDialogBuilder(this)
.setSingleChoiceItems(adapter, -1){ dialog, which ->
when (adapter.getItem(which)){
"image" -> startFileViewer(ImageViewer::class.java, fullPath)
"video" -> startFileViewer(VideoPlayer::class.java, fullPath)
"audio" -> startFileViewer(AudioPlayer::class.java, fullPath)
"text" -> startFileViewer(TextEditor::class.java, fullPath)
"external" -> if (usf_open){
openWithExternalApp(fullPath)
}
}
dialog.dismiss()
}
.setTitle(getString(R.string.open_as))
.setNegativeButton(R.string.cancel, null)
.show()
}
else -> showOpenAsDialog(fullPath)
}
}
}
@ -458,6 +460,7 @@ open class BaseExplorerActivity : BaseActivity() {
protected fun handleMenuItems(menu: Menu){
menu.findItem(R.id.rename).isVisible = false
menu.findItem(R.id.open_as)?.isVisible = false
if (usf_open){
menu.findItem(R.id.external_open)?.isVisible = false
}
@ -470,8 +473,11 @@ open class BaseExplorerActivity : BaseActivity() {
toolbar.setNavigationIcon(R.drawable.icon_arrow_back)
if (explorerAdapter.selectedItems.size == 1) {
menu.findItem(R.id.rename).isVisible = true
if (usf_open && explorerElements[explorerAdapter.selectedItems[0]].isRegularFile) {
menu.findItem(R.id.external_open)?.isVisible = true
if (explorerElements[explorerAdapter.selectedItems[0]].isRegularFile) {
menu.findItem(R.id.open_as)?.isVisible = true
if (usf_open) {
menu.findItem(R.id.external_open)?.isVisible = true
}
}
}
}
@ -520,6 +526,10 @@ open class BaseExplorerActivity : BaseActivity() {
dialog.show()
true
}
R.id.open_as -> {
showOpenAsDialog(PathUtils.pathJoin(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))
true
}
R.id.external_open -> {
if (usf_open){
openWithExternalApp(PathUtils.pathJoin(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))

View File

@ -48,6 +48,12 @@
android:visible="false"
android:title="@string/external_open"/>
<item
android:id="@+id/open_as"
app:showAsAction="never"
android:visible="false"
android:title="@string/open_as"/>
<item
android:id="@+id/rename"
app:showAsAction="never"

View File

@ -2,12 +2,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/external_open"
app:showAsAction="never"
android:visible="false"
android:title="@string/external_open"/>
<item
android:id="@+id/rename"
app:showAsAction="never"

View File

@ -14,6 +14,18 @@
android:visible="false"
android:icon="@drawable/icon_select_all"/>
<item
android:id="@+id/external_open"
app:showAsAction="never"
android:visible="false"
android:title="@string/external_open"/>
<item
android:id="@+id/open_as"
app:showAsAction="never"
android:visible="false"
android:title="@string/open_as"/>
<item
android:id="@+id/rename"
app:showAsAction="never"

View File

@ -111,7 +111,7 @@
<string name="preference_theme_color_summary">Definir uma cor personalizada do tema</string>
<string name="usf_home_warning_msg">DroidFS tenta ser o mais seguro possível. No entanto, a segurança muitas vezes resulta em falta de conforto. Por isso o DroidFS oferece opções adicionais que você pode alternar de acordo com as suas necessidades.\n\nAviso: estas opções podem ser PERIGOSAS. Não as utilize a menos que você saiba o que está fazendo. É altamente recomendável ler a documentação antes de ativá-las.</string>
<string name="see_unsafe_features">Ver opções perigosas</string>
<string name="open_as">Abrir como:</string>
<string name="open_as">Abrir como</string>
<string name="image">Imagem</string>
<string name="video">Vídeo</string>
<string name="audio">Áudio</string>

View File

@ -110,7 +110,7 @@
<string name="preference_theme_color_summary">Установить собственный цвет темы</string>
<string name="usf_home_warning_msg">DroidFS старается быть максимально безопасным, однако безопасность часто связана с появлением неудобств. Поэтому DroidFS предлагает дополнительные небезопасные функции, которые вы можете включить/отключить в соответствии со своими потребностями.\n\nПредупреждение: эти функции могут быть НЕБЕЗОПАСНЫМИ. Не используйте их, если не уверены в своих действиях. Настоятельно рекомендуется прочитать документацию перед их включением.</string>
<string name="see_unsafe_features">Посмотреть небезопасные функции</string>
<string name="open_as">Открыть как:</string>
<string name="open_as">Открыть как</string>
<string name="image">Изображение</string>
<string name="video">Видео</string>
<string name="audio">Аудио</string>

View File

@ -113,7 +113,7 @@
<string name="preference_theme_color_summary">Set a custom theme color</string>
<string name="usf_home_warning_msg">DroidFS try to be as secure as possible. However, security often involves lack of comfort. This is why DroidFS offer you additional unsafe features that you can enable/disable according to your needs.\n\nWarning: this features can be UNSAFE. Do not use them unless you know exactly what you are doing. It is highly recommended to read the documentation before enabling them.</string>
<string name="see_unsafe_features">See unsafe features</string>
<string name="open_as">Open as:</string>
<string name="open_as">Open as</string>
<string name="image">Image</string>
<string name="video">Video</string>
<string name="audio">Audio</string>