Skip to content

Commit

Permalink
Merge pull request #5649 from vector-im/hotfix/fre/rageshake_no_session
Browse files Browse the repository at this point in the history
Replace "open settings" button by "disable" action in RageShake dialog if there is no session
  • Loading branch information
Florian14 authored Apr 1, 2022
2 parents 664c345 + 4d37aa2 commit 45eb3bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/4445.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace "open settings" button by "disable" action in RageShake dialog if there is no session
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 45eb3bc

Please sign in to comment.