mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Add checkbox preference, remove PushRulePreference, Split adavanced fragment to new 3 new fragments and inherit common function
This commit is contained in:
parent
2948f03978
commit
d6f1f276c2
14 changed files with 383 additions and 335 deletions
|
@ -111,7 +111,6 @@ import im.vector.app.features.roomprofile.settings.RoomSettingsFragment
|
|||
import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment
|
||||
import im.vector.app.features.roomprofile.uploads.files.RoomUploadsFilesFragment
|
||||
import im.vector.app.features.roomprofile.uploads.media.RoomUploadsMediaFragment
|
||||
import im.vector.app.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment
|
||||
import im.vector.app.features.settings.VectorSettingsGeneralFragment
|
||||
import im.vector.app.features.settings.VectorSettingsHelpAboutFragment
|
||||
import im.vector.app.features.settings.VectorSettingsLabsFragment
|
||||
|
@ -390,10 +389,10 @@ interface FragmentModule {
|
|||
@FragmentKey(VectorSettingsNotificationsTroubleshootFragment::class)
|
||||
fun bindVectorSettingsNotificationsTroubleshootFragment(fragment: VectorSettingsNotificationsTroubleshootFragment): Fragment
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FragmentKey(VectorSettingsAdvancedNotificationPreferenceFragment::class)
|
||||
fun bindVectorSettingsAdvancedNotificationPreferenceFragment(fragment: VectorSettingsAdvancedNotificationPreferenceFragment): Fragment
|
||||
// @Binds
|
||||
// @IntoMap
|
||||
// @FragmentKey(VectorSettingsAdvancedNotificationPreferenceFragment::class)
|
||||
// fun bindVectorSettingsAdvancedNotificationPreferenceFragment(fragment: VectorSettingsAdvancedNotificationPreferenceFragment): Fragment
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.preference
|
||||
|
||||
import android.animation.Animator
|
||||
import android.animation.ArgbEvaluator
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
|
||||
open class VectorCheckboxPreference : CheckBoxPreference {
|
||||
// Note: @JvmOverload does not work here...
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
init {
|
||||
// Set to false to remove the space when there is no icon
|
||||
isIconSpaceReserved = true
|
||||
}
|
||||
|
||||
var isHighlighted = false
|
||||
set(value) {
|
||||
field = value
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
var currentHighlightAnimator: Animator? = null
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
// display the title in multi-line to avoid ellipsis.
|
||||
(holder.findViewById(android.R.id.title) as? TextView)?.isSingleLine = false
|
||||
|
||||
// cancel existing animation (find a way to resume if happens during anim?)
|
||||
currentHighlightAnimator?.cancel()
|
||||
|
||||
val itemView = holder.itemView
|
||||
if (isHighlighted) {
|
||||
val colorFrom = Color.TRANSPARENT
|
||||
val colorTo = ThemeUtils.getColor(itemView.context, R.attr.colorControlHighlight)
|
||||
currentHighlightAnimator = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo).apply {
|
||||
duration = 250 // milliseconds
|
||||
addUpdateListener { animator ->
|
||||
itemView.setBackgroundColor(animator.animatedValue as Int)
|
||||
}
|
||||
doOnEnd {
|
||||
currentHighlightAnimator = ValueAnimator.ofObject(ArgbEvaluator(), colorTo, colorFrom).apply {
|
||||
duration = 250 // milliseconds
|
||||
addUpdateListener { animator ->
|
||||
itemView.setBackgroundColor(animator.animatedValue as Int)
|
||||
}
|
||||
doOnEnd {
|
||||
isHighlighted = false
|
||||
}
|
||||
start()
|
||||
}
|
||||
}
|
||||
startDelay = 200
|
||||
start()
|
||||
}
|
||||
} else {
|
||||
itemView.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
|
||||
super.onBindViewHolder(holder)
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.preference.PushRulePreference
|
||||
import im.vector.app.core.preference.VectorPreference
|
||||
import im.vector.app.core.utils.toast
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsAdvancedNotificationPreferenceFragment @Inject constructor()
|
||||
: VectorSettingsBaseFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_advanced
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_advanced_preferences
|
||||
|
||||
override fun bindPref() {
|
||||
for (preferenceKey in prefKeyToPushRuleId.keys) {
|
||||
val preference = findPreference<VectorPreference>(preferenceKey)
|
||||
if (preference is PushRulePreference) {
|
||||
// preference.isEnabled = null != rules && isConnected && pushManager.areDeviceNotificationsAllowed()
|
||||
val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey])
|
||||
|
||||
if (ruleAndKind == null) {
|
||||
// The rule is not defined, hide the preference
|
||||
preference.isVisible = false
|
||||
} else {
|
||||
preference.isVisible = true
|
||||
preference.setPushRule(ruleAndKind)
|
||||
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val newRule = preference.createNewRule(newValue as Int)
|
||||
if (newRule != null) {
|
||||
displayLoadingView()
|
||||
|
||||
lifecycleScope.launch {
|
||||
val result = runCatching {
|
||||
session.updatePushRuleActions(ruleAndKind.kind,
|
||||
preference.ruleAndKind?.pushRule ?: ruleAndKind.pushRule,
|
||||
newRule)
|
||||
}
|
||||
if (!isAdded) {
|
||||
return@launch
|
||||
}
|
||||
hideLoadingView()
|
||||
result.onSuccess {
|
||||
preference.setPushRule(ruleAndKind.copy(pushRule = newRule))
|
||||
}
|
||||
result.onFailure { failure ->
|
||||
// Restore the previous value
|
||||
refreshDisplay()
|
||||
activity?.toast(errorFormatter.toHumanReadable(failure))
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshDisplay() {
|
||||
listView?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
* Companion
|
||||
* ========================================================================================== */
|
||||
|
||||
companion object {
|
||||
// preference name <-> rule Id
|
||||
private val prefKeyToPushRuleId = mapOf(
|
||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME,
|
||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_USER_NAME,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
|
||||
"SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_INVITE_ME,
|
||||
"SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY" to RuleIds.RULE_ID_CALL,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY" to RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_ROOM_NOTIF,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ENCRYPTED,
|
||||
"SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY" to RuleIds.RULE_ID_TOMBSTONE
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsGlobalNotificationPreferenceFragment @Inject constructor()
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_global
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_global
|
||||
|
||||
override val prefKeyToPushRuleId: Map<String, String>
|
||||
get() = mapOf(
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ONE_TO_ONE_ENCRYPTED_ROOM,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY" to RuleIds.RULE_ID_ENCRYPTED
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsKeywordAndMentionsNotificationPreferenceFragment @Inject constructor()
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_mentions_and_keywords
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_mentions_and_keywords
|
||||
|
||||
override val prefKeyToPushRuleId: Map<String, String>
|
||||
get() = mapOf(
|
||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME,
|
||||
"SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY" to RuleIds.RULE_ID_CONTAIN_USER_NAME,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_ROOM_NOTIF
|
||||
)
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import im.vector.app.R
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsOtherNotificationPreferenceFragment @Inject constructor()
|
||||
: VectorSettingsPushRuleNotificationPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notification_other
|
||||
|
||||
override val preferenceXmlRes = R.xml.vector_settings_notification_other
|
||||
|
||||
override val prefKeyToPushRuleId: Map<String, String>
|
||||
get() = mapOf(
|
||||
"SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY" to RuleIds.RULE_ID_INVITE_ME,
|
||||
"SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY" to RuleIds.RULE_ID_CALL,
|
||||
"SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY" to RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS,
|
||||
"SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY" to RuleIds.RULE_ID_TOMBSTONE
|
||||
)
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2018 New Vector Ltd
|
||||
* Copyright (c) 2021 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,43 +14,39 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package im.vector.app.core.preference
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.RadioGroup
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import im.vector.app.R
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.core.preference.VectorCheckboxPreference
|
||||
import im.vector.app.core.utils.toast
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.pushrules.Action
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
import org.matrix.android.sdk.api.pushrules.RuleSetKey
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRule
|
||||
import org.matrix.android.sdk.api.pushrules.rest.PushRuleAndKind
|
||||
|
||||
class PushRulePreference : VectorPreference {
|
||||
abstract class VectorSettingsPushRuleNotificationPreferenceFragment
|
||||
: VectorSettingsBaseFragment() {
|
||||
|
||||
/**
|
||||
* @return the selected push rule and its kind
|
||||
*/
|
||||
var ruleAndKind: PushRuleAndKind? = null
|
||||
private set
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
fun indexFromBooleanPreference(pushRuleOn: Boolean): Int {
|
||||
return if (pushRuleOn) {
|
||||
NOTIFICATION_NOISY_INDEX
|
||||
} else {
|
||||
NOTIFICATION_OFF_INDEX
|
||||
}
|
||||
}
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.vector_preference_push_rule
|
||||
fun booleanPreferenceFromIndex(index: Int): Boolean {
|
||||
return index != NOTIFICATION_OFF_INDEX
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bing rule status index
|
||||
*/
|
||||
private val ruleStatusIndex: Int
|
||||
get() {
|
||||
fun ruleStatusIndexFor(ruleAndKind: PushRuleAndKind? ): Int {
|
||||
val safeRule = ruleAndKind?.pushRule ?: return NOTIFICATION_OFF_INDEX
|
||||
|
||||
if (safeRule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
||||
|
@ -78,36 +74,16 @@ class PushRulePreference : VectorPreference {
|
|||
return NOTIFICATION_OFF_INDEX
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the push rule.
|
||||
*
|
||||
* @param pushRule
|
||||
*/
|
||||
fun setPushRule(pushRuleAndKind: PushRuleAndKind?) {
|
||||
ruleAndKind = pushRuleAndKind
|
||||
refreshSummary()
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the summary
|
||||
*/
|
||||
private fun refreshSummary() {
|
||||
summary = context.getString(when (ruleStatusIndex) {
|
||||
NOTIFICATION_OFF_INDEX -> R.string.notification_off
|
||||
NOTIFICATION_SILENT_INDEX -> R.string.notification_silent
|
||||
else -> R.string.notification_noisy
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a push rule with the updated required at index.
|
||||
*
|
||||
* @param index index
|
||||
* @return a push rule with the updated flags / null if there is no update
|
||||
*/
|
||||
fun createNewRule(index: Int): PushRule? {
|
||||
fun createNewRule(ruleAndKind: PushRuleAndKind?, index: Int): PushRule? {
|
||||
val safeRule = ruleAndKind?.pushRule ?: return null
|
||||
val safeKind = ruleAndKind?.kind ?: return null
|
||||
val safeKind = ruleAndKind.kind
|
||||
val ruleStatusIndex = ruleStatusIndexFor(ruleAndKind)
|
||||
|
||||
return if (index != ruleStatusIndex) {
|
||||
if (safeRule.ruleId == RuleIds.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS) {
|
||||
|
@ -126,7 +102,7 @@ class PushRulePreference : VectorPreference {
|
|||
.setNotify(true)
|
||||
.setNotificationSound()
|
||||
}
|
||||
else -> safeRule
|
||||
else -> safeRule
|
||||
}
|
||||
} else {
|
||||
if (NOTIFICATION_OFF_INDEX == index) {
|
||||
|
@ -160,43 +136,67 @@ class PushRulePreference : VectorPreference {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
holder.findViewById(android.R.id.summary)?.visibility = View.GONE
|
||||
holder.itemView.setOnClickListener(null)
|
||||
holder.itemView.setOnLongClickListener(null)
|
||||
override fun bindPref() {
|
||||
for (preferenceKey in prefKeyToPushRuleId.keys) {
|
||||
val preference = findPreference<VectorCheckboxPreference>(preferenceKey)!!
|
||||
// preference.isEnabled = null != rules && isConnected && pushManager.areDeviceNotificationsAllowed()
|
||||
val ruleAndKind: PushRuleAndKind? = session.getPushRules().findDefaultRule(prefKeyToPushRuleId[preferenceKey])
|
||||
|
||||
val radioGroup = holder.findViewById(R.id.bingPreferenceRadioGroup) as? RadioGroup
|
||||
radioGroup?.setOnCheckedChangeListener(null)
|
||||
if (ruleAndKind == null) {
|
||||
// The rule is not defined, hide the preference
|
||||
preference.isVisible = false
|
||||
} else {
|
||||
preference.isVisible = true
|
||||
|
||||
when (ruleStatusIndex) {
|
||||
NOTIFICATION_OFF_INDEX -> {
|
||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleOff)
|
||||
}
|
||||
NOTIFICATION_SILENT_INDEX -> {
|
||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleSilent)
|
||||
}
|
||||
else -> {
|
||||
radioGroup?.check(R.id.bingPreferenceRadioBingRuleNoisy)
|
||||
}
|
||||
}
|
||||
val index = ruleStatusIndexFor(ruleAndKind)
|
||||
val boolPreference = booleanPreferenceFromIndex(index)
|
||||
preference.isChecked = boolPreference
|
||||
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||
val newIndex = indexFromBooleanPreference(newValue as Boolean)
|
||||
val newRule = createNewRule(ruleAndKind, newIndex)
|
||||
|
||||
radioGroup?.setOnCheckedChangeListener { _, checkedId ->
|
||||
when (checkedId) {
|
||||
R.id.bingPreferenceRadioBingRuleOff -> {
|
||||
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_OFF_INDEX)
|
||||
}
|
||||
R.id.bingPreferenceRadioBingRuleSilent -> {
|
||||
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_SILENT_INDEX)
|
||||
}
|
||||
R.id.bingPreferenceRadioBingRuleNoisy -> {
|
||||
onPreferenceChangeListener?.onPreferenceChange(this, NOTIFICATION_NOISY_INDEX)
|
||||
if (newRule != null) {
|
||||
displayLoadingView()
|
||||
|
||||
lifecycleScope.launch {
|
||||
val result = runCatching {
|
||||
session.updatePushRuleActions(
|
||||
ruleAndKind.kind,
|
||||
ruleAndKind.pushRule,
|
||||
newRule
|
||||
)
|
||||
}
|
||||
if (!isAdded) {
|
||||
return@launch
|
||||
}
|
||||
hideLoadingView()
|
||||
result.onSuccess {
|
||||
preference.isChecked = newValue
|
||||
}
|
||||
result.onFailure { failure ->
|
||||
// Restore the previous value
|
||||
refreshDisplay()
|
||||
activity?.toast(errorFormatter.toHumanReadable(failure))
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun refreshDisplay() {
|
||||
listView?.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/* ==========================================================================================
|
||||
* Companion
|
||||
* ========================================================================================== */
|
||||
|
||||
abstract val prefKeyToPushRuleId: Map<String, String>
|
||||
|
||||
companion object {
|
||||
|
||||
// index in mRuleStatuses
|
|
@ -1,79 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:baselineAligned="false"
|
||||
android:clipToPadding="false"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingLeft"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingRight">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?textAppearanceListItem"
|
||||
android:textColor="?vctr_content_primary"
|
||||
tools:text="Title" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
style="@style/Widget.Vector.TextView.Body"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:maxLines="2"
|
||||
android:paddingTop="6dp"
|
||||
android:textAppearance="?textAppearanceListItemSecondary"
|
||||
android:textColor="?vctr_content_secondary"
|
||||
tools:text="Summary"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/bingPreferenceRadioGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/bingPreferenceRadioBingRuleOff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_off"
|
||||
tools:checked="true" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/bingPreferenceRadioBingRuleSilent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_silent" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/bingPreferenceRadioBingRuleNoisy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/notification_noisy" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -1075,6 +1075,12 @@
|
|||
<string name="settings_notification_advanced">Advanced Notification Settings</string>
|
||||
<string name="settings_notification_by_event">Notification importance by event</string>
|
||||
|
||||
<string name="settings_notification_global">Global Notifications</string>
|
||||
<string name="settings_notification_mentions_and_keywords">Mentions and Keywords</string>
|
||||
<string name="settings_notification_other">Other</string>
|
||||
|
||||
<string name="settings_notification_notify_me_for">Notify me for</string>
|
||||
|
||||
<string name="settings_notification_privacy">Notification privacy</string>
|
||||
<string name="settings_notification_troubleshoot">Troubleshoot Notifications</string>
|
||||
<string name="settings_troubleshoot_diagnostic">Troubleshooting diagnostics</string>
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:key="SETTINGS_NOTIFICATION_LEVEL"
|
||||
android:title="@string/settings_notification_by_event">
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_containing_my_display_name" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_containing_my_user_name" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_at_room" />
|
||||
|
||||
<!-- TODO Support message with keywords rule -->
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_one_to_one" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_e2e_one_to_one" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_group_chat" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_e2e_group_chat" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_invited_to_room" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_call_invitations" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_sent_by_bot" />
|
||||
|
||||
<im.vector.app.core.preference.PushRulePreference
|
||||
android:key="SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_when_rooms_are_upgraded" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:key="SETTINGS_OTHER"
|
||||
android:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_ONE_TO_ONE_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_one_to_one" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_ONE_ONE_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_e2e_one_to_one" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_group_chat" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_IN_E2E_GROUP_CHAT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_in_e2e_group_chat" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</PreferenceScreen>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:key="SETTINGS_KEYWORDS_AND_MENTIONS"
|
||||
android:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_DISPLAY_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_containing_my_display_name" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CONTAINING_MY_USER_NAME_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_containing_my_user_name" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_CONTAINING_AT_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_at_room" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</PreferenceScreen>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:key="SETTINGS_OTHER"
|
||||
android:title="@string/settings_notification_notify_me_for">
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_INVITED_TO_ROOM_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_invited_to_room" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_CALL_INVITATIONS_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_call_invitations" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_messages_sent_by_bot" />
|
||||
|
||||
<im.vector.app.core.preference.VectorCheckboxPreference
|
||||
android:key="SETTINGS_PUSH_RULE_ROOMS_UPGRADED_KEY"
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_when_rooms_are_upgraded" />
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
</PreferenceScreen>
|
|
@ -22,11 +22,24 @@
|
|||
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_GLOBAL_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:summary="@string/settings_notification_advanced_summary"
|
||||
android:title="@string/settings_notification_advanced"
|
||||
app:fragment="im.vector.app.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment" />
|
||||
android:title="@string/settings_notification_global"
|
||||
app:fragment="im.vector.app.features.settings.VectorSettingsGlobalNotificationPreferenceFragment" />
|
||||
|
||||
<!-- <im.vector.app.core.preference.VectorPreference-->
|
||||
<!-- android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"-->
|
||||
<!-- android:key="SETTINGS_NOTIFICATION_KEYWORD_AND_MENTIONS_PREFERENCE_KEY"-->
|
||||
<!-- android:persistent="false"-->
|
||||
<!-- android:title="@string/settings_notification_mentions_and_keywords"-->
|
||||
<!-- app:fragment="im.vector.app.features.settings.VectorSettingsKeywordAndMentionsNotificationPreferenceFragment" />-->
|
||||
|
||||
<!-- <im.vector.app.core.preference.VectorPreference-->
|
||||
<!-- android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"-->
|
||||
<!-- android:key="SETTINGS_NOTIFICATION_OTHER_PREFERENCE_KEY"-->
|
||||
<!-- android:persistent="false"-->
|
||||
<!-- android:title="@string/settings_notification_other"-->
|
||||
<!-- app:fragment="im.vector.app.features.settings.VectorSettingsOtherNotificationPreferenceFragment" />-->
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
|
|
Loading…
Reference in a new issue