Android: Use storage access framework for game list

This commit is contained in:
JosJuice 2020-11-08 18:41:01 +01:00
parent 2126f62111
commit ae8de35105
4 changed files with 25 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.utils.ContentHandler;
import org.dolphinemu.dolphinemu.utils.IniFile;
import java.io.File;
@ -58,8 +59,7 @@ public class GameFileCache
String path = dolphinIni.getString(Settings.SECTION_INI_GENERAL,
SettingsFile.KEY_ISO_PATH_BASE + i, "");
File folder = new File(path);
if (folder.exists())
if (path.startsWith("content://") ? ContentHandler.exists(path) : new File(path).exists())
{
pathSet.add(path);
}

View File

@ -163,7 +163,8 @@ public final class MainActivity extends AppCompatActivity implements MainView
@Override
public void launchFileListActivity()
{
FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
}
@Override
@ -201,7 +202,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
switch (requestCode)
{
case MainPresenter.REQUEST_DIRECTORY:
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result));
mPresenter.onDirectorySelected(result);
break;
case MainPresenter.REQUEST_GAME_FILE:

View File

@ -2,9 +2,11 @@ package org.dolphinemu.dolphinemu.ui.main;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
@ -17,6 +19,9 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.model.GameFileCache;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import java.util.Set;
public final class MainPresenter
{
@ -116,9 +121,19 @@ public final class MainPresenter
}
}
public void onDirectorySelected(String dir)
public void onDirectorySelected(Intent result)
{
mDirToAdd = dir;
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = result.getData();
Uri canonicalizedUri = contentResolver.canonicalize(uri);
if (canonicalizedUri != null)
uri = canonicalizedUri;
int takeFlags = result.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
mContext.getContentResolver().takePersistableUriPermission(uri, takeFlags);
mDirToAdd = uri.toString();
}
public void installWAD(String file)

View File

@ -168,7 +168,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView
@Override
public void launchFileListActivity()
{
FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
}
@Override
@ -225,7 +226,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
switch (requestCode)
{
case MainPresenter.REQUEST_DIRECTORY:
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result));
mPresenter.onDirectorySelected(result);
break;
case MainPresenter.REQUEST_GAME_FILE: