mirror of https://github.com/Corewala/Buran
Rearranged client cert section in settings
Also removed unnecessary "if true" statement
This commit is contained in:
parent
79056fe060
commit
b2ef138402
|
@ -8,8 +8,6 @@ class Buran: Application() {
|
||||||
const val DEFAULT_HOME_CAPSULE = "gemini://tlgs.one"
|
const val DEFAULT_HOME_CAPSULE = "gemini://tlgs.one"
|
||||||
const val DEFAULT_SEARCH_BASE = "gemini://tlgs.one/search?"
|
const val DEFAULT_SEARCH_BASE = "gemini://tlgs.one/search?"
|
||||||
|
|
||||||
const val FEATURE_CLIENT_CERTS = true
|
|
||||||
|
|
||||||
const val PREF_KEY_CLIENT_CERT_URI = "client_cert_uri"
|
const val PREF_KEY_CLIENT_CERT_URI = "client_cert_uri"
|
||||||
const val PREF_KEY_CLIENT_CERT_HUMAN_READABLE = "client_cert_uri_human_readable"
|
const val PREF_KEY_CLIENT_CERT_HUMAN_READABLE = "client_cert_uri_human_readable"
|
||||||
const val PREF_KEY_CLIENT_CERT_ACTIVE = "client_cert_active"
|
const val PREF_KEY_CLIENT_CERT_ACTIVE = "client_cert_active"
|
||||||
|
|
|
@ -97,8 +97,8 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
checkForUpdates.title = getString(R.string.check_for_updates)
|
checkForUpdates.title = getString(R.string.check_for_updates)
|
||||||
appCategory.addPreference(checkForUpdates)
|
appCategory.addPreference(checkForUpdates)
|
||||||
|
|
||||||
//Home - Certificates - Updates
|
//Certificates
|
||||||
buildClientCertificateSection(context, appCategory)
|
buildClientCertificateSection(context, screen)
|
||||||
|
|
||||||
//Appearance --------------------------------------------
|
//Appearance --------------------------------------------
|
||||||
buildAppearanceSection(context, appCategory)
|
buildAppearanceSection(context, appCategory)
|
||||||
|
@ -226,80 +226,82 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
accessibilityCategory.addPreference(showLinkButtonsPreference)
|
accessibilityCategory.addPreference(showLinkButtonsPreference)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildClientCertificateSection(context: Context?, appCategory: PreferenceCategory) {
|
private fun buildClientCertificateSection(context: Context?, screen: PreferenceScreen) {
|
||||||
if (Buran.FEATURE_CLIENT_CERTS) {
|
|
||||||
|
|
||||||
val aboutPref = Preference(context)
|
val certificateCategory = PreferenceCategory(context)
|
||||||
aboutPref.key = "unused_pref"
|
certificateCategory.key = "certificate_category"
|
||||||
aboutPref.summary = getString(R.string.pkcs_notice)
|
certificateCategory.title = getString(R.string.client_certificate)
|
||||||
aboutPref.isPersistent = false
|
screen.addPreference(certificateCategory)
|
||||||
aboutPref.isSelectable = false
|
|
||||||
appCategory.addPreference(aboutPref)
|
|
||||||
|
|
||||||
clientCertPref = Preference(context)
|
val aboutPref = Preference(context)
|
||||||
clientCertPref.title = getString(R.string.client_certificate)
|
aboutPref.summary = getString(R.string.pkcs_notice)
|
||||||
clientCertPref.key = Buran.PREF_KEY_CLIENT_CERT_HUMAN_READABLE
|
aboutPref.isPersistent = false
|
||||||
|
aboutPref.isSelectable = false
|
||||||
|
certificateCategory.addPreference(aboutPref)
|
||||||
|
|
||||||
val clientCertUriHumanReadable = preferenceManager.sharedPreferences.getString(
|
clientCertPref = Preference(context)
|
||||||
Buran.PREF_KEY_CLIENT_CERT_HUMAN_READABLE,
|
clientCertPref.title = getString(R.string.client_certificate)
|
||||||
null
|
clientCertPref.key = Buran.PREF_KEY_CLIENT_CERT_HUMAN_READABLE
|
||||||
)
|
|
||||||
|
|
||||||
val hasCert = clientCertUriHumanReadable != null
|
val clientCertUriHumanReadable = preferenceManager.sharedPreferences.getString(
|
||||||
if (!hasCert) {
|
Buran.PREF_KEY_CLIENT_CERT_HUMAN_READABLE,
|
||||||
clientCertPref.summary = getString(R.string.tap_to_select_client_certificate)
|
null
|
||||||
} else {
|
)
|
||||||
clientCertPref.summary = clientCertUriHumanReadable
|
|
||||||
|
val hasCert = clientCertUriHumanReadable != null
|
||||||
|
if (!hasCert) {
|
||||||
|
clientCertPref.summary = getString(R.string.tap_to_select_client_certificate)
|
||||||
|
} else {
|
||||||
|
clientCertPref.summary = clientCertUriHumanReadable
|
||||||
|
}
|
||||||
|
|
||||||
|
clientCertPref.setOnPreferenceClickListener {
|
||||||
|
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||||
|
addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
type = "*/*"
|
||||||
}
|
}
|
||||||
|
startActivityForResult(intent, PREFS_SET_CLIENT_CERT_REQ)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
clientCertPref.setOnPreferenceClickListener {
|
certificateCategory.addPreference(clientCertPref)
|
||||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
|
||||||
addCategory(Intent.CATEGORY_OPENABLE)
|
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
||||||
type = "*/*"
|
|
||||||
}
|
|
||||||
startActivityForResult(intent, PREFS_SET_CLIENT_CERT_REQ)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
appCategory.addPreference(clientCertPref)
|
|
||||||
|
|
||||||
|
|
||||||
val clientCertPassword = EditTextPreference(context)
|
val clientCertPassword = EditTextPreference(context)
|
||||||
clientCertPassword.key = Buran.PREF_KEY_CLIENT_CERT_PASSWORD
|
clientCertPassword.key = Buran.PREF_KEY_CLIENT_CERT_PASSWORD
|
||||||
clientCertPassword.title = getString(R.string.client_certificate_password)
|
clientCertPassword.title = getString(R.string.client_certificate_password)
|
||||||
|
|
||||||
val certPasword = preferenceManager.sharedPreferences.getString(
|
val certPasword = preferenceManager.sharedPreferences.getString(
|
||||||
Buran.PREF_KEY_CLIENT_CERT_PASSWORD,
|
Buran.PREF_KEY_CLIENT_CERT_PASSWORD,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
if (certPasword != null && certPasword.isNotEmpty()) {
|
if (certPasword != null && certPasword.isNotEmpty()) {
|
||||||
clientCertPassword.summary = getDots(certPasword)
|
clientCertPassword.summary = getDots(certPasword)
|
||||||
} else {
|
} else {
|
||||||
|
clientCertPassword.summary = getString(R.string.no_password)
|
||||||
|
}
|
||||||
|
clientCertPassword.dialogTitle = getString(R.string.client_certificate_password)
|
||||||
|
clientCertPassword.setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
val passphrase = "$newValue"
|
||||||
|
if (passphrase.isEmpty()) {
|
||||||
clientCertPassword.summary = getString(R.string.no_password)
|
clientCertPassword.summary = getString(R.string.no_password)
|
||||||
}
|
} else {
|
||||||
clientCertPassword.dialogTitle = getString(R.string.client_certificate_password)
|
clientCertPassword.summary = getDots(passphrase)
|
||||||
clientCertPassword.setOnPreferenceChangeListener { _, newValue ->
|
|
||||||
val passphrase = "$newValue"
|
|
||||||
if (passphrase.isEmpty()) {
|
|
||||||
clientCertPassword.summary = getString(R.string.no_password)
|
|
||||||
} else {
|
|
||||||
clientCertPassword.summary = getDots(passphrase)
|
|
||||||
}
|
|
||||||
|
|
||||||
true//update the value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
appCategory.addPreference(clientCertPassword)
|
true//update the value
|
||||||
|
}
|
||||||
|
|
||||||
useClientCertPreference = SwitchPreferenceCompat(context)
|
certificateCategory.addPreference(clientCertPassword)
|
||||||
useClientCertPreference.key = Buran.PREF_KEY_CLIENT_CERT_ACTIVE
|
|
||||||
useClientCertPreference.title = getString(R.string.use_client_certificate)
|
|
||||||
appCategory.addPreference(useClientCertPreference)
|
|
||||||
|
|
||||||
if (!hasCert) {
|
useClientCertPreference = SwitchPreferenceCompat(context)
|
||||||
useClientCertPreference.isVisible = false
|
useClientCertPreference.key = Buran.PREF_KEY_CLIENT_CERT_ACTIVE
|
||||||
}
|
useClientCertPreference.title = getString(R.string.use_client_certificate)
|
||||||
|
certificateCategory.addPreference(useClientCertPreference)
|
||||||
|
|
||||||
|
if (!hasCert) {
|
||||||
|
useClientCertPreference.isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue