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

Android: Bring back and update the game details dialog
This commit is contained in:
JosJuice 2019-11-25 11:31:37 +01:00 committed by GitHub
commit 70ee5234ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 310 additions and 31 deletions

View File

@ -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.

View File

@ -13,7 +13,7 @@ import android.view.ViewGroup;
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 final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
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 final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl
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;
}

View File

@ -13,7 +13,7 @@ import android.view.ViewGroup;
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 final class GameRowPresenter extends Presenter
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 final class GameRowPresenter extends Presenter
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;
});

View File

@ -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();
}
}

View File

@ -6,6 +6,7 @@ import android.os.Bundle;
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 org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
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,10 +44,12 @@ public class GameSettingsDialog extends DialogFragment
{
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) ->
@ -52,22 +57,26 @@ public class GameSettingsDialog extends DialogFragment
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;
}

View File

@ -54,11 +54,4 @@ public class GameFile
{
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";
}
}

View File

@ -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);
}
}

View File

@ -2,6 +2,7 @@ package org.dolphinemu.dolphinemu.utils;
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 @@ import java.io.File;
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 @@ public class PicassoUtils
.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.

Before

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,146 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:paddingBottom="24dp"
android:transitionName="card_game">
<TextView
android:id="@+id/text_game_title"
style="@android:style/TextAppearance.Material.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:ellipsize="end"
tools:text="Rhythm Heaven Fever"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_description"
style="@android:style/TextAppearance.Material.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
tools:text="Zany rhythm action!"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_game_title" />
<ImageView
android:id="@+id/banner"
android:layout_width="144dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
tools:src="@drawable/no_banner"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_description" />
<View
android:id="@+id/divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="#1F000000"
android:layout_marginTop="32dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/banner" />
<TextView
android:id="@+id/label_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="start"
android:text="@string/game_details_country"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider" />
<TextView
android:id="@+id/label_company"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="start"
android:text="@string/game_details_company"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_country" />
<TextView
android:id="@+id/label_game_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="start"
android:text="@string/game_details_game_id"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_company" />
<TextView
android:id="@+id/label_revision"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="start"
android:text="@string/game_details_revision"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/label_game_id"
app:layout_constraintBottom_toBottomOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/label_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="label_country,label_company,label_game_id,label_revision" />
<TextView
android:id="@+id/text_country"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:gravity="end"
tools:text="United States"
app:layout_constraintStart_toEndOf="@id/label_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/label_country" />
<TextView
android:id="@+id/text_company"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:gravity="end"
tools:text="Nintendo"
app:layout_constraintStart_toEndOf="@id/label_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/label_company" />
<TextView
android:id="@+id/text_game_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:gravity="end"
tools:text="SOME01"
app:layout_constraintStart_toEndOf="@id/label_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/label_game_id" />
<TextView
android:id="@+id/text_revision"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:gravity="end"
tools:text="0"
app:layout_constraintStart_toEndOf="@id/label_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBaseline_toBaselineOf="@id/label_revision" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -336,12 +336,14 @@
</string-array>
<string-array name="gameSettingsMenusGC">
<item>Details</item>
<item>Core Settings</item>
<item>GFX Settings</item>
<item>GameCube Controller Settings</item>
<item>Clear Game Settings</item>
</string-array>
<string-array name="gameSettingsMenusWii">
<item>Details</item>
<item>Core Settings</item>
<item>GFX Settings</item>
<item>GameCube Controller Settings</item>

View File

@ -280,10 +280,14 @@
<!-- Preferences Screen -->
<string name="preferences_save_exit">Save and Exit</string>
<string name="preferences_settings">Settings</string>
<string name="preferences_game_settings">Game Settings</string>
<string name="preferences_game_properties">Game Properties</string>
<string name="preferences_extensions">Extension Bindings</string>
<string name="game_ini_junk_title">Junk Data Found</string>
<string name="game_ini_junk_question">The settings file for this game contains junk data created by an old version of Dolphin. Would you like to fix this by deleting the settings file for this game? All game-specific settings and cheats that you have added will be removed. This cannot be undone.</string>
<string name="game_details_country">Country</string>
<string name="game_details_company">Company</string>
<string name="game_details_game_id">Game ID</string>
<string name="game_details_revision">Revision</string>
<!-- Emulation Menu -->
<string name="emulation_screenshot">Take Screenshot</string>