forked from GitHub-Mirror/riotX-android
Remove / Add pusher from enable notif preference
+Added Retrofit/Moshi null serializer for pusher kind
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package im.vector.riotredesign.core.pushers
|
||||
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.resources.AppNameProvider
|
||||
@ -29,6 +30,9 @@ class PushersManager(
|
||||
false,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
fun unregisterPusher(pushKey: String, callback: MatrixCallback<Unit>) {
|
||||
currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id),callback)
|
||||
}
|
||||
}
|
@ -243,6 +243,10 @@ public class PreferencesManager {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean areNotificationEnabledForDevice(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
|
||||
*
|
||||
|
@ -1,17 +0,0 @@
|
||||
package im.vector.riotredesign.features.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.platform.VectorBaseActivity
|
||||
import im.vector.riotredesign.core.platform.VectorPreferenceFragment
|
||||
|
||||
|
||||
class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notifications
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.vector_settings_notifications)
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package im.vector.riotredesign.features.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.SwitchPreference
|
||||
import im.vector.matrix.android.api.Matrix
|
||||
import im.vector.matrix.android.api.MatrixCallback
|
||||
import im.vector.matrix.android.api.session.pushers.PushersService
|
||||
import im.vector.riotredesign.R
|
||||
import im.vector.riotredesign.core.platform.VectorPreferenceFragment
|
||||
import im.vector.riotredesign.core.pushers.PushersManager
|
||||
import im.vector.riotredesign.push.fcm.FcmHelper
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.android.inject
|
||||
|
||||
|
||||
class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment() {
|
||||
|
||||
override var titleRes: Int = R.string.settings_notifications
|
||||
|
||||
val pushManager: PushersManager by inject()
|
||||
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.vector_settings_notifications)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
Matrix.getInstance().currentSession?.refreshPushers()
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
}
|
@ -7,8 +7,8 @@
|
||||
<!--android:title="@string/settings_enable_all_notif" />-->
|
||||
|
||||
<SwitchPreference
|
||||
|
||||
android:key="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:defaultValue="true"
|
||||
android:title="@string/settings_enable_this_device" />
|
||||
<!--android:dependency="SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY"-->
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
android:dependency="SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY"
|
||||
android:key="SETTINGS_NOTIFICATION_ADVANCED_PREFERENCE_KEY"
|
||||
android:persistent="false"
|
||||
android:visibility="gone"
|
||||
android:summary="@string/settings_notification_advanced_summary"
|
||||
android:title="@string/settings_notification_advanced"
|
||||
android:enabled="false"
|
||||
|
Reference in New Issue
Block a user