diff options
Diffstat (limited to 'src/android/app/src/main/java/org')
9 files changed, 53 insertions, 28 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java index 75395bd4c..7a1ddd38e 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.java @@ -141,9 +141,9 @@ public final class NativeLibrary { * Gets the embedded icon within the given ROM. * * @param filename the file path to the ROM. - * @return an integer array containing the color data for the icon. + * @return a byte array containing the JPEG data for the icon. */ - public static native int[] GetIcon(String filename); + public static native byte[] GetIcon(String filename); /** * Gets the embedded title of the given ISO/ROM. @@ -205,6 +205,11 @@ public final class NativeLibrary { public static native void StopEmulation(); /** + * Resets the in-memory ROM metadata cache. + */ + public static native void ResetRomMetadata(); + + /** * Returns true if emulation is running (or is paused). */ public static native boolean IsRunning(); diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.java index cd9f823d4..ed1a000c7 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.java @@ -86,11 +86,7 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl mCursor.getString(GameDatabase.GAME_COLUMN_PATH)); holder.textGameTitle.setText(mCursor.getString(GameDatabase.GAME_COLUMN_TITLE).replaceAll("[\\t\\n\\r]+", " ")); - holder.textCompany.setText(mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY)); - - String filepath = mCursor.getString(GameDatabase.GAME_COLUMN_PATH); - String filename = FileUtil.getFilename(YuzuApplication.getAppContext(), filepath); - holder.textFileName.setText(filename); + holder.textGameCaption.setText(mCursor.getString(GameDatabase.GAME_COLUMN_CAPTION)); // TODO These shouldn't be necessary once the move to a DB-based model is complete. holder.gameId = mCursor.getString(GameDatabase.GAME_COLUMN_GAME_ID); @@ -98,7 +94,7 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl holder.title = mCursor.getString(GameDatabase.GAME_COLUMN_TITLE); holder.description = mCursor.getString(GameDatabase.GAME_COLUMN_DESCRIPTION); holder.regions = mCursor.getString(GameDatabase.GAME_COLUMN_REGIONS); - holder.company = mCursor.getString(GameDatabase.GAME_COLUMN_COMPANY); + holder.company = mCursor.getString(GameDatabase.GAME_COLUMN_CAPTION); final int backgroundColorId = isValidGame(holder.path) ? R.color.view_background : R.color.view_disabled; View itemView = holder.getItemView(); diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.java index bc1b19bd1..681117268 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/Game.java @@ -47,7 +47,7 @@ public final class Game { cursor.getString(GameDatabase.GAME_COLUMN_REGIONS), cursor.getString(GameDatabase.GAME_COLUMN_PATH), cursor.getString(GameDatabase.GAME_COLUMN_GAME_ID), - cursor.getString(GameDatabase.GAME_COLUMN_COMPANY)); + cursor.getString(GameDatabase.GAME_COLUMN_CAPTION)); } public String getTitle() { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GameDatabase.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GameDatabase.java index 771e35c69..a10ac6ff2 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GameDatabase.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GameDatabase.java @@ -29,7 +29,7 @@ public final class GameDatabase extends SQLiteOpenHelper { public static final int GAME_COLUMN_DESCRIPTION = 3; public static final int GAME_COLUMN_REGIONS = 4; public static final int GAME_COLUMN_GAME_ID = 5; - public static final int GAME_COLUMN_COMPANY = 6; + public static final int GAME_COLUMN_CAPTION = 6; public static final int FOLDER_COLUMN_PATH = 1; public static final String KEY_DB_ID = "_id"; public static final String KEY_GAME_PATH = "path"; @@ -176,6 +176,9 @@ public final class GameDatabase extends SQLiteOpenHelper { return; } + // Ensure keys are loaded so that ROM metadata can be decrypted. + NativeLibrary.ReloadKeys(); + MinimalDocumentFile[] children = FileUtil.listFiles(context, parent); for (MinimalDocumentFile file : children) { if (file.isDirectory()) { diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.java index 7fdd692c2..552232bd3 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.java @@ -161,6 +161,7 @@ public final class MainActivity extends AppCompatActivity implements MainView { if (FileUtil.copyUriToInternalStorage(this, result.getData(), dstPath, "prod.keys")) { if (NativeLibrary.ReloadKeys()) { Toast.makeText(this, R.string.install_keys_success, Toast.LENGTH_SHORT).show(); + refreshFragment(); } else { Toast.makeText(this, R.string.install_keys_failure, Toast.LENGTH_SHORT).show(); launchFileListActivity(MainPresenter.REQUEST_INSTALL_KEYS); @@ -184,6 +185,7 @@ public final class MainActivity extends AppCompatActivity implements MainView { private void refreshFragment() { if (mPlatformGamesFragment != null) { + NativeLibrary.ResetRomMetadata(); mPlatformGamesFragment.refresh(); } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java index 6c327b1b8..2d74f43ca 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/platform/PlatformGamesFragment.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.widget.TextView; import androidx.core.content.ContextCompat; @@ -13,6 +14,7 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import org.yuzu.yuzu_emu.NativeLibrary; import org.yuzu.yuzu_emu.YuzuApplication; import org.yuzu.yuzu_emu.R; import org.yuzu.yuzu_emu.adapters.GameAdapter; @@ -43,19 +45,34 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam @Override public void onViewCreated(View view, Bundle savedInstanceState) { - int columns = getResources().getInteger(R.integer.game_grid_columns); - RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), columns); mAdapter = new GameAdapter(); - mRecyclerView.setLayoutManager(layoutManager); - mRecyclerView.setAdapter(mAdapter); - mRecyclerView.addItemDecoration(new GameAdapter.SpacesItemDecoration(ContextCompat.getDrawable(getActivity(), R.drawable.gamelist_divider), 1)); + // Organize our grid layout based on the current view. + if (isAdded()) { + view.getViewTreeObserver() + .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + if (view.getMeasuredWidth() == 0) { + return; + } + + int columns = view.getMeasuredWidth() / + requireContext().getResources().getDimensionPixelSize(R.dimen.card_width); + if (columns == 0) { + columns = 1; + } + view.getViewTreeObserver().removeOnGlobalLayoutListener(this); + GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), columns); + mRecyclerView.setLayoutManager(layoutManager); + mRecyclerView.setAdapter(mAdapter); + } + }); + } // Add swipe down to refresh gesture - final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.refresh_grid_games); + final SwipeRefreshLayout pullToRefresh = view.findViewById(R.id.swipe_refresh); pullToRefresh.setOnRefreshListener(() -> { - GameDatabase databaseHelper = YuzuApplication.databaseHelper; - databaseHelper.scanLibrary(databaseHelper.getWritableDatabase()); refresh(); pullToRefresh.setRefreshing(false); }); @@ -63,6 +80,8 @@ public final class PlatformGamesFragment extends Fragment implements PlatformGam @Override public void refresh() { + GameDatabase databaseHelper = YuzuApplication.databaseHelper; + databaseHelper.scanLibrary(databaseHelper.getWritableDatabase()); mPresenter.refresh(); updateTextView(); } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconRequestHandler.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconRequestHandler.java index b75dc9a62..fd43575de 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconRequestHandler.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconRequestHandler.java @@ -1,6 +1,7 @@ package org.yuzu.yuzu_emu.utils; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import com.squareup.picasso.Picasso; import com.squareup.picasso.Request; @@ -13,15 +14,16 @@ import java.nio.IntBuffer; public class GameIconRequestHandler extends RequestHandler { @Override public boolean canHandleRequest(Request data) { - return "iso".equals(data.uri.getScheme()); + return "content".equals(data.uri.getScheme()); } @Override public Result load(Request request, int networkPolicy) { - String url = request.uri.getHost() + request.uri.getPath(); - int[] vector = NativeLibrary.GetIcon(url); - Bitmap bitmap = Bitmap.createBitmap(48, 48, Bitmap.Config.RGB_565); - bitmap.copyPixelsFromBuffer(IntBuffer.wrap(vector)); + String gamePath = request.uri.toString(); + byte[] data = NativeLibrary.GetIcon(gamePath); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inMutable = true; + Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); return new Result(bitmap, Picasso.LoadedFrom.DISK); } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java index 5033691b3..504dc5b6d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/PicassoUtils.java @@ -31,7 +31,7 @@ public class PicassoUtils { public static void loadGameIcon(ImageView imageView, String gamePath) { Picasso .get() - .load(Uri.parse("iso:/" + gamePath)) + .load(Uri.parse(gamePath)) .fit() .centerInside() .config(Bitmap.Config.RGB_565) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/viewholders/GameViewHolder.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/viewholders/GameViewHolder.java index 2dc0f34f3..41b8c6a27 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/viewholders/GameViewHolder.java +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/viewholders/GameViewHolder.java @@ -16,8 +16,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder { private View itemView; public ImageView imageIcon; public TextView textGameTitle; - public TextView textCompany; - public TextView textFileName; + public TextView textGameCaption; public String gameId; @@ -36,8 +35,7 @@ public class GameViewHolder extends RecyclerView.ViewHolder { imageIcon = itemView.findViewById(R.id.image_game_screen); textGameTitle = itemView.findViewById(R.id.text_game_title); - textCompany = itemView.findViewById(R.id.text_company); - textFileName = itemView.findViewById(R.id.text_filename); + textGameCaption = itemView.findViewById(R.id.text_game_caption); } public View getItemView() { |