From 8b841aa7ba8b1bdcb6e631365c1bdc074867109c Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Wed, 21 Jun 2023 15:06:48 -0400 Subject: [PATCH] android: Convert memory sizes to resource --- .../yuzu_emu/activities/EmulationActivity.kt | 4 ++-- .../java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt | 17 +++++++++-------- src/android/app/src/main/res/values/strings.xml | 11 ++++++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt index 75d994c9c6..b1771b4247 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/activities/EmulationActivity.kt @@ -109,9 +109,9 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { Toast.makeText( this, getString( - R.string.device_memory_inadequate_description, + R.string.device_memory_inadequate, memoryUtil.getDeviceRAM(), - "8 GB" + "8 ${getString(R.string.memory_gigabyte)}" ), Toast.LENGTH_LONG ).show() diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt index 390767e473..18e5fa0b0d 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/MemoryUtil.kt @@ -5,22 +5,23 @@ package org.yuzu.yuzu_emu.utils import android.app.ActivityManager import android.content.Context +import org.yuzu.yuzu_emu.R import java.util.Locale -class MemoryUtil(context: Context) { +class MemoryUtil(val context: Context) { private val Long.floatForm: String get() = String.format(Locale.ROOT, "%.2f", this.toDouble()) private fun bytesToSizeUnit(size: Long): String { return when { - size < Kb -> size.floatForm + " byte" - size < Mb -> (size / Kb).floatForm + " KB" - size < Gb -> (size / Mb).floatForm + " MB" - size < Tb -> (size / Gb).floatForm + " GB" - size < Pb -> (size / Tb).floatForm + " TB" - size < Eb -> (size / Pb).floatForm + " Pb" - else -> (size / Eb).floatForm + " Eb" + size < Kb -> "${size.floatForm} ${context.getString(R.string.memory_byte)}" + size < Mb -> "${(size / Kb).floatForm} ${context.getString(R.string.memory_kilobyte)}" + size < Gb -> "${(size / Mb).floatForm} ${context.getString(R.string.memory_megabyte)}" + size < Tb -> "${(size / Gb).floatForm} ${context.getString(R.string.memory_gigabyte)}" + size < Pb -> "${(size / Tb).floatForm} ${context.getString(R.string.memory_terabyte)}" + size < Eb -> "${(size / Pb).floatForm} ${context.getString(R.string.memory_petabyte)}" + else -> "${(size / Eb).floatForm} ${context.getString(R.string.memory_exabyte)}" } } diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 7d37d2beee..85fc682f22 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -270,7 +270,7 @@ Fatal Error A fatal error occurred. Check the log for details.\nContinuing emulation may result in crashes and bugs. Turning off this setting will significantly reduce emulation performance! For the best experience, it is recommended that you leave this setting enabled. - Device RAM: %1$s\nRecommended: %2$s + Device RAM: %1$s\nRecommended: %2$s Japan @@ -301,6 +301,15 @@ Traditional Chinese (正體中文) Brazilian Portuguese (Português do Brasil) + + Byte + KB + MB + GB + TB + PB + EB + Vulkan None