diff --git a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt index 1741875..4d9887a 100644 --- a/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt +++ b/app/src/main/java/audio/funkwhale/ffa/activities/MainActivity.kt @@ -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()?.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() { diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/NowPlayingFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/NowPlayingFragment.kt index 539d652..b2fae8d 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/NowPlayingFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/NowPlayingFragment.kt @@ -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 diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt index 40c7e0e..2108cb2 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt @@ -98,7 +98,8 @@ object CommandBus { } object RequestBus { - private var _requests = MutableSharedFlow() + // `replay` allows send requests before the PlayerService starts listening + private var _requests = MutableSharedFlow(replay = 100) var requests = _requests.asSharedFlow() fun send(request: Request): Channel { return Channel().also { diff --git a/app/src/main/res/layout-land/fragment_now_playing.xml b/app/src/main/res/layout-land/fragment_now_playing.xml index 4480aaf..8cb4893 100644 --- a/app/src/main/res/layout-land/fragment_now_playing.xml +++ b/app/src/main/res/layout-land/fragment_now_playing.xml @@ -13,38 +13,32 @@ android:id="@+id/header" layout="@layout/partial_now_playing_header" /> - + app:srcCompat="@drawable/cover" + tools:src="@tools:sample/avatars" /> - - - - + diff --git a/app/src/main/res/layout/fragment_now_playing.xml b/app/src/main/res/layout/fragment_now_playing.xml index e22e1d0..93434f6 100644 --- a/app/src/main/res/layout/fragment_now_playing.xml +++ b/app/src/main/res/layout/fragment_now_playing.xml @@ -13,38 +13,28 @@ android:id="@+id/header" layout="@layout/partial_now_playing_header" /> - + app:layout_constraintTop_toBottomOf="@+id/header" + app:srcCompat="@drawable/cover" + tools:src="@tools:sample/avatars" + /> - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/partial_now_playing_header.xml b/app/src/main/res/layout/partial_now_playing_header.xml index 960c43f..5b1274d 100644 --- a/app/src/main/res/layout/partial_now_playing_header.xml +++ b/app/src/main/res/layout/partial_now_playing_header.xml @@ -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}" />