Fix bottom sheet being hidden in certain conditions

This commit is contained in:
Christophe Henry 2023-09-18 20:18:52 +02:00
parent 822adcac4a
commit b924a0c655
6 changed files with 72 additions and 67 deletions

View File

@ -40,6 +40,9 @@ import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.OAuth
import audio.funkwhale.ffa.utils.Request
import audio.funkwhale.ffa.utils.RequestBus
import audio.funkwhale.ffa.utils.Response
import audio.funkwhale.ffa.utils.Settings
import audio.funkwhale.ffa.utils.Userinfo
import audio.funkwhale.ffa.utils.authorize
@ -48,6 +51,7 @@ import audio.funkwhale.ffa.utils.logError
import audio.funkwhale.ffa.utils.mustNormalizeUrl
import audio.funkwhale.ffa.utils.onApi
import audio.funkwhale.ffa.utils.toast
import audio.funkwhale.ffa.utils.wait
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitStringResponse
import com.google.android.exoplayer2.offline.DownloadService
@ -56,8 +60,10 @@ import com.google.gson.Gson
import com.preference.PowerPreference
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.channels.consume
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch
import org.koin.java.KoinJavaComponent.inject
@ -83,7 +89,6 @@ class MainActivity : AppCompatActivity() {
AppContext.init(this)
binding = ActivityMainBinding.inflate(layoutInflater)
binding.nowPlayingBottomSheet.hide()
binding.nowPlayingBottomSheet.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) {
@ -125,7 +130,15 @@ class MainActivity : AppCompatActivity() {
MediaControlsManager.NOTIFICATION_ACTION_OPEN_QUEUE.toString() -> launchDialog(QueueFragment())
}
watchEventBus()
lifecycleScope.launch {
RequestBus.send(Request.GetQueue).wait<Response.Queue>()?.let {
if(it.queue.isNotEmpty()) binding.nowPlayingBottomSheet.show()
else binding.nowPlayingBottomSheet.hide()
}
// Watch the event bus only after to prevent concurrency in displaying the bottom sheet
watchEventBus()
}
}
override fun onResume() {

View File

@ -3,12 +3,9 @@ package audio.funkwhale.ffa.fragments
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.PopupMenu
import androidx.customview.widget.Openable
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.distinctUntilChanged
@ -21,9 +18,18 @@ import audio.funkwhale.ffa.model.Track
import audio.funkwhale.ffa.repositories.FavoritedRepository
import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.Repository
import audio.funkwhale.ffa.utils.*
import audio.funkwhale.ffa.utils.BottomSheetIneractable
import audio.funkwhale.ffa.utils.Command
import audio.funkwhale.ffa.utils.CommandBus
import audio.funkwhale.ffa.utils.CoverArt
import audio.funkwhale.ffa.utils.Event
import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.FFACache
import audio.funkwhale.ffa.utils.ProgressBus
import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.toIntOrElse
import audio.funkwhale.ffa.utils.untilNetwork
import audio.funkwhale.ffa.viewmodel.NowPlayingViewModel
import audio.funkwhale.ffa.views.NowPlayingBottomSheet
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -98,7 +98,8 @@ object CommandBus {
}
object RequestBus {
private var _requests = MutableSharedFlow<Request>()
// `replay` allows send requests before the PlayerService starts listening
private var _requests = MutableSharedFlow<Request>(replay = 100)
var requests = _requests.asSharedFlow()
fun send(request: Request): Channel<Response> {
return Channel<Response>().also {

View File

@ -13,38 +13,32 @@
android:id="@+id/header"
layout="@layout/partial_now_playing_header" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cover_container"
android:layout_width="wrap_content"
<audio.funkwhale.ffa.views.SquareImageView
android:id="@+id/now_playing_detail_cover"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header">
app:srcCompat="@drawable/cover"
tools:src="@tools:sample/avatars" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/now_playing_detail_cover"
android:layout_width="0dp"
android:layout_height="match_parent"
android:scaleType="fitCenter"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/cover"
tools:src="@tools:sample/avatars" />
<ImageButton
android:id="@+id/now_playing_details_info"
style="@style/IconButton"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="top|end"
android:layout_margin="8dp"
android:background="@drawable/circle"
android:contentDescription="@string/alt_track_info"
android:src="@drawable/more"
app:layout_constraintEnd_toEndOf="@id/now_playing_detail_cover"
app:layout_constraintTop_toTopOf="@id/now_playing_detail_cover"
app:tint="@color/controlForeground" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageButton
android:id="@+id/now_playing_details_info"
style="@style/IconButton"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="top|end"
android:layout_margin="8dp"
android:background="@drawable/circle"
android:contentDescription="@string/alt_track_info"
android:src="@drawable/more"
app:layout_constraintEnd_toEndOf="@id/now_playing_detail_cover"
app:layout_constraintTop_toTopOf="@id/now_playing_detail_cover"
app:tint="@color/controlForeground"
/>
<include
@ -57,7 +51,7 @@
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/cover_container"
app:layout_constraintStart_toEndOf="@id/now_playing_detail_cover"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -13,38 +13,28 @@
android:id="@+id/header"
layout="@layout/partial_now_playing_header" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cover_container"
<audio.funkwhale.ffa.views.SquareImageView
android:id="@+id/now_playing_detail_cover"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/header"
app:layout_constraintBottom_toTopOf="@id/controls">
app:layout_constraintTop_toBottomOf="@+id/header"
app:srcCompat="@drawable/cover"
tools:src="@tools:sample/avatars"
/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/now_playing_detail_cover"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:srcCompat="@drawable/cover"
tools:src="@tools:sample/avatars" />
<ImageButton
android:id="@+id/now_playing_details_info"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="@id/now_playing_detail_cover"
app:layout_constraintTop_toTopOf="@id/now_playing_detail_cover"
style="@style/IconButton"
android:layout_gravity="top|end"
android:background="@drawable/circle"
android:contentDescription="@string/alt_track_info"
android:src="@drawable/more"
app:tint="@color/controlForeground" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageButton
android:id="@+id/now_playing_details_info"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="@id/now_playing_detail_cover"
app:layout_constraintTop_toTopOf="@id/now_playing_detail_cover"
style="@style/IconButton"
android:layout_gravity="top|end"
android:background="@drawable/circle"
android:contentDescription="@string/alt_track_info"
android:src="@drawable/more"
app:tint="@color/controlForeground" />
<include
android:id="@+id/controls"
@ -53,6 +43,7 @@
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/now_playing_detail_cover"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@ -48,7 +48,7 @@
app:layout_constraintEnd_toEndOf="@id/now_playing_cover"
android:indeterminate="true"
android:indeterminateTint="@color/controlForeground"
android:visibility="@{isBuffering ? View.VISIBLE : View.GONE, default=gone}" />
android:visibility="@{isBuffering ? View.VISIBLE : View.INVISIBLE, default=invisible}" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/header_controls"