@@ -47,7 +47,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
4747 private val pushManager : PushersManager ,
4848 private val activeSessionHolder : ActiveSessionHolder ,
4949 private val vectorPreferences : VectorPreferences
50- ) : VectorSettingsBaseFragment() {
50+ ) : VectorSettingsBaseFragment(),
51+ BackgroundSyncModeChooserDialog .InteractionListener {
5152
5253 override var titleRes: Int = R .string.settings_notifications
5354 override val preferenceXmlRes = R .xml.vector_settings_notifications
@@ -73,28 +74,10 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
7374 findPreference<VectorPreference >(VectorPreferences .SETTINGS_FDROID_BACKGROUND_SYNC_MODE )?.let {
7475 it.onPreferenceClickListener = Preference .OnPreferenceClickListener {
7576 val initialMode = vectorPreferences.getFdroidSyncBackgroundMode()
76- val dialogFragment = BackgroundSyncModeChooserDialog .newInstance(
77- initialMode,
78- object : BackgroundSyncModeChooserDialog .InteractionListener {
79- override fun onOptionSelected (mode : BackgroundSyncMode ) {
80- // option has change, need to act
81- if (mode == BackgroundSyncMode .FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME ) {
82- // Important, Battery optim white listing is needed in this mode;
83- // Even if using foreground service with foreground notif, it stops to work
84- // in doze mode for certain devices :/
85- if (! isIgnoringBatteryOptimizations(requireContext())) {
86- requestDisablingBatteryOptimization(requireActivity(),
87- this @VectorSettingsNotificationPreferenceFragment,
88- REQUEST_BATTERY_OPTIMIZATION )
89- }
90- }
91- vectorPreferences.setFdroidSyncBackgroundMode(mode)
92- refreshBackgroundSyncPrefs()
93- }
94- }
95- )
96- activity?.supportFragmentManager?.let {
97- dialogFragment.show(it, " syncDialog" )
77+ val dialogFragment = BackgroundSyncModeChooserDialog .newInstance(initialMode)
78+ dialogFragment.interactionListener = this
79+ activity?.supportFragmentManager?.let {fm ->
80+ dialogFragment.show(fm, " syncDialog" )
9881 }
9982 true
10083 }
@@ -131,6 +114,23 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
131114 handleSystemPreference()
132115 }
133116
117+ // BackgroundSyncModeChooserDialog.InteractionListener
118+ override fun onOptionSelected (mode : BackgroundSyncMode ) {
119+ // option has change, need to act
120+ if (mode == BackgroundSyncMode .FDROID_BACKGROUND_SYNC_MODE_FOR_REALTIME ) {
121+ // Important, Battery optim white listing is needed in this mode;
122+ // Even if using foreground service with foreground notif, it stops to work
123+ // in doze mode for certain devices :/
124+ if (! isIgnoringBatteryOptimizations(requireContext())) {
125+ requestDisablingBatteryOptimization(requireActivity(),
126+ this @VectorSettingsNotificationPreferenceFragment,
127+ REQUEST_BATTERY_OPTIMIZATION )
128+ }
129+ }
130+ vectorPreferences.setFdroidSyncBackgroundMode(mode)
131+ refreshBackgroundSyncPrefs()
132+ }
133+
134134 private fun refreshBackgroundSyncPrefs () {
135135 findPreference<VectorPreference >(VectorPreferences .SETTINGS_FDROID_BACKGROUND_SYNC_MODE )?.let {
136136 it.summary = when (vectorPreferences.getFdroidSyncBackgroundMode()) {
@@ -251,6 +251,9 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
251251 if (context is VectorSettingsFragmentInteractionListener ) {
252252 interactionListener = context
253253 }
254+ (activity?.supportFragmentManager
255+ ?.findFragmentByTag(" syncDialog" ) as BackgroundSyncModeChooserDialog ? )
256+ ?.interactionListener = this
254257 }
255258
256259 override fun onDetach () {
0 commit comments