mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Use UICommon's game list code on Android
Deduplicates code, and gets rid of some problems the old code had (such as: bad performance when calling native functions, only one disc showing up for multi-disc games, Wii banners being low-res, unnecessarily much effort being needed for adding more metadata).
This commit is contained in:
@ -71,13 +71,7 @@
|
||||
</activity>
|
||||
|
||||
<service android:name=".services.DirectoryInitializationService"/>
|
||||
|
||||
<provider
|
||||
android:name=".model.GameProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
</provider>
|
||||
<service android:name=".services.GameFileCacheService"/>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
|
@ -2,22 +2,19 @@ package org.dolphinemu.dolphinemu;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.GameDatabase;
|
||||
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
|
||||
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
|
||||
|
||||
public class DolphinApplication extends Application
|
||||
{
|
||||
public static GameDatabase databaseHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
|
||||
System.loadLibrary("main");
|
||||
|
||||
if (PermissionsHandler.hasWriteAccess(getApplicationContext()))
|
||||
DirectoryInitializationService.startService(getApplicationContext());
|
||||
|
||||
databaseHelper = new GameDatabase(this);
|
||||
}
|
||||
}
|
||||
|
@ -260,34 +260,6 @@ public final class NativeLibrary
|
||||
*/
|
||||
public static native void SetConfig(String configFile, String Section, String Key, String Value);
|
||||
|
||||
/**
|
||||
* Gets the embedded banner within the given ISO/ROM.
|
||||
*
|
||||
* @param filename the file path to the ISO/ROM.
|
||||
*
|
||||
* @return an integer array containing the color data for the banner.
|
||||
*/
|
||||
public static native int[] GetBanner(String filename);
|
||||
|
||||
/**
|
||||
* Gets the embedded title of the given ISO/ROM.
|
||||
*
|
||||
* @param filename The file path to the ISO/ROM.
|
||||
*
|
||||
* @return the embedded title of the ISO/ROM.
|
||||
*/
|
||||
public static native String GetTitle(String filename);
|
||||
|
||||
public static native String GetDescription(String filename);
|
||||
public static native String GetGameId(String filename);
|
||||
|
||||
public static native int GetCountry(String filename);
|
||||
|
||||
public static native String GetCompany(String filename);
|
||||
public static native long GetFilesize(String filename);
|
||||
|
||||
public static native int GetPlatform(String filename);
|
||||
|
||||
/**
|
||||
* Gets the Dolphin version string.
|
||||
*
|
||||
@ -394,27 +366,6 @@ public final class NativeLibrary
|
||||
*/
|
||||
public static native void RefreshWiimotes();
|
||||
|
||||
/**
|
||||
* The methods C++ uses to find references to Java classes and methods
|
||||
* are really expensive. Rather than calling them every time we want to
|
||||
* run them, do it once when we load the native library.
|
||||
*/
|
||||
private static native void CacheClassesAndMethods();
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
System.loadLibrary("main");
|
||||
}
|
||||
catch (UnsatisfiedLinkError ex)
|
||||
{
|
||||
Log.error("[NativeLibrary] " + ex.toString());
|
||||
}
|
||||
|
||||
CacheClassesAndMethods();
|
||||
}
|
||||
|
||||
private static boolean alertResult = false;
|
||||
public static boolean displayAlertMsg(final String caption, final String text, final boolean yesNo)
|
||||
{
|
||||
|
@ -36,6 +36,7 @@ import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
|
||||
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
|
||||
import org.dolphinemu.dolphinemu.fragments.SaveLoadStateFragment;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.ui.main.MainActivity;
|
||||
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
@ -74,10 +75,12 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
private boolean activityRecreated;
|
||||
private String mScreenPath;
|
||||
private String mSelectedTitle;
|
||||
private int mPlatform;
|
||||
private String mPath;
|
||||
|
||||
public static final String EXTRA_SELECTED_GAME = "SelectedGame";
|
||||
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
|
||||
public static final String EXTRA_PLATFORM = "Platform";
|
||||
public static final String EXTRA_SCREEN_PATH = "ScreenPath";
|
||||
public static final String EXTRA_GRID_POSITION = "GridPosition";
|
||||
|
||||
@ -146,13 +149,14 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
|
||||
}
|
||||
|
||||
public static void launch(FragmentActivity activity, String path, String title, String screenshotPath, int position, View sharedView)
|
||||
public static void launch(FragmentActivity activity, GameFile gameFile, int position, View sharedView)
|
||||
{
|
||||
Intent launcher = new Intent(activity, EmulationActivity.class);
|
||||
|
||||
launcher.putExtra(EXTRA_SELECTED_GAME, path);
|
||||
launcher.putExtra(EXTRA_SELECTED_TITLE, title);
|
||||
launcher.putExtra(EXTRA_SCREEN_PATH, screenshotPath);
|
||||
launcher.putExtra(EXTRA_SELECTED_GAME, gameFile.getPath());
|
||||
launcher.putExtra(EXTRA_SELECTED_TITLE, gameFile.getTitle());
|
||||
launcher.putExtra(EXTRA_PLATFORM, gameFile.getPlatform());
|
||||
launcher.putExtra(EXTRA_SCREEN_PATH, gameFile.getScreenshotPath());
|
||||
launcher.putExtra(EXTRA_GRID_POSITION, position);
|
||||
|
||||
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
|
||||
@ -176,6 +180,7 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
Intent gameToEmulate = getIntent();
|
||||
mPath = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAME);
|
||||
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
|
||||
mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0);
|
||||
mScreenPath = gameToEmulate.getStringExtra(EXTRA_SCREEN_PATH);
|
||||
mPosition = gameToEmulate.getIntExtra(EXTRA_GRID_POSITION, -1);
|
||||
activityRecreated = false;
|
||||
@ -186,7 +191,9 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
restoreState(savedInstanceState);
|
||||
}
|
||||
|
||||
sIsGameCubeGame = Platform.fromNativeInt(NativeLibrary.GetPlatform(mPath)) == Platform.GAMECUBE;
|
||||
// TODO: The accurate way to find out which console we're emulating is to
|
||||
// first launch emulation and then ask the core which console we're emulating
|
||||
sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE;
|
||||
mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen");
|
||||
mControllerMappingHelper = new ControllerMappingHelper();
|
||||
|
||||
@ -284,6 +291,7 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
mEmulationFragment.saveTemporaryState();
|
||||
outState.putString(EXTRA_SELECTED_GAME, mPath);
|
||||
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
|
||||
outState.putInt(EXTRA_PLATFORM, mPlatform);
|
||||
outState.putString(EXTRA_SCREEN_PATH, mScreenPath);
|
||||
outState.putInt(EXTRA_GRID_POSITION, mPosition);
|
||||
super.onSaveInstanceState(outState);
|
||||
@ -293,6 +301,7 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
{
|
||||
mPath = savedInstanceState.getString(EXTRA_SELECTED_GAME);
|
||||
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
|
||||
mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM);
|
||||
mScreenPath = savedInstanceState.getString(EXTRA_SCREEN_PATH);
|
||||
mPosition = savedInstanceState.getInt(EXTRA_GRID_POSITION);
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ package org.dolphinemu.dolphinemu.adapters;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.database.Cursor;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -14,38 +12,30 @@ import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.model.GameDatabase;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
|
||||
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
|
||||
import org.dolphinemu.dolphinemu.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This adapter gets its information from a database Cursor. This fact, paired with the usage of
|
||||
* ContentProviders and Loaders, allows for efficient display of a limited view into a (possibly)
|
||||
* large dataset.
|
||||
*/
|
||||
public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> implements
|
||||
View.OnClickListener,
|
||||
View.OnLongClickListener
|
||||
{
|
||||
private Cursor mCursor;
|
||||
private GameDataSetObserver mObserver;
|
||||
|
||||
private boolean mDatasetValid;
|
||||
private List<GameFile> mGameFiles;
|
||||
|
||||
/**
|
||||
* Initializes the adapter's observer, which watches for changes to the dataset. The adapter will
|
||||
* display no data until a Cursor is supplied by a CursorLoader.
|
||||
* display no data until swapDataSet is called.
|
||||
*/
|
||||
public GameAdapter()
|
||||
{
|
||||
mDatasetValid = false;
|
||||
mObserver = new GameDataSetObserver();
|
||||
mGameFiles = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,34 +70,13 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
@Override
|
||||
public void onBindViewHolder(GameViewHolder holder, int position)
|
||||
{
|
||||
if (mDatasetValid)
|
||||
{
|
||||
if (mCursor.moveToPosition(position))
|
||||
{
|
||||
String screenPath = mCursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH);
|
||||
PicassoUtils.loadGameBanner(holder.imageScreenshot, screenPath, mCursor.getString(GameDatabase.GAME_COLUMN_PATH));
|
||||
GameFile gameFile = mGameFiles.get(position);
|
||||
PicassoUtils.loadGameBanner(holder.imageScreenshot, gameFile);
|
||||
|
||||
holder.textGameTitle.setText(mCursor.getString(GameDatabase.GAME_COLUMN_TITLE));
|
||||
holder.textCompany.setText(mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY));
|
||||
holder.textGameTitle.setText(gameFile.getTitle());
|
||||
holder.textCompany.setText(gameFile.getCompany());
|
||||
|
||||
// TODO These shouldn't be necessary once the move to a DB-based model is complete.
|
||||
holder.gameId = mCursor.getString(GameDatabase.GAME_COLUMN_GAME_ID);
|
||||
holder.path = mCursor.getString(GameDatabase.GAME_COLUMN_PATH);
|
||||
holder.title = mCursor.getString(GameDatabase.GAME_COLUMN_TITLE);
|
||||
holder.description = mCursor.getString(GameDatabase.GAME_COLUMN_DESCRIPTION);
|
||||
holder.country = mCursor.getInt(GameDatabase.GAME_COLUMN_COUNTRY);
|
||||
holder.company = mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY);
|
||||
holder.screenshotPath = mCursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[GameAdapter] Can't bind view; Cursor is not valid.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[GameAdapter] Can't bind view; dataset is not valid.");
|
||||
}
|
||||
holder.gameFile = gameFile;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,84 +87,27 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
if (mDatasetValid && mCursor != null)
|
||||
{
|
||||
return mCursor.getCount();
|
||||
}
|
||||
Log.error("[GameAdapter] Dataset is not valid.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the contents of the _id column for a given row.
|
||||
*
|
||||
* @param position The row for which Android wants an ID.
|
||||
* @return A valid ID from the database, or 0 if not available.
|
||||
*/
|
||||
@Override
|
||||
public long getItemId(int position)
|
||||
{
|
||||
if (mDatasetValid && mCursor != null)
|
||||
{
|
||||
if (mCursor.moveToPosition(position))
|
||||
{
|
||||
return mCursor.getLong(GameDatabase.COLUMN_DB_ID);
|
||||
}
|
||||
}
|
||||
|
||||
Log.error("[GameAdapter] Dataset is not valid.");
|
||||
return 0;
|
||||
return mGameFiles.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell Android whether or not each item in the dataset has a stable identifier.
|
||||
* Which it does, because it's a database, so always tell Android 'true'.
|
||||
*
|
||||
* @param hasStableIds ignored.
|
||||
*/
|
||||
@Override
|
||||
public void setHasStableIds(boolean hasStableIds)
|
||||
{
|
||||
super.setHasStableIds(true);
|
||||
super.setHasStableIds(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* When a load is finished, call this to replace the existing data with the newly-loaded
|
||||
* data.
|
||||
*
|
||||
* @param cursor The newly-loaded Cursor.
|
||||
* When a load is finished, call this to replace the existing data
|
||||
* with the newly-loaded data.
|
||||
*/
|
||||
public void swapCursor(Cursor cursor)
|
||||
public void swapDataSet(List<GameFile> gameFiles)
|
||||
{
|
||||
// Sanity check.
|
||||
if (cursor == mCursor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Before getting rid of the old cursor, disassociate it from the Observer.
|
||||
final Cursor oldCursor = mCursor;
|
||||
if (oldCursor != null && mObserver != null)
|
||||
{
|
||||
oldCursor.unregisterDataSetObserver(mObserver);
|
||||
}
|
||||
|
||||
mCursor = cursor;
|
||||
if (mCursor != null)
|
||||
{
|
||||
// Attempt to associate the new Cursor with the Observer.
|
||||
if (mObserver != null)
|
||||
{
|
||||
mCursor.registerDataSetObserver(mObserver);
|
||||
}
|
||||
|
||||
mDatasetValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mDatasetValid = false;
|
||||
}
|
||||
|
||||
mGameFiles = gameFiles;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@ -210,9 +122,7 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
GameViewHolder holder = (GameViewHolder) view.getTag();
|
||||
|
||||
EmulationActivity.launch((FragmentActivity) view.getContext(),
|
||||
holder.path,
|
||||
holder.title,
|
||||
holder.screenshotPath,
|
||||
holder.gameFile,
|
||||
holder.getAdapterPosition(),
|
||||
holder.imageScreenshot);
|
||||
}
|
||||
@ -227,13 +137,10 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
public boolean onLongClick(View view)
|
||||
{
|
||||
GameViewHolder holder = (GameViewHolder) view.getTag();
|
||||
|
||||
// Get the ID of the game we want to look at.
|
||||
String gameId = (String) holder.gameId;
|
||||
String gameId = holder.gameFile.getGameId();
|
||||
|
||||
FragmentActivity activity = (FragmentActivity) view.getContext();
|
||||
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle("Game Settings")
|
||||
.setItems(R.array.gameSettingsMenus, new DialogInterface.OnClickListener() {
|
||||
@ -290,25 +197,4 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
|
||||
outRect.top = space;
|
||||
}
|
||||
}
|
||||
|
||||
private final class GameDataSetObserver extends DataSetObserver
|
||||
{
|
||||
@Override
|
||||
public void onChanged()
|
||||
{
|
||||
super.onChanged();
|
||||
|
||||
mDatasetValid = true;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInvalidated()
|
||||
{
|
||||
super.onInvalidated();
|
||||
|
||||
mDatasetValid = false;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.Game;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
|
||||
import org.dolphinemu.dolphinemu.utils.SettingsFile;
|
||||
@ -50,28 +51,19 @@ public final class GameRowPresenter extends Presenter
|
||||
public void onBindViewHolder(ViewHolder viewHolder, Object item)
|
||||
{
|
||||
TvGameViewHolder holder = (TvGameViewHolder) viewHolder;
|
||||
Game game = (Game) item;
|
||||
|
||||
String screenPath = game.getScreenshotPath();
|
||||
GameFile gameFile = (GameFile) item;
|
||||
|
||||
holder.imageScreenshot.setImageDrawable(null);
|
||||
PicassoUtils.loadGameBanner(holder.imageScreenshot, screenPath, game.getPath());
|
||||
PicassoUtils.loadGameBanner(holder.imageScreenshot, gameFile);
|
||||
|
||||
holder.cardParent.setTitleText(game.getTitle());
|
||||
holder.cardParent.setContentText(game.getCompany());
|
||||
holder.cardParent.setTitleText(gameFile.getTitle());
|
||||
holder.cardParent.setContentText(gameFile.getCompany());
|
||||
|
||||
// TODO These shouldn't be necessary once the move to a DB-based model is complete.
|
||||
holder.gameId = game.getGameId();
|
||||
holder.path = game.getPath();
|
||||
holder.title = game.getTitle();
|
||||
holder.description = game.getDescription();
|
||||
holder.country = game.getCountry();
|
||||
holder.company = game.getCompany();
|
||||
holder.screenshotPath = game.getScreenshotPath();
|
||||
holder.gameFile = gameFile;
|
||||
|
||||
// Set the platform-dependent background color of the card
|
||||
int backgroundId;
|
||||
switch (game.getPlatform())
|
||||
switch (Platform.fromNativeInt(gameFile.getPlatform()))
|
||||
{
|
||||
case GAMECUBE:
|
||||
backgroundId = R.drawable.tv_card_background_gamecube;
|
||||
@ -93,7 +85,7 @@ public final class GameRowPresenter extends Presenter
|
||||
public boolean onLongClick(View view)
|
||||
{
|
||||
FragmentActivity activity = (FragmentActivity) view.getContext();
|
||||
|
||||
String gameId = gameFile.getGameId();
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle("Game Settings")
|
||||
@ -101,23 +93,23 @@ public final class GameRowPresenter extends Presenter
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_DOLPHIN, game.getGameId());
|
||||
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_DOLPHIN, gameId);
|
||||
break;
|
||||
case 1:
|
||||
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_GFX, game.getGameId());
|
||||
SettingsActivity.launch(activity, SettingsFile.FILE_NAME_GFX, gameId);
|
||||
break;
|
||||
case 2:
|
||||
String path = DirectoryInitializationService.getUserDirectory() + "/GameSettings/" + game.getGameId() + ".ini";
|
||||
String path = DirectoryInitializationService.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
|
||||
File gameSettingsFile = new File(path);
|
||||
if (gameSettingsFile.exists())
|
||||
{
|
||||
if (gameSettingsFile.delete())
|
||||
{
|
||||
Toast.makeText(view.getContext(), "Cleared settings for " + game.getGameId(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(view.getContext(), "Cleared settings for " + gameId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(view.getContext(), "Unable to clear settings for " + game.getGameId(), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(view.getContext(), "Unable to clear settings for " + gameId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -12,32 +12,24 @@ import android.widget.TextView;
|
||||
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
|
||||
public final class GameDetailsDialog extends DialogFragment
|
||||
{
|
||||
private static final String ARG_GAME_TITLE = "game_title";
|
||||
private static final String ARG_GAME_DESCRIPTION = "game_description";
|
||||
private static final String ARG_GAME_COUNTRY = "game_country";
|
||||
private static final String ARG_GAME_DATE = "game_date";
|
||||
private static final String ARG_GAME_PATH = "game_path";
|
||||
private static final String ARG_GAME_SCREENSHOT_PATH = "game_screenshot_path";
|
||||
|
||||
// TODO Add all of this to the Loader in GameActivity.java
|
||||
public static GameDetailsDialog newInstance(String title, String description, int country, String company, String path, String screenshotPath)
|
||||
public static GameDetailsDialog newInstance(String gamePath)
|
||||
{
|
||||
GameDetailsDialog fragment = new GameDetailsDialog();
|
||||
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putString(ARG_GAME_TITLE, title);
|
||||
arguments.putString(ARG_GAME_DESCRIPTION, description);
|
||||
arguments.putInt(ARG_GAME_COUNTRY, country);
|
||||
arguments.putString(ARG_GAME_DATE, company);
|
||||
arguments.putString(ARG_GAME_PATH, path);
|
||||
arguments.putString(ARG_GAME_SCREENSHOT_PATH, screenshotPath);
|
||||
arguments.putString(ARG_GAME_PATH, gamePath);
|
||||
fragment.setArguments(arguments);
|
||||
|
||||
return fragment;
|
||||
@ -46,42 +38,38 @@ public final class GameDetailsDialog extends DialogFragment
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
GameFile gameFile = GameFileCacheService.addOrGet(getArguments().getString(ARG_GAME_PATH));
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
ViewGroup contents = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.dialog_game_details, null);
|
||||
|
||||
final ImageView imageGameScreen = (ImageView) contents.findViewById(R.id.image_game_screen);
|
||||
CircleImageView circleBanner = (CircleImageView) contents.findViewById(R.id.circle_banner);
|
||||
final ImageView imageGameScreen = contents.findViewById(R.id.image_game_screen);
|
||||
CircleImageView circleBanner = contents.findViewById(R.id.circle_banner);
|
||||
|
||||
TextView textTitle = (TextView) contents.findViewById(R.id.text_game_title);
|
||||
TextView textDescription = (TextView) contents.findViewById(R.id.text_company);
|
||||
TextView textTitle = contents.findViewById(R.id.text_game_title);
|
||||
TextView textDescription = contents.findViewById(R.id.text_description);
|
||||
|
||||
TextView textCountry = (TextView) contents.findViewById(R.id.text_country);
|
||||
TextView textDate = (TextView) contents.findViewById(R.id.text_date);
|
||||
TextView textCountry = contents.findViewById(R.id.text_country);
|
||||
TextView textCompany = contents.findViewById(R.id.text_company);
|
||||
|
||||
FloatingActionButton buttonLaunch = (FloatingActionButton) contents.findViewById(R.id.button_launch);
|
||||
FloatingActionButton buttonLaunch = contents.findViewById(R.id.button_launch);
|
||||
|
||||
int countryIndex = getArguments().getInt(ARG_GAME_COUNTRY);
|
||||
String country = getResources().getStringArray(R.array.countryNames)[countryIndex];
|
||||
String country = getResources().getStringArray(R.array.countryNames)[gameFile.getCountry()];
|
||||
|
||||
textTitle.setText(getArguments().getString(ARG_GAME_TITLE));
|
||||
textDescription.setText(getArguments().getString(ARG_GAME_DESCRIPTION));
|
||||
textTitle.setText(gameFile.getTitle());
|
||||
textDescription.setText(gameFile.getDescription());
|
||||
textCountry.setText(country);
|
||||
textDate.setText(getArguments().getString(ARG_GAME_DATE));
|
||||
textCompany.setText(gameFile.getCompany());
|
||||
|
||||
buttonLaunch.setOnClickListener(view ->
|
||||
{
|
||||
// Start the emulation activity and send the path of the clicked ROM to it.
|
||||
EmulationActivity.launch(getActivity(),
|
||||
getArguments().getString(ARG_GAME_PATH),
|
||||
getArguments().getString(ARG_GAME_TITLE),
|
||||
getArguments().getString(ARG_GAME_SCREENSHOT_PATH),
|
||||
-1,
|
||||
imageGameScreen);
|
||||
EmulationActivity.launch(getActivity(), gameFile, -1, imageGameScreen);
|
||||
});
|
||||
|
||||
// Fill in the view contents.
|
||||
Picasso.with(imageGameScreen.getContext())
|
||||
.load(getArguments().getString(ARG_GAME_SCREENSHOT_PATH))
|
||||
.load(getArguments().getString(gameFile.getScreenshotPath()))
|
||||
.fit()
|
||||
.centerCrop()
|
||||
.noFade()
|
||||
|
@ -1,95 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FileListItem implements Comparable<FileListItem>
|
||||
{
|
||||
public static final int TYPE_FOLDER = 0;
|
||||
public static final int TYPE_GC = 1;
|
||||
public static final int TYPE_WII = 2;
|
||||
public static final int TYPE_WII_WARE = 3;
|
||||
public static final int TYPE_OTHER = 4;
|
||||
|
||||
private int mType;
|
||||
private String mFilename;
|
||||
private String mPath;
|
||||
|
||||
public FileListItem(File file)
|
||||
{
|
||||
mPath = file.getAbsolutePath();
|
||||
mFilename = file.getName();
|
||||
|
||||
if (file.isDirectory())
|
||||
{
|
||||
mType = TYPE_FOLDER;
|
||||
}
|
||||
else
|
||||
{
|
||||
int extensionStart = mPath.lastIndexOf('.');
|
||||
if (extensionStart < 1)
|
||||
{
|
||||
// Ignore hidden files & files without extensions.
|
||||
mType = TYPE_OTHER;
|
||||
}
|
||||
else
|
||||
{
|
||||
String fileExtension = mPath.substring(extensionStart);
|
||||
|
||||
// The extensions we care about.
|
||||
Set<String> allowedExtensions = new HashSet<String>(Arrays.asList(
|
||||
".ciso", ".dff", ".dol", ".elf", ".gcm", ".gcz", ".iso", ".tgc", ".wad", ".wbfs"));
|
||||
|
||||
// Check that the file has an extension we care about before trying to read out of it.
|
||||
if (allowedExtensions.contains(fileExtension.toLowerCase()))
|
||||
{
|
||||
// Add 1 because 0 = TYPE_FOLDER
|
||||
mType = NativeLibrary.GetPlatform(mPath) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mType = TYPE_OTHER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
public String getFilename()
|
||||
{
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FileListItem theOther)
|
||||
{
|
||||
if (theOther.getType() == getType())
|
||||
{
|
||||
return getFilename().toLowerCase().compareTo(theOther.getFilename().toLowerCase());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getType() > theOther.getType())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.os.Environment;
|
||||
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
|
||||
public final class Game
|
||||
{
|
||||
// Copied from IVolume::ECountry. Update these if that is ever modified.
|
||||
public static final int COUNTRY_EUROPE = 0;
|
||||
public static final int COUNTRY_JAPAN = 1;
|
||||
public static final int COUNTRY_USA = 2;
|
||||
public static final int COUNTRY_AUSTRALIA = 3;
|
||||
public static final int COUNTRY_FRANCE = 4;
|
||||
public static final int COUNTRY_GERMANY = 5;
|
||||
public static final int COUNTRY_ITALY = 6;
|
||||
public static final int COUNTRY_KOREA = 7;
|
||||
public static final int COUNTRY_NETHERLANDS = 8;
|
||||
public static final int COUNTRY_RUSSIA = 9;
|
||||
public static final int COUNTRY_SPAIN = 10;
|
||||
public static final int COUNTRY_TAIWAN = 11;
|
||||
public static final int COUNTRY_WORLD = 12;
|
||||
public static final int COUNTRY_UNKNOWN = 13;
|
||||
|
||||
private static final String PATH_SCREENSHOT_FOLDER = "file://" + Environment.getExternalStorageDirectory().getPath() + "/dolphin-emu/ScreenShots/";
|
||||
|
||||
private String mTitle;
|
||||
private String mDescription;
|
||||
private String mPath;
|
||||
private String mGameId;
|
||||
private String mScreenshotPath;
|
||||
private String mCompany;
|
||||
|
||||
private Platform mPlatform;
|
||||
private int mCountry;
|
||||
|
||||
public Game(Platform platform, String title, String description, int country, String path, String gameId, String company, String screenshotPath)
|
||||
{
|
||||
mPlatform = platform;
|
||||
mTitle = title;
|
||||
mDescription = description;
|
||||
mCountry = country;
|
||||
mPath = path;
|
||||
mGameId = gameId;
|
||||
mCompany = company;
|
||||
mScreenshotPath = screenshotPath;
|
||||
}
|
||||
|
||||
public Platform getPlatform()
|
||||
{
|
||||
return mPlatform;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
public String getCompany()
|
||||
{
|
||||
return mCompany;
|
||||
}
|
||||
|
||||
public int getCountry()
|
||||
{
|
||||
return mCountry;
|
||||
}
|
||||
|
||||
public String getPath()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
public String getGameId()
|
||||
{
|
||||
return mGameId;
|
||||
}
|
||||
|
||||
public String getScreenshotPath()
|
||||
{
|
||||
return mScreenshotPath;
|
||||
}
|
||||
|
||||
public static ContentValues asContentValues(Platform platform, String title, String description, int country, String path, String gameId, String company)
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
String screenPath = PATH_SCREENSHOT_FOLDER + gameId + "/" + gameId + "-1.png";
|
||||
|
||||
values.put(GameDatabase.KEY_GAME_PLATFORM, platform.toInt());
|
||||
values.put(GameDatabase.KEY_GAME_TITLE, title);
|
||||
values.put(GameDatabase.KEY_GAME_DESCRIPTION, description);
|
||||
values.put(GameDatabase.KEY_GAME_COUNTRY, company);
|
||||
values.put(GameDatabase.KEY_GAME_PATH, path);
|
||||
values.put(GameDatabase.KEY_GAME_ID, gameId);
|
||||
values.put(GameDatabase.KEY_GAME_COMPANY, company);
|
||||
values.put(GameDatabase.KEY_GAME_SCREENSHOT_PATH, screenPath);
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public static Game fromCursor(Cursor cursor)
|
||||
{
|
||||
return new Game(Platform.fromInt(cursor.getInt(GameDatabase.GAME_COLUMN_PLATFORM)),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_TITLE),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_DESCRIPTION),
|
||||
cursor.getInt(GameDatabase.GAME_COLUMN_COUNTRY),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_PATH),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_GAME_ID),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_COMPANY),
|
||||
cursor.getString(GameDatabase.GAME_COLUMN_SCREENSHOT_PATH));
|
||||
}
|
||||
}
|
@ -1,299 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
|
||||
/**
|
||||
* A helper class that provides several utilities simplifying interaction with
|
||||
* the SQLite database.
|
||||
*/
|
||||
public final class GameDatabase extends SQLiteOpenHelper
|
||||
{
|
||||
private static final int DB_VERSION = 1;
|
||||
|
||||
public static final int COLUMN_DB_ID = 0;
|
||||
|
||||
public static final int GAME_COLUMN_PATH = 1;
|
||||
public static final int GAME_COLUMN_PLATFORM = 2;
|
||||
public static final int GAME_COLUMN_TITLE = 3;
|
||||
public static final int GAME_COLUMN_DESCRIPTION = 4;
|
||||
public static final int GAME_COLUMN_COUNTRY = 5;
|
||||
public static final int GAME_COLUMN_GAME_ID = 6;
|
||||
public static final int GAME_COLUMN_COMPANY = 7;
|
||||
public static final int GAME_COLUMN_SCREENSHOT_PATH = 8;
|
||||
|
||||
public static final String KEY_DB_ID = "_id";
|
||||
|
||||
public static final String KEY_GAME_PATH = "path";
|
||||
public static final String KEY_GAME_PLATFORM = "platform";
|
||||
public static final String KEY_GAME_TITLE = "title";
|
||||
public static final String KEY_GAME_DESCRIPTION = "description";
|
||||
public static final String KEY_GAME_COUNTRY = "country";
|
||||
public static final String KEY_GAME_ID = "game_id";
|
||||
public static final String KEY_GAME_COMPANY = "company";
|
||||
public static final String KEY_GAME_SCREENSHOT_PATH = "screenshot_path";
|
||||
public static final String TABLE_NAME_GAMES = "games";
|
||||
|
||||
private static final String TYPE_PRIMARY = " INTEGER PRIMARY KEY";
|
||||
private static final String TYPE_INTEGER = " INTEGER";
|
||||
private static final String TYPE_STRING = " TEXT";
|
||||
|
||||
private static final String SEPARATOR = ", ";
|
||||
|
||||
private static final String SQL_CREATE_GAMES = "CREATE TABLE " + TABLE_NAME_GAMES + "("
|
||||
+ KEY_DB_ID + TYPE_PRIMARY + SEPARATOR
|
||||
+ KEY_GAME_PATH + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_PLATFORM + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_TITLE + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_DESCRIPTION + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_COUNTRY + TYPE_INTEGER + SEPARATOR
|
||||
+ KEY_GAME_ID + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_COMPANY + TYPE_STRING + SEPARATOR
|
||||
+ KEY_GAME_SCREENSHOT_PATH + TYPE_STRING + ")";
|
||||
|
||||
private static final String SQL_DELETE_GAMES = "DROP TABLE IF EXISTS " + TABLE_NAME_GAMES;
|
||||
|
||||
private static final String GAME_FOLDER_PATHS_PREFERENCE = "gameFolderPaths";
|
||||
|
||||
private static final Set<String> EMPTY_SET = new HashSet<>();
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public GameDatabase(Context context)
|
||||
{
|
||||
// Superclass constructor builds a database or uses an existing one.
|
||||
super(context, "games.db", null, DB_VERSION);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database)
|
||||
{
|
||||
Log.debug("[GameDatabase] GameDatabase - Creating database...");
|
||||
|
||||
execSqlAndLog(database, SQL_CREATE_GAMES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase database, int oldVersion, int newVersion)
|
||||
{
|
||||
Log.verbose("[GameDatabase] Downgrades not supporting, clearing databases..");
|
||||
execSqlAndLog(database, SQL_DELETE_GAMES);
|
||||
execSqlAndLog(database, SQL_CREATE_GAMES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion)
|
||||
{
|
||||
Log.info("[GameDatabase] Upgrading database from schema version " + oldVersion + " to " + newVersion);
|
||||
|
||||
// Delete all the games
|
||||
execSqlAndLog(database, SQL_DELETE_GAMES);
|
||||
execSqlAndLog(database, SQL_CREATE_GAMES);
|
||||
|
||||
Log.verbose("[GameDatabase] Re-scanning library with new schema.");
|
||||
scanLibrary(database);
|
||||
}
|
||||
|
||||
public void addGameFolder(String path)
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
Set<String> folderPaths = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET);
|
||||
Set<String> newFolderPaths = new HashSet<>(folderPaths);
|
||||
newFolderPaths.add(path);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putStringSet(GAME_FOLDER_PATHS_PREFERENCE, newFolderPaths);
|
||||
editor.apply();
|
||||
|
||||
scanLibrary(getWritableDatabase());
|
||||
}
|
||||
|
||||
public void scanLibrary(SQLiteDatabase database)
|
||||
{
|
||||
// Before scanning known folders, go through the game table and remove any entries for which the file itself is missing.
|
||||
Cursor fileCursor = database.query(TABLE_NAME_GAMES,
|
||||
null, // Get all columns.
|
||||
null, // Get all rows.
|
||||
null,
|
||||
null, // No grouping.
|
||||
null,
|
||||
null); // Order of games is irrelevant.
|
||||
|
||||
// Possibly overly defensive, but ensures that moveToNext() does not skip a row.
|
||||
fileCursor.moveToPosition(-1);
|
||||
|
||||
while (fileCursor.moveToNext())
|
||||
{
|
||||
String gamePath = fileCursor.getString(GAME_COLUMN_PATH);
|
||||
File game = new File(gamePath);
|
||||
|
||||
if (!game.exists())
|
||||
{
|
||||
Log.error("[GameDatabase] Game file no longer exists. Removing from the library: " + gamePath);
|
||||
database.delete(TABLE_NAME_GAMES,
|
||||
KEY_DB_ID + " = ?",
|
||||
new String[]{Long.toString(fileCursor.getLong(COLUMN_DB_ID))});
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> allowedExtensions = new HashSet<String>(Arrays.asList(
|
||||
".ciso", ".dff", ".dol", ".elf", ".gcm", ".gcz", ".iso", ".tgc", ".wad", ".wbfs"));
|
||||
|
||||
// Iterate through all results of the DB query (i.e. all folders in the library.)
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
Set<String> folderPaths = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET);
|
||||
Set<String> newFolderPaths = new HashSet<>();
|
||||
for (String folderPath : folderPaths)
|
||||
{
|
||||
File folder = new File(folderPath);
|
||||
boolean deleteFolder = false;
|
||||
|
||||
Log.info("[GameDatabase] Reading files from library folder: " + folderPath);
|
||||
|
||||
// Iterate through every file in the folder.
|
||||
File[] children = folder.listFiles();
|
||||
|
||||
if (children != null)
|
||||
{
|
||||
for (File file : children)
|
||||
{
|
||||
if (!file.isHidden() && !file.isDirectory())
|
||||
{
|
||||
String filePath = file.getPath();
|
||||
|
||||
int extensionStart = filePath.lastIndexOf('.');
|
||||
if (extensionStart > 0)
|
||||
{
|
||||
String fileExtension = filePath.substring(extensionStart);
|
||||
|
||||
// Check that the file has an extension we care about before trying to read out of it.
|
||||
if (allowedExtensions.contains(fileExtension.toLowerCase()))
|
||||
{
|
||||
String name = NativeLibrary.GetTitle(filePath);
|
||||
|
||||
// If the game's title field is empty, use the filename.
|
||||
if (name.isEmpty())
|
||||
{
|
||||
name = filePath.substring(filePath.lastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
String gameId = NativeLibrary.GetGameId(filePath);
|
||||
|
||||
// If the game's ID field is empty, use the filename without extension.
|
||||
if (gameId.isEmpty())
|
||||
{
|
||||
gameId = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf("."));
|
||||
}
|
||||
|
||||
Platform platform = Platform.fromNativeInt(NativeLibrary.GetPlatform(filePath));
|
||||
|
||||
ContentValues game = Game.asContentValues(platform,
|
||||
name,
|
||||
NativeLibrary.GetDescription(filePath).replace("\n", " "),
|
||||
NativeLibrary.GetCountry(filePath),
|
||||
filePath,
|
||||
gameId,
|
||||
NativeLibrary.GetCompany(filePath));
|
||||
|
||||
// Try to update an existing game first.
|
||||
int rowsMatched = database.update(TABLE_NAME_GAMES, // Which table to update.
|
||||
game, // The values to fill the row with.
|
||||
KEY_GAME_ID + " = ?", // The WHERE clause used to find the right row.
|
||||
new String[]{game.getAsString(KEY_GAME_ID)}); // The ? in WHERE clause is replaced with this,
|
||||
// which is provided as an array because there
|
||||
// could potentially be more than one argument.
|
||||
|
||||
// If update fails, insert a new game instead.
|
||||
if (rowsMatched == 0)
|
||||
{
|
||||
Log.verbose("[GameDatabase] Adding game: " + game.getAsString(KEY_GAME_TITLE));
|
||||
database.insert(TABLE_NAME_GAMES, null, game);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.verbose("[GameDatabase] Updated game: " + game.getAsString(KEY_GAME_TITLE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the folder is empty because it no longer exists, remove it from the library.
|
||||
else if (!folder.exists())
|
||||
{
|
||||
Log.error("[GameDatabase] Folder no longer exists. Removing from the library: " + folderPath);
|
||||
deleteFolder = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[GameDatabase] Folder contains no games: " + folderPath);
|
||||
}
|
||||
|
||||
if (!deleteFolder)
|
||||
{
|
||||
newFolderPaths.add(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
fileCursor.close();
|
||||
database.close();
|
||||
|
||||
if (folderPaths.size() != newFolderPaths.size())
|
||||
{
|
||||
// One or more folders are being deleted
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putStringSet(GAME_FOLDER_PATHS_PREFERENCE, newFolderPaths);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
public Observable<Cursor> getGamesForPlatform(final Platform platform)
|
||||
{
|
||||
return Observable.create(subscriber ->
|
||||
{
|
||||
Log.info("[GameDatabase] Reading games list...");
|
||||
|
||||
String[] whereArgs = new String[]{Integer.toString(platform.toInt())};
|
||||
|
||||
SQLiteDatabase database = getReadableDatabase();
|
||||
Cursor resultCursor = database.query(
|
||||
TABLE_NAME_GAMES,
|
||||
null,
|
||||
KEY_GAME_PLATFORM + " = ?",
|
||||
whereArgs,
|
||||
null,
|
||||
null,
|
||||
KEY_GAME_TITLE + " ASC"
|
||||
);
|
||||
|
||||
// Pass the result cursor to the consumer.
|
||||
subscriber.onNext(resultCursor);
|
||||
|
||||
// Tell the consumer we're done; it will unsubscribe implicitly.
|
||||
subscriber.onCompleted();
|
||||
});
|
||||
}
|
||||
|
||||
private void execSqlAndLog(SQLiteDatabase database, String sql)
|
||||
{
|
||||
Log.verbose("[GameDatabase] Executing SQL: " + sql);
|
||||
database.execSQL(sql);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
public class GameFile
|
||||
{
|
||||
private long mPointer; // Do not rename or move without editing the native code
|
||||
|
||||
private GameFile(long pointer)
|
||||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
public native int getPlatform();
|
||||
public native String getTitle();
|
||||
public native String getDescription();
|
||||
public native String getCompany();
|
||||
public native int getCountry();
|
||||
public native String getPath();
|
||||
public native String getGameId();
|
||||
public native int[] getBanner();
|
||||
public native int getBannerWidth();
|
||||
public native int getBannerHeight();
|
||||
|
||||
public String getScreenshotPath()
|
||||
{
|
||||
String gameId = getGameId();
|
||||
return "file://" + Environment.getExternalStorageDirectory().getPath() +
|
||||
"/dolphin-emu/ScreenShots/" + gameId + "/" + gameId + "-1.png";
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GameFileCache
|
||||
{
|
||||
private static final String GAME_FOLDER_PATHS_PREFERENCE = "gameFolderPaths";
|
||||
private static final Set<String> EMPTY_SET = new HashSet<>();
|
||||
|
||||
private long mPointer; // Do not rename or move without editing the native code
|
||||
|
||||
public GameFileCache(String path)
|
||||
{
|
||||
mPointer = newGameFileCache(path);
|
||||
}
|
||||
|
||||
private static native long newGameFileCache(String path);
|
||||
|
||||
@Override
|
||||
public native void finalize();
|
||||
|
||||
public static void addGameFolder(String path, Context context)
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> folderPaths = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET);
|
||||
Set<String> newFolderPaths = new HashSet<>(folderPaths);
|
||||
newFolderPaths.add(path);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putStringSet(GAME_FOLDER_PATHS_PREFERENCE, newFolderPaths);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void removeNonExistentGameFolders(Context context)
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> folderPaths = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET);
|
||||
Set<String> newFolderPaths = new HashSet<>();
|
||||
for (String folderPath : folderPaths)
|
||||
{
|
||||
File folder = new File(folderPath);
|
||||
if (folder.exists())
|
||||
{
|
||||
newFolderPaths.add(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (folderPaths.size() != newFolderPaths.size())
|
||||
{
|
||||
// One or more folders are being deleted
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putStringSet(GAME_FOLDER_PATHS_PREFERENCE, newFolderPaths);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans through the file system and updates the cache to match.
|
||||
* @return true if the cache was modified
|
||||
*/
|
||||
public boolean scanLibrary(Context context)
|
||||
{
|
||||
removeNonExistentGameFolders(context);
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
Set<String> folderPathsSet = preferences.getStringSet(GAME_FOLDER_PATHS_PREFERENCE, EMPTY_SET);
|
||||
String[] folderPaths = folderPathsSet.toArray(new String[folderPathsSet.size()]);
|
||||
|
||||
boolean cacheChanged = update(folderPaths);
|
||||
cacheChanged |= updateAdditionalMetadata();
|
||||
if (cacheChanged)
|
||||
{
|
||||
save();
|
||||
}
|
||||
return cacheChanged;
|
||||
}
|
||||
|
||||
public native GameFile[] getAllGames();
|
||||
public native GameFile addOrGet(String gamePath);
|
||||
private native boolean update(String[] folderPaths);
|
||||
private native boolean updateAdditionalMetadata();
|
||||
public native boolean load();
|
||||
private native boolean save();
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.model;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.dolphinemu.dolphinemu.BuildConfig;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
/**
|
||||
* Provides an interface allowing Activities to interact with the SQLite database.
|
||||
* CRUD methods in this class can be called by Activities using getContentResolver().
|
||||
*/
|
||||
public final class GameProvider extends ContentProvider
|
||||
{
|
||||
public static final String REFRESH_LIBRARY = "refresh";
|
||||
|
||||
public static final String AUTHORITY = "content://" + BuildConfig.APPLICATION_ID + ".provider";
|
||||
public static final Uri URI_GAME = Uri.parse(AUTHORITY + "/" + GameDatabase.TABLE_NAME_GAMES + "/");
|
||||
public static final Uri URI_REFRESH = Uri.parse(AUTHORITY + "/" + REFRESH_LIBRARY + "/");
|
||||
|
||||
public static final String MIME_TYPE_FOLDER = "vnd.android.cursor.item/vnd.dolphin.folder";
|
||||
public static final String MIME_TYPE_GAME = "vnd.android.cursor.item/vnd.dolphin.game";
|
||||
|
||||
|
||||
private GameDatabase mDbHelper;
|
||||
|
||||
@Override
|
||||
public boolean onCreate()
|
||||
{
|
||||
Log.info("[GameProvider] Creating Content Provider...");
|
||||
|
||||
mDbHelper = new GameDatabase(getContext());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
|
||||
{
|
||||
Log.info("[GameProvider] Querying URI: " + uri);
|
||||
|
||||
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
||||
|
||||
String table = uri.getLastPathSegment();
|
||||
|
||||
if (table == null)
|
||||
{
|
||||
Log.error("[GameProvider] Badly formatted URI: " + uri);
|
||||
return null;
|
||||
}
|
||||
|
||||
Cursor cursor = db.query(table, projection, selection, selectionArgs, null, null, sortOrder);
|
||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(@NonNull Uri uri)
|
||||
{
|
||||
Log.verbose("[GameProvider] Getting MIME type for URI: " + uri);
|
||||
String lastSegment = uri.getLastPathSegment();
|
||||
|
||||
if (lastSegment == null)
|
||||
{
|
||||
Log.error("[GameProvider] Badly formatted URI: " + uri);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (lastSegment.equals(GameDatabase.TABLE_NAME_GAMES))
|
||||
{
|
||||
return MIME_TYPE_GAME;
|
||||
}
|
||||
|
||||
Log.error("[GameProvider] Unknown MIME type for URI: " + uri);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(@NonNull Uri uri, ContentValues values)
|
||||
{
|
||||
Log.info("[GameProvider] Inserting row at URI: " + uri);
|
||||
|
||||
SQLiteDatabase database = mDbHelper.getWritableDatabase();
|
||||
String table = uri.getLastPathSegment();
|
||||
|
||||
long id = -1;
|
||||
|
||||
if (table != null)
|
||||
{
|
||||
if (table.equals(REFRESH_LIBRARY))
|
||||
{
|
||||
Log.info("[GameProvider] URI specified table REFRESH_LIBRARY. No insertion necessary; refreshing library contents...");
|
||||
mDbHelper.scanLibrary(database);
|
||||
return uri;
|
||||
}
|
||||
|
||||
id = database.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
|
||||
|
||||
// If insertion was successful...
|
||||
if (id > 0)
|
||||
{
|
||||
// Notify the UI that its contents should be refreshed.
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
uri = Uri.withAppendedPath(uri, Long.toString(id));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[GameProvider] Row already exists: " + uri + " id: " + id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[GameProvider] Badly formatted URI: " + uri);
|
||||
}
|
||||
|
||||
database.close();
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs)
|
||||
{
|
||||
Log.error("[GameProvider] Delete operations unsupported. URI: " + uri);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs)
|
||||
{
|
||||
Log.error("[GameProvider] Update operations unsupported. URI: " + uri);
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
*/
|
||||
public final class DirectoryInitializationService extends IntentService
|
||||
{
|
||||
public static final String BROADCAST_ACTION = "org.dolphinemu.dolphinemu.BROADCAST";
|
||||
public static final String BROADCAST_ACTION = "org.dolphinemu.dolphinemu.DIRECTORY_INITIALIZATION";
|
||||
|
||||
public static final String EXTRA_STATE = "directoryState";
|
||||
private static volatile DirectoryInitializationState directoryState = null;
|
||||
|
@ -0,0 +1,125 @@
|
||||
package org.dolphinemu.dolphinemu.services;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.model.GameFileCache;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* A service that loads game list data on a separate thread.
|
||||
*/
|
||||
public final class GameFileCacheService extends IntentService
|
||||
{
|
||||
public static final String BROADCAST_ACTION = "org.dolphinemu.dolphinemu.GAME_FILE_CACHE_UPDATED";
|
||||
|
||||
private static final String ACTION_LOAD = "org.dolphinemu.dolphinemu.LOAD_GAME_FILE_CACHE";
|
||||
private static final String ACTION_RESCAN = "org.dolphinemu.dolphinemu.RESCAN_GAME_FILE_CACHE";
|
||||
|
||||
private static GameFileCache gameFileCache = null;
|
||||
private static AtomicReference<GameFile[]> gameFiles = new AtomicReference<>(new GameFile[]{});
|
||||
|
||||
public GameFileCacheService()
|
||||
{
|
||||
// Superclass constructor is called to name the thread on which this service executes.
|
||||
super("GameFileCacheService");
|
||||
}
|
||||
|
||||
public static List<GameFile> getGameFilesForPlatform(Platform platform)
|
||||
{
|
||||
GameFile[] allGames = gameFiles.get();
|
||||
ArrayList<GameFile> platformGames = new ArrayList<>();
|
||||
for (GameFile game : allGames)
|
||||
{
|
||||
if (Platform.fromNativeInt(game.getPlatform()) == platform)
|
||||
{
|
||||
platformGames.add(game);
|
||||
}
|
||||
}
|
||||
return platformGames;
|
||||
}
|
||||
|
||||
private static void startService(Context context, String action)
|
||||
{
|
||||
Intent intent = new Intent(context, GameFileCacheService.class);
|
||||
intent.setAction(action);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously loads the game file cache from disk without checking
|
||||
* which games are present on the file system.
|
||||
*/
|
||||
public static void startLoad(Context context)
|
||||
{
|
||||
startService(context, ACTION_LOAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously scans for games in the user's configured folders,
|
||||
* updating the game file cache with the results.
|
||||
* If startLoad hasn't been called before this, this has no effect.
|
||||
*/
|
||||
public static void startRescan(Context context)
|
||||
{
|
||||
startService(context, ACTION_RESCAN);
|
||||
}
|
||||
|
||||
public static GameFile addOrGet(String gamePath)
|
||||
{
|
||||
// The existence of this one function, which is called from one
|
||||
// single place, forces us to use synchronization in onHandleIntent...
|
||||
// A bit annoying, but should be good enough for now
|
||||
synchronized (gameFileCache)
|
||||
{
|
||||
return gameFileCache.addOrGet(gamePath);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent)
|
||||
{
|
||||
// Load the game list cache if it isn't already loaded, otherwise do nothing
|
||||
if (ACTION_LOAD.equals(intent.getAction()) && gameFileCache == null)
|
||||
{
|
||||
GameFileCache temp = new GameFileCache(getCacheDir() + File.separator + "gamelist.cache");
|
||||
synchronized (temp)
|
||||
{
|
||||
gameFileCache = temp;
|
||||
gameFileCache.load();
|
||||
updateGameFileArray();
|
||||
}
|
||||
}
|
||||
|
||||
// Rescan the file system and update the game list cache with the results
|
||||
if (ACTION_RESCAN.equals(intent.getAction()) && gameFileCache != null)
|
||||
{
|
||||
synchronized (gameFileCache)
|
||||
{
|
||||
if (gameFileCache.scanLibrary(this))
|
||||
{
|
||||
updateGameFileArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGameFileArray()
|
||||
{
|
||||
GameFile[] gameFilesTemp = gameFileCache.getAllGames();
|
||||
Arrays.sort(gameFilesTemp, (lhs, rhs) -> lhs.getTitle().compareTo(rhs.getTitle()));
|
||||
gameFiles.set(gameFilesTemp);
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_ACTION));
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
@ -18,12 +17,11 @@ import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.adapters.PlatformPagerAdapter;
|
||||
import org.dolphinemu.dolphinemu.model.GameProvider;
|
||||
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesView;
|
||||
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.AddDirectoryHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
|
||||
import org.dolphinemu.dolphinemu.utils.StartupHandler;
|
||||
@ -39,7 +37,7 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
private TabLayout mTabLayout;
|
||||
private FloatingActionButton mFab;
|
||||
|
||||
private MainPresenter mPresenter = new MainPresenter(this);
|
||||
private MainPresenter mPresenter = new MainPresenter(this, this);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
@ -67,7 +65,11 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
} else {
|
||||
showGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
mViewPager.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
@ -76,7 +78,14 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
mPresenter.addDirIfNeeded(new AddDirectoryHelper(this));
|
||||
mPresenter.addDirIfNeeded(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
mPresenter.onDestroy();
|
||||
}
|
||||
|
||||
// TODO: Replace with a ButterKnife injection.
|
||||
@ -106,13 +115,6 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
mToolbar.setSubtitle(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
getContentResolver().insert(GameProvider.URI_REFRESH, null);
|
||||
refreshAllFragments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshFragmentScreenshot(int fragmentPosition)
|
||||
{
|
||||
@ -138,12 +140,6 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
FileBrowserHelper.openDirectoryPicker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGames(Platform platform, Cursor games)
|
||||
{
|
||||
// no-op. Handled by PlatformGamesFragment.
|
||||
}
|
||||
|
||||
/**
|
||||
* @param requestCode An int describing whether the Activity that is returning did so successfully.
|
||||
* @param resultCode An int describing what Activity is giving us this callback.
|
||||
@ -174,12 +170,12 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
case PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION:
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
DirectoryInitializationService.startService(this);
|
||||
|
||||
PlatformPagerAdapter platformPagerAdapter = new PlatformPagerAdapter(
|
||||
getSupportFragmentManager(), this);
|
||||
mViewPager.setAdapter(platformPagerAdapter);
|
||||
mTabLayout.setupWithViewPager(mViewPager);
|
||||
mViewPager.setVisibility(View.VISIBLE);
|
||||
GameFileCacheService.startLoad(this);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
@ -200,17 +196,17 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
return mPresenter.handleOptionSelection(item.getItemId());
|
||||
return mPresenter.handleOptionSelection(item.getItemId(), this);
|
||||
}
|
||||
|
||||
private void refreshAllFragments()
|
||||
public void showGames()
|
||||
{
|
||||
for (Platform platform : Platform.values())
|
||||
{
|
||||
PlatformGamesView fragment = getPlatformGamesView(platform);
|
||||
if (fragment != null)
|
||||
{
|
||||
fragment.refresh();
|
||||
fragment.showGames();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,57 @@
|
||||
package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.dolphinemu.dolphinemu.BuildConfig;
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.GameDatabase;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
import org.dolphinemu.dolphinemu.utils.AddDirectoryHelper;
|
||||
import org.dolphinemu.dolphinemu.model.GameFileCache;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
import org.dolphinemu.dolphinemu.utils.SettingsFile;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public final class MainPresenter
|
||||
{
|
||||
public static final int REQUEST_ADD_DIRECTORY = 1;
|
||||
public static final int REQUEST_EMULATE_GAME = 2;
|
||||
|
||||
private final MainView mView;
|
||||
private final Context mContext;
|
||||
private BroadcastReceiver mBroadcastReceiver = null;
|
||||
private String mDirToAdd;
|
||||
|
||||
public MainPresenter(MainView view)
|
||||
public MainPresenter(MainView view, Context context)
|
||||
{
|
||||
mView = view;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void onCreate()
|
||||
{
|
||||
String versionName = BuildConfig.VERSION_NAME;
|
||||
mView.setVersionString(versionName);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(GameFileCacheService.BROADCAST_ACTION);
|
||||
mBroadcastReceiver = new BroadcastReceiver()
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
mView.showGames();
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager.getInstance(mContext).registerReceiver(mBroadcastReceiver, filter);
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
{
|
||||
if (mBroadcastReceiver != null)
|
||||
{
|
||||
LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mBroadcastReceiver);
|
||||
}
|
||||
}
|
||||
|
||||
public void onFabClick()
|
||||
@ -36,7 +59,7 @@ public final class MainPresenter
|
||||
mView.launchFileListActivity();
|
||||
}
|
||||
|
||||
public boolean handleOptionSelection(int itemId)
|
||||
public boolean handleOptionSelection(int itemId, Context context)
|
||||
{
|
||||
switch (itemId)
|
||||
{
|
||||
@ -57,9 +80,7 @@ public final class MainPresenter
|
||||
return true;
|
||||
|
||||
case R.id.menu_refresh:
|
||||
GameDatabase databaseHelper = DolphinApplication.databaseHelper;
|
||||
databaseHelper.scanLibrary(databaseHelper.getWritableDatabase());
|
||||
mView.refresh();
|
||||
GameFileCacheService.startRescan(context);
|
||||
return true;
|
||||
|
||||
case R.id.button_add_directory:
|
||||
@ -70,13 +91,13 @@ public final class MainPresenter
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addDirIfNeeded(AddDirectoryHelper helper)
|
||||
public void addDirIfNeeded(Context context)
|
||||
{
|
||||
if (mDirToAdd != null)
|
||||
{
|
||||
helper.addDirectory(mDirToAdd, mView::refresh);
|
||||
|
||||
GameFileCache.addGameFolder(mDirToAdd, context);
|
||||
mDirToAdd = null;
|
||||
GameFileCacheService.startRescan(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,15 +110,4 @@ public final class MainPresenter
|
||||
{
|
||||
mView.refreshFragmentScreenshot(resultCode);
|
||||
}
|
||||
|
||||
|
||||
public void loadGames(final Platform platform)
|
||||
{
|
||||
GameDatabase databaseHelper = DolphinApplication.databaseHelper;
|
||||
|
||||
databaseHelper.getGamesForPlatform(platform)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(games -> mView.showGames(platform, games));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
|
||||
/**
|
||||
@ -19,11 +20,6 @@ public interface MainView
|
||||
*/
|
||||
void setVersionString(String version);
|
||||
|
||||
/**
|
||||
* Tell the view to refresh its contents.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* Tell the view to tell the currently displayed {@link android.support.v4.app.Fragment}
|
||||
* to refresh the screenshot at the given position in its list of games.
|
||||
@ -38,11 +34,7 @@ public interface MainView
|
||||
void launchFileListActivity();
|
||||
|
||||
/**
|
||||
* To be called when an asynchronous database read completes. Passes the
|
||||
* result, in this case a {@link Cursor} to the view.
|
||||
*
|
||||
* @param platform Which platform to show games for.
|
||||
* @param games A Cursor containing the games read from the database.
|
||||
* To be called when the game file cache is updated.
|
||||
*/
|
||||
void showGames(Platform platform, Cursor games);
|
||||
void showGames();
|
||||
}
|
||||
|
@ -2,13 +2,10 @@ package org.dolphinemu.dolphinemu.ui.main;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v17.leanback.app.BrowseFragment;
|
||||
import android.support.v17.leanback.app.BrowseSupportFragment;
|
||||
import android.support.v17.leanback.database.CursorMapper;
|
||||
import android.support.v17.leanback.widget.ArrayObjectAdapter;
|
||||
import android.support.v17.leanback.widget.CursorObjectAdapter;
|
||||
import android.support.v17.leanback.widget.HeaderItem;
|
||||
import android.support.v17.leanback.widget.ListRow;
|
||||
import android.support.v17.leanback.widget.ListRowPresenter;
|
||||
@ -21,20 +18,22 @@ import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
|
||||
import org.dolphinemu.dolphinemu.adapters.GameRowPresenter;
|
||||
import org.dolphinemu.dolphinemu.adapters.SettingsRowPresenter;
|
||||
import org.dolphinemu.dolphinemu.model.Game;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.model.TvSettingsItem;
|
||||
import org.dolphinemu.dolphinemu.services.DirectoryInitializationService;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
import org.dolphinemu.dolphinemu.ui.platform.Platform;
|
||||
import org.dolphinemu.dolphinemu.ui.settings.SettingsActivity;
|
||||
import org.dolphinemu.dolphinemu.utils.AddDirectoryHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.PermissionsHandler;
|
||||
import org.dolphinemu.dolphinemu.utils.StartupHandler;
|
||||
import org.dolphinemu.dolphinemu.viewholders.TvGameViewHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
{
|
||||
private MainPresenter mPresenter = new MainPresenter(this);
|
||||
private MainPresenter mPresenter = new MainPresenter(this, this);
|
||||
|
||||
private BrowseSupportFragment mBrowseFragment;
|
||||
|
||||
@ -59,7 +58,14 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
mPresenter.addDirIfNeeded(new AddDirectoryHelper(this));
|
||||
mPresenter.addDirIfNeeded(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
mPresenter.onDestroy();
|
||||
}
|
||||
|
||||
void setupUI() {
|
||||
@ -82,7 +88,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
if (item instanceof TvSettingsItem)
|
||||
{
|
||||
TvSettingsItem settingsItem = (TvSettingsItem) item;
|
||||
mPresenter.handleOptionSelection(settingsItem.getItemId());
|
||||
mPresenter.handleOptionSelection(settingsItem.getItemId(), this);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,9 +96,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
|
||||
// Start the emulation activity and send the path of the clicked ISO to it.
|
||||
EmulationActivity.launch(TvMainActivity.this,
|
||||
holder.path,
|
||||
holder.title,
|
||||
holder.screenshotPath,
|
||||
holder.gameFile,
|
||||
-1,
|
||||
holder.imageScreenshot);
|
||||
}
|
||||
@ -108,12 +112,6 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
mBrowseFragment.setTitle(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
recreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshFragmentScreenshot(int fragmentPosition)
|
||||
{
|
||||
@ -133,15 +131,9 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGames(Platform platform, Cursor games)
|
||||
public void showGames()
|
||||
{
|
||||
ListRow row = buildGamesRow(platform, games);
|
||||
|
||||
// Add row to the adapter only if it is not empty.
|
||||
if (row != null)
|
||||
{
|
||||
mRowsAdapter.add(row);
|
||||
}
|
||||
recreate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,7 +168,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
case PermissionsHandler.REQUEST_CODE_WRITE_PERMISSION:
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
DirectoryInitializationService.startService(this);
|
||||
loadGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.write_permission_needed, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
@ -194,48 +186,36 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||
|
||||
if (PermissionsHandler.hasWriteAccess(this))
|
||||
{
|
||||
loadGames();
|
||||
GameFileCacheService.startLoad(this);
|
||||
}
|
||||
|
||||
mRowsAdapter.add(buildSettingsRow());
|
||||
|
||||
for (Platform platform : Platform.values())
|
||||
{
|
||||
ListRow row = buildGamesRow(platform, GameFileCacheService.getGameFilesForPlatform(platform));
|
||||
|
||||
// Add row to the adapter only if it is not empty.
|
||||
if (row != null)
|
||||
{
|
||||
mRowsAdapter.add(row);
|
||||
}
|
||||
}
|
||||
|
||||
mBrowseFragment.setAdapter(mRowsAdapter);
|
||||
}
|
||||
|
||||
private void loadGames() {
|
||||
for (Platform platform : Platform.values()) {
|
||||
mPresenter.loadGames(platform);
|
||||
}
|
||||
}
|
||||
|
||||
private ListRow buildGamesRow(Platform platform, Cursor games)
|
||||
private ListRow buildGamesRow(Platform platform, Collection<GameFile> gameFiles)
|
||||
{
|
||||
// Create an adapter for this row.
|
||||
CursorObjectAdapter row = new CursorObjectAdapter(new GameRowPresenter());
|
||||
|
||||
// If cursor is empty, don't return a Row.
|
||||
if (!games.moveToFirst())
|
||||
// If there are no games, don't return a Row.
|
||||
if (gameFiles.size() == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
row.changeCursor(games);
|
||||
row.setMapper(new CursorMapper()
|
||||
{
|
||||
@Override
|
||||
protected void bindColumns(Cursor cursor)
|
||||
{
|
||||
// No-op? Not sure what this does.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object bind(Cursor cursor)
|
||||
{
|
||||
return Game.fromCursor(cursor);
|
||||
}
|
||||
});
|
||||
|
||||
String headerName = platform.getHeaderName();
|
||||
// Create an adapter for this row.
|
||||
ArrayObjectAdapter row = new ArrayObjectAdapter(new GameRowPresenter());
|
||||
row.addAll(0, gameFiles);
|
||||
|
||||
// Create a header for this row.
|
||||
HeaderItem header = new HeaderItem(platform.toInt(), platform.getHeaderName());
|
||||
|
@ -23,11 +23,9 @@ public enum Platform
|
||||
|
||||
public static Platform fromNativeInt(int i)
|
||||
{
|
||||
// If the game's platform field is empty, file under Wiiware. // TODO Something less dum
|
||||
if (i == -1) {
|
||||
return Platform.WIIWARE;
|
||||
}
|
||||
return values()[i];
|
||||
// TODO: Proper support for DOL and ELF files
|
||||
boolean in_range = i >= 0 && i < values().length;
|
||||
return values()[in_range ? i : WIIWARE.value];
|
||||
}
|
||||
|
||||
public static Platform fromPosition(int position)
|
||||
@ -44,4 +42,4 @@ public enum Platform
|
||||
{
|
||||
return headerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.dolphinemu.dolphinemu.ui.platform;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
@ -12,13 +11,15 @@ import android.view.ViewGroup;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.adapters.GameAdapter;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class PlatformGamesFragment extends Fragment implements PlatformGamesView
|
||||
{
|
||||
private static final String ARG_PLATFORM = "platform";
|
||||
|
||||
private PlatformGamesPresenter mPresenter = new PlatformGamesPresenter(this);
|
||||
|
||||
private GameAdapter mAdapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
@ -37,8 +38,6 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mPresenter.onCreate((Platform) getArguments().getSerializable(ARG_PLATFORM));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -49,8 +48,6 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
||||
|
||||
findViews(rootView);
|
||||
|
||||
mPresenter.onCreateView();
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@ -65,6 +62,8 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(8));
|
||||
|
||||
showGames();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,12 +72,6 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
||||
mAdapter.notifyItemChanged(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
mPresenter.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(String gameId)
|
||||
{
|
||||
@ -86,11 +79,12 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showGames(Cursor games)
|
||||
public void showGames()
|
||||
{
|
||||
if (mAdapter != null)
|
||||
{
|
||||
mAdapter.swapCursor(games);
|
||||
Platform platform = (Platform) getArguments().getSerializable(ARG_PLATFORM);
|
||||
mAdapter.swapDataSet(GameFileCacheService.getGameFilesForPlatform(platform));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.ui.platform;
|
||||
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.model.GameDatabase;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
public final class PlatformGamesPresenter
|
||||
{
|
||||
private final PlatformGamesView mView;
|
||||
|
||||
private Platform mPlatform;
|
||||
|
||||
public PlatformGamesPresenter(PlatformGamesView view)
|
||||
{
|
||||
mView = view;
|
||||
}
|
||||
|
||||
public void onCreate(Platform platform)
|
||||
{
|
||||
mPlatform = platform;
|
||||
}
|
||||
|
||||
public void onCreateView()
|
||||
{
|
||||
loadGames();
|
||||
}
|
||||
|
||||
public void refresh()
|
||||
{
|
||||
Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Refreshing...");
|
||||
loadGames();
|
||||
}
|
||||
|
||||
private void loadGames()
|
||||
{
|
||||
Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Loading games...");
|
||||
|
||||
GameDatabase databaseHelper = DolphinApplication.databaseHelper;
|
||||
|
||||
databaseHelper.getGamesForPlatform(mPlatform)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(games ->
|
||||
{
|
||||
Log.debug("[PlatformGamesPresenter] " + mPlatform + ": Load finished, swapping cursor...");
|
||||
|
||||
mView.showGames(games);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,17 +1,14 @@
|
||||
package org.dolphinemu.dolphinemu.ui.platform;
|
||||
|
||||
import android.database.Cursor;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstraction for a screen representing a single platform's games.
|
||||
*/
|
||||
public interface PlatformGamesView
|
||||
{
|
||||
/**
|
||||
* Tell the view to refresh its contents.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* Tell the view that a certain game's screenshot has been updated,
|
||||
* and should be redrawn on-screen.
|
||||
@ -29,10 +26,7 @@ public interface PlatformGamesView
|
||||
void onItemClick(String gameId);
|
||||
|
||||
/**
|
||||
* To be called when an asynchronous database read completes. Passes the
|
||||
* result, in this case a {@link Cursor}, to the view.
|
||||
*
|
||||
* @param games A Cursor containing the games read from the database.
|
||||
* To be called when the game file cache is updated.
|
||||
*/
|
||||
void showGames(Cursor games);
|
||||
void showGames();
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.model.GameDatabase;
|
||||
|
||||
public class AddDirectoryHelper
|
||||
{
|
||||
private Context mContext;
|
||||
|
||||
public interface AddDirectoryListener
|
||||
{
|
||||
void onDirectoryAdded();
|
||||
}
|
||||
|
||||
public AddDirectoryHelper(Context context)
|
||||
{
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public void addDirectory(String dir, AddDirectoryListener addDirectoryListener)
|
||||
{
|
||||
new AsyncTask<String, Void, Void>()
|
||||
{
|
||||
@Override
|
||||
protected Void doInBackground(String... params)
|
||||
{
|
||||
for (String path : params)
|
||||
{
|
||||
DolphinApplication.databaseHelper.addGameFolder(path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result)
|
||||
{
|
||||
addDirectoryListener.onDirectoryAdded();
|
||||
}
|
||||
}.execute(dir);
|
||||
}
|
||||
}
|
@ -7,22 +7,28 @@ import com.squareup.picasso.Request;
|
||||
import com.squareup.picasso.RequestHandler;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
public class GameBannerRequestHandler extends RequestHandler {
|
||||
GameFile mGameFile;
|
||||
|
||||
public GameBannerRequestHandler(GameFile gameFile)
|
||||
{
|
||||
mGameFile = gameFile;
|
||||
}
|
||||
@Override
|
||||
public boolean canHandleRequest(Request data) {
|
||||
return "iso".equals(data.uri.getScheme());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result load(Request request, int networkPolicy) throws IOException {
|
||||
String url = request.uri.getHost() + request.uri.getPath();
|
||||
int[] vector = NativeLibrary.GetBanner(url);
|
||||
int width = 96;
|
||||
int height = 32;
|
||||
public Result load(Request request, int networkPolicy) {
|
||||
int[] vector = mGameFile.getBanner();
|
||||
int width = mGameFile.getBannerWidth();
|
||||
int height = mGameFile.getBannerHeight();
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setPixels(vector, 0, width, 0, 0, width, height);
|
||||
return new Result(bitmap, Picasso.LoadedFrom.DISK);
|
||||
|
@ -7,17 +7,18 @@ import android.widget.ImageView;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
public class PicassoUtils {
|
||||
public static void loadGameBanner(ImageView imageView, String screenshotPath, String gamePath) {
|
||||
File file = new File(URI.create(screenshotPath));
|
||||
if (file.exists()) {
|
||||
public static void loadGameBanner(ImageView imageView, GameFile gameFile) {
|
||||
File screenshotFile = new File(URI.create(gameFile.getScreenshotPath()));
|
||||
if (screenshotFile.exists()) {
|
||||
// Fill in the view contents.
|
||||
Picasso.with(imageView.getContext())
|
||||
.load(screenshotPath)
|
||||
.load(gameFile.getScreenshotPath())
|
||||
.fit()
|
||||
.centerCrop()
|
||||
.noFade()
|
||||
@ -27,11 +28,11 @@ public class PicassoUtils {
|
||||
.into(imageView);
|
||||
} else {
|
||||
Picasso picassoInstance = new Picasso.Builder(imageView.getContext())
|
||||
.addRequestHandler(new GameBannerRequestHandler())
|
||||
.addRequestHandler(new GameBannerRequestHandler(gameFile))
|
||||
.build();
|
||||
|
||||
picassoInstance
|
||||
.load(Uri.parse("iso:/" + gamePath))
|
||||
.load(Uri.parse("iso:/" + gameFile.getPath()))
|
||||
.fit()
|
||||
.noFade()
|
||||
.noPlaceholder()
|
||||
|
@ -6,6 +6,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
|
||||
/**
|
||||
* A simple class that stores references to views so that the GameAdapter doesn't need to
|
||||
@ -17,15 +18,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder
|
||||
public TextView textGameTitle;
|
||||
public TextView textCompany;
|
||||
|
||||
public String gameId;
|
||||
|
||||
// TODO Not need any of this stuff. Currently only the properties dialog needs it.
|
||||
public String path;
|
||||
public String title;
|
||||
public String description;
|
||||
public int country;
|
||||
public String company;
|
||||
public String screenshotPath;
|
||||
public GameFile gameFile;
|
||||
|
||||
public GameViewHolder(View itemView)
|
||||
{
|
||||
@ -33,8 +26,8 @@ public class GameViewHolder extends RecyclerView.ViewHolder
|
||||
|
||||
itemView.setTag(this);
|
||||
|
||||
imageScreenshot = (ImageView) itemView.findViewById(R.id.image_game_screen);
|
||||
textGameTitle = (TextView) itemView.findViewById(R.id.text_game_title);
|
||||
textCompany = (TextView) itemView.findViewById(R.id.text_company);
|
||||
imageScreenshot = itemView.findViewById(R.id.image_game_screen);
|
||||
textGameTitle = itemView.findViewById(R.id.text_game_title);
|
||||
textCompany = itemView.findViewById(R.id.text_company);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import android.support.v17.leanback.widget.Presenter;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.dolphinemu.dolphinemu.model.GameFile;
|
||||
|
||||
/**
|
||||
* A simple class that stores references to views so that the GameAdapter doesn't need to
|
||||
* keep calling findViewById(), which is expensive.
|
||||
@ -15,15 +17,7 @@ public final class TvGameViewHolder extends Presenter.ViewHolder
|
||||
|
||||
public ImageView imageScreenshot;
|
||||
|
||||
public String gameId;
|
||||
|
||||
// TODO Not need any of this stuff. Currently only the properties dialog needs it.
|
||||
public String path;
|
||||
public String title;
|
||||
public String description;
|
||||
public int country;
|
||||
public String company;
|
||||
public String screenshotPath;
|
||||
public GameFile gameFile;
|
||||
|
||||
public TvGameViewHolder(View itemView)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@
|
||||
tools:text="Rhythm Heaven Fever"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_company"
|
||||
android:id="@+id/text_description"
|
||||
style="@android:style/TextAppearance.Material.Caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -66,7 +66,7 @@
|
||||
android:layout_height="1dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@+id/text_company"
|
||||
android:layout_below="@+id/text_description"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="#1F000000"/>
|
||||
|
||||
@ -96,13 +96,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/icon_country"
|
||||
android:layout_alignStart="@+id/text_company"
|
||||
android:layout_alignStart="@+id/text_description"
|
||||
android:layout_alignTop="@+id/icon_country"
|
||||
android:gravity="center_vertical"
|
||||
tools:text="United States"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_date"
|
||||
android:id="@+id/text_company"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignBottom="@+id/icon_company"
|
||||
|
Reference in New Issue
Block a user