Android: Display covers in game list

This commit is contained in:
Connor McLaughlin 2020-11-28 00:11:20 +10:00
parent 3137eb41c4
commit bb1e3a0692
4 changed files with 48 additions and 7 deletions

View file

@ -930,7 +930,7 @@ DEFINE_JNI_ARGS_METHOD(jarray, AndroidHostInterface_getGameListEntries, jobject
jmethodID entry_constructor = jmethodID entry_constructor =
env->GetMethodID(entry_class, "<init>", env->GetMethodID(entry_class, "<init>",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/" "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLjava/lang/"
"String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); "String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
Assert(entry_constructor != nullptr); Assert(entry_constructor != nullptr);
AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj); AndroidHostInterface* hi = AndroidHelpers::GetNativeClass(env, obj);
@ -943,6 +943,7 @@ DEFINE_JNI_ARGS_METHOD(jarray, AndroidHostInterface_getGameListEntries, jobject
const Timestamp modified_ts( const Timestamp modified_ts(
Timestamp::FromUnixTimestamp(static_cast<Timestamp::UnixTimestampValue>(entry.last_modified_time))); Timestamp::FromUnixTimestamp(static_cast<Timestamp::UnixTimestampValue>(entry.last_modified_time)));
const std::string file_title_str(System::GetTitleForPath(entry.path.c_str())); const std::string file_title_str(System::GetTitleForPath(entry.path.c_str()));
const std::string cover_path_str(hi->GetGameList()->GetCoverImagePathForEntry(&entry));
jstring path = env->NewStringUTF(entry.path.c_str()); jstring path = env->NewStringUTF(entry.path.c_str());
jstring code = env->NewStringUTF(entry.code.c_str()); jstring code = env->NewStringUTF(entry.code.c_str());
@ -952,11 +953,12 @@ DEFINE_JNI_ARGS_METHOD(jarray, AndroidHostInterface_getGameListEntries, jobject
jstring type = env->NewStringUTF(GameList::EntryTypeToString(entry.type)); jstring type = env->NewStringUTF(GameList::EntryTypeToString(entry.type));
jstring compatibility_rating = jstring compatibility_rating =
env->NewStringUTF(GameList::EntryCompatibilityRatingToString(entry.compatibility_rating)); env->NewStringUTF(GameList::EntryCompatibilityRatingToString(entry.compatibility_rating));
jstring cover_path = (cover_path_str.empty()) ? nullptr : env->NewStringUTF(cover_path_str.c_str());
jstring modified_time = env->NewStringUTF(modified_ts.ToString("%Y/%m/%d, %H:%M:%S")); jstring modified_time = env->NewStringUTF(modified_ts.ToString("%Y/%m/%d, %H:%M:%S"));
jlong size = entry.total_size; jlong size = entry.total_size;
jobject entry_jobject = env->NewObject(entry_class, entry_constructor, path, code, title, file_title, size, jobject entry_jobject = env->NewObject(entry_class, entry_constructor, path, code, title, file_title, size,
modified_time, region, type, compatibility_rating); modified_time, region, type, compatibility_rating, cover_path);
env->SetObjectArrayElement(entry_array, counter++, entry_jobject); env->SetObjectArrayElement(entry_array, counter++, entry_jobject);
} }

View file

@ -1,5 +1,7 @@
package com.github.stenzek.duckstation; package com.github.stenzek.duckstation;
import android.net.Uri;
import android.os.AsyncTask;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -31,16 +33,17 @@ public class GameListEntry {
private DiscRegion mRegion; private DiscRegion mRegion;
private EntryType mType; private EntryType mType;
private CompatibilityRating mCompatibilityRating; private CompatibilityRating mCompatibilityRating;
private String mCoverPath;
public GameListEntry(String path, String code, String title, String fileTitle, long size, String modifiedTime, String region, public GameListEntry(String path, String code, String title, String fileTitle, long size, String modifiedTime, String region,
String type, String compatibilityRating) { String type, String compatibilityRating, String coverPath) {
mPath = path; mPath = path;
mCode = code; mCode = code;
mTitle = title; mTitle = title;
mFileTitle = fileTitle; mFileTitle = fileTitle;
mSize = size; mSize = size;
mModifiedTime = modifiedTime; mModifiedTime = modifiedTime;
mCoverPath = coverPath;
try { try {
mRegion = DiscRegion.valueOf(region); mRegion = DiscRegion.valueOf(region);
@ -144,8 +147,12 @@ public class GameListEntry {
break; break;
} }
((ImageView) view.findViewById(R.id.game_list_view_entry_type_icon)) ImageView icon = ((ImageView) view.findViewById(R.id.game_list_view_entry_type_icon));
.setImageDrawable(ContextCompat.getDrawable(view.getContext(), typeDrawableId)); icon.setImageDrawable(ContextCompat.getDrawable(view.getContext(), typeDrawableId));
if (mCoverPath != null) {
new ImageLoadTask(icon).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, mCoverPath);
}
int compatibilityDrawableId; int compatibilityDrawableId;
switch (mCompatibilityRating) switch (mCompatibilityRating)

View file

@ -0,0 +1,32 @@
package com.github.stenzek.duckstation;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;
import java.lang.ref.WeakReference;
public class ImageLoadTask extends AsyncTask<String, Void, Bitmap> {
private WeakReference<ImageView> mView;
public ImageLoadTask(ImageView view) {
mView = new WeakReference<>(view);
}
@Override
protected Bitmap doInBackground(String... strings) {
try {
return BitmapFactory.decodeFile(strings[0]);
} catch (Exception e) {
return null;
}
}
@Override
protected void onPostExecute(Bitmap bitmap) {
ImageView iv = mView.get();
if (iv != null)
iv.setImageBitmap(bitmap);
}
}

View file

@ -63,7 +63,7 @@
android:id="@+id/game_list_view_entry_region_icon" android:id="@+id/game_list_view_entry_region_icon"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="28dp" android:layout_height="28dp"
android:layout_marginTop="8dp" android:layout_marginTop="4dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" android:focusableInTouchMode="false"