Merge pull request #232 from vector-im/feature/settings_v2_clean_notif

Cleans notification pref screen
This commit is contained in:
Benoit Marty 2019-06-27 14:12:12 +02:00 committed by GitHub
commit f98f0e1a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 168 additions and 309 deletions

View File

@ -61,4 +61,6 @@ interface PushersService {
}

fun livePushers(): LiveData<List<Pusher>>

fun pushers() : List<Pusher>
}

View File

@ -503,6 +503,10 @@ internal class DefaultSession(override val sessionParams: SessionParams) : Sessi
return pushersService.livePushers()
}

override fun pushers(): List<Pusher> {
return pushersService.pushers()
}

override fun getPushRules(scope: String): List<PushRule> {
return pushRuleService.getPushRules(scope)
}

View File

@ -97,7 +97,7 @@ internal class DefaultPusherService(
}

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
.configureWith(params)
.dispatchTo(callback)
@ -111,4 +111,8 @@ internal class DefaultPusherService(
{ it.asDomain() }
)
}

override fun pushers(): List<Pusher> {
return monarchy.fetchAllCopiedSync { PusherEntity.where(it, sessionParam.credentials.userId) }.map { it.asDomain() }
}
}

View File

@ -21,6 +21,7 @@ import im.vector.riotredesign.R
import im.vector.riotredesign.core.utils.startAddGoogleAccountIntent
import im.vector.riotredesign.features.settings.troubleshoot.NotificationTroubleshootTestManager
import im.vector.riotredesign.features.settings.troubleshoot.TroubleshootTest
import im.vector.riotredesign.push.fcm.FcmHelper
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)) + "********************"
description = fragment.getString(R.string.settings_troubleshoot_test_fcm_success, tok)
Timber.e("Retrieved FCM token success [$it].")
FcmHelper.storeFcmToken(fragment.requireContext(),tok)
}
status = TestStatus.SUCCESS
}

View File

@ -16,8 +16,16 @@
package im.vector.riotredesign.gplay.features.settings.troubleshoot

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.core.pushers.PushersManager
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
@ -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) {

override fun perform() {
/*
TODO
Matrix.getInstance(VectorApp.getInstance().baseContext).pushManager.forceSessionsRegistration(object : MatrixCallback<Unit> {
override fun onSuccess(info: Void?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_success)
status = TestStatus.SUCCESS
//Check if we have a registered pusher for this token
val fcmToken = FcmHelper.getFcmToken(fragment.requireContext()) ?: run {
status = TestStatus.FAILED
return
}

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?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}
status = TestStatus.FAILED

override fun onMatrixError(e: MatrixError?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}

override fun onUnexpectedError(e: Exception?) {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_failed, e?.localizedMessage)
status = TestStatus.FAILED
}
})
*/

status = TestStatus.FAILED
} else {
description = fragment.getString(R.string.settings_troubleshoot_test_token_registration_success)
status = TestStatus.SUCCESS
}

}


View File

@ -6,6 +6,7 @@ import im.vector.riotredesign.R
import im.vector.riotredesign.core.resources.AppNameProvider
import im.vector.riotredesign.core.resources.LocaleProvider
import im.vector.riotredesign.core.resources.StringProvider
import java.util.*

private const val DEFAULT_PUSHER_FILE_TAG = "mobile"

@ -16,10 +17,10 @@ class PushersManager(
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())

currentSession.addHttpPusher(
return currentSession.addHttpPusher(
pushKey,
stringProvider.getString(R.string.pusher_app_id),
profileTag,

View File

@ -25,14 +25,15 @@ import android.net.Uri;
import android.provider.MediaStore;
import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import im.vector.riotredesign.R;
import im.vector.riotredesign.features.homeserver.ServerUrlsRepository;
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_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_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_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";
@ -245,6 +246,13 @@ public class PreferencesManager {
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.
*

View File

@ -16,14 +16,13 @@

package im.vector.riotredesign.features.settings

import androidx.preference.EditTextPreference
import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.SwitchPreference
import im.vector.matrix.android.api.Matrix
import im.vector.matrix.android.api.MatrixCallback
import im.vector.matrix.android.api.pushrules.RuleIds
import im.vector.riotredesign.R
import im.vector.riotredesign.core.preference.BingRule
import im.vector.riotredesign.core.pushers.PushersManager
import im.vector.riotredesign.push.fcm.FcmHelper
import org.koin.android.ext.android.inject
@ -36,45 +35,19 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(

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() {
for (preferenceKey in mPrefKeyToBingRuleId.keys) {
val preference = findPreference(preferenceKey)
findPreference(PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY).let { pref ->
val pushRuleService = Matrix.getInstance().currentSession ?: return
val mRuleMaster = pushRuleService.getPushRules()
.find { it.ruleId == RuleIds.RULE_ID_DISABLE_ALL }

if (null != preference) {
if (preference is SwitchPreference) {
preference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValueAsVoid ->
// 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
}
}
if (mRuleMaster == null) {
pref.isVisible = false
return
}

val areNotifEnabledAtAccountLevelt = !mRuleMaster.enabled
(pref as SwitchPreference).isChecked = areNotifEnabledAtAccountLevelt
}
}

@ -85,227 +58,70 @@ class VectorSettingsNotificationPreferenceFragment : VectorSettingsBaseFragment(
}

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 -> {
val isConnected = matrixInstance.isConnected
val isAllowed = pushManager.areDeviceNotificationsAllowed()

// 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)
}
}
updateEnabledForDevice(preference)
true
}

// check if there is an update

// 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.
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()
}
})
}
PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> {
updateEnabledForAccount(preference)
true
}
else -> {
return super.onPreferenceTreeClick(preference)
}
}
*/

}

/**
* Refresh the background sync preference
*/
private fun refreshBackgroundSyncPrefs() {
/* TODO
activity?.let { activity ->
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
private fun updateEnabledForDevice(preference: Preference?) {
val switchPref = preference as SwitchPreference
if (switchPref.isChecked) {
FcmHelper.getFcmToken(requireContext())?.let {
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) {
pushManager.registerPusherWithFcmKey(it)
}
}

mSyncRequestDelayPreference?.let {
it.summary = secondsToText(delay)
it.text = delay.toString() + ""

it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
var newDelay = delay

try {
newDelay = Integer.parseInt(newValue as String)
} catch (e: Exception) {
Timber.e(e, "## refreshBackgroundSyncPrefs : parseInt failed " + e.message)
} else {
FcmHelper.getFcmToken(requireContext())?.let {
pushManager.unregisterPusher(it, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
Matrix.getInstance().currentSession?.refreshPushers()
super.onSuccess(data)
}

if (newDelay != delay) {
pushManager.backgroundSyncDelay = newDelay * 1000

activity.runOnUiThread { refreshBackgroundSyncPrefs() }
override fun onFailure(failure: Throwable) {
Matrix.getInstance().currentSession?.refreshPushers()
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
}

false
}
})
}
}
*/
}

companion object {
private const val DUMMY_RULE = "DUMMY_RULE"

// preference name <-> rule Id
private var mPrefKeyToBingRuleId = mapOf(
PreferencesManager.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY to BingRule.RULE_ID_DISABLE_ALL,
PreferencesManager.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY to DUMMY_RULE,
PreferencesManager.SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY to DUMMY_RULE
)
private fun updateEnabledForAccount(preference: Preference?) {
val pushRuleService = Matrix.getInstance().currentSession ?: return
val switchPref = preference as SwitchPreference
pushRuleService.getPushRules()
.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()
}
})
}

}

}

View File

@ -16,20 +16,20 @@
package im.vector.riotredesign.features.settings.troubleshoot

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.riotredesign.R
import im.vector.riotredesign.features.settings.PreferencesManager
import im.vector.riotredesign.features.settings.VectorSettingsFragmentInteractionListener
import im.vector.riotredesign.features.notifications.NotificationAction

class TestBingRulesSettings(val fragment: Fragment, val session: Session) : TroubleshootTest(R.string.settings_troubleshoot_test_bing_settings_title) {

private val testedRules = emptyArray<String>()
/* TODO
arrayOf(BingRule.RULE_ID_CONTAIN_DISPLAY_NAME,
BingRule.RULE_ID_CONTAIN_USER_NAME,
BingRule.RULE_ID_ONE_TO_ONE_ROOM,
BingRule.RULE_ID_ALL_OTHER_MESSAGES_ROOMS)
*/
private val testedRules =
listOf(RuleIds.RULE_ID_CONTAIN_DISPLAY_NAME,
RuleIds.RULE_ID_CONTAIN_USER_NAME,
RuleIds.RULE_ID_ONE_TO_ONE_ROOM,
RuleIds.RULE_ID_ALL_OTHER_MESSAGES_ROOMS)


val ruleSettingsName = arrayOf(R.string.settings_containing_my_display_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)

override fun perform() {
val pushRules = null // TODO session.dataHandler.pushRules()
val pushRules = session.getPushRules()
if (pushRules == null) {
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed_to_load_rules)
status = TestStatus.FAILED
@ -45,32 +45,34 @@ class TestBingRulesSettings(val fragment: Fragment, val session: Session) : Trou
var oneOrMoreRuleIsOff = false
var oneOrMoreRuleAreSilent = false
for ((index, ruleId) in testedRules.withIndex()) {
/* TODO
pushRules.findDefaultRule(ruleId)?.let { rule ->
if (!rule.isEnabled || rule.shouldNotNotify()) {
pushRules.find { it.ruleId == ruleId }?.let { rule ->
val actions = Action.mapFrom(rule) ?: return@let
val notifAction = NotificationAction.extractFrom(actions)
if (!rule.enabled || !notifAction.shouldNotify) {
//off
oneOrMoreRuleIsOff = true
} else if (rule.notificationSound == null) {
} else if (notifAction.soundName == null) {
//silent
oneOrMoreRuleAreSilent = true
} else {
//noisy
}
}
*/

}

if (oneOrMoreRuleIsOff) {
description = fragment.getString(R.string.settings_troubleshoot_test_bing_settings_failed)
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_bing_settings_quickfix) {
override fun doFix() {
val activity = fragment.activity
if (activity is VectorSettingsFragmentInteractionListener) {
activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)
}
activity?.supportFragmentManager?.popBackStack()
}
}
//TODO
// quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_bing_settings_quickfix) {
// override fun doFix() {
// val activity = fragment.activity
// if (activity is VectorSettingsFragmentInteractionListener) {
// activity.requestHighlightPreferenceKeyOnResume(PreferencesManager.SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY)
// }
// activity?.supportFragmentManager?.popBackStack()
// }
// }
status = TestStatus.FAILED
} else {
if (oneOrMoreRuleAreSilent) {

View File

@ -17,6 +17,7 @@ package im.vector.riotredesign.features.settings.troubleshoot

import androidx.fragment.app.Fragment
import im.vector.riotredesign.R
import im.vector.riotredesign.features.settings.PreferencesManager

/**
* 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) {

override fun perform() {
/* TODO
val pushManager = Matrix.getInstance(fragment.activity).pushManager
if (pushManager.areDeviceNotificationsAllowed()) {

if (PreferencesManager.areNotificationEnabledForDevice(fragment.requireContext())) {
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_success)
quickFix = null
status = TestStatus.SUCCESS
} else {
quickFix = object : TroubleshootQuickFix(R.string.settings_troubleshoot_test_device_settings_quickfix) {
override fun doFix() {
pushManager.setDeviceNotificationsAllowed(true)
PreferencesManager.setNotificationEnabledForDevice(fragment.requireContext(), true)
manager?.retry()
}

}
description = fragment.getString(R.string.settings_troubleshoot_test_device_settings_failed)
status = TestStatus.FAILED
}
*/
status = TestStatus.FAILED
}
}

View File

@ -31,4 +31,7 @@
<string name="preference_voice_and_video">Voice &amp; Video</string>
<string name="preference_root_help_about">Help &amp; About</string>


<string name="settings_troubleshoot_test_token_registration_quick_fix">Register token</string>

</resources>

View File

@ -17,10 +17,10 @@
android:key="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
android:title="@string/settings_enable_this_device" />

<im.vector.riotredesign.core.preference.VectorSwitchPreference
android:dependency="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"
android:key="SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"
android:title="@string/settings_turn_screen_on" />
<!--<im.vector.riotredesign.core.preference.VectorSwitchPreference-->
<!--android:dependency="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"-->
<!--android:key="SETTINGS_TURN_SCREEN_ON_PREFERENCE_KEY"-->
<!--android:title="@string/settings_turn_screen_on" />-->

<im.vector.riotredesign.core.preference.VectorPreference
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
@ -39,7 +39,6 @@

</im.vector.riotredesign.core.preference.VectorPreferenceCategory>

<im.vector.riotredesign.core.preference.VectorPreferenceDivider />

<!--im.vector.riotredesign.core.preference.VectorPreferenceCategory
android:key="SETTINGS_BACKGROUND_SYNC_PREFERENCE_KEY"