Android: Use storage access framework for importing WADs

This is part of my efforts to add support for scoped storage.
I figured I would start with a relatively simple feature to
make sure that everyone is fine with the approach I'm taking
before I tackle more complicated features like the game list.
This commit is contained in:
JosJuice 2020-07-18 11:37:41 +02:00
parent a9b15dfe3c
commit 8f712114b6
5 changed files with 12 additions and 13 deletions

View File

@ -293,9 +293,6 @@ public final class SettingsAdapter extends RecyclerView.Adapter<SettingViewHolde
case MainPresenter.REQUEST_GAME_FILE:
extensions = FileBrowserHelper.GAME_EXTENSIONS;
break;
case MainPresenter.REQUEST_WAD_FILE:
extensions = FileBrowserHelper.WAD_EXTENSION;
break;
default:
throw new InvalidParameterException("Unhandled request code");
}

View File

@ -171,8 +171,10 @@ public final class MainActivity extends AppCompatActivity implements MainView
@Override
public void launchInstallWAD()
{
FileBrowserHelper.openFilePicker(this, MainPresenter.REQUEST_WAD_FILE, false,
FileBrowserHelper.WAD_EXTENSION);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, MainPresenter.REQUEST_WAD_FILE);
}
/**
@ -199,7 +201,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
break;
case MainPresenter.REQUEST_WAD_FILE:
mPresenter.installWAD(FileBrowserHelper.getSelectedPath(result));
mPresenter.installWAD(result.getData().toString());
break;
}
}

View File

@ -16,6 +16,7 @@ import org.dolphinemu.dolphinemu.R;
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;
public final class MainPresenter
{
@ -99,7 +100,7 @@ public final class MainPresenter
return true;
case R.id.menu_install_wad:
mView.launchInstallWAD();
new AfterDirectoryInitializationRunner().run(context, true, mView::launchInstallWAD);
return true;
}

View File

@ -172,8 +172,10 @@ public final class TvMainActivity extends FragmentActivity implements MainView
@Override
public void launchInstallWAD()
{
FileBrowserHelper.openFilePicker(this, MainPresenter.REQUEST_WAD_FILE, false,
FileBrowserHelper.WAD_EXTENSION);
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, MainPresenter.REQUEST_WAD_FILE);
}
@Override
@ -211,7 +213,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
break;
case MainPresenter.REQUEST_WAD_FILE:
mPresenter.installWAD(FileBrowserHelper.getSelectedPath(result));
mPresenter.installWAD(result.getData().toString());
break;
}
}

View File

@ -27,9 +27,6 @@ public final class FileBrowserHelper
public static final HashSet<String> RAW_EXTENSION = new HashSet<>(Collections.singletonList(
"raw"));
public static final HashSet<String> WAD_EXTENSION = new HashSet<>(Collections.singletonList(
"wad"));
public static void openDirectoryPicker(FragmentActivity activity, HashSet<String> extensions)
{
Intent i = new Intent(activity, CustomFilePickerActivity.class);