forked from KotatsuApp/Kotatsu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crashes and improve predictive back support
- Loading branch information
Showing
10 changed files
with
56 additions
and
22 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
28 changes: 22 additions & 6 deletions
28
app/src/main/kotlin/org/koitharu/kotatsu/core/ui/sheet/BottomSheetCollapseCallback.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 |
---|---|---|
@@ -1,30 +1,46 @@ | ||
package org.koitharu.kotatsu.core.ui.sheet | ||
|
||
import android.annotation.SuppressLint | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.activity.BackEventCompat | ||
import androidx.activity.OnBackPressedCallback | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HALF_EXPANDED | ||
import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN | ||
|
||
class BottomSheetCollapseCallback( | ||
private val behavior: BottomSheetBehavior<*>, | ||
) : OnBackPressedCallback(behavior.state == STATE_EXPANDED) { | ||
private val sheet: ViewGroup, | ||
private val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(sheet), | ||
) : OnBackPressedCallback(behavior.state == STATE_EXPANDED || behavior.state == STATE_HALF_EXPANDED) { | ||
|
||
init { | ||
behavior.addBottomSheetCallback( | ||
object : BottomSheetBehavior.BottomSheetCallback() { | ||
|
||
@SuppressLint("SwitchIntDef") | ||
override fun onStateChanged(view: View, state: Int) { | ||
isEnabled = state == STATE_EXPANDED || state == STATE_HALF_EXPANDED | ||
when (state) { | ||
STATE_EXPANDED, | ||
STATE_HALF_EXPANDED -> isEnabled = true | ||
|
||
STATE_COLLAPSED, | ||
STATE_HIDDEN -> isEnabled = false | ||
} | ||
} | ||
|
||
override fun onSlide(p0: View, p1: Float) = Unit | ||
}, | ||
) | ||
} | ||
|
||
override fun handleOnBackPressed() { | ||
behavior.state = STATE_COLLAPSED | ||
} | ||
override fun handleOnBackPressed() = behavior.handleBackInvoked() | ||
|
||
override fun handleOnBackCancelled() = behavior.cancelBackProgress() | ||
|
||
override fun handleOnBackProgressed(backEvent: BackEventCompat) = behavior.updateBackProgress(backEvent) | ||
|
||
override fun handleOnBackStarted(backEvent: BackEventCompat) = behavior.startBackProgress(backEvent) | ||
} |
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