Merge pull request #5649 from vector-im/hotfix/fre/rageshake_no_session

Replace "open settings" button by "disable" action in RageShake dialog if there is no session
This commit is contained in:
Florian Renaud 2022-04-01 17:56:49 +02:00 committed by GitHub
commit 45eb3bcbc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

1
changelog.d/4445.bugfix Normal file
View File

@ -0,0 +1 @@
Replace "open settings" button by "disable" action in RageShake dialog if there is no session

View File

@ -24,6 +24,7 @@ import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.squareup.seismic.ShakeDetector
import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.hardware.vibrate
import im.vector.app.features.navigation.Navigator
import im.vector.app.features.settings.VectorPreferences
@ -33,6 +34,7 @@ import javax.inject.Inject
class RageShake @Inject constructor(private val activity: FragmentActivity,
private val bugReporter: BugReporter,
private val navigator: Navigator,
private val sessionHolder: ActiveSessionHolder,
private val vectorPreferences: VectorPreferences) : ShakeDetector.Listener {
private var shakeDetector: ShakeDetector? = null
@ -75,7 +77,13 @@ class RageShake @Inject constructor(private val activity: FragmentActivity,
MaterialAlertDialogBuilder(activity)
.setMessage(R.string.send_bug_report_alert_message)
.setPositiveButton(R.string.yes) { _, _ -> openBugReportScreen() }
.setNeutralButton(R.string.settings) { _, _ -> openSettings() }
.also {
if (sessionHolder.hasActiveSession()) {
it.setNeutralButton(R.string.settings) { _, _ -> openSettings() }
} else {
it.setNeutralButton(R.string.action_disable) { _, _ -> disableRageShake() }
}
}
.setOnDismissListener { dialogDisplayed = false }
.setNegativeButton(R.string.no, null)
.show()
@ -90,6 +98,11 @@ class RageShake @Inject constructor(private val activity: FragmentActivity,
navigator.openSettings(activity, VectorSettingsActivity.EXTRA_DIRECT_ACCESS_ADVANCED_SETTINGS)
}
private fun disableRageShake() {
vectorPreferences.setRageshakeEnabled(false)
stop()
}
companion object {
/**
* Check if the feature is available

View File

@ -865,6 +865,17 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return defaultPrefs.getBoolean(SETTINGS_INTERFACE_BUBBLE_KEY, getDefault(R.bool.settings_interface_bubble_default))
}
/**
* Update the rage shake enabled status.
*
* @param isEnabled true to enable rage shake.
*/
fun setRageshakeEnabled(isEnabled: Boolean) {
defaultPrefs.edit {
putBoolean(SETTINGS_USE_RAGE_SHAKE_KEY, isEnabled)
}
}
/**
* Tells if the rage shake is used.
*

View File

@ -358,6 +358,7 @@
<string name="action_switch">Switch</string>
<string name="action_unpublish">Unpublish</string>
<string name="action_enable">Enable</string>
<string name="action_disable">Disable</string>
<string name="action_not_now">Not now</string>
<string name="action_agree">Agree</string>
<string name="action_change">"Change"</string>