Skip to content

Commit

Permalink
Update AkinatorHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Dec 28, 2021
1 parent 2737c48 commit a975739
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "me.kyuubiran.akinatorhelper"
minSdk 21
targetSdk 32
versionCode 4
versionName "1.4"
versionCode 5
versionName "1.5"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ object AkinatorHelper {
mSetGameUnlocked.invoke(akGameFactoryInstance)
}

private val mAddOneWonGame by lazy {
findMethod(C_AK_GAME_FACTORY) {
name == "addOneWonGame"
}
}

fun addOneWonGame() {
mAddOneWonGame.invoke(akGameFactoryInstance)
}

private val mAddOneLostGame by lazy {
findMethod(C_AK_GAME_FACTORY) {
name == "addOneLostGame"
}
}

fun addOneLostGame() {
mAddOneLostGame.invoke(akGameFactoryInstance)
}

}

var isGameUnlocked: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.app.AlertDialog
import android.os.Bundle
import android.preference.Preference
import android.preference.PreferenceFragment
import android.text.InputType
import android.widget.EditText
import com.github.kyuubiran.ezxhelper.init.EzXHelperInit
import com.github.kyuubiran.ezxhelper.utils.Log
import me.kyuubiran.akinatorhelper.BuildConfig
Expand All @@ -28,11 +30,38 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {

setView(prefsFragment.view)
setTitle(activity.getString(R.string.app_name))

setPositiveButton(R.string.close, null)
setCancelable(false)
}

class PrefsFragment : PreferenceFragment(), Preference.OnPreferenceChangeListener,
Preference.OnPreferenceClickListener {

private fun showEditDialog(
title: String,
hint: String = "",
cancelable: Boolean = true,
defText: String = "",
inputType: Int = InputType.TYPE_CLASS_TEXT,
onConfirm: ((String) -> Unit)? = null,
onCancel: ((String) -> Unit)? = null
) {
val et = EditText(this.activity).also {
it.hint = hint
it.inputType = inputType
it.setText(defText)
}
AlertDialog.Builder(this.activity).run {
setTitle(title)
setView(et)
setCancelable(cancelable)
setPositiveButton(R.string.confirm) { _, _ -> onConfirm?.invoke(et.text.toString()) }
setNegativeButton(R.string.cancel) { _, _ -> onCancel?.invoke(et.text.toString()) }
show()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.setting_dialog_prefs)
Expand All @@ -43,6 +72,8 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {

findPreference("unlock_game").onPreferenceClickListener = this
findPreference("relock_game").onPreferenceClickListener = this
findPreference("add_win_times").onPreferenceClickListener = this
findPreference("add_lose_times").onPreferenceClickListener = this
findPreference("goto_github").onPreferenceClickListener = this

findPreference("module_version").summary =
Expand Down Expand Up @@ -80,6 +111,46 @@ class SettingDialog(activity: Activity) : AlertDialog.Builder(activity) {
AkinatorHelper.isGameUnlocked = false
Log.toast(getString(R.string.relock_game_success))
}
"add_win_times" -> {
showEditDialog(
getString(R.string.increase_win_times_title),
getString(R.string.times_to_add),
defText = "1",
inputType = InputType.TYPE_CLASS_NUMBER,
onConfirm = {
(it.toIntOrNull() ?: 0).let { num ->
if (num < 1) {
Log.toast(getString(R.string.num_must_be_greater_than_zero))
return@showEditDialog
}
repeat(num) {
AkinatorHelper.Methods.addOneWonGame()
}
Log.toast(getString(R.string.success_increate_win_times, num))
}
}
)
}
"add_lose_times" -> {
showEditDialog(
getString(R.string.increase_lose_times_title),
getString(R.string.times_to_add),
defText = "1",
inputType = InputType.TYPE_CLASS_NUMBER,
onConfirm = {
(it.toIntOrNull() ?: 0).let { num ->
if (num < 1) {
Log.toast(getString(R.string.num_must_be_greater_than_zero))
return@showEditDialog
}
repeat(num) {
AkinatorHelper.Methods.addOneWonGame()
}
Log.toast(getString(R.string.success_increate_lose_times, num))
}
}
)
}
"goto_github" -> {
openUrl("https://github.com/KyuubiRan/AkinatorHelper")
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@
<string name="module_version_title">模块版本</string>
<string name="author_title">模块作者</string>
<string name="all_item_bought_title">解锁商店所有物品</string>
<string name="confirm">确认</string>
<string name="cancel">取消</string>
<string name="increase_win_times_title">增加胜利次数</string>
<string name="increase_lose_times_title">增加失败次数</string>
<string name="times_to_add">增加的次数</string>
<string name="local_hack_title">本地修改</string>
<string name="success_increate_win_times">已增加%d次胜利次数</string>
<string name="success_increate_lose_times">已增加%d次失败次数</string>
<string name="num_must_be_greater_than_zero">数字必须大于0!</string>
<string name="save">保存</string>
<string name="close">关闭</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@
<string name="author_title">Module author</string>
<string name="author_summary" translatable="false">KyuubiRan</string>
<string name="all_item_bought_title">Unlock all items in the shop</string>
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="increase_win_times_title">Increase win times</string>
<string name="increase_lose_times_title">Increase lose times</string>
<string name="times_to_add">Times to add</string>
<string name="local_hack_title">Local hack</string>
<string name="success_increate_win_times">Increase %d win times</string>
<string name="success_increate_lose_times">Increase %d lose times</string>
<string name="num_must_be_greater_than_zero">The number must be greater than zero!</string>
<string name="save">Save</string>
<string name="close">Close</string>
</resources>
29 changes: 18 additions & 11 deletions app/src/main/res/xml/setting_dialog_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
android:title="@string/all_item_bought_title" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/unlock_relock_game_title">
<PreferenceCategory android:title="@string/local_hack_title">
<Preference
android:key="add_win_times"
android:title="@string/increase_win_times_title" />
<Preference
android:key="add_lose_times"
android:title="@string/increase_lose_times_title" />

<Preference
android:key="unlock_game"
android:title="@string/unlock_game_title" />
Expand All @@ -27,20 +34,20 @@
android:title="@string/relock_game_title" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/other_title">
<Preference
android:key="author"
android:title="@string/author_title"
android:summary="@string/author_summary"/>
<PreferenceCategory android:title="@string/other_title">
<Preference
android:key="author"
android:summary="@string/author_summary"
android:title="@string/author_title" />

<Preference
android:key="module_version"
android:title="@string/module_version_title" />
<Preference
android:key="module_version"
android:title="@string/module_version_title" />

<Preference
android:key="goto_github"
android:title="@string/goto_github_title"
android:summary="@string/goto_github_summary"/>
android:summary="@string/goto_github_summary"
android:title="@string/goto_github_title" />
</PreferenceCategory>

</PreferenceScreen>

0 comments on commit a975739

Please sign in to comment.