Skip to content

Commit

Permalink
Add option to control toolbar opening with swipe-in gesture
Browse files Browse the repository at this point in the history
Re #200
  • Loading branch information
gujjwal00 committed Feb 22, 2024
1 parent 2b191b8 commit 5cd63e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/com/gaurav/avnc/ui/vnc/Toolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ class Toolbar(private val activity: VncActivity, private val dispatcher: Dispatc
}

fun updateLockMode(isConnected: Boolean) {
val mode = if (isConnected) DrawerLayout.LOCK_MODE_UNDEFINED else DrawerLayout.LOCK_MODE_LOCKED_CLOSED
drawerLayout.setDrawerLockMode(mode)
if (isConnected && viewModel.pref.viewer.toolbarOpenWithSwipe)
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED)
else
drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
}

private fun toast(@StringRes msgRes: Int) = Toast.makeText(activity, msgRes, Toast.LENGTH_SHORT).show()
Expand Down Expand Up @@ -157,7 +159,7 @@ class Toolbar(private val activity: VncActivity, private val dispatcher: Dispatc
* Note: Some ROMs, e.g. MIUI, completely ignore whatever is set here.
*/
private fun setupGestureExclusionRect() {
if (Build.VERSION.SDK_INT >= 29) {
if (Build.VERSION.SDK_INT >= 29 && viewModel.pref.viewer.toolbarOpenWithSwipe) {
binding.primaryButtons.addOnLayoutChangeListener { _, _, top, _, bottom, _, _, _, _ ->
val rect = Rect(drawerView.left, top, drawerView.right, bottom)

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/gaurav/avnc/util/AppPreferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AppPreferences(context: Context) {
val drawBehindCutout; get() = prefs.getBoolean("viewer_draw_behind_cutout", false)
val keepScreenOn; get() = prefs.getBoolean("keep_screen_on", true)
val toolbarAlignment; get() = prefs.getString("toolbar_alignment", "start")
val toolbarOpenWithSwipe; get() = prefs.getBoolean("toolbar_open_with_swipe", true)
val zoomMax; get() = prefs.getInt("zoom_max", 500) / 100F
val zoomMin; get() = prefs.getInt("zoom_min", 50) / 100F
val perOrientationZoom; get() = prefs.getBoolean("per_orientation_zoom", true)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
<string name="pref_toolbar_alignment">Alignment</string>
<string name="pref_toolbar_alignment_option_start">Start</string>
<string name="pref_toolbar_alignment_option_end">End</string>
<string name="pref_toolbar_open_with_swipe">Swipe-in from edge to open</string>
<string name="pref_show_gesture_style_toggle">Show gesture style toggle</string>
<string name="pref_zoom">Zoom</string>
<string name="pref_zoom_min">Minimum</string>
<string name="pref_zoom_max">Maximum</string>
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/xml/pref_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@
app:title="@string/pref_toolbar_alignment"
app:useSimpleSummaryProvider="true" />

<SwitchPreference
app:defaultValue="true"
app:key="toolbar_open_with_swipe"
app:title="@string/pref_toolbar_open_with_swipe" />

<SwitchPreference
app:defaultValue="true"
app:key="toolbar_show_gesture_style_toggle"
app:title="Show gesture style toggle" />
app:title="@string/pref_show_gesture_style_toggle" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 5cd63e0

Please sign in to comment.