mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-09 00:29:00 +01:00
UP: Setting to force re-register UP
Also move all notification settings to notification settings Change-Id: I8eee2d289e67e16b61542930a55706bb29b361af
This commit is contained in:
parent
d87c03c505
commit
adfa2b36af
@ -17,6 +17,7 @@ package im.vector.app.core.pushers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.edit
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
@ -83,9 +84,15 @@ object UPHelper {
|
||||
}
|
||||
}
|
||||
|
||||
fun registerUnifiedPush(context: Context) {
|
||||
fun registerUnifiedPush(context: Context, forceShowSelection: Boolean = false, onDoneRunnable: Runnable? = null) {
|
||||
val up = Registration()
|
||||
if (up.getDistributor(context).isNotEmpty()) {
|
||||
if (forceShowSelection) {
|
||||
// Un-register first
|
||||
up.unregisterApp(context)
|
||||
up.saveDistributor(context, "")
|
||||
storeUpEndpoint(context, null)
|
||||
storePushGateway(context, null)
|
||||
} else if (up.getDistributor(context).isNotEmpty()) {
|
||||
up.registerApp(context)
|
||||
return
|
||||
}
|
||||
@ -101,10 +108,18 @@ object UPHelper {
|
||||
/**
|
||||
* Fallback with sync service
|
||||
*/
|
||||
if (forceShowSelection) {
|
||||
Toast.makeText(context.applicationContext, R.string.toast_unifiedpush_no_push_distributor, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
onDoneRunnable?.run()
|
||||
}
|
||||
1 -> {
|
||||
if (forceShowSelection) {
|
||||
Toast.makeText(context.applicationContext, context.getString(R.string.toast_unifiedpush_one_push_distributor, distributors.first()), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
up.saveDistributor(context, distributors.first())
|
||||
up.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
}
|
||||
else -> {
|
||||
val builder: AlertDialog.Builder = MaterialAlertDialogBuilder(context)
|
||||
@ -128,6 +143,13 @@ object UPHelper {
|
||||
up.saveDistributor(context, distributor)
|
||||
Timber.i("Saving distributor: $distributor")
|
||||
up.registerApp(context)
|
||||
onDoneRunnable?.run()
|
||||
}
|
||||
builder.setOnDismissListener {
|
||||
onDoneRunnable?.run()
|
||||
}
|
||||
builder.setOnCancelListener {
|
||||
onDoneRunnable?.run()
|
||||
}
|
||||
val dialog: AlertDialog = builder.create()
|
||||
dialog.show()
|
||||
|
@ -17,15 +17,9 @@
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.R
|
||||
import im.vector.app.core.preference.VectorSwitchPreference
|
||||
import im.vector.app.core.pushers.UPHelper
|
||||
import im.vector.app.features.themes.ThemeUtils
|
||||
import im.vector.app.features.MainActivity
|
||||
import im.vector.app.features.MainActivityArgs
|
||||
import javax.inject.Inject
|
||||
|
||||
class VectorSettingsLabsFragment @Inject constructor(
|
||||
@ -62,9 +56,5 @@ class VectorSettingsLabsFragment @Inject constructor(
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_VOICE_MESSAGE)?.isEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
||||
Handler(Looper.getMainLooper()).postDelayed({ context?.let { UPHelper.registerUnifiedPush(it)} } , 1000)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Parcelable
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@ -43,6 +45,7 @@ import im.vector.app.features.settings.BackgroundSyncModeChooserDialog
|
||||
import im.vector.app.features.settings.VectorPreferences
|
||||
import im.vector.app.features.settings.VectorSettingsBaseFragment
|
||||
import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener
|
||||
import im.vector.app.features.settings.VectorSettingsLabsFragment
|
||||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.pushrules.RuleIds
|
||||
@ -117,6 +120,20 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, _ ->
|
||||
Handler(Looper.getMainLooper()).postDelayed({ context?.let { UPHelper.registerUnifiedPush(it)} } , 1000)
|
||||
true
|
||||
}
|
||||
|
||||
findPreference<VectorPreference>(SETTINGS_UNIFIED_PUSH_RE_REGISTER)?.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
updateEnabledForDevice(false)
|
||||
UPHelper.registerUnifiedPush(requireContext(), forceShowSelection = true) {
|
||||
updateEnabledForDevice(true)
|
||||
Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() } , 500)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
refreshBackgroundSyncPrefs()
|
||||
|
||||
handleSystemPreference()
|
||||
@ -279,7 +296,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
|
||||
return when (preference?.key) {
|
||||
VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY -> {
|
||||
updateEnabledForDevice(preference)
|
||||
updateEnabledForDevice(preference as SwitchPreference)
|
||||
true
|
||||
}
|
||||
VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> {
|
||||
@ -292,9 +309,14 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEnabledForDevice(preference: Preference?) {
|
||||
val switchPref = preference as SwitchPreference
|
||||
if (switchPref.isChecked) {
|
||||
private fun updateEnabledForDevice(preference: SwitchPreference) {
|
||||
updateEnabledForDevice(preference.isChecked)
|
||||
}
|
||||
|
||||
private fun updateEnabledForDevice(enabled: Boolean) {
|
||||
val pref = findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_ENABLE_THIS_DEVICE_PREFERENCE_KEY)
|
||||
pref?.isChecked = enabled
|
||||
if (enabled) {
|
||||
UPHelper.registerUnifiedPush(requireContext())
|
||||
} else {
|
||||
UPHelper.getUpEndpoint(requireContext())?.let {
|
||||
@ -318,7 +340,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
return@fold
|
||||
}
|
||||
// revert the check box
|
||||
switchPref.isChecked = !switchPref.isChecked
|
||||
pref?.isChecked = true
|
||||
Toast.makeText(activity, R.string.unknown_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
)
|
||||
@ -352,4 +374,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val SETTINGS_UNIFIED_PUSH_RE_REGISTER = "SETTINGS_UNIFIED_PUSH_RE_REGISTER"
|
||||
}
|
||||
}
|
||||
|
@ -136,5 +136,8 @@
|
||||
<string name="settings_unifiedpush">UnifiedPush</string>
|
||||
<string name="settings_unifiedpush_force_custom_gateway">Force custom push gateway</string>
|
||||
<string name="settings_unifiedpush_force_custom_gateway_summary">Only enable this if your push endpoint does not require an external gateway.</string>
|
||||
<string name="settings_unifiedpush_reregister">Re-register push distributor</string>
|
||||
<string name="toast_unifiedpush_no_push_distributor">No push distributor found!</string>
|
||||
<string name="toast_unifiedpush_one_push_distributor">Registered push distributor %1$s</string>
|
||||
|
||||
</resources>
|
||||
|
@ -82,15 +82,5 @@
|
||||
android:summary="@string/labs_use_restricted_join_rule_desc"/>
|
||||
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
|
||||
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:title="@string/settings_unifiedpush">
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:key="SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
||||
android:title="@string/settings_unifiedpush_force_custom_gateway"
|
||||
android:summary="@string/settings_unifiedpush_force_custom_gateway_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
@ -130,4 +130,25 @@
|
||||
android:key="SETTINGS_NOTIFICATIONS_TARGETS_PREFERENCE_KEY"
|
||||
android:title="@string/settings_notifications_targets" /-->
|
||||
|
||||
<im.vector.app.core.preference.VectorPreferenceCategory
|
||||
android:title="@string/settings_unifiedpush">
|
||||
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:persistent="false"
|
||||
android:key="SETTINGS_UNIFIED_PUSH_RE_REGISTER"
|
||||
android:title="@string/settings_unifiedpush_reregister" />
|
||||
|
||||
<im.vector.app.core.preference.VectorSwitchPreference
|
||||
android:key="SETTINGS_UNIFIED_PUSH_FORCE_CUSTOM_GATEWAY"
|
||||
android:title="@string/settings_unifiedpush_force_custom_gateway"
|
||||
android:summary="@string/settings_unifiedpush_force_custom_gateway_summary"
|
||||
android:defaultValue="false" />
|
||||
|
||||
<im.vector.app.core.preference.VectorPreference
|
||||
android:persistent="false"
|
||||
android:title="@string/settings_notifications_targets"
|
||||
app:fragment="im.vector.app.features.settings.push.PushGatewaysFragment" />
|
||||
|
||||
</im.vector.app.core.preference.VectorPreferenceCategory>
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user