[android] Add play time editing and fix some issues
Some checks failed
eden-license / license-header (pull_request) Failing after 27s
Some checks failed
eden-license / license-header (pull_request) Failing after 27s
This commit is contained in:
parent
8e38ff23f0
commit
4c7c2957ac
7 changed files with 171 additions and 11 deletions
|
@ -215,6 +215,7 @@ object NativeLibrary {
|
|||
external fun playTimeManagerGetPlayTime(programId: String): Long
|
||||
external fun playTimeManagerGetCurrentTitleId(): Long
|
||||
external fun playTimeManagerResetProgramPlayTime(programId: String)
|
||||
external fun playTimeManagerSetPlayTime(programId: String, playTimeSeconds: Long)
|
||||
|
||||
var coreErrorAlertResult = false
|
||||
val coreErrorAlertLock = Object()
|
||||
|
|
|
@ -145,11 +145,95 @@ class GamePropertiesFragment : Fragment() {
|
|||
else -> "${seconds}s"
|
||||
}
|
||||
|
||||
append("Playtime: ")
|
||||
append(getString(R.string.playtime))
|
||||
append(readablePlayTime)
|
||||
}
|
||||
|
||||
binding.playtime.setOnClickListener {
|
||||
showEditPlaytimeDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showEditPlaytimeDialog() {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_playtime, null)
|
||||
val hoursLayout =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputLayout>(R.id.layout_hours)
|
||||
val minutesLayout =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputLayout>(R.id.layout_minutes)
|
||||
val secondsLayout =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputLayout>(R.id.layout_seconds)
|
||||
val hoursInput =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.input_hours)
|
||||
val minutesInput =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.input_minutes)
|
||||
val secondsInput =
|
||||
dialogView.findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.input_seconds)
|
||||
|
||||
val playTimeSeconds = NativeLibrary.playTimeManagerGetPlayTime(args.game.programId)
|
||||
val hours = playTimeSeconds / 3600
|
||||
val minutes = (playTimeSeconds % 3600) / 60
|
||||
val seconds = playTimeSeconds % 60
|
||||
|
||||
hoursInput.setText(hours.toString())
|
||||
minutesInput.setText(minutes.toString())
|
||||
secondsInput.setText(seconds.toString())
|
||||
|
||||
val dialog = com.google.android.material.dialog.MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.edit_playtime)
|
||||
.setView(dialogView)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create()
|
||||
|
||||
dialog.setOnShowListener {
|
||||
val positiveButton = dialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE)
|
||||
positiveButton.setOnClickListener {
|
||||
hoursLayout.error = null
|
||||
minutesLayout.error = null
|
||||
secondsLayout.error = null
|
||||
|
||||
val hoursText = hoursInput.text.toString()
|
||||
val minutesText = minutesInput.text.toString()
|
||||
val secondsText = secondsInput.text.toString()
|
||||
|
||||
val hoursValue = hoursText.toLongOrNull() ?: 0
|
||||
val minutesValue = minutesText.toLongOrNull() ?: 0
|
||||
val secondsValue = secondsText.toLongOrNull() ?: 0
|
||||
|
||||
var hasError = false
|
||||
|
||||
// normally cant be above 9999
|
||||
if (hoursValue < 0 || hoursValue > 9999) {
|
||||
hoursLayout.error = getString(R.string.hours_must_be_between_0_and_9999)
|
||||
hasError = true
|
||||
}
|
||||
|
||||
if (minutesValue < 0 || minutesValue > 59) {
|
||||
minutesLayout.error = getString(R.string.minutes_must_be_between_0_and_59)
|
||||
hasError = true
|
||||
}
|
||||
|
||||
if (secondsValue < 0 || secondsValue > 59) {
|
||||
secondsLayout.error = getString(R.string.seconds_must_be_between_0_and_59)
|
||||
hasError = true
|
||||
}
|
||||
|
||||
if (!hasError) {
|
||||
val totalSeconds = hoursValue * 3600 + minutesValue * 60 + secondsValue
|
||||
NativeLibrary.playTimeManagerSetPlayTime(args.game.programId, totalSeconds)
|
||||
getPlayTime()
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.playtime_updated_successfully,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
private fun reloadList() {
|
||||
_binding ?: return
|
||||
|
||||
|
@ -331,6 +415,7 @@ class GamePropertiesFragment : Fragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
driverViewModel.updateDriverNameForGame(args.game)
|
||||
getPlayTime()
|
||||
}
|
||||
|
||||
private fun setInsets() =
|
||||
|
|
|
@ -779,6 +779,14 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_playTimeManagerResetProgramPlayTime(J
|
|||
}
|
||||
}
|
||||
|
||||
void Java_org_yuzu_yuzu_1emu_NativeLibrary_playTimeManagerSetPlayTime(JNIEnv* env, jobject obj,
|
||||
jstring jprogramId, jlong playTimeSeconds) {
|
||||
u64 program_id = EmulationSession::GetProgramId(env, jprogramId);
|
||||
if (play_time_manager) {
|
||||
play_time_manager->SetPlayTime(program_id, static_cast<u64>(playTimeSeconds));
|
||||
}
|
||||
}
|
||||
|
||||
jstring Java_org_yuzu_yuzu_1emu_NativeLibrary_getAppletLaunchPath(JNIEnv* env, jclass clazz,
|
||||
jlong jid) {
|
||||
auto bis_system =
|
||||
|
|
|
@ -110,9 +110,9 @@
|
|||
style="?attr/textAppearanceBodyMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="@id/title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/about_game_filename"
|
||||
android:ellipsize="none"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAlignment="center"
|
||||
tools:text="Game Playtime" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
59
src/android/app/src/main/res/layout/dialog_edit_playtime.xml
Normal file
59
src/android/app/src/main/res/layout/dialog_edit_playtime.xml
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/layout_hours"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:hint="@string/hours"
|
||||
app:boxBackgroundMode="outline">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/input_hours"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:maxLength="4" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/layout_minutes"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:hint="@string/minutes"
|
||||
app:boxBackgroundMode="outline">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/input_minutes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:maxLength="2" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/layout_seconds"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/seconds"
|
||||
app:boxBackgroundMode="outline">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/input_seconds"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:maxLength="2" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -85,8 +85,8 @@
|
|||
style="?attr/textAppearanceBodyMedium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintStart_toStartOf="@id/title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/about_game_filename"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textAlignment="center"
|
||||
tools:text="Game Playtime" />
|
||||
|
||||
|
||||
|
|
|
@ -757,6 +757,18 @@
|
|||
<string name="copy_details">Copy details</string>
|
||||
<string name="add_ons">Add-ons</string>
|
||||
<string name="add_ons_description">Toggle mods, updates and DLC</string>
|
||||
<string name="playtime">Playtime:</string>
|
||||
<string name="reset_playtime">Clear Playtime</string>
|
||||
<string name="reset_playtime_description">Reset the current game\'s playtime back to 0 seconds</string>
|
||||
<string name="reset_playtime_warning_description">This will clear the current game\'s playtime data. Are you sure?</string>
|
||||
<string name="playtime_reset_successfully">Playtime has been reset</string>
|
||||
<string name="edit_playtime">Edit Playtime</string>
|
||||
<string name="hours">Hours</string>
|
||||
<string name="minutes">Minutes</string>
|
||||
<string name="hours_must_be_between_0_and_9999">Hours must be between 0 and 9999</string>
|
||||
<string name="minutes_must_be_between_0_and_59">Minutes must be between 0 and 59</string>
|
||||
<string name="seconds_must_be_between_0_and_59">Seconds must be between 0 and 59</string>
|
||||
<string name="playtime_updated_successfully">Playtime updated successfully</string>
|
||||
<string name="clear_shader_cache">Clear shader cache</string>
|
||||
<string name="clear_shader_cache_description">Removes all shaders built while playing this game</string>
|
||||
<string name="clear_shader_cache_warning_description">You will experience more stuttering as the shader cache regenerates</string>
|
||||
|
@ -1632,9 +1644,4 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
</string>
|
||||
<string name="playtime_format">Playtime: %1$d h, %2$d m</string>
|
||||
<string name="reset_playtime">Clear Playtime</string>
|
||||
<string name="reset_playtime_description">Reset the current game\'s playtime back to 0 seconds</string>
|
||||
<string name="reset_playtime_warning_description">This will clear the current game\'s playtime data. Are you sure?</string>
|
||||
<string name="playtime_reset_successfully">Playtime has been reset</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue