Skip to content
Permalink
Browse files
Merge pull request #6085 from hackbar/cleanup
Minor Android UI code cleanups
  • Loading branch information
Helios747 committed Sep 29, 2017
2 parents 7704bd5 + 3c3d0fa commit 187d443
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 117 deletions.
@@ -41,6 +41,7 @@
import org.dolphinemu.dolphinemu.fragments.MenuFragment;
import org.dolphinemu.dolphinemu.fragments.SaveStateFragment;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.Animations;
import org.dolphinemu.dolphinemu.utils.Java_GCAdapter;
import org.dolphinemu.dolphinemu.utils.Java_WiimoteAdapter;
@@ -298,7 +299,7 @@ public void run()

mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

mIsGameCubeGame = (NativeLibrary.GetPlatform(path) == 0);
mIsGameCubeGame = Platform.fromNativeInt(NativeLibrary.GetPlatform(path)) == Platform.GAMECUBE;
}

@Override
@@ -1,7 +1,10 @@
package org.dolphinemu.dolphinemu.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v17.leanback.widget.ImageCardView;
import android.support.v17.leanback.widget.Presenter;
import android.support.v4.content.ContextCompat;
import android.view.ViewGroup;
import android.widget.ImageView;

@@ -16,18 +19,11 @@
*/
public final class GameRowPresenter extends Presenter
{
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent)
{
// Create a new view.
ImageCardView gameCard = new ImageCardView(parent.getContext())
{
@Override
public void setSelected(boolean selected)
{
setCardBackground(this, selected);
super.setSelected(selected);
}
};
ImageCardView gameCard = new ImageCardView(parent.getContext());

gameCard.setMainImageAdjustViewBounds(true);
gameCard.setMainImageDimensions(480, 320);
@@ -36,12 +32,11 @@ public void setSelected(boolean selected)
gameCard.setFocusable(true);
gameCard.setFocusableInTouchMode(true);

setCardBackground(gameCard, false);

// Use that view to create a ViewHolder.
return new TvGameViewHolder(gameCard);
}

@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item)
{
TvGameViewHolder holder = (TvGameViewHolder) viewHolder;
@@ -64,45 +59,30 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
holder.company = game.getCompany();
holder.screenshotPath = game.getScreenshotPath();

// Set the platform-dependent background color of the card
int backgroundId;
switch (game.getPlatform())
{
case Game.PLATFORM_GC:
holder.cardParent.setTag(R.color.dolphin_accent_gamecube);
case GAMECUBE:
backgroundId = R.drawable.tv_card_background_gamecube;
break;

case Game.PLATFORM_WII:
holder.cardParent.setTag(R.color.dolphin_accent_wii);
case WII:
backgroundId = R.drawable.tv_card_background_wii;
break;

case Game.PLATFORM_WII_WARE:
holder.cardParent.setTag(R.color.dolphin_accent_wiiware);
case WIIWARE:
backgroundId = R.drawable.tv_card_background_wiiware;
break;

default:
holder.cardParent.setTag(android.R.color.holo_red_dark);
break;
throw new AssertionError("Not reachable.");
}
Context context = holder.cardParent.getContext();
Drawable background = ContextCompat.getDrawable(context, backgroundId);
holder.cardParent.setInfoAreaBackground(background);
}

@Override
public void onUnbindViewHolder(ViewHolder viewHolder)
{
// no op
}

public void setCardBackground(ImageCardView view, boolean selected)
{
int backgroundColor;

if (selected)
{
// TODO: 7/20/15 Try using view tag to set color
backgroundColor = (int) view.getTag();
}
else
{
backgroundColor = R.color.tv_card_unselected;
}

view.setInfoAreaBackgroundColor(view.getResources().getColor(backgroundColor));
}
}
@@ -10,6 +10,7 @@
import android.text.style.ImageSpan;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.ui.platform.PlatformGamesFragment;

public class PlatformPagerAdapter extends FragmentPagerAdapter
@@ -32,7 +33,7 @@ public PlatformPagerAdapter(FragmentManager fm, Context context)
@Override
public Fragment getItem(int position)
{
return PlatformGamesFragment.newInstance(position);
return PlatformGamesFragment.newInstance(Platform.fromPosition(position));
}

@Override
@@ -4,13 +4,10 @@
import android.database.Cursor;
import android.os.Environment;

import org.dolphinemu.dolphinemu.ui.platform.Platform;

public final class Game
{
public static final int PLATFORM_GC = 0;
public static final int PLATFORM_WII = 1;
public static final int PLATFORM_WII_WARE = 2;
public static final int PLATFORM_ALL = 3;

// 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;
@@ -36,10 +33,10 @@
private String mScreenshotPath;
private String mCompany;

private int mPlatform;
private Platform mPlatform;
private int mCountry;

public Game(int platform, String title, String description, int country, String path, String gameId, String company, String screenshotPath)
public Game(Platform platform, String title, String description, int country, String path, String gameId, String company, String screenshotPath)
{
mPlatform = platform;
mTitle = title;
@@ -51,7 +48,7 @@ public Game(int platform, String title, String description, int country, String
mScreenshotPath = screenshotPath;
}

public int getPlatform()
public Platform getPlatform()
{
return mPlatform;
}
@@ -91,13 +88,13 @@ public String getScreenshotPath()
return mScreenshotPath;
}

public static ContentValues asContentValues(int platform, String title, String description, int country, String path, String gameId, String company)
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);
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);
@@ -111,7 +108,7 @@ public static ContentValues asContentValues(int platform, String title, String d

public static Game fromCursor(Cursor cursor)
{
return new Game(cursor.getInt(GameDatabase.GAME_COLUMN_PLATFORM),
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),
@@ -7,6 +7,7 @@
import android.database.sqlite.SQLiteOpenHelper;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.Log;

import java.io.File;
@@ -200,12 +201,7 @@ public void scanLibrary(SQLiteDatabase database)
gameId = filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf("."));
}

// If the game's platform field is empty, file under Wiiware. // TODO Something less dum
int platform = NativeLibrary.GetPlatform(filePath);
if (platform == -1)
{
platform = Game.PLATFORM_WII_WARE;
}
Platform platform = Platform.fromNativeInt(NativeLibrary.GetPlatform(filePath));

ContentValues game = Game.asContentValues(platform,
name,
@@ -257,31 +253,22 @@ else if (!folder.exists())
database.close();
}

public Observable<Cursor> getGamesForPlatform(final int platform)
public Observable<Cursor> getGamesForPlatform(final Platform platform)
{
return Observable.create(new Observable.OnSubscribe<Cursor>()
{
@Override
public void call(Subscriber<? super Cursor> subscriber)
{
Log.info("[GameDatabase] [GameDatabase] Reading games list...");

String whereClause = null;
String[] whereArgs = null;
Log.info("[GameDatabase] Reading games list...");

// If -1 passed in, return all games. Else, return games for one platform only.
if (platform >= 0)
{
whereClause = KEY_GAME_PLATFORM + " = ?";
whereArgs = new String[]{Integer.toString(platform)};
}
String[] whereArgs = new String[]{Integer.toString(platform.toInt())};

SQLiteDatabase database = getReadableDatabase();

Cursor resultCursor = database.query(
TABLE_NAME_GAMES,
null,
whereClause,
KEY_GAME_PLATFORM + " = ?",
whereArgs,
null,
null,
@@ -20,6 +20,7 @@
import org.dolphinemu.dolphinemu.activities.AddDirectoryActivity;
import org.dolphinemu.dolphinemu.adapters.PlatformPagerAdapter;
import org.dolphinemu.dolphinemu.model.GameProvider;
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.PermissionsHandler;
@@ -114,7 +115,8 @@ public void refresh()
public void refreshFragmentScreenshot(int fragmentPosition)
{
// Invalidate Picasso image so that the new screenshot is animated in.
PlatformGamesView fragment = getPlatformGamesView(mViewPager.getCurrentItem());
Platform platform = Platform.fromPosition(mViewPager.getCurrentItem());
PlatformGamesView fragment = getPlatformGamesView(platform);

if (fragment != null)
{
@@ -135,7 +137,7 @@ public void launchFileListActivity()
}

@Override
public void showGames(int platformIndex, Cursor games)
public void showGames(Platform platform, Cursor games)
{
// no-op. Handled by PlatformGamesFragment.
}
@@ -189,15 +191,17 @@ public boolean onOptionsItemSelected(MenuItem item)

private void refreshFragment()
{
PlatformGamesView fragment = getPlatformGamesView(mViewPager.getCurrentItem());

Platform platform = Platform.fromPosition(mViewPager.getCurrentItem());
PlatformGamesView fragment = getPlatformGamesView(platform);
if (fragment != null)
{
fragment.refresh();
}
}

@Nullable
private PlatformGamesView getPlatformGamesView(int platform)
private PlatformGamesView getPlatformGamesView(Platform platform)
{
String fragmentTag = "android:switcher:" + mViewPager.getId() + ":" + platform;

@@ -2,10 +2,12 @@


import android.database.Cursor;

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.SettingsFile;

import rx.android.schedulers.AndroidSchedulers;
@@ -87,19 +89,19 @@ public void handleActivityResult(int requestCode, int resultCode)
}
}

public void loadGames(final int platformIndex)
public void loadGames(final Platform platform)
{
GameDatabase databaseHelper = DolphinApplication.databaseHelper;

databaseHelper.getGamesForPlatform(platformIndex)
databaseHelper.getGamesForPlatform(platform)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Cursor>()
{
@Override
public void call(Cursor games)
{
mView.showGames(platformIndex, games);
mView.showGames(platform, games);
}
}
);
@@ -2,6 +2,8 @@

import android.database.Cursor;

import org.dolphinemu.dolphinemu.ui.platform.Platform;

/**
* Abstraction for the screen that shows on application launch.
* Implementations will differ primarily to target touch-screen
@@ -39,8 +41,8 @@
* To be called when an asynchronous database read completes. Passes the
* result, in this case a {@link Cursor} to the view.
*
* @param platformIndex Which platform contains these games.
* @param platform Which platform to show games for.
* @param games A Cursor containing the games read from the database.
*/
void showGames(int platformIndex, Cursor games);
void showGames(Platform platform, Cursor games);
}

0 comments on commit 187d443

Please sign in to comment.