mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 16:32:39 +00:00
pass file name to savefile intent
This commit is contained in:
2 files changed
+12
-8
No files matched your search
@@ -7,18 +7,25 @@ import android.net.Uri
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.provider.DocumentsContract
|
import android.provider.DocumentsContract
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
|
import androidx.documentfile.provider.DocumentFile
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
open class GeodeSaveFileActivityResult : ActivityResultContract<GeodeSaveFileActivityResult.SaveFileParams, Uri?>() {
|
open class GeodeSaveFileActivityResult : ActivityResultContract<GeodeSaveFileActivityResult.SaveFileParams, Uri?>() {
|
||||||
class SaveFileParams(val mimeType: String?, val defaultPath: Uri?) {}
|
class SaveFileParams(val mimeType: String?, val initialPath: File?)
|
||||||
override fun createIntent(context: Context, input: SaveFileParams): Intent {
|
override fun createIntent(context: Context, input: SaveFileParams): Intent {
|
||||||
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||||
.setType(input.mimeType ?: "*/*")
|
.setType(input.mimeType ?: "*/*")
|
||||||
|
|
||||||
|
if (input.initialPath != null) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
if (input.defaultPath != null) {
|
val uri = DocumentFile.fromFile(input.initialPath).uri
|
||||||
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, input.defaultPath)
|
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
intent.putExtra(Intent.EXTRA_TITLE, input.initialPath.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -320,15 +320,12 @@ object GeodeUtils {
|
|||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun createFile(path: String): Boolean {
|
fun createFile(path: String): Boolean {
|
||||||
var uri: Uri?
|
val initialPath = File(path)
|
||||||
DocumentFile.fromFile(File(path)).also {
|
|
||||||
uri = it.uri
|
|
||||||
}
|
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
checkForFilePermissions(
|
checkForFilePermissions(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
saveFileResultLauncher.launch(GeodeSaveFileActivityResult.SaveFileParams(null, uri))
|
saveFileResultLauncher.launch(GeodeSaveFileActivityResult.SaveFileParams(null, initialPath))
|
||||||
},
|
},
|
||||||
onFailure = { failedCallback() }
|
onFailure = { failedCallback() }
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user