Skip to content
Permalink
Browse files
Merge pull request #9569 from JosJuice/android-mainpresenter-skip-scan
Android: Move "skip scanning" logic to MainPresenter
  • Loading branch information
leoetlino committed Mar 7, 2021
2 parents 089250f + 3f71c36 commit a5555c6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 73 deletions.
@@ -44,16 +44,13 @@
import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer;
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.main.TvMainActivity;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.MotionListener;
import org.dolphinemu.dolphinemu.utils.Rumble;
import org.dolphinemu.dolphinemu.utils.TvUtil;

import java.io.File;
import java.lang.annotation.Retention;
@@ -245,14 +242,7 @@ protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

if (TvUtil.isLeanback(getApplicationContext()))
{
TvMainActivity.skipRescanningLibrary();
}
else
{
MainActivity.skipRescanningLibrary();
}
MainPresenter.skipRescanningLibrary();

if (savedInstanceState == null)
{
@@ -414,7 +404,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
if (requestCode == REQUEST_CHANGE_DISC)
{
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
if (resultCode == RESULT_OK)
{
NativeLibrary.ChangeDisc(result.getData().toString());
}
@@ -19,11 +19,8 @@

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.main.TvMainActivity;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.TvUtil;

import java.util.Set;

@@ -62,14 +59,7 @@ protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

if (TvUtil.isLeanback(getApplicationContext()))
{
TvMainActivity.skipRescanningLibrary();
}
else
{
MainActivity.skipRescanningLibrary();
}
MainPresenter.skipRescanningLibrary();

setContentView(R.layout.activity_settings);

@@ -179,7 +169,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
super.onActivityResult(requestCode, resultCode, result);

// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
if (resultCode == RESULT_OK)
{
if (requestCode != MainPresenter.REQUEST_DIRECTORY)
{
@@ -47,7 +47,6 @@ public final class MainActivity extends AppCompatActivity
private Toolbar mToolbar;
private TabLayout mTabLayout;
private FloatingActionButton mFab;
private static boolean sShouldRescanLibrary = true;

private final MainPresenter mPresenter = new MainPresenter(this, this);

@@ -82,7 +81,7 @@ protected void onResume()
{
super.onResume();

boolean cacheAlreadyLoading = GameFileCacheService.isLoading();
mPresenter.onResume();

if (DirectoryInitialization.shouldStart(this))
{
@@ -91,22 +90,9 @@ protected void onResume()
.run(this, false, this::setPlatformTabsAndStartGameFileCacheService);
}

mPresenter.addDirIfNeeded();

// In case the user changed a setting that affects how games are displayed,
// such as system language, cover downloading...
forEachPlatformGamesView(PlatformGamesView::refetchMetadata);

if (sShouldRescanLibrary && !cacheAlreadyLoading)
{
new AfterDirectoryInitializationRunner().run(this, false, () ->
{
setRefreshing(true);
GameFileCacheService.startRescan(this);
});
}

sShouldRescanLibrary = true;
}

@Override
@@ -129,7 +115,7 @@ protected void onStop()
super.onStop();
if (isChangingConfigurations())
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
StartupHandler.setSessionTime(this);
}
@@ -201,7 +187,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
super.onActivityResult(requestCode, resultCode, result);

// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
if (resultCode == RESULT_OK)
{
Uri uri = result.getData();
switch (requestCode)
@@ -236,7 +222,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
}
else
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
}

@@ -353,9 +339,4 @@ public void onTabSelected(@NonNull TabLayout.Tab tab)
showGames();
GameFileCacheService.startLoad(this);
}

public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}
@@ -36,6 +36,8 @@
public static final int REQUEST_WAD_FILE = 4;
public static final int REQUEST_WII_SAVE_FILE = 5;

private static boolean sShouldRescanLibrary = true;

private final MainView mView;
private final Context mContext;
private BroadcastReceiver mBroadcastReceiver = null;
@@ -122,13 +124,24 @@ public boolean handleOptionSelection(int itemId, Context context)
return false;
}

public void addDirIfNeeded()
public void onResume()
{
if (mDirToAdd != null)
{
GameFileCache.addGameFolder(mDirToAdd);
mDirToAdd = null;
}

if (sShouldRescanLibrary && !GameFileCacheService.isLoading())
{
new AfterDirectoryInitializationRunner().run(mContext, false, () ->
{
mView.setRefreshing(true);
GameFileCacheService.startRescan(mContext);
});
}

sShouldRescanLibrary = true;
}

/**
@@ -263,4 +276,9 @@ private void runOnThreadAndShowResult(int progressMessage, Supplier<String> f)
});
}, mContext.getResources().getString(progressMessage)).start();
}

public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}
@@ -28,7 +28,6 @@
import org.dolphinemu.dolphinemu.model.TvSettingsItem;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
@@ -42,8 +41,6 @@
public final class TvMainActivity extends FragmentActivity
implements MainView, SwipeRefreshLayout.OnRefreshListener
{
private static boolean sShouldRescanLibrary = true;

private final MainPresenter mPresenter = new MainPresenter(this, this);

private SwipeRefreshLayout mSwipeRefresh;
@@ -74,30 +71,17 @@ protected void onResume()
{
super.onResume();

boolean cacheAlreadyLoading = GameFileCacheService.isLoading();
mPresenter.onResume();

if (DirectoryInitialization.shouldStart(this))
{
DirectoryInitialization.start(this);
GameFileCacheService.startLoad(this);
}

mPresenter.addDirIfNeeded();

// In case the user changed a setting that affects how games are displayed,
// such as system language, cover downloading...
refetchMetadata();

if (sShouldRescanLibrary && !cacheAlreadyLoading)
{
new AfterDirectoryInitializationRunner().run(this, false, () ->
{
setRefreshing(true);
GameFileCacheService.startRescan(this);
});
}

sShouldRescanLibrary = true;
}

@Override
@@ -118,10 +102,12 @@ protected void onStart()
protected void onStop()
{
super.onStop();

if (isChangingConfigurations())
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}

StartupHandler.setSessionTime(this);
}

@@ -247,7 +233,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
super.onActivityResult(requestCode, resultCode, result);

// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
if (resultCode == RESULT_OK)
{
Uri uri = result.getData();
switch (requestCode)
@@ -282,7 +268,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent result)
}
else
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
}

@@ -398,9 +384,4 @@ private ListRow buildSettingsRow()

return new ListRow(header, rowItems);
}

public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}

0 comments on commit a5555c6

Please sign in to comment.