Android: Check for granted permission when returning to MainActivity
This commit is contained in:
parent
b1fecbb71c
commit
8bd704304e
|
@ -25,7 +25,7 @@ public class DolphinApplication extends Application
|
|||
Java_GCAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
Java_WiimoteAdapter.manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
|
||||
if (PermissionsHandler.hasWriteAccess(getApplicationContext()))
|
||||
if (DirectoryInitialization.shouldStart(getApplicationContext()))
|
||||
DirectoryInitialization.start(getApplicationContext());
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,16 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
|||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
if (DirectoryInitialization.shouldStart(this))
|
||||
{
|
||||
DirectoryInitialization.start(this);
|
||||
new AfterDirectoryInitializationRunner()
|
||||
.run(this, false, this::setPlatformTabsAndStartGameFileCacheService);
|
||||
}
|
||||
|
||||
mPresenter.addDirIfNeeded(this);
|
||||
|
||||
if (sShouldRescanLibrary)
|
||||
{
|
||||
GameFileCacheService.startRescan(this);
|
||||
|
|
|
@ -63,7 +63,15 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
|||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
if (DirectoryInitialization.shouldStart(this))
|
||||
{
|
||||
DirectoryInitialization.start(this);
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
|
||||
mPresenter.addDirIfNeeded(this);
|
||||
|
||||
if (sShouldRescanLibrary)
|
||||
{
|
||||
GameFileCacheService.startRescan(this);
|
||||
|
|
|
@ -53,6 +53,9 @@ public final class DirectoryInitialization
|
|||
|
||||
public static void start(Context context)
|
||||
{
|
||||
if (!isDolphinDirectoryInitializationRunning.compareAndSet(false, true))
|
||||
return;
|
||||
|
||||
// Can take a few seconds to run, so don't block UI thread.
|
||||
//noinspection TrivialFunctionalExpressionUsage
|
||||
((Runnable) () -> init(context)).run();
|
||||
|
@ -60,9 +63,6 @@ public final class DirectoryInitialization
|
|||
|
||||
private static void init(Context context)
|
||||
{
|
||||
if (!isDolphinDirectoryInitializationRunning.compareAndSet(false, true))
|
||||
return;
|
||||
|
||||
if (directoryState != DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED)
|
||||
{
|
||||
if (PermissionsHandler.hasWriteAccess(context))
|
||||
|
@ -196,6 +196,12 @@ public final class DirectoryInitialization
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean shouldStart(Context context)
|
||||
{
|
||||
return !isDolphinDirectoryInitializationRunning.get() &&
|
||||
getDolphinDirectoriesState(context) == DirectoryInitializationState.NOT_YET_INITIALIZED;
|
||||
}
|
||||
|
||||
public static boolean areDolphinDirectoriesReady()
|
||||
{
|
||||
return directoryState == DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED;
|
||||
|
|
Loading…
Reference in New Issue