From fb177631ef0e5e0f361cb9ef5fd34b0e4d4a9212 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 1 Mar 2023 13:36:53 -0500 Subject: [PATCH] Android: Convert ReadOnlyCheat to Kotlin --- .../features/cheats/model/ReadOnlyCheat.java | 36 ------------------- .../features/cheats/model/ReadOnlyCheat.kt | 31 ++++++++++++++++ 2 files changed, 31 insertions(+), 36 deletions(-) delete mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java create mode 100644 Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.kt diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java deleted file mode 100644 index 9751c414f8..0000000000 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.java +++ /dev/null @@ -1,36 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later - -package org.dolphinemu.dolphinemu.features.cheats.model; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public abstract class ReadOnlyCheat implements Cheat -{ - private Runnable mChangedCallback = null; - - public int trySet(@NonNull String name, @NonNull String creator, @NonNull String notes, - @NonNull String code) - { - throw new UnsupportedOperationException(); - } - - public void setEnabled(boolean enabled) - { - setEnabledImpl(enabled); - onChanged(); - } - - public void setChangedCallback(@Nullable Runnable callback) - { - mChangedCallback = callback; - } - - protected void onChanged() - { - if (mChangedCallback != null) - mChangedCallback.run(); - } - - protected abstract void setEnabledImpl(boolean enabled); -} diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.kt new file mode 100644 index 0000000000..542a407792 --- /dev/null +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/cheats/model/ReadOnlyCheat.kt @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +package org.dolphinemu.dolphinemu.features.cheats.model + +abstract class ReadOnlyCheat : Cheat { + private var onChangedCallback: Runnable? = null + + override fun setCheat( + name: String, + creator: String, + notes: String, + code: String + ): Int { + throw UnsupportedOperationException() + } + + override fun setEnabled(isChecked: Boolean) { + setEnabledImpl(isChecked) + onChanged() + } + + override fun setChangedCallback(callback: Runnable?) { + onChangedCallback = callback + } + + protected fun onChanged() { + if (onChangedCallback != null) onChangedCallback!!.run() + } + + protected abstract fun setEnabledImpl(enabled: Boolean) +}