From 8fb4e62c28ae58b4f94c64f091d389499d3104cc Mon Sep 17 00:00:00 2001 From: KikiManjaro Date: Sun, 7 Aug 2022 03:52:14 +0200 Subject: [PATCH] Add version information about rom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review: Co-authored-by: Niccolò Betto --- app/src/main/cpp/loader_jni.cpp | 2 ++ app/src/main/cpp/skyline/vfs/nacp.cpp | 5 +++++ app/src/main/cpp/skyline/vfs/nacp.h | 2 ++ app/src/main/java/emu/skyline/AppDialog.kt | 1 + .../java/emu/skyline/adapter/AppViewItem.kt | 9 ++++++++ .../main/java/emu/skyline/data/DataItem.kt | 5 +++++ .../main/java/emu/skyline/loader/RomFile.kt | 17 +++++++++++---- app/src/main/res/layout/app_dialog.xml | 14 ++++++++++++- app/src/main/res/layout/app_item_grid.xml | 14 ++++++++++++- .../main/res/layout/app_item_grid_compact.xml | 21 ++++++++++++++++++- app/src/main/res/layout/app_item_linear.xml | 16 +++++++++++++- 11 files changed, 98 insertions(+), 8 deletions(-) diff --git a/app/src/main/cpp/loader_jni.cpp b/app/src/main/cpp/loader_jni.cpp index ba2044c1..d05e02a3 100644 --- a/app/src/main/cpp/loader_jni.cpp +++ b/app/src/main/cpp/loader_jni.cpp @@ -53,6 +53,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn jfieldID applicationNameField{env->GetFieldID(clazz, "applicationName", "Ljava/lang/String;")}; jfieldID applicationAuthorField{env->GetFieldID(clazz, "applicationAuthor", "Ljava/lang/String;")}; jfieldID rawIconField{env->GetFieldID(clazz, "rawIcon", "[B")}; + jfieldID applicationVersionField{env->GetFieldID(clazz, "applicationVersion", "Ljava/lang/String;")}; if (loader->nacp) { auto language{skyline::language::GetApplicationLanguage(static_cast(systemLanguage))}; @@ -61,6 +62,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str())); env->SetObjectField(thiz, applicationAuthorField, env->NewStringUTF(loader->nacp->GetApplicationPublisher(language).c_str())); + env->SetObjectField(thiz, applicationVersionField, env->NewStringUTF(loader->nacp->GetApplicationVersion().c_str())); auto icon{loader->GetIcon(language)}; jbyteArray iconByteArray{env->NewByteArray(static_cast(icon.size()))}; diff --git a/app/src/main/cpp/skyline/vfs/nacp.cpp b/app/src/main/cpp/skyline/vfs/nacp.cpp index b498d0ee..e430b972 100644 --- a/app/src/main/cpp/skyline/vfs/nacp.cpp +++ b/app/src/main/cpp/skyline/vfs/nacp.cpp @@ -33,4 +33,9 @@ namespace skyline::vfs { auto applicationPublisher{span(nacpContents.titleEntries.at(static_cast(language)).applicationPublisher)}; return std::string(applicationPublisher.as_string(true)); } + + std::string NACP::GetApplicationVersion() { + auto applicationPublisher{span(nacpContents.displayVersion)}; + return std::string(applicationPublisher.as_string(true)); + } } diff --git a/app/src/main/cpp/skyline/vfs/nacp.h b/app/src/main/cpp/skyline/vfs/nacp.h index 2fa78e56..3d2d2ef4 100644 --- a/app/src/main/cpp/skyline/vfs/nacp.h +++ b/app/src/main/cpp/skyline/vfs/nacp.h @@ -48,5 +48,7 @@ namespace skyline::vfs { std::string GetApplicationName(language::ApplicationLanguage language); std::string GetApplicationPublisher(language::ApplicationLanguage language); + + std::string GetApplicationVersion(); }; } diff --git a/app/src/main/java/emu/skyline/AppDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt index c054f057..d6086b94 100644 --- a/app/src/main/java/emu/skyline/AppDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -77,6 +77,7 @@ class AppDialog : BottomSheetDialogFragment() { binding.gameIcon.setImageBitmap(item.icon ?: missingIcon) binding.gameTitle.text = item.title binding.gameSubtitle.text = item.subTitle ?: item.loaderResultString(requireContext()) + binding.gameVersion.text = item.version ?: item.loaderResultString(requireContext()) binding.gamePlay.isEnabled = item.loaderResult == LoaderResult.Success binding.gamePlay.setOnClickListener { diff --git a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt index df93385c..8ce9ac24 100644 --- a/app/src/main/java/emu/skyline/adapter/AppViewItem.kt +++ b/app/src/main/java/emu/skyline/adapter/AppViewItem.kt @@ -46,6 +46,8 @@ interface LayoutBinding : ViewBinding { val textSubtitle : TextView + val textVersion : TextView + val icon : ImageView } @@ -56,6 +58,8 @@ class ListBinding(parent : ViewGroup) : LayoutBinding { override val textSubtitle = binding.textSubtitle + override val textVersion = binding.textVersion + override val icon = binding.icon } @@ -66,6 +70,8 @@ class GridBinding(parent : ViewGroup) : LayoutBinding { override val textSubtitle = binding.textSubtitle + override val textVersion = binding.textVersion + override val icon = binding.icon } @@ -76,6 +82,8 @@ class GridCompatBinding(parent : ViewGroup) : LayoutBinding val nameIndex : Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME) cursor.moveToFirst() cursor.getString(nameIndex) - }!!.dropLast(format.name.length + 1), null, null, format, uri, loaderResult) + }!!.dropLast(format.name.length + 1), null, null, null, format, uri, loaderResult) private fun writeObject(output : ObjectOutputStream) { output.writeUTF(name) @@ -77,6 +77,8 @@ data class AppEntry(var name : String, var author : String?, var icon : Bitmap?, output.writeBoolean(author != null) if (author != null) output.writeUTF(author) + if (version != null) + output.writeUTF(version) output.writeInt(loaderResult.value) output.writeBoolean(icon != null) icon?.let { @@ -119,6 +121,11 @@ internal class RomFile(context : Context, format : RomFormat, uri : Uri, systemL */ private var rawIcon : ByteArray? = null + /** + * @note This field is filled in by native code + */ + private var applicationVersion : String? = null + val appEntry : AppEntry var result = LoaderResult.Success @@ -133,8 +140,10 @@ internal class RomFile(context : Context, format : RomFormat, uri : Uri, systemL appEntry = applicationName?.let { name -> applicationAuthor?.let { author -> - rawIcon?.let { icon -> - AppEntry(name, author, BitmapFactory.decodeByteArray(icon, 0, icon.size), format, uri, result) + applicationVersion?.let { version -> + rawIcon?.let { icon -> + AppEntry(name, author, BitmapFactory.decodeByteArray(icon, 0, icon.size), version, format, uri, result) + } } } } ?: AppEntry(context, format, uri, result) diff --git a/app/src/main/res/layout/app_dialog.xml b/app/src/main/res/layout/app_dialog.xml index b008535d..69dcedda 100644 --- a/app/src/main/res/layout/app_dialog.xml +++ b/app/src/main/res/layout/app_dialog.xml @@ -45,11 +45,23 @@ app:layout_constraintTop_toBottomOf="@id/game_title" tools:text="Nintendo" /> + + diff --git a/app/src/main/res/layout/app_item_grid.xml b/app/src/main/res/layout/app_item_grid.xml index 6b60952b..553f60b0 100644 --- a/app/src/main/res/layout/app_item_grid.xml +++ b/app/src/main/res/layout/app_item_grid.xml @@ -45,10 +45,22 @@ android:layout_height="wrap_content" android:layout_marginStart="10dp" android:layout_marginEnd="10dp" - android:layout_marginBottom="10dp" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:textSize="12sp" tools:text="Subtitle" /> + + diff --git a/app/src/main/res/layout/app_item_grid_compact.xml b/app/src/main/res/layout/app_item_grid_compact.xml index 193bfea7..fe5e4180 100644 --- a/app/src/main/res/layout/app_item_grid_compact.xml +++ b/app/src/main/res/layout/app_item_grid_compact.xml @@ -49,6 +49,25 @@ android:id="@+id/text_subtitle" android:layout_width="0dp" android:layout_height="wrap_content" + android:alpha="242.25" + android:ellipsize="marquee" + android:fadingEdge="horizontal" + android:marqueeRepeatLimit="marquee_forever" + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:singleLine="true" + android:textAlignment="viewStart" + android:textAppearance="?android:attr/textAppearanceListItemSecondary" + android:textColor="@android:color/white" + app:layout_constraintBottom_toTopOf="@id/text_version" + app:layout_constraintEnd_toEndOf="@id/icon" + app:layout_constraintStart_toStartOf="@id/icon" + tools:text="Subtitle" /> + + + tools:text="Version" /> diff --git a/app/src/main/res/layout/app_item_linear.xml b/app/src/main/res/layout/app_item_linear.xml index 7fbf68a7..5b007448 100644 --- a/app/src/main/res/layout/app_item_linear.xml +++ b/app/src/main/res/layout/app_item_linear.xml @@ -44,10 +44,24 @@ android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textColor="@android:color/tertiary_text_light" app:layout_constrainedWidth="true" - app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0" app:layout_constraintStart_toEndOf="@id/icon" app:layout_constraintTop_toBottomOf="@+id/text_title" tools:text="SubTitle" /> + +