Android: Remove inheritance from Game model, and improve the relevance of its content

This commit is contained in:
Eder Bastos 2015-05-16 20:52:55 -04:00
parent 4c786cb70c
commit 5b0c047e0b
17 changed files with 156 additions and 227 deletions

View File

@ -134,9 +134,11 @@ public final class NativeLibrary
public static native String GetGameId(String filename);
public static native int GetCountry(String filename);
public static native String GetDate(String filename);
public static native String GetCompany(String filename);
public static native long GetFilesize(String filename);
public static native boolean IsWiiTitle(String filename);
public static native int GetPlatform(String filename);
/**
* Gets the Dolphin version string.

View File

@ -179,12 +179,14 @@ public final class GameGridActivity extends Activity
// Check that the file has an appropriate extension before trying to read out of it.
if (exts.contains(entryName.toLowerCase().substring(entryName.lastIndexOf('.'))))
{
GcGame game = new GcGame(NativeLibrary.GetTitle(entry.getAbsolutePath()),
NativeLibrary.GetDescription(entry.getAbsolutePath()).replace("\n", " "),
NativeLibrary.GetCountry(entry.getAbsolutePath()),
entry.getAbsolutePath(),
NativeLibrary.GetGameId(entry.getAbsolutePath()),
NativeLibrary.GetDate(entry.getAbsolutePath()));
String absolutePath = entry.getAbsolutePath();
Game game = new Game(NativeLibrary.GetPlatform(absolutePath),
NativeLibrary.GetTitle(absolutePath),
NativeLibrary.GetDescription(absolutePath).replace("\n", " "),
NativeLibrary.GetCountry(absolutePath),
absolutePath,
NativeLibrary.GetGameId(absolutePath),
NativeLibrary.GetCompany(absolutePath));
gameList.add(game);
}

View File

@ -79,9 +79,9 @@ public class GameAdapter extends RecyclerView.Adapter<GameViewHolder> implements
.into(holder.imageScreenshot);
holder.textGameTitle.setText(game.getTitle());
if (game.getDescription() != null)
if (game.getCompany() != null)
{
holder.textDescription.setText(game.getDescription());
holder.textCompany.setText(game.getCompany());
}
holder.path = game.getPath();

View File

@ -39,7 +39,7 @@ public class GameDetailsDialog extends DialogFragment
arguments.putString(ARGUMENT_GAME_TITLE, game.getTitle());
arguments.putString(ARGUMENT_GAME_DESCRIPTION, game.getDescription());
arguments.putInt(ARGUMENT_GAME_COUNTRY, game.getCountry());
arguments.putString(ARGUMENT_GAME_DATE, game.getDate());
arguments.putString(ARGUMENT_GAME_DATE, game.getCompany());
arguments.putString(ARGUMENT_GAME_PATH, game.getPath());
arguments.putString(ARGUMENT_GAME_SCREENSHOT_PATH, game.getScreenPath());
fragment.setArguments(arguments);
@ -57,7 +57,7 @@ public class GameDetailsDialog extends DialogFragment
CircleImageView circleBanner = (CircleImageView) contents.findViewById(R.id.circle_banner);
TextView textTitle = (TextView) contents.findViewById(R.id.text_game_title);
TextView textDescription = (TextView) contents.findViewById(R.id.text_game_description);
TextView textDescription = (TextView) contents.findViewById(R.id.text_company);
TextView textCountry = (TextView) contents.findViewById(R.id.text_country);
TextView textDate = (TextView) contents.findViewById(R.id.text_date);

View File

@ -10,10 +10,11 @@ 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_OTHER = 3;
public static final int TYPE_GC = 0;
public static final int TYPE_WII = 1;
public static final int TYPE_WII_WARE = 2;
public static final int TYPE_OTHER = 4;
public static final int TYPE_FOLDER = 5;
private int mType;
private String mFilename;
@ -48,7 +49,7 @@ public class FileListItem implements Comparable<FileListItem>
// Check that the file has an extension we care about before trying to read out of it.
if (allowedExtensions.contains(fileExtension))
{
mType = NativeLibrary.IsWiiTitle(mPath) ? TYPE_WII : TYPE_GC;
mType = NativeLibrary.GetPlatform(mPath);
}
else
{

View File

@ -1,6 +1,8 @@
package org.dolphinemu.dolphinemu.model;
public interface Game
import java.io.File;
public class Game
{
public static final int PLATFORM_GC = 0;
public static final int PLATFORM_WII = 1;
@ -22,19 +24,85 @@ public interface Game
public static final int COUNTRY_WORLD = 12;
public static final int COUNTRY_UNKNOWN = 13;
public int getPlatform();
private static final String PATH_SCREENSHOT_FOLDER = "file:///sdcard/dolphin-emu/ScreenShots/";
public String getDate();
private String mTitle;
private String mDescription;
private String mPath;
private String mGameId;
private String mScreenshotFolderPath;
private String mCompany;
public String getTitle();
private int mPlatform;
private int mCountry;
public String getDescription();
public Game(int platform, String title, String description, int country, String path, String gameId, String company)
{
mPlatform = platform;
mTitle = title;
mDescription = description;
mCountry = country;
mPath = path;
mGameId = gameId;
mCompany = company;
mScreenshotFolderPath = PATH_SCREENSHOT_FOLDER + getGameId() + "/";
}
public int getCountry();
public int getPlatform()
{
return mPlatform;
}
public String getPath();
public String getTitle()
{
return mTitle;
}
public String getGameId();
public String getDescription()
{
return mDescription;
}
public String getScreenPath();
public String getCompany()
{
return mCompany;
}
public int getCountry()
{
return mCountry;
}
public String getPath()
{
return mPath;
}
public String getGameId()
{
return mGameId;
}
public String getScreenshotFolderPath()
{
return mScreenshotFolderPath;
}
public String getScreenPath()
{
// Count how many screenshots are available, so we can use the most recent one.
File screenshotFolder = new File(mScreenshotFolderPath.substring(mScreenshotFolderPath.indexOf('s') - 1));
int screenCount = 0;
if (screenshotFolder.isDirectory())
{
screenCount = screenshotFolder.list().length;
}
String screenPath = mScreenshotFolderPath
+ getGameId() + "-"
+ screenCount + ".png";
return screenPath;
}
}

View File

@ -1,96 +0,0 @@
package org.dolphinemu.dolphinemu.model;
import java.io.File;
public final class GcGame implements Game
{
private String mTitle;
private String mDescription;
private String mPath;
private String mGameId;
private String mScreenshotFolderPath;
private String mDate;
private int mCountry;
private int mPlatform = PLATFORM_GC;
private static final String PATH_SCREENSHOT_FOLDER = "file:///sdcard/dolphin-emu/ScreenShots/";
public GcGame(String title, String description, int country, String path, String gameId, String date)
{
mTitle = title;
mDescription = description;
mCountry = country;
mPath = path;
mGameId = gameId;
mDate = date;
mScreenshotFolderPath = PATH_SCREENSHOT_FOLDER + getGameId() + "/";
}
@Override
public int getPlatform()
{
return mPlatform;
}
@Override
public String getTitle()
{
return mTitle;
}
@Override
public String getDescription()
{
return mDescription;
}
@Override
public String getDate()
{
return mDate;
}
@Override
public int getCountry()
{
return mCountry;
}
@Override
public String getPath()
{
return mPath;
}
public String getGameId()
{
return mGameId;
}
public String getScreenshotFolderPath()
{
return mScreenshotFolderPath;
}
@Override
public String getScreenPath()
{
// Count how many screenshots are available, so we can use the most recent one.
File screenshotFolder = new File(mScreenshotFolderPath.substring(mScreenshotFolderPath.indexOf('s') - 1));
int screenCount = 0;
if (screenshotFolder.isDirectory())
{
screenCount = screenshotFolder.list().length;
}
String screenPath = mScreenshotFolderPath
+ getGameId() + "-"
+ screenCount + ".png";
return screenPath;
}
}

View File

@ -1,53 +0,0 @@
package org.dolphinemu.dolphinemu.model;
public final class WiiGame implements Game
{
@Override
public int getPlatform()
{
return 0;
}
@Override
public String getDate()
{
return null;
}
@Override
public String getTitle()
{
return null;
}
@Override
public String getDescription()
{
return null;
}
@Override
public int getCountry()
{
return 13;
}
@Override
public String getPath()
{
return null;
}
@Override
public String getGameId()
{
return null;
}
@Override
public String getScreenPath()
{
return null;
}
}

View File

@ -1,16 +1,11 @@
package org.dolphinemu.dolphinemu.viewholders;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.dialogs.GameDetailsDialog;
import org.dolphinemu.dolphinemu.emulation.EmulationActivity;
import org.dolphinemu.dolphinemu.model.Game;
@ -18,7 +13,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder
{
public ImageView imageScreenshot;
public TextView textGameTitle;
public TextView textDescription;
public TextView textCompany;
// Used to handle onClick(). Set this in onBindViewHolder().
public String path;
@ -33,6 +28,6 @@ public class GameViewHolder extends RecyclerView.ViewHolder
imageScreenshot = (ImageView) itemView.findViewById(R.id.image_game_screen);
textGameTitle = (TextView) itemView.findViewById(R.id.text_game_title);
textDescription = (TextView) itemView.findViewById(R.id.text_game_description);
textCompany = (TextView) itemView.findViewById(R.id.text_company);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

View File

@ -40,7 +40,7 @@
tools:text="The Legend of Zelda: The Wind Waker"/>
<TextView
android:id="@+id/text_game_description"
android:id="@+id/text_company"
style="@android:style/TextAppearance.Material.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -51,7 +51,7 @@
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
tools:text="Zany rhythm action!"/>
tools:text="Nintendo"/>
</LinearLayout>

View File

@ -32,6 +32,7 @@
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:transitionName="image_game_screen"
tools:scaleType="centerCrop"
tools:src="@drawable/placeholder_screenshot"/>
<TextView
@ -46,12 +47,10 @@
android:layout_marginTop="24dp"
android:layout_toEndOf="@+id/circle_banner"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
tools:text="Rhythm Heaven Fever"/>
<TextView
android:id="@+id/text_game_description"
android:id="@+id/text_company"
style="@android:style/TextAppearance.Material.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -59,7 +58,6 @@
android:layout_alignStart="@+id/text_game_title"
android:layout_below="@+id/text_game_title"
android:layout_marginTop="8dp"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed odio vel quam auctor euismod. Pellentesque odio nibh, fermentum ut hendrerit id, ultrices et justo. "
tools:text="Zany rhythm action!"
/>
@ -69,7 +67,7 @@
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/text_game_description"
android:layout_below="@+id/text_company"
android:layout_marginTop="16dp"
android:background="#1F000000"/>
@ -85,14 +83,14 @@
android:src="@drawable/ic_country"/>
<ImageView
android:id="@+id/icon_year"
android:id="@+id/icon_company"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignStart="@+id/icon_country"
android:layout_below="@+id/icon_country"
android:layout_marginTop="16dp"
android:padding="6dp"
android:src="@drawable/ic_date"
android:src="@drawable/ic_company"
android:layout_marginBottom="16dp"/>
<TextView
@ -100,22 +98,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/icon_country"
android:layout_alignStart="@+id/text_game_description"
android:layout_alignStart="@+id/text_company"
android:layout_alignTop="@+id/icon_country"
android:gravity="center_vertical"
android:text="United States"
tools:text="United States"/>
<TextView
android:id="@+id/text_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/icon_year"
android:layout_alignBottom="@+id/icon_company"
android:layout_alignStart="@+id/text_country"
android:layout_alignTop="@+id/icon_year"
android:layout_alignTop="@+id/icon_company"
android:gravity="center_vertical"
android:text="2010"
tools:text="2010"/>
tools:text="Nintendo"/>
<ImageButton
android:id="@+id/button_launch"

View File

@ -162,23 +162,6 @@ static bool LoadBanner(std::string filename, u32 *Banner)
return false;
}
static bool IsWiiTitle(std::string filename)
{
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
bool is_wii_title = pVolume->IsWiiDisc() || pVolume->IsWadFile();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Is %s a Wii Disc: %s", filename.c_str(), is_wii_title ? "Yes" : "No" );
return is_wii_title;
}
// Technically correct.
return false;
}
static int GetCountry(std::string filename)
{
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
@ -192,10 +175,41 @@ static int GetCountry(std::string filename)
return country;
}
// Technically correct.
// Return UNKNOWN
return 13;
}
static int GetPlatform(std::string filename)
{
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr)
{
bool is_wii_disc = pVolume->IsWiiDisc();
bool is_wii_wad = pVolume->IsWadFile();
if (is_wii_disc)
{
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii disc.");
// See Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/Game.java
return 1;
}
else if (is_wii_wad)
{
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Wii WAD.");
return 2;
}
else
{
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Volume is a Gamecube disc.");
return 0;
}
}
return -1;
}
static std::string GetTitle(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Title for file: %s", filename.c_str());
@ -292,15 +306,15 @@ static std::string GetGameId(std::string filename)
return std::string ("");
}
static std::string GetApploaderDate(std::string filename)
static std::string GetCompany(std::string filename)
{
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Date for file: %s", filename.c_str());
__android_log_print(ANDROID_LOG_WARN, DOLPHIN_TAG, "Getting Company for file: %s", filename.c_str());
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(filename);
if (pVolume != nullptr)
{
std::string date = pVolume->GetApploaderDate();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Date: %s", date.c_str());
std::string date = pVolume->GetCompany();
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Company: %s", date.c_str());
return date;
}
@ -349,9 +363,9 @@ JNIEXPORT jintArray JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetBann
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDescription(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDate(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsWiiTitle(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv *env, jobject obj, jstring jFilename);
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv *env, jobject obj);
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SupportsNEON(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv *env, jobject obj);
@ -423,11 +437,11 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameId
return env->NewStringUTF(id.c_str());
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDate(JNIEnv *env, jobject obj, jstring jFilename)
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCompany(JNIEnv *env, jobject obj, jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
std::string date = GetApploaderDate(filename);
return env->NewStringUTF(date.c_str());
std::string company = GetCompany(filename);
return env->NewStringUTF(company.c_str());
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCountry(JNIEnv *env, jobject obj, jstring jFilename)
@ -444,11 +458,11 @@ JNIEXPORT jlong JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetFilesize
return size;
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsWiiTitle(JNIEnv *env, jobject obj, jstring jFilename)
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetPlatform(JNIEnv *env, jobject obj, jstring jFilename)
{
std::string filename = GetJString(env, jFilename);
bool wiiDisc = IsWiiTitle(filename);
return wiiDisc;
int platform = GetPlatform(filename);
return platform;
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv *env, jobject obj)