android: Convert FileBrowserHelper to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-11 00:36:55 -05:00 committed by bunnei
parent c9d2d74f1f
commit 7fb7f3e83f
2 changed files with 26 additions and 25 deletions

View File

@ -1,25 +0,0 @@
package org.yuzu.yuzu_emu.utils;
import android.content.Intent;
import androidx.fragment.app.FragmentActivity;
public final class FileBrowserHelper {
public static void openDirectoryPicker(FragmentActivity activity, int requestCode, int title) {
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
i.putExtra(Intent.EXTRA_TITLE, title);
activity.startActivityForResult(i, requestCode);
}
public static void openFilePicker(FragmentActivity activity, int requestCode, int title) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_TITLE, title);
intent.setType("*/*");
activity.startActivityForResult(intent, requestCode);
}
public static String getSelectedDirectory(Intent result) {
return result.getDataString();
}
}

View File

@ -0,0 +1,26 @@
package org.yuzu.yuzu_emu.utils
import android.content.Intent
import androidx.fragment.app.FragmentActivity
object FileBrowserHelper {
fun openDirectoryPicker(activity: FragmentActivity, requestCode: Int, title: Int) {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
i.putExtra(Intent.EXTRA_TITLE, title)
activity.startActivityForResult(i, requestCode)
}
fun openFilePicker(activity: FragmentActivity, requestCode: Int, title: Int) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.flags =
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
intent.putExtra(Intent.EXTRA_TITLE, title)
intent.type = "*/*"
activity.startActivityForResult(intent, requestCode)
}
fun getSelectedDirectory(result: Intent): String? {
return result.dataString
}
}