Skip to content

Commit

Permalink
Make game compatibility sections optional
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart committed Dec 31, 2023
1 parent ffea618 commit 7a0a1bc
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
return settings?.gamesManager?.let {
try {
val amiiboId = Amiibo.dataToId(tagData)
txtUsage.text = it.getGamesCompatibility(amiiboId)
txtUsage.text = it.getGamesCompatibility(prefs, amiiboId)
true
} catch (ex: Exception) {
Debug.warn(ex)
Expand Down Expand Up @@ -1902,7 +1902,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener,
Intent.FLAG_GRANT_READ_URI_PERMISSION
or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
)
val pickedDir = DocumentFile.fromTreeUri(this, treeUri!!)
val pickedDir = DocumentFile.fromTreeUri(this, treeUri)

// List all existing files inside picked directory
if (null != pickedDir) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/hiddenramblings/tagmo/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ class Preferences(context: Context) {
putString(eliteSignature, value)
}

private val showCompat3DS = "settings_show_games_ds"
fun showCompat3DS(): Boolean {
return getBoolean(showCompat3DS, true)
}

fun showCompat3DS(value: Boolean) {
putBoolean(showCompat3DS, value)
}

private val showCompatWiiU = "settings_show_games_wii"
fun showCompatWiiU(): Boolean {
return getBoolean(showCompatWiiU, true)
}

fun showCompatWiiU(value: Boolean) {
putBoolean(showCompatWiiU, value)
}

private val showCompatSwitch = "settings_show_games_nx"
fun showCompatSwitch(): Boolean {
return getBoolean(showCompatSwitch, true)
}

fun showCompatSwitch(value: Boolean) {
putBoolean(showCompatSwitch, value)
}

private val disableDebug = "settings_disable_debug"
fun disableDebug(): Boolean {
return getBoolean(disableDebug, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hiddenramblings.tagmo.amiibo.games

import android.content.Context
import android.net.Uri
import com.hiddenramblings.tagmo.Preferences
import com.hiddenramblings.tagmo.R
import com.hiddenramblings.tagmo.TagMo
import com.hiddenramblings.tagmo.amiibo.Amiibo
Expand All @@ -20,35 +21,42 @@ class GamesManager {
private val gamesSwitch = HashMap<Long, GamesSwitch>()
private val games = HashMap<String, GameTitles>()

fun getGamesCompatibility(amiiboId: Long): String {
fun getGamesCompatibility(prefs: Preferences, amiiboId: Long): String {
val usage = StringBuilder()
val amiibo3DS = games3DS[amiiboId]
if (amiibo3DS?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_ds))
if (prefs.showCompat3DS()) {
val amiibo3DS = games3DS[amiiboId]
if (amiibo3DS?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_ds))
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiibo3DS.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_ds))
}
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiibo3DS.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_ds))
}
usage.append(Debug.separator).append(Debug.separator)
val amiiboWiiU = gamesWiiU[amiiboId]
if (amiiboWiiU?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_wiiu))
if (prefs.showCompatWiiU()) {
val amiiboWiiU = gamesWiiU[amiiboId]
if (amiiboWiiU?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_wiiu))
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiiboWiiU.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_wiiu))
}
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiiboWiiU.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_wiiu))
}
usage.append(Debug.separator).append(Debug.separator)
val amiiboSwitch = gamesSwitch[amiiboId]
if (amiiboSwitch?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_switch))
if (prefs.showCompatSwitch()) {
val amiiboSwitch = gamesSwitch[amiiboId]
if (amiiboSwitch?.stringList?.isNotBlank() == true) {
usage.append(TagMo.appContext.getString(R.string.games_nx))
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiiboSwitch.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_nx))
}
usage.append(Debug.separator).append(Debug.separator)
usage.append(amiiboSwitch.stringList)
} else {
usage.append(TagMo.appContext.getString(R.string.no_games_switch))
}
return usage.append(Debug.separator).toString()
return usage.toString()
}

val gameTitles: Collection<GameTitles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class BrowserFragment : Fragment(), OnFoomiiboClickListener {
settings.gamesManager?.let {
try {
val amiiboId = Amiibo.dataToId(tagData)
txtUsage.text = it.getGamesCompatibility(amiiboId)
txtUsage.text = it.getGamesCompatibility(prefs, amiiboId)
} catch (ex: Exception) {
Debug.warn(ex)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ class SettingsFragment : PreferenceFragmentCompat() {
super@SettingsFragment.onPreferenceTreeClick(it)
}
}
findPreference<SwitchPreferenceCompat>(getString(R.string.settings_show_games_ds))?.apply {
isChecked = prefs.showCompat3DS()
onPreferenceClickListener = Preference.OnPreferenceClickListener {
prefs.showCompat3DS(isChecked)
super@SettingsFragment.onPreferenceTreeClick(it)
}
}
findPreference<SwitchPreferenceCompat>(getString(R.string.settings_show_games_wii))?.apply {
isChecked = prefs.showCompatWiiU()
onPreferenceClickListener = Preference.OnPreferenceClickListener {
prefs.showCompatWiiU(isChecked)
super@SettingsFragment.onPreferenceTreeClick(it)
}
}
findPreference<SwitchPreferenceCompat>(getString(R.string.settings_show_games_nx))?.apply {
isChecked = prefs.showCompatSwitch()
onPreferenceClickListener = Preference.OnPreferenceClickListener {
prefs.showCompatSwitch(isChecked)
super@SettingsFragment.onPreferenceTreeClick(it)
}
}
findPreference<ListPreference>(getString(R.string.setting_database_source))?.apply {
setValueIndex(prefs.databaseSource())
summary = entry
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<string name="settings_enable_power_tag_support" translatable="false">enable_power_tag_support</string>
<string name="settings_enable_elite_support" translatable="false">enable_elite_support</string>
<string name="settings_elite_signature" translatable="false">settings_elite_signature</string>
<string name="settings_show_games_ds" translatable="false">settings_show_games_ds</string>
<string name="settings_show_games_wii" translatable="false">settings_show_games_wii</string>
<string name="settings_show_games_nx" translatable="false">settings_show_games_nx</string>
<string name="setting_database_source" translatable="false">setting_database_source</string>
<string name="settings_import_info" translatable="false">import_info</string>
<string name="settings_reset_info" translatable="false">reset_info</string>
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@

<string name="games_ds">3DS Compatibility</string>
<string name="games_wiiu">WiiU Compatibility</string>
<string name="games_switch">Switch Compatibility</string>
<string name="games_nx">Switch Compatibility</string>
<string name="no_games_ds">No 3DS compatibility</string>
<string name="no_games_wiiu">No WiiU compatibility</string>
<string name="no_games_switch">No Switch compatibility</string>
<string name="no_games_nx">No Switch compatibility</string>

<string name="properties">Properties</string>
<string name="mii" translatable="false">Mii</string>
Expand Down Expand Up @@ -253,6 +253,10 @@
<string name="lock_elite_warning">Lock N2 Elite Hardware?</string>
<string name="unlock_elite_warning">Unlock N2 Elite Hardware</string>
<string name="elite_signature">N2 Elite ID: %1$s</string>
<string name="prefs_game_compat">Game Compatibility</string>
<string name="enable_ds_compat">Show 3DS Games</string>
<string name="enable_wii_compat">Show Wii U Games</string>
<string name="enable_nx_compat">Show Switch Games</string>
<string name="amiibo_info">amiibo Database</string>
<string name="pref_database_source">Preferred AmiiboAPI Database</string>
<string name="sync_amiibo_info">Sync database with AmiiboAPI</string>
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/xml/preference_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@
android:title="@string/enable_elite" />
</androidx.preference.PreferenceCategory>

<androidx.preference.PreferenceCategory
android:title="@string/prefs_game_compat">
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/settings_show_games_ds"
android:title="@string/enable_ds_compat" />

<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/settings_show_games_wii"
android:title="@string/enable_wii_compat" />

<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/settings_show_games_nx"
android:title="@string/enable_nx_compat" />
</androidx.preference.PreferenceCategory>

<androidx.preference.PreferenceCategory
android:title="@string/amiibo_api_url">
<androidx.preference.ListPreference
Expand Down

0 comments on commit 7a0a1bc

Please sign in to comment.