Skip to content
Permalink
Browse files

Merge pull request #8188 from JosJuice/android-game-details

Android: Bring back and update the game details dialog
  • Loading branch information
JosJuice committed Nov 25, 2019
2 parents ac77df9 + 9639dde commit 70ee5234ba4782ae9e16a81266f97024a96245cf
Showing with 310 additions and 31 deletions.
  1. +1 −0 Source/Android/app/build.gradle
  2. +6 −5 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java
  3. +6 −5 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameRowPresenter.java
  4. +71 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/GameDetailsDialog.java
  5. +18 −9 ...main/java/org/dolphinemu/dolphinemu/dialogs/{GameSettingsDialog.java → GamePropertiesDialog.java}
  6. +0 −7 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFile.java
  7. +36 −0 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/GameBannerRequestHandler.java
  8. +19 −4 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/PicassoUtils.java
  9. BIN Source/Android/app/src/main/res/drawable-hdpi/ic_company.png
  10. BIN Source/Android/app/src/main/res/drawable-hdpi/ic_country.png
  11. BIN Source/Android/app/src/main/res/drawable-xhdpi/ic_company.png
  12. BIN Source/Android/app/src/main/res/drawable-xhdpi/ic_country.png
  13. BIN Source/Android/app/src/main/res/drawable-xxhdpi/ic_company.png
  14. BIN Source/Android/app/src/main/res/drawable-xxhdpi/ic_country.png
  15. BIN Source/Android/app/src/main/res/drawable-xxxhdpi/ic_company.png
  16. BIN Source/Android/app/src/main/res/drawable-xxxhdpi/ic_country.png
  17. +146 −0 Source/Android/app/src/main/res/layout/dialog_game_details.xml
  18. +2 −0 Source/Android/app/src/main/res/values/arrays.xml
  19. +5 −1 Source/Android/app/src/main/res/values/strings.xml
@@ -80,6 +80,7 @@ dependencies {
implementation 'androidx.exifinterface:exifinterface:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'

// Android TV UI libraries.
@@ -13,7 +13,7 @@

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.dialogs.GameSettingsDialog;
import org.dolphinemu.dolphinemu.dialogs.GamePropertiesDialog;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
import org.dolphinemu.dolphinemu.viewholders.GameViewHolder;
@@ -69,7 +69,7 @@ public GameViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
public void onBindViewHolder(GameViewHolder holder, int position)
{
GameFile gameFile = mGameFiles.get(position);
PicassoUtils.loadGameBanner(holder.imageScreenshot, gameFile);
PicassoUtils.loadGameCover(holder.imageScreenshot, gameFile);

holder.textGameTitle.setText(gameFile.getTitle());
holder.textCompany.setText(gameFile.getCompany());
@@ -145,10 +145,11 @@ public boolean onLongClick(View view)
return true;
}

GameSettingsDialog fragment =
GameSettingsDialog.newInstance(gameId, holder.gameFile.getPlatform());
GamePropertiesDialog fragment =
GamePropertiesDialog
.newInstance(holder.gameFile.getPath(), gameId, holder.gameFile.getPlatform());
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
.add(fragment, GameSettingsDialog.TAG).commit();
.add(fragment, GamePropertiesDialog.TAG).commit();
return true;
}

@@ -13,7 +13,7 @@
import android.widget.ImageView;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.dialogs.GameSettingsDialog;
import org.dolphinemu.dolphinemu.dialogs.GamePropertiesDialog;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.ui.platform.Platform;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;
@@ -49,7 +49,7 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
GameFile gameFile = (GameFile) item;

holder.imageScreenshot.setImageDrawable(null);
PicassoUtils.loadGameBanner(holder.imageScreenshot, gameFile);
PicassoUtils.loadGameCover(holder.imageScreenshot, gameFile);

holder.cardParent.setTitleText(gameFile.getTitle());
holder.cardParent.setContentText(gameFile.getCompany());
@@ -90,10 +90,11 @@ public void onBindViewHolder(ViewHolder viewHolder, Object item)
return true;
}

GameSettingsDialog fragment =
GameSettingsDialog.newInstance(gameId, holder.gameFile.getPlatform());
GamePropertiesDialog fragment =
GamePropertiesDialog.newInstance(holder.gameFile.getPath(), gameId,
holder.gameFile.getPlatform());
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction()
.add(fragment, GameSettingsDialog.TAG).commit();
.add(fragment, GamePropertiesDialog.TAG).commit();

return true;
});
@@ -0,0 +1,71 @@
package org.dolphinemu.dolphinemu.dialogs;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.utils.PicassoUtils;

public final class GameDetailsDialog extends DialogFragment
{
private static final String ARG_GAME_PATH = "game_path";

public static GameDetailsDialog newInstance(String gamePath)
{
GameDetailsDialog fragment = new GameDetailsDialog();

Bundle arguments = new Bundle();
arguments.putString(ARG_GAME_PATH, gamePath);
fragment.setArguments(arguments);

return fragment;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
GameFile gameFile = GameFileCacheService.addOrGet(getArguments().getString(ARG_GAME_PATH));

AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
ViewGroup contents = (ViewGroup) getActivity().getLayoutInflater()
.inflate(R.layout.dialog_game_details, null);

ImageView banner = contents.findViewById(R.id.banner);

TextView textTitle = contents.findViewById(R.id.text_game_title);
TextView textDescription = contents.findViewById(R.id.text_description);

TextView textCountry = contents.findViewById(R.id.text_country);
TextView textCompany = contents.findViewById(R.id.text_company);
TextView textGameId = contents.findViewById(R.id.text_game_id);
TextView textRevision = contents.findViewById(R.id.text_revision);

String country = getResources().getStringArray(R.array.countryNames)[gameFile.getCountry()];
String description = gameFile.getDescription();

textTitle.setText(gameFile.getTitle());
textDescription.setText(gameFile.getDescription());
if (description.isEmpty())
{
textDescription.setVisibility(View.GONE);
}
textCountry.setText(country);
textCompany.setText(gameFile.getCompany());
textGameId.setText(gameFile.getGameId());
textRevision.setText(Integer.toString(gameFile.getRevision()));

PicassoUtils.loadGameBanner(banner, gameFile);

builder.setView(contents);
return builder.create();
}
}
@@ -6,6 +6,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;

import android.widget.Toast;

@@ -17,17 +18,19 @@

import java.io.File;

public class GameSettingsDialog extends DialogFragment
public class GamePropertiesDialog extends DialogFragment
{
public static final String TAG = "GameSettingsDialog";
public static final String TAG = "GamePropertiesDialog";
public static final String ARG_PATH = "path";
public static final String ARG_GAMEID = "game_id";
public static final String ARG_PLATFORM = "platform";

public static GameSettingsDialog newInstance(String gameId, int platform)
public static GamePropertiesDialog newInstance(String path, String gameId, int platform)
{
GameSettingsDialog fragment = new GameSettingsDialog();
GamePropertiesDialog fragment = new GamePropertiesDialog();

Bundle arguments = new Bundle();
arguments.putString(ARG_PATH, path);
arguments.putString(ARG_GAMEID, gameId);
arguments.putInt(ARG_PLATFORM, platform);
fragment.setArguments(arguments);
@@ -41,33 +44,39 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());

String path = requireArguments().getString(ARG_PATH);
String gameId = requireArguments().getString(ARG_GAMEID);
int platform = requireArguments().getInt(ARG_PLATFORM);

builder.setTitle(requireContext().getString(R.string.preferences_game_settings) + ": " + gameId)
builder.setTitle(requireContext()
.getString(R.string.preferences_game_properties) + ": " + gameId)
.setItems(platform == Platform.GAMECUBE.toInt() ?
R.array.gameSettingsMenusGC :
R.array.gameSettingsMenusWii, (dialog, which) ->
{
switch (which)
{
case 0:
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId);
GameDetailsDialog.newInstance(path).show((requireActivity())
.getSupportFragmentManager(), "game_details");
break;
case 1:
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId);
SettingsActivity.launch(getContext(), MenuTag.CONFIG, gameId);
break;
case 2:
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId);
SettingsActivity.launch(getContext(), MenuTag.GRAPHICS, gameId);
break;
case 3:
SettingsActivity.launch(getContext(), MenuTag.GCPAD_TYPE, gameId);
break;
case 4:
// Clear option for GC, Wii controls for else
if (platform == Platform.GAMECUBE.toInt())
clearGameSettings(gameId);
else
SettingsActivity.launch(getActivity(), MenuTag.WIIMOTE, gameId);
break;
case 4:
case 5:
clearGameSettings(gameId);
break;
}
@@ -54,11 +54,4 @@ public String getCustomCoverPath()
{
return getPath().substring(0, getPath().lastIndexOf(".")) + ".cover.png";
}

public String getScreenshotPath()
{
String gameId = getGameId();
return "file://" + Environment.getExternalStorageDirectory().getPath() +
"/dolphin-emu/ScreenShots/" + gameId + "/" + gameId + "-1.png";
}
}
@@ -0,0 +1,36 @@
package org.dolphinemu.dolphinemu.utils;

import android.graphics.Bitmap;

import com.squareup.picasso.Picasso;
import com.squareup.picasso.Request;
import com.squareup.picasso.RequestHandler;

import org.dolphinemu.dolphinemu.model.GameFile;

public class GameBannerRequestHandler extends RequestHandler
{
private final GameFile mGameFile;

public GameBannerRequestHandler(GameFile gameFile)
{
mGameFile = gameFile;
}

@Override
public boolean canHandleRequest(Request data)
{
return true;
}

@Override
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);
}
}
@@ -2,6 +2,7 @@

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.widget.ImageView;

import com.squareup.picasso.Callback;
@@ -15,6 +16,22 @@
public class PicassoUtils
{
public static void loadGameBanner(ImageView imageView, GameFile gameFile)
{
Picasso picassoInstance = new Picasso.Builder(imageView.getContext())
.addRequestHandler(new GameBannerRequestHandler(gameFile))
.build();

picassoInstance
.load(Uri.parse("iso:/" + gameFile.getPath()))
.fit()
.noFade()
.noPlaceholder()
.config(Bitmap.Config.RGB_565)
.error(R.drawable.no_banner)
.into(imageView);
}

public static void loadGameCover(ImageView imageView, GameFile gameFile)
{
File cover = new File(gameFile.getCustomCoverPath());
if (cover.exists())
@@ -41,10 +58,8 @@ else if ((cover = new File(gameFile.getCoverPath())).exists())
.error(R.drawable.no_banner)
.into(imageView);
}
/**
* GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting
* the cover will be by the disk's region, second will be the US cover, and third EN.
*/
// GameTDB has a pretty close to complete collection for US/EN covers. First pass at getting
// the cover will be by the disk's region, second will be the US cover, and third EN.
else
{
Picasso.get()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 70ee523

Please sign in to comment.
You can’t perform that action at this time.