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"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.1.6"
versionCode 2
versionName "1.1.7"
ndk {
abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a'

View File

@ -1,24 +1,19 @@
package sushi.hardcore.droidfs.adapters
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.widgets.ColoredImageView
class OpenAsDialogAdapter(context: Context) : IconTextDialogAdapter(context) {
private val openAsItems = listOf(
class OpenAsDialogAdapter(context: Context, showOpenWithExternalApp: Boolean) : IconTextDialogAdapter(context) {
private val openAsItems = mutableListOf(
listOf("image", R.string.image, R.drawable.icon_file_image),
listOf("video", R.string.video, R.drawable.icon_file_video),
listOf("audio", R.string.audio, R.drawable.icon_file_audio),
listOf("text", R.string.text, R.drawable.icon_file_text)
)
init {
if (showOpenWithExternalApp){
openAsItems.add(listOf("external", R.string.external_open, R.drawable.icon_open_in_new))
}
items = openAsItems
}
}

View File

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

View File

@ -679,7 +679,7 @@ class ExplorerActivity : BaseExplorerActivity() {
}
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)
for (e in explorerElements) {
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.Intent
import android.net.Uri
import android.webkit.MimeTypeMap
import androidx.appcompat.app.AppCompatActivity
import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.provider.RestrictedFileProvider
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
import java.io.File
import java.net.URLConnection
import kotlin.collections.ArrayList
object ExternalProvider {
private const val content_type_all = "*/*"
private var storedFiles: MutableList<Uri> = ArrayList()
private fun getContentType(filename: String, previous_content_type: String?): String? {
if (content_type_all != previous_content_type) {
var contentType = URLConnection.guessContentTypeFromName(filename)
var contentType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(File(filename).extension)
if (contentType == null) {
contentType = content_type_all
}