Merge pull request #4744 from Bnyro/master

fix: hide autoplay countdown when miniplayer visible
This commit is contained in:
Bnyro 2023-09-10 14:20:45 +02:00 committed by GitHub
commit d45a954d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,14 +8,21 @@ import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.os.postDelayed
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.get
import com.github.libretube.R
import com.github.libretube.databinding.AutoplayCountdownBinding
import com.github.libretube.ui.activities.MainActivity
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.models.PlayerViewModel
class AutoplayCountdownView(
context: Context,
attributeSet: AttributeSet?
) : FrameLayout(context, attributeSet) {
private val layoutInflater = LayoutInflater.from(context)
private val playerViewModel: PlayerViewModel get() = ViewModelProvider(context as MainActivity).get()
val binding = AutoplayCountdownBinding.inflate(layoutInflater, this, true)
private var onCountdownEnd: () -> Unit = {}
private var hideSelf: () -> Unit = {}
@ -34,7 +41,6 @@ class AutoplayCountdownView(
}
fun startCountdown(onEnd: () -> Unit) {
this.isVisible = true
onCountdownEnd = {
hideSelf.invoke()
onEnd.invoke()
@ -53,6 +59,8 @@ class AutoplayCountdownView(
return
}
// only show countdown when mini player not visible
this.isVisible = playerViewModel.isMiniPlayerVisible.value == false
binding.currentState.text = context.getString(
R.string.playing_next,
currentTimerState.toString()