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.Event
import audio.funkwhale.ffa.utils.EventBus import audio.funkwhale.ffa.utils.EventBus
import audio.funkwhale.ffa.utils.OAuth 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.Settings
import audio.funkwhale.ffa.utils.Userinfo import audio.funkwhale.ffa.utils.Userinfo
import audio.funkwhale.ffa.utils.authorize 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.mustNormalizeUrl
import audio.funkwhale.ffa.utils.onApi import audio.funkwhale.ffa.utils.onApi
import audio.funkwhale.ffa.utils.toast import audio.funkwhale.ffa.utils.toast
import audio.funkwhale.ffa.utils.wait
import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitStringResponse import com.github.kittinunf.fuel.coroutines.awaitStringResponse
import com.google.android.exoplayer2.offline.DownloadService import com.google.android.exoplayer2.offline.DownloadService
@ -56,8 +60,10 @@ import com.google.gson.Gson
import com.preference.PowerPreference import com.preference.PowerPreference
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.channels.consume
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.koin.java.KoinJavaComponent.inject import org.koin.java.KoinJavaComponent.inject
@ -83,7 +89,6 @@ class MainActivity : AppCompatActivity() {
AppContext.init(this) AppContext.init(this)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
binding.nowPlayingBottomSheet.hide()
binding.nowPlayingBottomSheet.addBottomSheetCallback( binding.nowPlayingBottomSheet.addBottomSheetCallback(
object : BottomSheetBehavior.BottomSheetCallback() { object : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, newState: Int) { override fun onStateChanged(bottomSheet: View, newState: Int) {
@ -125,7 +130,15 @@ class MainActivity : AppCompatActivity() {
MediaControlsManager.NOTIFICATION_ACTION_OPEN_QUEUE.toString() -> launchDialog(QueueFragment()) 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() { override fun onResume() {

View File

@ -3,12 +3,9 @@ package audio.funkwhale.ffa.fragments
import android.os.Bundle import android.os.Bundle
import android.view.Gravity import android.view.Gravity
import android.view.View import android.view.View
import android.widget.Button
import android.widget.SeekBar import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.PopupMenu
import androidx.customview.widget.Openable
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.distinctUntilChanged 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.FavoritedRepository
import audio.funkwhale.ffa.repositories.FavoritesRepository import audio.funkwhale.ffa.repositories.FavoritesRepository
import audio.funkwhale.ffa.repositories.Repository 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.viewmodel.NowPlayingViewModel
import audio.funkwhale.ffa.views.NowPlayingBottomSheet
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

View File

@ -98,7 +98,8 @@ object CommandBus {
} }
object RequestBus { 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() var requests = _requests.asSharedFlow()
fun send(request: Request): Channel<Response> { fun send(request: Request): Channel<Response> {
return Channel<Response>().also { return Channel<Response>().also {

View File

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

View File

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

View File

@ -48,7 +48,7 @@
app:layout_constraintEnd_toEndOf="@id/now_playing_cover" app:layout_constraintEnd_toEndOf="@id/now_playing_cover"
android:indeterminate="true" android:indeterminate="true"
android:indeterminateTint="@color/controlForeground" 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 <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/header_controls" android:id="@+id/header_controls"