Feature complete; still WIP
This commit is contained in:
parent
f7fbf467b0
commit
442efff000
3 changed files with 33 additions and 15 deletions
|
@ -233,7 +233,7 @@ interface SubscriptionDao {
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT
|
SELECT
|
||||||
s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.upAppId, s.upConnectorToken,
|
s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.authUserId, s.upAppId, s.upConnectorToken,
|
||||||
COUNT(n.id) totalCount,
|
COUNT(n.id) totalCount,
|
||||||
COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount,
|
COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount,
|
||||||
IFNULL(MAX(n.timestamp),0) AS lastActive
|
IFNULL(MAX(n.timestamp),0) AS lastActive
|
||||||
|
@ -246,7 +246,7 @@ interface SubscriptionDao {
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
SELECT
|
SELECT
|
||||||
s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.upAppId, s.upConnectorToken,
|
s.id, s.baseUrl, s.topic, s.instant, s.mutedUntil, s.authUserId, s.upAppId, s.upConnectorToken,
|
||||||
COUNT(n.id) totalCount,
|
COUNT(n.id) totalCount,
|
||||||
COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount,
|
COUNT(CASE n.notificationId WHEN 0 THEN NULL ELSE n.id END) newCount,
|
||||||
IFNULL(MAX(n.timestamp),0) AS lastActive
|
IFNULL(MAX(n.timestamp),0) AS lastActive
|
||||||
|
|
|
@ -73,33 +73,50 @@ class DetailSettingsActivity : AppCompatActivity() {
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
val subscription = repository.getSubscription(subscriptionId) ?: return@launch
|
val subscription = repository.getSubscription(subscriptionId) ?: return@launch
|
||||||
val users = repository.getUsers().filter { it.baseUrl == subscription.baseUrl }
|
val users = repository.getUsers().filter { it.baseUrl == subscription.baseUrl }
|
||||||
|
val authUser = users.firstOrNull { it.id == subscription.authUserId }
|
||||||
|
Log.d(TAG, "subscription: $subscription")
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
loadView(subscription.id, users)
|
loadView(subscription, authUser, users)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadView(subscriptionId: Long, users: List<User>) {
|
private fun loadView(subscription: Subscription, authUser: User?, users: List<User>) {
|
||||||
// Login user
|
// Login user
|
||||||
val authUserPrefId = context?.getString(R.string.detail_settings_auth_user_key) ?: return
|
val anonUser = User(0, "", getString(R.string.detail_settings_auth_user_entry_anon), "")
|
||||||
val authUser: ListPreference? = findPreference(authUserPrefId)
|
val usersWithAnon = users.toMutableList()
|
||||||
authUser?.entries = users.map { it.username }.toTypedArray()
|
usersWithAnon.add(0, anonUser)
|
||||||
authUser?.entryValues = users.map { it.id.toString() }.toTypedArray()
|
val authUserPrefId = getString(R.string.detail_settings_auth_user_key)
|
||||||
authUser?.preferenceDataStore = object : PreferenceDataStore() {
|
val authUserPref: ListPreference? = findPreference(authUserPrefId)
|
||||||
|
authUserPref?.entries = usersWithAnon.map { it.username }.toTypedArray()
|
||||||
|
authUserPref?.entryValues = usersWithAnon.map { it.id.toString() }.toTypedArray()
|
||||||
|
authUserPref?.value = authUser?.id?.toString() ?: anonUser.id.toString()
|
||||||
|
Log.d(TAG, "--> ${authUser?.id?.toString() ?: anonUser.id.toString()}")
|
||||||
|
authUserPref?.summaryProvider = Preference.SummaryProvider<ListPreference> { pref ->
|
||||||
|
when (pref.value) {
|
||||||
|
anonUser.id.toString() -> getString(R.string.detail_settings_auth_user_summary_none)
|
||||||
|
else -> {
|
||||||
|
val username = users.firstOrNull { it.id.toString() == pref.value } ?: "?"
|
||||||
|
getString(R.string.detail_settings_auth_user_summary_user_x, username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
authUserPref?.preferenceDataStore = object : PreferenceDataStore() {
|
||||||
override fun putString(key: String?, value: String?) {
|
override fun putString(key: String?, value: String?) {
|
||||||
val authUserId = when (value) {
|
val newAuthUserId = when (value) {
|
||||||
"" -> null
|
anonUser.id.toString() -> null
|
||||||
else -> value?.toLongOrNull()
|
else -> value?.toLongOrNull()
|
||||||
}
|
}
|
||||||
lifecycleScope.launch(Dispatchers.IO) {
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
Log.d(TAG, "Updating auth user ID to $authUserId for subscription $subscriptionId")
|
Log.d(TAG, "Updating subscription ${subscription.id} with new auth user ID $newAuthUserId")
|
||||||
repository.updateSubscriptionAuthUserId(subscriptionId, authUserId)
|
repository.updateSubscriptionAuthUserId(subscription.id, newAuthUserId)
|
||||||
|
Log.d(TAG, "after save: ${repository.getSubscription(subscription.id)}")
|
||||||
serviceManager.refresh()
|
serviceManager.refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun getString(key: String?, defValue: String?): String? {
|
override fun getString(key: String?, defValue: String?): String? {
|
||||||
Log.d(TAG, "getstring called $key $defValue")
|
Log.d(TAG, "getstring called $key $defValue -> ${authUser?.id?.toString() ?: anonUser.id.toString()}")
|
||||||
return "xxx"
|
return authUser?.id?.toString() ?: anonUser.id.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,6 +180,7 @@
|
||||||
<string name="detail_settings_auth_header_summary">For topics that require a login, you may pick the login user here. You can add/edit users in the main settings.</string>
|
<string name="detail_settings_auth_header_summary">For topics that require a login, you may pick the login user here. You can add/edit users in the main settings.</string>
|
||||||
<string name="detail_settings_auth_user_key">SubscriptionAuthUserKey</string>
|
<string name="detail_settings_auth_user_key">SubscriptionAuthUserKey</string>
|
||||||
<string name="detail_settings_auth_user_title">Login user</string>
|
<string name="detail_settings_auth_user_title">Login user</string>
|
||||||
|
<string name="detail_settings_auth_user_entry_anon">Anonymous login</string>
|
||||||
<string name="detail_settings_auth_user_summary_none">No user selected to log in to the topic</string>
|
<string name="detail_settings_auth_user_summary_none">No user selected to log in to the topic</string>
|
||||||
<string name="detail_settings_auth_user_summary_user_x">User %1$s selected as a login user</string>
|
<string name="detail_settings_auth_user_summary_user_x">User %1$s selected as a login user</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue