2952/proxy (#2961)

* replace hard-coded strings with existing constants

* proxy port

* * custom proxy port and hostname inputs
* typesafety, refactor, linting, unit tests

* relocate ProxyConfiguration in app structure

* remove unused editTextPreference fn

* allow preference category to have no title

* refactor proxy prefs hierarchy/dependency
This commit is contained in:
kylegoetz 2022-12-07 12:29:18 -06:00 committed by GitHub
commit 25443217c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 21 deletions

View file

@ -19,9 +19,11 @@ import android.os.Bundle
import androidx.preference.PreferenceFragmentCompat
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.settings.editTextPreference
import com.keylesspalace.tusky.settings.ProxyConfiguration
import com.keylesspalace.tusky.settings.makePreferenceScreen
import com.keylesspalace.tusky.settings.preferenceCategory
import com.keylesspalace.tusky.settings.switchPreference
import com.keylesspalace.tusky.settings.validatedEditTextPreference
import kotlin.system.exitProcess
class ProxyPreferencesFragment : PreferenceFragmentCompat() {
@ -36,18 +38,29 @@ class ProxyPreferencesFragment : PreferenceFragmentCompat() {
setDefaultValue(false)
}
editTextPreference {
setTitle(R.string.pref_title_http_proxy_server)
key = PrefKeys.HTTP_PROXY_SERVER
isIconSpaceReserved = false
setSummaryProvider { text }
}
preferenceCategory { category ->
category.dependency = PrefKeys.HTTP_PROXY_ENABLED
category.isIconSpaceReserved = false
editTextPreference {
setTitle(R.string.pref_title_http_proxy_port)
key = PrefKeys.HTTP_PROXY_PORT
isIconSpaceReserved = false
setSummaryProvider { text }
validatedEditTextPreference(null, ProxyConfiguration::isValidHostname) {
setTitle(R.string.pref_title_http_proxy_server)
key = PrefKeys.HTTP_PROXY_SERVER
isIconSpaceReserved = false
setSummaryProvider { text }
}
val portErrorMessage = getString(
R.string.pref_title_http_proxy_port_message,
ProxyConfiguration.MIN_PROXY_PORT,
ProxyConfiguration.MAX_PROXY_PORT
)
validatedEditTextPreference(portErrorMessage, ProxyConfiguration::isValidProxyPort) {
setTitle(R.string.pref_title_http_proxy_port)
key = PrefKeys.HTTP_PROXY_PORT
isIconSpaceReserved = false
setSummaryProvider { text }
}
}
}
}