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:
parent
59c24381a3
commit
25443217c2
6 changed files with 143 additions and 21 deletions
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue