Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Sep 13, 2023
1 parent b1d198d commit 28b9137
Showing 1 changed file with 31 additions and 61 deletions.
92 changes: 31 additions & 61 deletions app/src/main/java/org/akanework/gramophone/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MainActivity : AppCompatActivity(), Player.Listener {
)
if (duration != null && !isUserTracking) {
bottomSheetFullSlider.value =
instance.currentPosition.toFloat() / duration.toFloat()
(instance.currentPosition.toFloat() / duration.toFloat()).coerceAtMost(1f)
bottomSheetFullPosition.text = position
}
}
Expand Down Expand Up @@ -143,11 +143,7 @@ class MainActivity : AppCompatActivity(), Player.Listener {
}
if (standardBottomSheetBehavior.state != BottomSheetBehavior.STATE_EXPANDED) {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
previewPlayer.alpha = 1f
previewPlayer.visibility = View.VISIBLE
Handler(Looper.getMainLooper()).postDelayed({
standardBottomSheetBehavior.isHideable = false
}, 200)
standardBottomSheetBehavior.isHideable = false
}
},
200,
Expand Down Expand Up @@ -175,9 +171,7 @@ class MainActivity : AppCompatActivity(), Player.Listener {
if (!standardBottomSheetBehavior.isHideable) {
standardBottomSheetBehavior.isHideable = true
}
Handler(Looper.getMainLooper()).postDelayed({
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
}, 200)
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN
}
}

Expand Down Expand Up @@ -327,8 +321,6 @@ class MainActivity : AppCompatActivity(), Player.Listener {
standardBottomSheet.setOnClickListener {
if (standardBottomSheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
fullPlayer.visibility = View.VISIBLE
previewPlayer.visibility = View.GONE
}
}

Expand Down Expand Up @@ -401,13 +393,10 @@ class MainActivity : AppCompatActivity(), Player.Listener {

bottomSheetFullSlideUpButton.setOnClickListener {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
Handler(Looper.getMainLooper()).postDelayed(
{
fullPlayer.visibility = View.GONE
previewPlayer.visibility = View.VISIBLE
},
200,
)
}

val bottomSheetBackCallback = onBackPressedDispatcher.addCallback(this) {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
}

standardBottomSheetBehavior.addBottomSheetCallback(
Expand All @@ -416,16 +405,31 @@ class MainActivity : AppCompatActivity(), Player.Listener {
bottomSheet: View,
newState: Int,
) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED
&& previewPlayer.isVisible) {
fullPlayer.visibility = View.GONE
previewPlayer.alpha = 1f
} else if (newState == BottomSheetBehavior.STATE_DRAGGING) {
fullPlayer.visibility = View.VISIBLE
previewPlayer.visibility = View.VISIBLE
} else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
previewPlayer.visibility = View.GONE
when (newState) {
BottomSheetBehavior.STATE_COLLAPSED -> {
fullPlayer.visibility = View.GONE
previewPlayer.visibility = View.VISIBLE
previewPlayer.alpha = 1f
}

BottomSheetBehavior.STATE_DRAGGING,
BottomSheetBehavior.STATE_SETTLING,
BottomSheetBehavior.STATE_HALF_EXPANDED -> {
fullPlayer.visibility = View.VISIBLE
previewPlayer.visibility = View.VISIBLE
}

BottomSheetBehavior.STATE_EXPANDED -> {
previewPlayer.visibility = View.GONE
fullPlayer.visibility = View.VISIBLE
}

BottomSheetBehavior.STATE_HIDDEN -> {
previewPlayer.visibility = View.GONE
fullPlayer.visibility = View.GONE
}
}
bottomSheetBackCallback.isEnabled = newState == BottomSheetBehavior.STATE_EXPANDED
}

override fun onSlide(
Expand All @@ -451,24 +455,6 @@ class MainActivity : AppCompatActivity(), Player.Listener {
Constants.PERMISSION_READ_MEDIA_AUDIO,
)
}
onBackInvokedDispatcher.registerOnBackInvokedCallback(
OnBackInvokedDispatcher.PRIORITY_DEFAULT
) {
if (standardBottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
Handler(Looper.getMainLooper()).postDelayed(
{
fullPlayer.visibility = View.GONE
previewPlayer.visibility = View.VISIBLE
},
200,
)
} else if (isTaskRoot) {
moveTaskToBack(true)
} else {
supportFragmentManager.popBackStack()
}
}
} else {
if (ContextCompat.checkSelfPermission(
this,
Expand All @@ -482,22 +468,6 @@ class MainActivity : AppCompatActivity(), Player.Listener {
Constants.PERMISSION_READ_EXTERNAL_STORAGE,
)
}
onBackPressedDispatcher.addCallback(this) {
if (standardBottomSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) {
standardBottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
Handler(Looper.getMainLooper()).postDelayed(
{
fullPlayer.visibility = View.GONE
previewPlayer.visibility = View.VISIBLE
},
200,
)
} else if (isTaskRoot) {
moveTaskToBack(true)
} else {
supportFragmentManager.popBackStack()
}
}
}
}

Expand Down

0 comments on commit 28b9137

Please sign in to comment.