Fix NPE in SyncSettings
This commit is contained in:
@@ -44,6 +44,6 @@ class SyncSettingsFragment : BasePreferenceFragment(R.string.sync_settings), Fra
|
|||||||
|
|
||||||
private fun bindHostSummary() {
|
private fun bindHostSummary() {
|
||||||
val preference = findPreference<Preference>(SyncSettings.KEY_SYNC_URL) ?: return
|
val preference = findPreference<Preference>(SyncSettings.KEY_SYNC_URL) ?: return
|
||||||
preference.summary = syncSettings.syncURL
|
preference.summary = syncSettings.syncUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class SyncAuthenticator(
|
|||||||
private fun tryRefreshToken() = runCatching {
|
private fun tryRefreshToken() = runCatching {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
authApi.authenticate(
|
authApi.authenticate(
|
||||||
syncSettings.syncURL,
|
syncSettings.syncUrl,
|
||||||
account.name,
|
account.name,
|
||||||
accountManager.getPassword(account),
|
accountManager.getPassword(account),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,13 +27,9 @@ class SyncSettings(
|
|||||||
|
|
||||||
@get:WorkerThread
|
@get:WorkerThread
|
||||||
@set:WorkerThread
|
@set:WorkerThread
|
||||||
var syncURL: String
|
var syncUrl: String
|
||||||
get() = account?.let {
|
get() = account?.let {
|
||||||
val result = accountManager.getUserData(it, KEY_SYNC_URL)
|
accountManager.getUserData(it, KEY_SYNC_URL)?.withHttpSchema()
|
||||||
if (!result.startsWith("http://") && !result.startsWith("https://")) {
|
|
||||||
return "http://$result"
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}.ifNullOrEmpty { defaultSyncUrl }
|
}.ifNullOrEmpty { defaultSyncUrl }
|
||||||
set(value) {
|
set(value) {
|
||||||
account?.let {
|
account?.let {
|
||||||
@@ -43,6 +39,12 @@ class SyncSettings(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
|
private fun String.withHttpSchema(): String = if (!startsWith("http://") && !startsWith("https://")) {
|
||||||
|
"http://$this"
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
const val KEY_SYNC_URL = "host"
|
const val KEY_SYNC_URL = "host"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class SyncHelper @AssistedInject constructor(
|
|||||||
.addInterceptor(SyncInterceptor(context, account))
|
.addInterceptor(SyncInterceptor(context, account))
|
||||||
.build()
|
.build()
|
||||||
private val baseUrl: String by lazy {
|
private val baseUrl: String by lazy {
|
||||||
settings.syncURL
|
settings.syncUrl
|
||||||
}
|
}
|
||||||
private val defaultGcPeriod: Long // gc period if sync enabled
|
private val defaultGcPeriod: Long // gc period if sync enabled
|
||||||
get() = TimeUnit.DAYS.toMillis(4)
|
get() = TimeUnit.DAYS.toMillis(4)
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class SyncHostDialogFragment : AlertDialogFragment<PreferenceDialogAutocompletet
|
|||||||
binding.message.setText(R.string.sync_host_description)
|
binding.message.setText(R.string.sync_host_description)
|
||||||
val entries = binding.root.resources.getStringArray(R.array.sync_url_list)
|
val entries = binding.root.resources.getStringArray(R.array.sync_url_list)
|
||||||
val editText = binding.edit
|
val editText = binding.edit
|
||||||
editText.setText(arguments?.getString(KEY_SYNC_URL).ifNullOrEmpty { syncSettings.syncURL })
|
editText.setText(arguments?.getString(KEY_SYNC_URL).ifNullOrEmpty { syncSettings.syncUrl })
|
||||||
editText.threshold = 0
|
editText.threshold = 0
|
||||||
editText.setAdapter(ArrayAdapter(binding.root.context, android.R.layout.simple_spinner_dropdown_item, entries))
|
editText.setAdapter(ArrayAdapter(binding.root.context, android.R.layout.simple_spinner_dropdown_item, entries))
|
||||||
binding.dropdown.setOnClickListener {
|
binding.dropdown.setOnClickListener {
|
||||||
@@ -69,7 +69,7 @@ class SyncHostDialogFragment : AlertDialogFragment<PreferenceDialogAutocompletet
|
|||||||
if (!result.startsWith("https://") && !result.startsWith("http://")) {
|
if (!result.startsWith("https://") && !result.startsWith("http://")) {
|
||||||
scheme = "http://"
|
scheme = "http://"
|
||||||
}
|
}
|
||||||
syncSettings.syncURL = "$scheme$result"
|
syncSettings.syncUrl = "$scheme$result"
|
||||||
parentFragmentManager.setFragmentResult(REQUEST_KEY, bundleOf(KEY_SYNC_URL to "$scheme$result"))
|
parentFragmentManager.setFragmentResult(REQUEST_KEY, bundleOf(KEY_SYNC_URL to "$scheme$result"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user