mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Android: Add helper class AfterDirectoryInitializationRunner
This commit is contained in:
@ -0,0 +1,50 @@
|
|||||||
|
package org.dolphinemu.dolphinemu.utils;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
|
public class AfterDirectoryInitializationRunner
|
||||||
|
{
|
||||||
|
private DirectoryStateReceiver directoryStateReceiver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a Runnable after directory initialization has finished.
|
||||||
|
*
|
||||||
|
* If this is called when directory initialization already is done,
|
||||||
|
* the Runnable will be executed immediately. If this is called before
|
||||||
|
* directory initialization is done, the Runnable will be executed
|
||||||
|
* after directory initialization finishes successfully, or never
|
||||||
|
* in case directory initialization doesn't finish successfully.
|
||||||
|
*
|
||||||
|
* Calling this function multiple times per object is not supported.
|
||||||
|
*/
|
||||||
|
public void run(Context context, Runnable runnable)
|
||||||
|
{
|
||||||
|
if (!DirectoryInitialization.areDolphinDirectoriesReady())
|
||||||
|
{
|
||||||
|
// Wait for directories to get initialized
|
||||||
|
IntentFilter statusIntentFilter = new IntentFilter(
|
||||||
|
DirectoryInitialization.BROADCAST_ACTION);
|
||||||
|
|
||||||
|
directoryStateReceiver = new DirectoryStateReceiver(directoryInitializationState ->
|
||||||
|
{
|
||||||
|
if (directoryInitializationState ==
|
||||||
|
DirectoryInitialization.DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED)
|
||||||
|
{
|
||||||
|
LocalBroadcastManager.getInstance(context).unregisterReceiver(directoryStateReceiver);
|
||||||
|
directoryStateReceiver = null;
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Registers the DirectoryStateReceiver and its intent filters
|
||||||
|
LocalBroadcastManager.getInstance(context).registerReceiver(
|
||||||
|
directoryStateReceiver,
|
||||||
|
statusIntentFilter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,8 +18,6 @@ import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
|||||||
|
|
||||||
public class Analytics
|
public class Analytics
|
||||||
{
|
{
|
||||||
private static DirectoryStateReceiver directoryStateReceiver;
|
|
||||||
|
|
||||||
private static final String analyticsAsked =
|
private static final String analyticsAsked =
|
||||||
Settings.SECTION_ANALYTICS + "_" + SettingsFile.KEY_ANALYTICS_PERMISSION_ASKED;
|
Settings.SECTION_ANALYTICS + "_" + SettingsFile.KEY_ANALYTICS_PERMISSION_ASKED;
|
||||||
private static final String analyticsEnabled =
|
private static final String analyticsEnabled =
|
||||||
@ -35,31 +33,8 @@ public class Analytics
|
|||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (!preferences.getBoolean(analyticsAsked, false))
|
if (!preferences.getBoolean(analyticsAsked, false))
|
||||||
{
|
{
|
||||||
if (!DirectoryInitialization.areDolphinDirectoriesReady())
|
new AfterDirectoryInitializationRunner().run(context,
|
||||||
{
|
() -> showMessage(context, preferences));
|
||||||
// Wait for directories to get initialized
|
|
||||||
IntentFilter statusIntentFilter = new IntentFilter(
|
|
||||||
DirectoryInitialization.BROADCAST_ACTION);
|
|
||||||
|
|
||||||
directoryStateReceiver = new DirectoryStateReceiver(directoryInitializationState ->
|
|
||||||
{
|
|
||||||
if (directoryInitializationState ==
|
|
||||||
DirectoryInitialization.DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED)
|
|
||||||
{
|
|
||||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(directoryStateReceiver);
|
|
||||||
directoryStateReceiver = null;
|
|
||||||
showMessage(context, preferences);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Registers the DirectoryStateReceiver and its intent filters
|
|
||||||
LocalBroadcastManager.getInstance(context).registerReceiver(
|
|
||||||
directoryStateReceiver,
|
|
||||||
statusIntentFilter);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
showMessage(context, preferences);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user