forked from geode-sdk/android-launcher
have internal links open storage provider
This commit is contained in:
2 files changed
+55
-13
No files matched your search
@@ -3,11 +3,13 @@ package com.geode.launcher
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.CancellationSignal
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.provider.DocumentsContract
|
||||
import android.provider.DocumentsProvider
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.annotation.RequiresApi
|
||||
import com.geode.launcher.utils.LaunchUtils
|
||||
import java.io.File
|
||||
|
||||
@@ -150,7 +152,7 @@ class UserDirectoryProvider : DocumentsProvider() {
|
||||
notifyFileChange(file)
|
||||
}
|
||||
|
||||
override fun renameDocument(documentId: String, displayName: String): String? {
|
||||
override fun renameDocument(documentId: String, displayName: String): String {
|
||||
val file = getFileForDocumentId(documentId)
|
||||
val dest = findFileNameForNewFile(File(file.parentFile, displayName))
|
||||
file.renameTo(dest)
|
||||
@@ -203,4 +205,19 @@ class UserDirectoryProvider : DocumentsProvider() {
|
||||
val uri = getDocumentUri(parentDocumentId)
|
||||
context!!.contentResolver.notifyChange(uri, null)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun findDocumentPath(
|
||||
parentDocumentId: String?,
|
||||
childDocumentId: String
|
||||
): DocumentsContract.Path {
|
||||
if (!parentDocumentId.isNullOrEmpty()) {
|
||||
// not implementing this for now...
|
||||
return super.findDocumentPath(parentDocumentId, childDocumentId)
|
||||
}
|
||||
|
||||
val nonRootPath = listOf(ROOT) + childDocumentId.removePrefix(ROOT).split("/")
|
||||
|
||||
return DocumentsContract.Path(ROOT, nonRootPath)
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.geode.launcher.BuildConfig
|
||||
import com.geode.launcher.R
|
||||
import com.geode.launcher.UserDirectoryProvider
|
||||
import com.geode.launcher.activityresult.GeodeOpenFileActivityResult
|
||||
import com.geode.launcher.activityresult.GeodeOpenFilesActivityResult
|
||||
import com.geode.launcher.activityresult.GeodeSaveFileActivityResult
|
||||
@@ -167,24 +168,48 @@ object GeodeUtils {
|
||||
// TODO As of now this is unused
|
||||
@JvmStatic
|
||||
fun openFolder(path: String): Boolean {
|
||||
activity.get()?.run {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
val context = activity.get()!!
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val documentFile = DocumentFile.fromFile(File(path))
|
||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, documentFile.uri)
|
||||
val pathFile = File(path)
|
||||
val baseDirectory = LaunchUtils.getBaseDirectory(context)
|
||||
val isInternalPath = pathFile.startsWith(baseDirectory)
|
||||
|
||||
val intent = if (isInternalPath) {
|
||||
// TODO: figure out how to get this to point to the path it should be pointing at
|
||||
// (the best i got was pointing at a file)
|
||||
// val relativePath = pathFile.relativeTo(baseDirectory)
|
||||
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
data = DocumentsContract.buildRootUri(
|
||||
"${context.packageName}.user", UserDirectoryProvider.ROOT
|
||||
)
|
||||
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_PREFIX_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
|
||||
intent.setType("*/*")
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val documentFile = DocumentFile.fromFile(File(path))
|
||||
putExtra(DocumentsContract.EXTRA_INITIAL_URI, documentFile.uri)
|
||||
}
|
||||
|
||||
if (intent.resolveActivity(packageManager) != null) {
|
||||
startActivity(intent)
|
||||
return true
|
||||
type = "*/*"
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
return try {
|
||||
context.startActivity(intent)
|
||||
true
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private external fun selectFileCallback(path: String)
|
||||
|
||||
Reference in new issue
Block a user