External open choice in Open as dialog

This commit is contained in:
Hardcore Sushi 2020-09-05 11:37:47 +02:00
parent ef83e1c1fc
commit c588773dea
5 changed files with 20 additions and 19 deletions

View File

@ -14,8 +14,8 @@ android {
applicationId "sushi.hardcore.droidfs" applicationId "sushi.hardcore.droidfs"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 1 versionCode 2
versionName "1.1.6" versionName "1.1.7"
ndk { ndk {
abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a' abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a'

View File

@ -1,24 +1,19 @@
package sushi.hardcore.droidfs.adapters package sushi.hardcore.droidfs.adapters
import android.content.Context import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.view.marginEnd
import androidx.core.view.setPadding
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.widgets.ColoredImageView
class OpenAsDialogAdapter(context: Context) : IconTextDialogAdapter(context) { class OpenAsDialogAdapter(context: Context, showOpenWithExternalApp: Boolean) : IconTextDialogAdapter(context) {
private val openAsItems = listOf( private val openAsItems = mutableListOf(
listOf("image", R.string.image, R.drawable.icon_file_image), listOf("image", R.string.image, R.drawable.icon_file_image),
listOf("video", R.string.video, R.drawable.icon_file_video), listOf("video", R.string.video, R.drawable.icon_file_video),
listOf("audio", R.string.audio, R.drawable.icon_file_audio), listOf("audio", R.string.audio, R.drawable.icon_file_audio),
listOf("text", R.string.text, R.drawable.icon_file_text) listOf("text", R.string.text, R.drawable.icon_file_text)
) )
init { init {
if (showOpenWithExternalApp){
openAsItems.add(listOf("external", R.string.external_open, R.drawable.icon_open_in_new))
}
items = openAsItems items = openAsItems
} }
} }

View File

@ -102,6 +102,11 @@ open class BaseExplorerActivity : BaseActivity() {
startActivity(intent) startActivity(intent)
} }
private fun openWithExternalApp(fullPath: String){
isStartingActivity = true
ExternalProvider.open(this, gocryptfsVolume, fullPath)
}
protected open fun onExplorerItemClick(position: Int) { protected open fun onExplorerItemClick(position: Int) {
val wasSelecting = explorerAdapter.selectedItems.isNotEmpty() val wasSelecting = explorerAdapter.selectedItems.isNotEmpty()
explorerAdapter.onItemClick(position) explorerAdapter.onItemClick(position)
@ -128,7 +133,7 @@ open class BaseExplorerActivity : BaseActivity() {
startFileViewer(AudioPlayer::class.java, fullPath) startFileViewer(AudioPlayer::class.java, fullPath)
} }
else -> { else -> {
val adapter = OpenAsDialogAdapter(this) val adapter = OpenAsDialogAdapter(this, usf_open)
ColoredAlertDialogBuilder(this) ColoredAlertDialogBuilder(this)
.setSingleChoiceItems(adapter, -1){ dialog, which -> .setSingleChoiceItems(adapter, -1){ dialog, which ->
when (adapter.getItem(which)){ when (adapter.getItem(which)){
@ -136,6 +141,9 @@ open class BaseExplorerActivity : BaseActivity() {
"video" -> startFileViewer(VideoPlayer::class.java, fullPath) "video" -> startFileViewer(VideoPlayer::class.java, fullPath)
"audio" -> startFileViewer(AudioPlayer::class.java, fullPath) "audio" -> startFileViewer(AudioPlayer::class.java, fullPath)
"text" -> startFileViewer(TextEditor::class.java, fullPath) "text" -> startFileViewer(TextEditor::class.java, fullPath)
"external" -> if (usf_open){
openWithExternalApp(fullPath)
}
} }
dialog.dismiss() dialog.dismiss()
} }
@ -390,8 +398,7 @@ open class BaseExplorerActivity : BaseActivity() {
} }
R.id.external_open -> { R.id.external_open -> {
if (usf_open){ if (usf_open){
isStartingActivity = true openWithExternalApp(PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))
ExternalProvider.open(this, gocryptfsVolume, PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))
unselectAll() unselectAll()
} }
true true

View File

@ -679,7 +679,7 @@ class ExplorerActivity : BaseExplorerActivity() {
} }
private fun recursiveExportDirectory(plain_directory_path: String, treeDocumentFile: DocumentFile): String? { private fun recursiveExportDirectory(plain_directory_path: String, treeDocumentFile: DocumentFile): String? {
treeDocumentFile.createDirectory(plain_directory_path)?.let {childTree -> treeDocumentFile.createDirectory(File(plain_directory_path).name)?.let {childTree ->
val explorerElements = gocryptfsVolume.listDir(plain_directory_path) val explorerElements = gocryptfsVolume.listDir(plain_directory_path)
for (e in explorerElements) { for (e in explorerElements) {
val fullPath = PathUtils.path_join(plain_directory_path, e.name) val fullPath = PathUtils.path_join(plain_directory_path, e.name)

View File

@ -3,20 +3,19 @@ package sushi.hardcore.droidfs.util
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.webkit.MimeTypeMap
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.provider.RestrictedFileProvider import sushi.hardcore.droidfs.provider.RestrictedFileProvider
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
import java.io.File import java.io.File
import java.net.URLConnection
import kotlin.collections.ArrayList
object ExternalProvider { object ExternalProvider {
private const val content_type_all = "*/*" private const val content_type_all = "*/*"
private var storedFiles: MutableList<Uri> = ArrayList() private var storedFiles: MutableList<Uri> = ArrayList()
private fun getContentType(filename: String, previous_content_type: String?): String? { private fun getContentType(filename: String, previous_content_type: String?): String? {
if (content_type_all != previous_content_type) { if (content_type_all != previous_content_type) {
var contentType = URLConnection.guessContentTypeFromName(filename) var contentType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(File(filename).extension)
if (contentType == null) { if (contentType == null) {
contentType = content_type_all contentType = content_type_all
} }