-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Support predicative back gesture
Fixes: #1103
- Loading branch information
Showing
11 changed files
with
139 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/java/me/zhanghai/android/files/ui/DrawerLayoutOnBackPressedCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2024 Hai Zhang <dreaming.in.code.zh@gmail.com> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.ui | ||
|
||
import android.view.View | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.core.view.GravityCompat | ||
import androidx.drawerlayout.widget.DrawerLayout | ||
import androidx.drawerlayout.widget.DrawerLayout.SimpleDrawerListener | ||
|
||
class DrawerLayoutOnBackPressedCallback( | ||
private val drawerLayout: DrawerLayout, | ||
private val gravity: Int = GravityCompat.START | ||
) : OnBackPressedCallback(drawerLayout.isDrawerVisibleAndUnlocked(gravity)) { | ||
init { | ||
drawerLayout.addDrawerListener( | ||
object : SimpleDrawerListener() { | ||
override fun onDrawerOpened(drawerView: View) { | ||
isEnabled = drawerLayout.isDrawerVisibleAndUnlocked(gravity) | ||
} | ||
|
||
override fun onDrawerClosed(drawerView: View) { | ||
isEnabled = drawerLayout.isDrawerVisibleAndUnlocked(gravity) | ||
} | ||
} | ||
) | ||
} | ||
|
||
override fun handleOnBackPressed() { | ||
drawerLayout.closeDrawer(gravity) | ||
} | ||
} | ||
|
||
private fun DrawerLayout.isDrawerVisibleAndUnlocked(gravity: Int): Boolean = | ||
isDrawerVisible(gravity) && getDrawerLockMode(gravity) == DrawerLayout.LOCK_MODE_UNLOCKED |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/me/zhanghai/android/files/ui/SpeedDialViewOnBackPressedCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024 Hai Zhang <dreaming.in.code.zh@gmail.com> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.ui | ||
|
||
import androidx.activity.OnBackPressedCallback | ||
import com.leinardi.android.speeddial.SpeedDialView | ||
|
||
class SpeedDialViewOnBackPressedCallback( | ||
private val speedDialView: SpeedDialView | ||
) : OnBackPressedCallback(speedDialView.isOpen) { | ||
init { | ||
speedDialView.setOnChangeListener( | ||
object : SpeedDialView.OnChangeListener { | ||
override fun onMainActionSelected(): Boolean = false | ||
|
||
override fun onToggleChanged(isOpen: Boolean) { | ||
isEnabled = speedDialView.isOpen | ||
} | ||
} | ||
) | ||
} | ||
|
||
override fun handleOnBackPressed() { | ||
speedDialView.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters