Author: Adam <git@apiote.xyz>
advanced settings
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/xyz/apiote/bimba/czwek/settings/ServerChooserActivity.kt b/app/src/main/java/xyz/apiote/bimba/czwek/settings/ServerChooserActivity.kt index 80c0975d04174d0958a97d6e5f3f03342c3ea17f..d1d96616c5998e2ed5f21c1da8719658f57fe9b6 100644 --- a/app/src/main/java/xyz/apiote/bimba/czwek/settings/ServerChooserActivity.kt +++ b/app/src/main/java/xyz/apiote/bimba/czwek/settings/ServerChooserActivity.kt @@ -3,6 +3,7 @@ import android.content.Context import android.content.Intent import android.content.SharedPreferences +import android.graphics.Color import android.net.ConnectivityManager import android.os.Bundle import android.util.Log @@ -46,12 +47,16 @@ if (intent.getBooleanExtra("simple", false)) { setServer("bimba.apiote.xyz", "") checkServer(true) } else { - _binding = ActivityServerChooserBinding.inflate(layoutInflater) setContentView(binding.root) preferences.edit(true) { putBoolean("inFeedsTransaction", true) + } + + if (preferences.getBoolean("shibboleet", false)) { + binding.button.setBackgroundColor(Color.rgb(35, 93, 121)) + binding.button.setTextColor(Color.WHITE) } binding.button.isEnabled = false @@ -67,11 +72,43 @@ } } binding.button.setOnClickListener { - setServer( - binding.serverField.editText!!.text.toString(), - binding.tokenField.editText!!.text.toString() - ) - checkServer(false) + when (binding.serverField.editText!!.text.toString()) { + ":shibboleet" -> { + binding.button.setBackgroundColor(Color.rgb(35, 93, 121)) + binding.button.setTextColor(Color.WHITE) + preferences.edit(true) { + putBoolean("shibboleet", true) + } + if (!preferences.getBoolean("firstRun", true)) { + Server.get(this).let { server -> + binding.serverField.editText!!.setText(server.host) + binding.tokenField.editText!!.setText(server.token) + } + } + } + + ";shibboleet" -> { + _binding = ActivityServerChooserBinding.inflate(layoutInflater) + setContentView(binding.root) + preferences.edit(true) { + putBoolean("shibboleet", false) + } + if (!preferences.getBoolean("firstRun", true)) { + Server.get(this).let { server -> + binding.serverField.editText!!.setText(server.host) + binding.tokenField.editText!!.setText(server.token) + } + } + } + + else -> { + setServer( + binding.serverField.editText!!.text.toString(), + binding.tokenField.editText!!.text.toString() + ) + checkServer(false) + } + } } } } @@ -114,23 +151,45 @@ Log.w("ServerChooser", e.message) showDialog(R.string.error, R.string.error_traffic_spec, R.drawable.error_server, null) return@launch } - val token = preferences.getString("token", "") - updateServer(bimba.servers[0]["url"]!!) - if (bimba.isPrivate() && token == "") { - showDialog(R.string.error, R.string.server_private_question, R.drawable.error_sec, null) + if (isSimple) { + updateServer(bimba.servers[0]["url"]!!) + moveOn(bimba, true) return@launch } - if (bimba.isRateLimited() && token == "" && !isSimple) { - showDialog( - R.string.rate_limit, R.string.server_rate_limited_question, R.drawable.error_limit - ) { - runFeedsActivity() + + if (preferences.getBoolean("shibboleet", false)) { + val validServers = bimba.servers.filter { !it.getOrDefault("url", null).isNullOrBlank() } + if (validServers.size > 1) { + val servers = validServers.toTypedArray() + MaterialAlertDialogBuilder(this@ServerChooserActivity) + .setTitle(R.string.choose_server) + .setItems(servers.map { it["description"] }.toTypedArray()) { _, i -> + updateServer(servers[i]["url"].toString()) + moveOn(bimba, false) + } + .show() } - return@launch } - runFeedsActivity() } + } + + private fun moveOn(bimba: Bimba, isSimple: Boolean) { + val token = preferences.getString("token", "") + + if (bimba.isPrivate() && token == "") { + showDialog(R.string.error, R.string.server_private_question, R.drawable.error_sec, null) + return + } + if (bimba.isRateLimited() && token == "" && !isSimple) { + showDialog( + R.string.rate_limit, R.string.server_rate_limited_question, R.drawable.error_limit + ) { + runFeedsActivity() + } + return + } + runFeedsActivity() } private fun setServer(hostname: String, token: String) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3254f20c981d230bde33e2f2c049458a0222176b..366e44ad629b6ee47e17bf3409aa8f01d0291896 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,4 +86,5 @@Malformed URL provided <string name="error_traffic_spec">Cannot verify traffic server</string> <string name="stops_near_code">Stops near %1$s</string> <string name="code_is_not_full">Code is not full</string> + <string name="choose_server">Choose server flavour</string> </resources> \ No newline at end of file