Merge pull request #9569 from JosJuice/android-mainpresenter-skip-scan

Android: Move "skip scanning" logic to MainPresenter
This commit is contained in:
Léo Lam 2021-03-07 11:51:03 +01:00 committed by GitHub
commit a5555c6300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 73 deletions

View File

@ -44,16 +44,13 @@ import org.dolphinemu.dolphinemu.fragments.MenuFragment;
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 @@ public final class EmulationActivity extends AppCompatActivity
{
super.onCreate(savedInstanceState);
if (TvUtil.isLeanback(getApplicationContext()))
{
TvMainActivity.skipRescanningLibrary();
}
else
{
MainActivity.skipRescanningLibrary();
}
MainPresenter.skipRescanningLibrary();
if (savedInstanceState == null)
{
@ -414,7 +404,7 @@ public final class EmulationActivity extends AppCompatActivity
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());
}

View File

@ -19,11 +19,8 @@ import androidx.lifecycle.ViewModelProvider;
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 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
{
super.onCreate(savedInstanceState);
if (TvUtil.isLeanback(getApplicationContext()))
{
TvMainActivity.skipRescanningLibrary();
}
else
{
MainActivity.skipRescanningLibrary();
}
MainPresenter.skipRescanningLibrary();
setContentView(R.layout.activity_settings);
@ -179,7 +169,7 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
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)
{

View File

@ -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 @@ public final class MainActivity extends AppCompatActivity
{
super.onResume();
boolean cacheAlreadyLoading = GameFileCacheService.isLoading();
mPresenter.onResume();
if (DirectoryInitialization.shouldStart(this))
{
@ -91,22 +90,9 @@ public final class MainActivity extends AppCompatActivity
.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 @@ public final class MainActivity extends AppCompatActivity
super.onStop();
if (isChangingConfigurations())
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
StartupHandler.setSessionTime(this);
}
@ -201,7 +187,7 @@ public final class MainActivity extends AppCompatActivity
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 @@ public final class MainActivity extends AppCompatActivity
}
else
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
}
@ -353,9 +339,4 @@ public final class MainActivity extends AppCompatActivity
showGames();
GameFileCacheService.startLoad(this);
}
public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}

View File

@ -36,6 +36,8 @@ public final class MainPresenter
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 final class MainPresenter
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 @@ public final class MainPresenter
});
}, mContext.getResources().getString(progressMessage)).start();
}
public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}

View File

@ -28,7 +28,6 @@ import org.dolphinemu.dolphinemu.model.GameFile;
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 @@ import java.util.Collection;
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,7 +71,7 @@ public final class TvMainActivity extends FragmentActivity
{
super.onResume();
boolean cacheAlreadyLoading = GameFileCacheService.isLoading();
mPresenter.onResume();
if (DirectoryInitialization.shouldStart(this))
{
@ -82,22 +79,9 @@ public final class TvMainActivity extends FragmentActivity
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 @@ public final class TvMainActivity extends FragmentActivity
protected void onStop()
{
super.onStop();
if (isChangingConfigurations())
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
StartupHandler.setSessionTime(this);
}
@ -247,7 +233,7 @@ public final class TvMainActivity extends FragmentActivity
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 @@ public final class TvMainActivity extends FragmentActivity
}
else
{
skipRescanningLibrary();
MainPresenter.skipRescanningLibrary();
}
}
@ -398,9 +384,4 @@ public final class TvMainActivity extends FragmentActivity
return new ListRow(header, rowItems);
}
public static void skipRescanningLibrary()
{
sShouldRescanLibrary = false;
}
}