Skip to content

Commit

Permalink
Merge pull request #11296 from t895/tv-game-details-fix
Browse files Browse the repository at this point in the history
Android: Fix GameDetailsDialog on leanback
  • Loading branch information
JosJuice committed Nov 23, 2022
2 parents 0ef6d30 + 6e5f546 commit ddf63ba
Show file tree
Hide file tree
Showing 2 changed files with 347 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.databinding.DialogGameDetailsBinding;
import org.dolphinemu.dolphinemu.databinding.DialogGameDetailsTvBinding;
import org.dolphinemu.dolphinemu.model.GameFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheManager;
import org.dolphinemu.dolphinemu.utils.GlideUtils;
Expand All @@ -39,66 +41,132 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
{
GameFile gameFile = GameFileCacheManager.addOrGet(getArguments().getString(ARG_GAME_PATH));

DialogGameDetailsBinding binding = DialogGameDetailsBinding.inflate(getLayoutInflater());

String country = getResources().getStringArray(R.array.countryNames)[gameFile.getCountry()];
String description = gameFile.getDescription();
String fileSize = NativeLibrary.FormatSize(gameFile.getFileSize(), 2);

binding.textGameTitle.setText(gameFile.getTitle());
binding.textDescription.setText(gameFile.getDescription());
if (description.isEmpty())
// TODO: Remove dialog_game_details_tv if we switch to an AppCompatActivity for leanback
DialogGameDetailsBinding binding;
DialogGameDetailsTvBinding tvBinding;
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext());
if (requireActivity() instanceof AppCompatActivity)
{
binding.textDescription.setVisibility(View.GONE);
}
binding = DialogGameDetailsBinding.inflate(getLayoutInflater());

binding.textCountry.setText(country);
binding.textCompany.setText(gameFile.getCompany());
binding.textGameId.setText(gameFile.getGameId());
binding.textRevision.setText(String.valueOf(gameFile.getRevision()));
binding.textGameTitle.setText(gameFile.getTitle());
binding.textDescription.setText(gameFile.getDescription());
if (description.isEmpty())
{
binding.textDescription.setVisibility(View.GONE);
}

if (!gameFile.shouldShowFileFormatDetails())
{
binding.labelFileFormat.setText(R.string.game_details_file_size);
binding.textFileFormat.setText(fileSize);
binding.textCountry.setText(country);
binding.textCompany.setText(gameFile.getCompany());
binding.textGameId.setText(gameFile.getGameId());
binding.textRevision.setText(String.valueOf(gameFile.getRevision()));

if (!gameFile.shouldShowFileFormatDetails())
{
binding.labelFileFormat.setText(R.string.game_details_file_size);
binding.textFileFormat.setText(fileSize);

binding.labelCompression.setVisibility(View.GONE);
binding.textCompression.setVisibility(View.GONE);
binding.labelBlockSize.setVisibility(View.GONE);
binding.textBlockSize.setVisibility(View.GONE);
binding.labelCompression.setVisibility(View.GONE);
binding.textCompression.setVisibility(View.GONE);
binding.labelBlockSize.setVisibility(View.GONE);
binding.textBlockSize.setVisibility(View.GONE);
}
else
{
long blockSize = gameFile.getBlockSize();
String compression = gameFile.getCompressionMethod();

binding.textFileFormat.setText(
getResources().getString(R.string.game_details_size_and_format,
gameFile.getFileFormatName(), fileSize));

if (compression.isEmpty())
{
binding.textCompression.setText(R.string.game_details_no_compression);
}
else
{
binding.textCompression.setText(gameFile.getCompressionMethod());
}

if (blockSize > 0)
{
binding.textBlockSize.setText(NativeLibrary.FormatSize(blockSize, 0));
}
else
{
binding.labelBlockSize.setVisibility(View.GONE);
binding.textBlockSize.setVisibility(View.GONE);
}
}

GlideUtils.loadGameBanner(binding.banner, gameFile);

builder.setView(binding.getRoot());
}
else
{
long blockSize = gameFile.getBlockSize();
String compression = gameFile.getCompressionMethod();

binding.textFileFormat.setText(getResources().getString(R.string.game_details_size_and_format,
gameFile.getFileFormatName(), fileSize));
tvBinding = DialogGameDetailsTvBinding.inflate(getLayoutInflater());

if (compression.isEmpty())
{
binding.textCompression.setText(R.string.game_details_no_compression);
}
else
tvBinding.textGameTitle.setText(gameFile.getTitle());
tvBinding.textDescription.setText(gameFile.getDescription());
if (description.isEmpty())
{
binding.textCompression.setText(gameFile.getCompressionMethod());
tvBinding.textDescription.setVisibility(View.GONE);
}

if (blockSize > 0)
tvBinding.textCountry.setText(country);
tvBinding.textCompany.setText(gameFile.getCompany());
tvBinding.textGameId.setText(gameFile.getGameId());
tvBinding.textRevision.setText(String.valueOf(gameFile.getRevision()));

if (!gameFile.shouldShowFileFormatDetails())
{
binding.textBlockSize.setText(NativeLibrary.FormatSize(blockSize, 0));
tvBinding.labelFileFormat.setText(R.string.game_details_file_size);
tvBinding.textFileFormat.setText(fileSize);

tvBinding.labelCompression.setVisibility(View.GONE);
tvBinding.textCompression.setVisibility(View.GONE);
tvBinding.labelBlockSize.setVisibility(View.GONE);
tvBinding.textBlockSize.setVisibility(View.GONE);
}
else
{
binding.labelBlockSize.setVisibility(View.GONE);
binding.textBlockSize.setVisibility(View.GONE);
long blockSize = gameFile.getBlockSize();
String compression = gameFile.getCompressionMethod();

tvBinding.textFileFormat.setText(
getResources().getString(R.string.game_details_size_and_format,
gameFile.getFileFormatName(), fileSize));

if (compression.isEmpty())
{
tvBinding.textCompression.setText(R.string.game_details_no_compression);
}
else
{
tvBinding.textCompression.setText(gameFile.getCompressionMethod());
}

if (blockSize > 0)
{
tvBinding.textBlockSize.setText(NativeLibrary.FormatSize(blockSize, 0));
}
else
{
tvBinding.labelBlockSize.setVisibility(View.GONE);
tvBinding.textBlockSize.setVisibility(View.GONE);
}
}
}

GlideUtils.loadGameBanner(binding.banner, gameFile);
GlideUtils.loadGameBanner(tvBinding.banner, gameFile);

return new MaterialAlertDialogBuilder(requireActivity())
.setView(binding.getRoot())
.create();
builder.setView(tvBinding.getRoot());
}
return builder.create();
}
}
Loading

0 comments on commit ddf63ba

Please sign in to comment.