mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 10:55:38 +03:00
Merge pull request #232 from vector-im/feature/settings_v2_clean_notif
Cleans notification pref screen
This commit is contained in:
commit
f98f0e1a87
12 changed files with 168 additions and 309 deletions
|
@ -61,4 +61,6 @@ interface PushersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun livePushers(): LiveData<List<Pusher>>
|
fun livePushers(): LiveData<List<Pusher>>
|
||||||
|
|
||||||
|
fun pushers() : List<Pusher>
|
||||||
}
|
}
|
|
@ -503,6 +503,10 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
|
||||||
return pushersService.livePushers()
|
return pushersService.livePushers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun pushers(): List<Pusher> {
|
||||||
|
return pushersService.pushers()
|
||||||
|
}
|
||||||
|
|
||||||
override fun getPushRules(scope: String): List<PushRule> {
|
override fun getPushRules(scope: String): List<PushRule> {
|
||||||
return pushRuleService.getPushRules(scope)
|
return pushRuleService.getPushRules(scope)
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ internal class DefaultPusherService(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeHttpPusher(pushkey: String, appId: String, callback: MatrixCallback<Unit>) {
|
override fun removeHttpPusher(pushkey: String, appId: String, callback: MatrixCallback<Unit>) {
|
||||||
val params = RemovePusherTask.Params(sessionParam.credentials.userId,pushkey,appId)
|
val params = RemovePusherTask.Params(sessionParam.credentials.userId, pushkey, appId)
|
||||||
removePusherTask
|
removePusherTask
|
||||||
.configureWith(params)
|
.configureWith(params)
|
||||||
.dispatchTo(callback)
|
.dispatchTo(callback)
|
||||||
|
@ -111,4 +111,8 @@ internal class DefaultPusherService(
|
||||||
{ it.asDomain() }
|
{ it.asDomain() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun pushers(): List<Pusher> {
|
||||||
|
return monarchy.fetchAllCopiedSync { PusherEntity.where(it, sessionParam.credentials.userId) }.map { it.asDomain() }
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.utils.startAddGoogleAccountIntent
|
import im.vector.riotredesign.core.utils.startAddGoogleAccountIntent
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
||||||
|
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -58,6 +59,7 @@ class TestFirebaseToken(val fragment: Fragment) : TroubleshootTest(R.string.sett
|
||||||
val tok = it.substring(0, Math.min(8, it.length)) + "********************"
|
val tok = it.substring(0, Math.min(8, it.length)) + "********************"
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_fcm_success, tok)
|
description = fragment.getString(R.string.settings_troubleshoot_test_fcm_success, tok)
|
||||||
Timber.e("Retrieved FCM token success [$it].")
|
Timber.e("Retrieved FCM token success [$it].")
|
||||||
|
FcmHelper.storeFcmToken(fragment.requireContext(),tok)
|
||||||
}
|
}
|
||||||
status = TestStatus.SUCCESS
|
status = TestStatus.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,16 @@
|
||||||
package im.vector.riotredesign.gplay.features.settings.troubleshoot
|
package im.vector.riotredesign.gplay.features.settings.troubleshoot
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import androidx.work.WorkInfo
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import im.vector.matrix.android.api.Matrix
|
||||||
|
import im.vector.matrix.android.api.session.pushers.PusherState
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.core.pushers.PushersManager
|
||||||
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
||||||
|
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||||
|
import org.koin.android.ext.android.get
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force registration of the token to HomeServer
|
* Force registration of the token to HomeServer
|
||||||
|
@ -25,32 +33,45 @@ import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
|
||||||
class TestTokenRegistration(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) {
|
class TestTokenRegistration(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_token_registration_title) {
|
||||||
|
|
||||||
override fun perform() {
|
override fun perform() {
|
||||||
/*
|
//Check if we have a registered pusher for this token
|
||||||
TODO
|
val fcmToken = FcmHelper.getFcmToken(fragment.requireContext()) ?: run {
|
||||||
Matrix.getInstance(VectorApp.getInstance().baseContext).pushManager.forceSessionsRegistration(object : MatrixCallback<Unit> {
|
status = TestStatus.FAILED
|
||||||
override fun onSuccess(info: Void?) {
|
return
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_success)
|
}
|
||||||
status = TestStatus.SUCCESS
|
|
||||||
|
val session = Matrix.getInstance().currentSession ?: run {
|
||||||
|
status = TestStatus.FAILED
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val pusher = session.pushers().filter {
|
||||||
|
it.pushKey == fcmToken && it.state == PusherState.REGISTERED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pusher == null) {
|
||||||
|
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, null)
|
||||||
|
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_token_registration_quick_fix) {
|
||||||
|
override fun doFix() {
|
||||||
|
val workId = fragment.get<PushersManager>().registerPusherWithFcmKey(fcmToken)
|
||||||
|
WorkManager.getInstance().getWorkInfoByIdLiveData(workId).observe(fragment, Observer { workInfo ->
|
||||||
|
if (workInfo != null) {
|
||||||
|
if (workInfo.state == WorkInfo.State.SUCCEEDED) {
|
||||||
|
manager?.retry()
|
||||||
|
} else if (workInfo.state == WorkInfo.State.FAILED) {
|
||||||
|
manager?.retry()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNetworkError(e: Exception?) {
|
status = TestStatus.FAILED
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
|
|
||||||
status = TestStatus.FAILED
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMatrixError(e: MatrixError?) {
|
} else {
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
|
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_success)
|
||||||
status = TestStatus.FAILED
|
status = TestStatus.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUnexpectedError(e: Exception?) {
|
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
|
|
||||||
status = TestStatus.FAILED
|
|
||||||
}
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
status = TestStatus.FAILED
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.resources.AppNameProvider
|
import im.vector.riotredesign.core.resources.AppNameProvider
|
||||||
import im.vector.riotredesign.core.resources.LocaleProvider
|
import im.vector.riotredesign.core.resources.LocaleProvider
|
||||||
import im.vector.riotredesign.core.resources.StringProvider
|
import im.vector.riotredesign.core.resources.StringProvider
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
private const val DEFAULT_PUSHER_FILE_TAG = "mobile"
|
private const val DEFAULT_PUSHER_FILE_TAG = "mobile"
|
||||||
|
|
||||||
|
@ -16,10 +17,10 @@ class PushersManager(
|
||||||
private val appNameProvider: AppNameProvider
|
private val appNameProvider: AppNameProvider
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun registerPusherWithFcmKey(pushKey: String) {
|
fun registerPusherWithFcmKey(pushKey: String) : UUID {
|
||||||
var profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + Math.abs(currentSession.sessionParams.credentials.userId.hashCode())
|
var profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + Math.abs(currentSession.sessionParams.credentials.userId.hashCode())
|
||||||
|
|
||||||
currentSession.addHttpPusher(
|
return currentSession.addHttpPusher(
|
||||||
pushKey,
|
pushKey,
|
||||||
stringProvider.getString(R.string.pusher_app_id),
|
stringProvider.getString(R.string.pusher_app_id),
|
||||||
profileTag,
|
profileTag,
|
||||||
|
|
|
@ -25,14 +25,15 @@ import android.net.Uri;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import im.vector.riotredesign.R;
|
import im.vector.riotredesign.R;
|
||||||
import im.vector.riotredesign.features.homeserver.ServerUrlsRepository;
|
import im.vector.riotredesign.features.homeserver.ServerUrlsRepository;
|
||||||
import im.vector.riotredesign.features.themes.ThemeUtils;
|
import im.vector.riotredesign.features.themes.ThemeUtils;
|
||||||
|
@ -117,7 +118,7 @@ public class PreferencesManager {
|
||||||
public static final String SETTINGS_NOTIFICATIONS_KEY = "SETTINGS_NOTIFICATIONS_KEY";
|
public static final String SETTINGS_NOTIFICATIONS_KEY = "SETTINGS_NOTIFICATIONS_KEY";
|
||||||
public static final String SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY = "SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY";
|
public static final String SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY = "SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY";
|
||||||
public static final String SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY = "SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY";
|
public static final String SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY = "SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY";
|
||||||
public static final String SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY = "SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY";
|
// public static final String SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY = "SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY";
|
||||||
public static final String SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY";
|
public static final String SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_CALL_NOTIFICATION_PREFERENCE_KEY";
|
||||||
public static final String SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY";
|
public static final String SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_NOISY_NOTIFICATION_PREFERENCE_KEY";
|
||||||
public static final String SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY";
|
public static final String SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY = "SETTINGS_SYSTEM_SILENT_NOTIFICATION_PREFERENCE_KEY";
|
||||||
|
@ -245,6 +246,13 @@ public class PreferencesManager {
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, true);
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setNotificationEnabledForDevice(Context context, Boolean enabled) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
|
.edit()
|
||||||
|
.putBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, enabled)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
|
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,14 +16,13 @@
|
||||||
|
|
||||||
package im.vector.riotredesign.features.settings
|
package im.vector.riotredesign.features.settings
|
||||||
|
|
||||||
import androidx.preference.EditTextPreference
|
import android.widget.Toast
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceCategory
|
|
||||||
import androidx.preference.SwitchPreference
|
import androidx.preference.SwitchPreference
|
||||||
import im.vector.matrix.android.api.Matrix
|
import im.vector.matrix.android.api.Matrix
|
||||||
import im.vector.matrix.android.api.MatrixCallback
|
import im.vector.matrix.android.api.MatrixCallback
|
||||||
|
import im.vector.matrix.android.api.pushrules.RuleIds
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.core.preference.BingRule
|
|
||||||
import im.vector.riotredesign.core.pushers.PushersManager
|
import im.vector.riotredesign.core.pushers.PushersManager
|
||||||
import im.vector.riotredesign.push.fcm.FcmHelper
|
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
|
@ -36,45 +35,19 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
|
||||||
|
|
||||||
val pushManager: PushersManager by inject()
|
val pushManager: PushersManager by inject()
|
||||||
|
|
||||||
// background sync category
|
|
||||||
private val mSyncRequestTimeoutPreference by lazy {
|
|
||||||
// ? Cause it can be removed
|
|
||||||
findPreference(PreferencesManager.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY) as EditTextPreference?
|
|
||||||
}
|
|
||||||
private val mSyncRequestDelayPreference by lazy {
|
|
||||||
// ? Cause it can be removed
|
|
||||||
findPreference(PreferencesManager.SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY) as EditTextPreference?
|
|
||||||
}
|
|
||||||
|
|
||||||
private val backgroundSyncCategory by lazy {
|
|
||||||
findPreference(PreferencesManager.SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY)
|
|
||||||
}
|
|
||||||
private val backgroundSyncDivider by lazy {
|
|
||||||
findPreference(PreferencesManager.SETTINGS_BACKGROUND_SYNC_DIVIDER_PREFERENCE_KEY)
|
|
||||||
}
|
|
||||||
private val backgroundSyncPreference by lazy {
|
|
||||||
findPreference(PreferencesManager.SETTINGS_ENABLE_BACKGROUND_SYNC_PREFERENCE_KEY) as SwitchPreference
|
|
||||||
}
|
|
||||||
|
|
||||||
private val notificationsSettingsCategory by lazy {
|
|
||||||
findPreference(PreferencesManager.SETTINGS_NOTIFICATIONS_KEY) as PreferenceCategory
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun bindPref() {
|
override fun bindPref() {
|
||||||
for (preferenceKey in mPrefKeyToBingRuleId.keys) {
|
findPreference(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY).let { pref ->
|
||||||
val preference = findPreference(preferenceKey)
|
val pushRuleService = Matrix.getInstance().currentSession ?: return
|
||||||
|
val mRuleMaster = pushRuleService.getPushRules()
|
||||||
|
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
|
||||||
|
|
||||||
if (null != preference) {
|
if (mRuleMaster == null) {
|
||||||
if (preference is SwitchPreference) {
|
pref.isVisible = false
|
||||||
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValueAsVoid ->
|
return
|
||||||
// on some old android APIs,
|
|
||||||
// the callback is called even if there is no user interaction
|
|
||||||
// so the value will be checked to ensure there is really no update.
|
|
||||||
// TODO onPushRuleClick(preference.key, newValueAsVoid as Boolean)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val areNotifEnabledAtAccountLevelt = !mRuleMaster.enabled
|
||||||
|
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevelt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,227 +58,70 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||||
if (preference?.key == PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY) {
|
|
||||||
val switchPref = preference as SwitchPreference
|
|
||||||
if (switchPref.isChecked) {
|
|
||||||
FcmHelper.getFcmToken(requireContext())?.let {
|
|
||||||
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) {
|
|
||||||
pushManager.registerPusherWithFcmKey(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FcmHelper.getFcmToken(requireContext())?.let {
|
|
||||||
pushManager.unregisterPusher(it, object : MatrixCallback<Unit> {
|
|
||||||
override fun onSuccess(data: Unit) {
|
|
||||||
super.onSuccess(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
|
||||||
super.onFailure(failure)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onPreferenceTreeClick(preference)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update a push rule.
|
|
||||||
*/
|
|
||||||
private fun onPushRuleClick(preferenceKey: String, newValue: Boolean) {
|
|
||||||
notImplemented()
|
|
||||||
/* TODO
|
|
||||||
val matrixInstance = Matrix.getInstance(context)
|
|
||||||
val pushManager = matrixInstance.pushManager
|
|
||||||
|
|
||||||
Timber.v("onPushRuleClick $preferenceKey : set to $newValue")
|
|
||||||
|
|
||||||
when (preferenceKey) {
|
|
||||||
|
|
||||||
PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY -> {
|
|
||||||
if (pushManager.isScreenTurnedOn != newValue) {
|
|
||||||
pushManager.isScreenTurnedOn = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return when (preference?.key) {
|
||||||
PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> {
|
PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> {
|
||||||
val isConnected = matrixInstance.isConnected
|
updateEnabledForDevice(preference)
|
||||||
val isAllowed = pushManager.areDeviceNotificationsAllowed()
|
true
|
||||||
|
|
||||||
// avoid useless update
|
|
||||||
if (isAllowed == newValue) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pushManager.setDeviceNotificationsAllowed(!isAllowed)
|
|
||||||
|
|
||||||
// when using FCM
|
|
||||||
// need to register on servers
|
|
||||||
if (isConnected && pushManager.useFcm() && (pushManager.isServerRegistered || pushManager.isServerUnRegistered)) {
|
|
||||||
val listener = object : MatrixCallback<Unit> {
|
|
||||||
|
|
||||||
private fun onDone() {
|
|
||||||
activity?.runOnUiThread {
|
|
||||||
hideLoadingView(true)
|
|
||||||
refreshPushersList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSuccess(info: Void?) {
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMatrixError(e: MatrixError?) {
|
|
||||||
// Set again the previous state
|
|
||||||
pushManager.setDeviceNotificationsAllowed(isAllowed)
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onNetworkError(e: java.lang.Exception?) {
|
|
||||||
// Set again the previous state
|
|
||||||
pushManager.setDeviceNotificationsAllowed(isAllowed)
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onUnexpectedError(e: java.lang.Exception?) {
|
|
||||||
// Set again the previous state
|
|
||||||
pushManager.setDeviceNotificationsAllowed(isAllowed)
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
displayLoadingView()
|
|
||||||
if (pushManager.isServerRegistered) {
|
|
||||||
pushManager.unregister(listener)
|
|
||||||
} else {
|
|
||||||
pushManager.register(listener)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> {
|
||||||
// check if there is an update
|
updateEnabledForAccount(preference)
|
||||||
|
true
|
||||||
// on some old android APIs,
|
}
|
||||||
// the callback is called even if there is no user interaction
|
else -> {
|
||||||
// so the value will be checked to ensure there is really no update.
|
return super.onPreferenceTreeClick(preference)
|
||||||
else -> {
|
|
||||||
|
|
||||||
val ruleId = mPrefKeyToBingRuleId[preferenceKey]
|
|
||||||
val rule = session.dataHandler.pushRules()?.findDefaultRule(ruleId)
|
|
||||||
|
|
||||||
// check if there is an update
|
|
||||||
var curValue = null != rule && rule.isEnabled
|
|
||||||
|
|
||||||
if (TextUtils.equals(ruleId, BingRule.RULE_ID_DISABLE_ALL) || TextUtils.equals(ruleId, BingRule.RULE_ID_SUPPRESS_BOTS_NOTIFICATIONS)) {
|
|
||||||
curValue = !curValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// on some old android APIs,
|
|
||||||
// the callback is called even if there is no user interaction
|
|
||||||
// so the value will be checked to ensure there is really no update.
|
|
||||||
if (newValue == curValue) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null != rule) {
|
|
||||||
displayLoadingView()
|
|
||||||
session.dataHandler.bingRulesManager.updateEnableRuleStatus(rule, !rule.isEnabled, object : BingRulesManager.onBingRuleUpdateListener {
|
|
||||||
private fun onDone() {
|
|
||||||
refreshDisplay()
|
|
||||||
hideLoadingView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBingRuleUpdateSuccess() {
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBingRuleUpdateFailure(errorMessage: String) {
|
|
||||||
activity?.toast(errorMessage)
|
|
||||||
onDone()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fun updateEnabledForDevice(preference: Preference?) {
|
||||||
* Refresh the background sync preference
|
val switchPref = preference as SwitchPreference
|
||||||
*/
|
if (switchPref.isChecked) {
|
||||||
private fun refreshBackgroundSyncPrefs() {
|
FcmHelper.getFcmToken(requireContext())?.let {
|
||||||
/* TODO
|
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) {
|
||||||
activity?.let { activity ->
|
pushManager.registerPusherWithFcmKey(it)
|
||||||
val pushManager = Matrix.getInstance(activity).pushManager
|
|
||||||
|
|
||||||
val timeout = pushManager.backgroundSyncTimeOut / 1000
|
|
||||||
val delay = pushManager.backgroundSyncDelay / 1000
|
|
||||||
|
|
||||||
// update the settings
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(activity).edit {
|
|
||||||
putString(PreferencesManager.SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY, timeout.toString() + "")
|
|
||||||
putString(PreferencesManager.SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY, delay.toString() + "")
|
|
||||||
}
|
|
||||||
|
|
||||||
mSyncRequestTimeoutPreference?.let {
|
|
||||||
it.summary = secondsToText(timeout)
|
|
||||||
it.text = timeout.toString() + ""
|
|
||||||
|
|
||||||
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
|
||||||
var newTimeOut = timeout
|
|
||||||
|
|
||||||
try {
|
|
||||||
newTimeOut = Integer.parseInt(newValue as String)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "## refreshBackgroundSyncPrefs : parseInt failed " + e.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newTimeOut != timeout) {
|
|
||||||
pushManager.backgroundSyncTimeOut = newTimeOut * 1000
|
|
||||||
|
|
||||||
activity.runOnUiThread { refreshBackgroundSyncPrefs() }
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
mSyncRequestDelayPreference?.let {
|
FcmHelper.getFcmToken(requireContext())?.let {
|
||||||
it.summary = secondsToText(delay)
|
pushManager.unregisterPusher(it, object : MatrixCallback<Unit> {
|
||||||
it.text = delay.toString() + ""
|
override fun onSuccess(data: Unit) {
|
||||||
|
Matrix.getInstance().currentSession?.refreshPushers()
|
||||||
it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
super.onSuccess(data)
|
||||||
var newDelay = delay
|
|
||||||
|
|
||||||
try {
|
|
||||||
newDelay = Integer.parseInt(newValue as String)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Timber.e(e, "## refreshBackgroundSyncPrefs : parseInt failed " + e.message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newDelay != delay) {
|
override fun onFailure(failure: Throwable) {
|
||||||
pushManager.backgroundSyncDelay = newDelay * 1000
|
Matrix.getInstance().currentSession?.refreshPushers()
|
||||||
|
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||||
activity.runOnUiThread { refreshBackgroundSyncPrefs() }
|
|
||||||
}
|
}
|
||||||
|
})
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val DUMMY_RULE = "DUMMY_RULE"
|
|
||||||
|
|
||||||
// preference name <-> rule Id
|
private fun updateEnabledForAccount(preference: Preference?) {
|
||||||
private var mPrefKeyToBingRuleId = mapOf(
|
val pushRuleService = Matrix.getInstance().currentSession ?: return
|
||||||
PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY to BingRule.RULE_ID_DISABLE_ALL,
|
val switchPref = preference as SwitchPreference
|
||||||
PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY to DUMMY_RULE,
|
pushRuleService.getPushRules()
|
||||||
PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY to DUMMY_RULE
|
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }
|
||||||
)
|
?.let {
|
||||||
|
//Trick, we must enable this room to disable notifications
|
||||||
|
pushRuleService.updatePushRuleEnableStatus("override", it, !switchPref.isChecked,
|
||||||
|
object : MatrixCallback<Unit> {
|
||||||
|
|
||||||
|
override fun onSuccess(data: Unit) {
|
||||||
|
pushRuleService.fetchPushRules()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(failure: Throwable) {
|
||||||
|
//revert the check box
|
||||||
|
switchPref.isChecked = !switchPref.isChecked
|
||||||
|
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,20 +16,20 @@
|
||||||
package im.vector.riotredesign.features.settings.troubleshoot
|
package im.vector.riotredesign.features.settings.troubleshoot
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import im.vector.matrix.android.api.pushrules.Action
|
||||||
|
import im.vector.matrix.android.api.pushrules.RuleIds
|
||||||
import im.vector.matrix.android.api.session.Session
|
import im.vector.matrix.android.api.session.Session
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.features.settings.PreferencesManager
|
import im.vector.riotredesign.features.notifications.NotificationAction
|
||||||
import im.vector.riotredesign.features.settings.VectorSettingsFragmentInteractionListener
|
|
||||||
|
|
||||||
class TestBingRulesSettings(val fragment: Fragment, val session: Session) : TroubleshootTest(R.string.settings_troubleshoot_test_bing_settings_title) {
|
class TestBingRulesSettings(val fragment: Fragment, val session: Session) : TroubleshootTest(R.string.settings_troubleshoot_test_bing_settings_title) {
|
||||||
|
|
||||||
private val testedRules = emptyArray<String>()
|
private val testedRules =
|
||||||
/* TODO
|
listOf(RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME,
|
||||||
arrayOf(BingRule.RULE_ID_CONTAIN_DISPLAY_NAME,
|
RuleIds.RULE_ID_CONTAIN_USER_NAME,
|
||||||
BingRule.RULE_ID_CONTAIN_USER_NAME,
|
RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
|
||||||
BingRule.RULE_ID_ONE_TO_ONE_ROOM,
|
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS)
|
||||||
BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS)
|
|
||||||
*/
|
|
||||||
|
|
||||||
val ruleSettingsName = arrayOf(R.string.settings_containing_my_display_name,
|
val ruleSettingsName = arrayOf(R.string.settings_containing_my_display_name,
|
||||||
R.string.settings_containing_my_user_name,
|
R.string.settings_containing_my_user_name,
|
||||||
|
@ -37,7 +37,7 @@ class TestBingRulesSettings(val fragment: Fragment, val session: Session) : Trou
|
||||||
R.string.settings_messages_in_group_chat)
|
R.string.settings_messages_in_group_chat)
|
||||||
|
|
||||||
override fun perform() {
|
override fun perform() {
|
||||||
val pushRules = null // TODO session.dataHandler.pushRules()
|
val pushRules = session.getPushRules()
|
||||||
if (pushRules == null) {
|
if (pushRules == null) {
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed_to_load_rules)
|
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed_to_load_rules)
|
||||||
status = TestStatus.FAILED
|
status = TestStatus.FAILED
|
||||||
|
@ -45,32 +45,34 @@ class TestBingRulesSettings(val fragment: Fragment, val session: Session) : Trou
|
||||||
var oneOrMoreRuleIsOff = false
|
var oneOrMoreRuleIsOff = false
|
||||||
var oneOrMoreRuleAreSilent = false
|
var oneOrMoreRuleAreSilent = false
|
||||||
for ((index, ruleId) in testedRules.withIndex()) {
|
for ((index, ruleId) in testedRules.withIndex()) {
|
||||||
/* TODO
|
pushRules.find { it.ruleId == ruleId }?.let { rule ->
|
||||||
pushRules.findDefaultRule(ruleId)?.let { rule ->
|
val actions = Action.mapFrom(rule) ?: return@let
|
||||||
if (!rule.isEnabled || rule.shouldNotNotify()) {
|
val notifAction = NotificationAction.extractFrom(actions)
|
||||||
|
if (!rule.enabled || !notifAction.shouldNotify) {
|
||||||
//off
|
//off
|
||||||
oneOrMoreRuleIsOff = true
|
oneOrMoreRuleIsOff = true
|
||||||
} else if (rule.notificationSound == null) {
|
} else if (notifAction.soundName == null) {
|
||||||
//silent
|
//silent
|
||||||
oneOrMoreRuleAreSilent = true
|
oneOrMoreRuleAreSilent = true
|
||||||
} else {
|
} else {
|
||||||
//noisy
|
//noisy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oneOrMoreRuleIsOff) {
|
if (oneOrMoreRuleIsOff) {
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed)
|
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed)
|
||||||
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_bing_settings_quickfix) {
|
//TODO
|
||||||
override fun doFix() {
|
// quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_bing_settings_quickfix) {
|
||||||
val activity = fragment.activity
|
// override fun doFix() {
|
||||||
if (activity is VectorSettingsFragmentInteractionListener) {
|
// val activity = fragment.activity
|
||||||
activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)
|
// if (activity is VectorSettingsFragmentInteractionListener) {
|
||||||
}
|
// activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)
|
||||||
activity?.supportFragmentManager?.popBackStack()
|
// }
|
||||||
}
|
// activity?.supportFragmentManager?.popBackStack()
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
status = TestStatus.FAILED
|
status = TestStatus.FAILED
|
||||||
} else {
|
} else {
|
||||||
if (oneOrMoreRuleAreSilent) {
|
if (oneOrMoreRuleAreSilent) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ package im.vector.riotredesign.features.settings.troubleshoot
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
|
import im.vector.riotredesign.features.settings.PreferencesManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if notifications are enable in the system settings for this app.
|
* Checks if notifications are enable in the system settings for this app.
|
||||||
|
@ -24,24 +25,20 @@ import im.vector.riotredesign.R
|
||||||
class TestDeviceSettings(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_device_settings_title) {
|
class TestDeviceSettings(val fragment: Fragment) : TroubleshootTest(R.string.settings_troubleshoot_test_device_settings_title) {
|
||||||
|
|
||||||
override fun perform() {
|
override fun perform() {
|
||||||
/* TODO
|
|
||||||
val pushManager = Matrix.getInstance(fragment.activity).pushManager
|
if (PreferencesManager.areNotificationEnabledForDevice(fragment.requireContext())) {
|
||||||
if (pushManager.areDeviceNotificationsAllowed()) {
|
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_success)
|
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_success)
|
||||||
quickFix = null
|
quickFix = null
|
||||||
status = TestStatus.SUCCESS
|
status = TestStatus.SUCCESS
|
||||||
} else {
|
} else {
|
||||||
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) {
|
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) {
|
||||||
override fun doFix() {
|
override fun doFix() {
|
||||||
pushManager.setDeviceNotificationsAllowed(true)
|
PreferencesManager.setNotificationEnabledForDevice(fragment.requireContext(), true)
|
||||||
manager?.retry()
|
manager?.retry()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_failed)
|
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_failed)
|
||||||
status = TestStatus.FAILED
|
status = TestStatus.FAILED
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
status = TestStatus.FAILED
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,4 +31,7 @@
|
||||||
<string name="preference_voice_and_video">Voice & Video</string>
|
<string name="preference_voice_and_video">Voice & Video</string>
|
||||||
<string name="preference_root_help_about">Help & About</string>
|
<string name="preference_root_help_about">Help & About</string>
|
||||||
|
|
||||||
|
|
||||||
|
<string name="settings_troubleshoot_test_token_registration_quick_fix">Register token</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -17,10 +17,10 @@
|
||||||
android:key="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
android:key="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||||
android:title="@string/settings_enable_this_device" />
|
android:title="@string/settings_enable_this_device" />
|
||||||
|
|
||||||
<im.vector.riotredesign.core.preference.VectorSwitchPreference
|
<!--<im.vector.riotredesign.core.preference.VectorSwitchPreference-->
|
||||||
android:dependency="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"
|
<!--android:dependency="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"-->
|
||||||
android:key="SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"
|
<!--android:key="SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"-->
|
||||||
android:title="@string/settings_turn_screen_on" />
|
<!--android:title="@string/settings_turn_screen_on" />-->
|
||||||
|
|
||||||
<im.vector.riotredesign.core.preference.VectorPreference
|
<im.vector.riotredesign.core.preference.VectorPreference
|
||||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||||
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
</im.vector.riotredesign.core.preference.VectorPreferenceCategory>
|
</im.vector.riotredesign.core.preference.VectorPreferenceCategory>
|
||||||
|
|
||||||
<im.vector.riotredesign.core.preference.VectorPreferenceDivider />
|
|
||||||
|
|
||||||
<!--im.vector.riotredesign.core.preference.VectorPreferenceCategory
|
<!--im.vector.riotredesign.core.preference.VectorPreferenceCategory
|
||||||
android:key="SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY"
|
android:key="SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY"
|
||||||
|
|
Loading…
Reference in a new issue