Skip to content
Permalink
Browse files
Merge pull request #9146 from JosJuice/android-disable-cover-download
Android: Allow disabling cover downloading
  • Loading branch information
leoetlino committed Oct 20, 2020
2 parents 49b7f10 + 6380c65 commit 2e86e1a
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 39 deletions.
@@ -120,6 +120,14 @@ public void swapDataSet(List<GameFile> gameFiles)
notifyDataSetChanged();
}

/**
* Re-fetches game metadata from the game file cache.
*/
public void refetchMetadata()
{
notifyItemRangeChanged(0, getItemCount());
}

/**
* Launches the game that was clicked on.
*
@@ -49,4 +49,10 @@ public void setBoolean(Settings settings, boolean newValue)
{
NativeConfig.setBoolean(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}

public static boolean getBooleanGlobal(String file, String section, String key,
boolean defaultValue)
{
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
}
}
@@ -0,0 +1,57 @@
package org.dolphinemu.dolphinemu.features.settings.model;

public class AdHocStringSetting implements AbstractStringSetting
{
private final String mFile;
private final String mSection;
private final String mKey;
private final String mDefaultValue;

public AdHocStringSetting(String file, String section, String key, String defaultValue)
{
mFile = file;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;

if (!NativeConfig.isSettingSaveable(file, section, key))
{
throw new IllegalArgumentException("File/section/key is unknown or legacy");
}
}

@Override
public boolean isOverridden(Settings settings)
{
return NativeConfig.isOverridden(mFile, mSection, mKey);
}

@Override
public boolean isRuntimeEditable()
{
return true;
}

@Override
public boolean delete(Settings settings)
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}

@Override
public String getString(Settings settings)
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}

@Override
public void setString(Settings settings, String newValue)
{
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}

public static String getStringGlobal(String file, String section, String key, String defaultValue)
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
}
}
@@ -38,6 +38,8 @@ public enum BooleanSetting implements AbstractBooleanSetting

MAIN_RECURSIVE_ISO_PATHS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL,
"RecursiveISOPaths", false),
MAIN_USE_GAME_COVERS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_GENERAL,
"UseGameCovers", true),

SYSCONF_SCREENSAVER(Settings.FILE_SYSCONF, "IPL", "SSV", false),
SYSCONF_WIDESCREEN(Settings.FILE_SYSCONF, "IPL", "AR", true),
@@ -191,4 +193,9 @@ public void setBoolean(Settings settings, boolean newValue)
settings.getSection(mFile, mSection).setBoolean(mKey, newValue);
}
}

public boolean getBooleanGlobal()
{
return NativeConfig.getBoolean(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
}
@@ -73,4 +73,9 @@ public void setFloat(Settings settings, float newValue)
settings.getSection(mFile, mSection).setFloat(mKey, newValue);
}
}

public float getFloatGlobal()
{
return NativeConfig.getFloat(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
}
@@ -130,4 +130,9 @@ public void setInt(Settings settings, int newValue)
settings.getSection(mFile, mSection).setInt(mKey, newValue);
}
}

public int getIntGlobal()
{
return NativeConfig.getInt(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
}
@@ -104,4 +104,9 @@ public void setString(Settings settings, String newValue)
settings.getSection(mFile, mSection).setString(mKey, newValue);
}
}

public String getStringGlobal()
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
}
@@ -224,7 +224,6 @@ private void addConfigSettings(ArrayList<SettingsItem> sl)
sl.add(new SubmenuSetting(R.string.advanced_submenu, MenuTag.CONFIG_ADVANCED));
sl.add(new SubmenuSetting(R.string.log_submenu, MenuTag.CONFIG_LOG));
sl.add(new SubmenuSetting(R.string.debug_submenu, MenuTag.DEBUG));
sl.add(new HeaderSetting(R.string.gametdb_thanks, 0));
}

private void addGeneralSettings(ArrayList<SettingsItem> sl)
@@ -247,6 +246,8 @@ private void addInterfaceSettings(ArrayList<SettingsItem> sl)
R.string.panic_handlers_description));
sl.add(new CheckBoxSetting(BooleanSetting.MAIN_OSD_MESSAGES, R.string.osd_messages,
R.string.osd_messages_description));
sl.add(new CheckBoxSetting(BooleanSetting.MAIN_USE_GAME_COVERS, R.string.download_game_covers,
0));
}

private void addAudioSettings(ArrayList<SettingsItem> sl)
@@ -152,8 +152,7 @@ public void onResume()

LinearLayout options = requireView().findViewById(R.id.layout_options);

Settings settings = ((EmulationActivity) requireActivity()).getSettings();
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBoolean(settings);
boolean savestatesEnabled = BooleanSetting.MAIN_ENABLE_SAVESTATES.getBooleanGlobal();
int savestateVisibility = savestatesEnabled ? View.VISIBLE : View.GONE;
options.findViewById(R.id.menu_quicksave).setVisibility(savestateVisibility);
options.findViewById(R.id.menu_quickload).setVisibility(savestateVisibility);
@@ -81,12 +81,7 @@ private void removeNonExistentGameFolders(Context context)
*/
public boolean scanLibrary(Context context)
{
boolean recursiveScan;
try (Settings settings = new Settings())
{
settings.loadSettings(null);
recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBoolean(settings);
}
boolean recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBooleanGlobal();

removeNonExistentGameFolders(context);

@@ -87,6 +87,10 @@ protected void onResume()

mPresenter.addDirIfNeeded(this);

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

if (sShouldRescanLibrary)
{
GameFileCacheService.startRescan(this);
@@ -254,6 +258,18 @@ public void showGames()
}
}

private void refetchMetadata()
{
for (Platform platform : Platform.values())
{
PlatformGamesView fragment = getPlatformGamesView(platform);
if (fragment != null)
{
fragment.refetchMetadata();
}
}
}

@Nullable
private PlatformGamesView getPlatformGamesView(Platform platform)
{
@@ -289,11 +305,7 @@ public void onTabSelected(@NonNull TabLayout.Tab tab)
}
});

try (Settings settings = new Settings())
{
settings.loadSettings(null);
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getInt(settings));
}
mViewPager.setCurrentItem(IntSetting.MAIN_LAST_PLATFORM_TAB.getIntGlobal());

showGames();
GameFileCacheService.startLoad(this);
@@ -32,6 +32,7 @@
import org.dolphinemu.dolphinemu.utils.TvUtil;
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;

import java.util.ArrayList;
import java.util.Collection;

public final class TvMainActivity extends FragmentActivity implements MainView
@@ -42,6 +43,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView

private BrowseSupportFragment mBrowseFragment;

private ArrayList<ArrayObjectAdapter> mGameRows = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState)
{
@@ -72,6 +75,10 @@ protected void onResume()

mPresenter.addDirIfNeeded(this);

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

if (sShouldRescanLibrary)
{
GameFileCacheService.startRescan(this);
@@ -185,6 +192,14 @@ public void showGames()
buildRowsAdapter();
}

private void refetchMetadata()
{
for (ArrayObjectAdapter row : mGameRows)
{
row.notifyArrayItemRangeChanged(0, row.size());
}
}

/**
* Callback from AddDirectoryActivity. Applies any changes necessary to the GameGridActivity.
*
@@ -244,6 +259,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
private void buildRowsAdapter()
{
ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
mGameRows.clear();

if (PermissionsHandler.hasWriteAccess(this))
{
@@ -278,6 +294,9 @@ private ListRow buildGamesRow(Platform platform, Collection<GameFile> gameFiles)
ArrayObjectAdapter row = new ArrayObjectAdapter(new GameRowPresenter());
row.addAll(0, gameFiles);

// Keep a reference to the row in case we need to refresh it.
mGameRows.add(row);

// Create a header for this row.
HeaderItem header = new HeaderItem(platform.toInt(), platform.getHeaderName());

@@ -85,6 +85,12 @@ public void showGames()
}
}

@Override
public void refetchMetadata()
{
mAdapter.refetchMetadata();
}

private void findViews(View root)
{
mRecyclerView = root.findViewById(R.id.grid_games);
@@ -25,4 +25,9 @@
* To be called when the game file cache is updated.
*/
void showGames();

/**
* Re-fetches game metadata from the game file cache.
*/
void refetchMetadata();
}
@@ -24,44 +24,41 @@ public static void checkAnalyticsInit(Context context)
{
new AfterDirectoryInitializationRunner().run(context, false, () ->
{
Settings settings = new Settings();
settings.loadSettings(null);
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBoolean(settings))
{
showMessage(context, settings);
}
else
if (!BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.getBooleanGlobal())
{
settings.close();
showMessage(context);
}
});
}

private static void showMessage(Context context, Settings settings)
private static void showMessage(Context context)
{
new AlertDialog.Builder(context, R.style.DolphinDialogBase)
.setTitle(context.getString(R.string.analytics))
.setMessage(context.getString(R.string.analytics_desc))
.setPositiveButton(R.string.yes, (dialogInterface, i) ->
{
firstAnalyticsAdd(settings, true);
firstAnalyticsAdd(true);
})
.setNegativeButton(R.string.no, (dialogInterface, i) ->
{
firstAnalyticsAdd(settings, false);
firstAnalyticsAdd(false);
})
.show();
}

private static void firstAnalyticsAdd(Settings settings, boolean enabled)
private static void firstAnalyticsAdd(boolean enabled)
{
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);
try (Settings settings = new Settings())
{
settings.loadSettings(null);

// Context is set to null to avoid toasts
settings.saveSettings(null, null);
BooleanSetting.MAIN_ANALYTICS_ENABLED.setBoolean(settings, enabled);
BooleanSetting.MAIN_ANALYTICS_PERMISSION_ASKED.setBoolean(settings, true);

settings.close();
// Context is set to null to avoid toasts
settings.saveSettings(null, null);
}
}

public static void sendReport(String endpoint, byte[] data)
@@ -10,6 +10,7 @@
import com.squareup.picasso.Picasso;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.model.GameFile;

import java.io.File;
@@ -62,7 +63,7 @@ else if ((cover = new File(gameFile.getCoverPath(context))).exists())
}
// GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting
// the cover will be by the disk's region, second will be the US cover, and third EN.
else
else if (BooleanSetting.MAIN_USE_GAME_COVERS.getBooleanGlobal())
{
Picasso.get()
.load(CoverHelper.buildGameTDBUrl(gameFile, CoverHelper.getRegion(gameFile)))
@@ -136,5 +137,16 @@ public void onError(Exception ex)
}
});
}
else
{
Picasso.get()
.load(R.drawable.no_banner)
.noFade()
.noPlaceholder()
.fit()
.centerInside()
.config(Bitmap.Config.ARGB_8888)
.into(imageView);
}
}
}

0 comments on commit 2e86e1a

Please sign in to comment.