Skip to content

Commit cbdd683

Browse files
committed
Completely track file removal with isInPosition
1 parent 5f99bb2 commit cbdd683

File tree

4 files changed

+27
-39
lines changed

4 files changed

+27
-39
lines changed

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/details/FileDetailsView.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ private fun NowPlayingFileMenu(
195195
)
196196

197197
val isInPosition by nowPlayingFileDetailsState.isInPosition.subscribeAsState()
198-
val isRemoving by nowPlayingFileDetailsState.isRemoving.subscribeAsState()
199198
val removeFileLabel = stringResource(id = R.string.btn_remove_file)
200199
ColumnMenuIcon(
201200
onClick = { nowPlayingFileDetailsState.removeFile() },
@@ -204,7 +203,7 @@ private fun NowPlayingFileMenu(
204203
label = removeFileLabel,
205204
labelMaxLines = 1,
206205
modifier = modifier,
207-
enabled = !isLoading && !isRemoving && isInPosition
206+
enabled = !isLoading && isInPosition
208207
)
209208

210209
val playLabel = stringResource(id = R.string.skip_to)
@@ -224,7 +223,7 @@ private fun NowPlayingFileMenu(
224223
}
225224

226225
@Composable
227-
fun FileRating(viewModel: FileDetailsState, mediaStylePalette: MediaStylePalette, modifier: Modifier) {
226+
private fun FileRating(viewModel: FileDetailsState, mediaStylePalette: MediaStylePalette, modifier: Modifier) {
228227
val rating by viewModel.rating.subscribeAsState()
229228

230229
RatingBar(
@@ -236,7 +235,7 @@ fun FileRating(viewModel: FileDetailsState, mediaStylePalette: MediaStylePalette
236235
}
237236

238237
@Composable
239-
fun rememberComputedColorPalette(
238+
private fun rememberComputedColorPalette(
240239
paletteProvider: MediaStylePaletteProvider,
241240
coverArt: Bitmap?
242241
): State<MediaStylePalette> {
@@ -259,7 +258,7 @@ fun rememberComputedColorPalette(
259258
}
260259

261260
@Composable
262-
fun FilePropertyHeader(
261+
private fun FilePropertyHeader(
263262
viewModel: FileDetailsState,
264263
palette: MediaStylePalette,
265264
modifier: Modifier = Modifier,
@@ -298,7 +297,7 @@ fun FilePropertyHeader(
298297
}
299298

300299
@Composable
301-
fun FilePropertyRow(
300+
private fun FilePropertyRow(
302301
viewModel: FileDetailsState,
303302
property: FileDetailsViewModel.FilePropertyViewModel,
304303
palette: MediaStylePalette
@@ -543,7 +542,7 @@ private fun FileDetailsEditor(
543542
}
544543

545544
@Composable
546-
fun FileDetailsSingleColumn(
545+
private fun FileDetailsSingleColumn(
547546
viewModel: FileDetailsState,
548547
navigateApplication: NavigateApplication,
549548
coverArtBitmap: Bitmap?,
@@ -765,7 +764,7 @@ fun FileDetailsSingleColumn(
765764

766765
@OptIn(ExperimentalComposeUiApi::class)
767766
@Composable
768-
fun BoxWithConstraintsScope.FileDetailsTwoColumn(
767+
private fun BoxWithConstraintsScope.FileDetailsTwoColumn(
769768
viewModel: FileDetailsState,
770769
navigateApplication: NavigateApplication,
771770
coverArtBitmap: Bitmap?,

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/details/NowPlayingFileDetailsState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ import com.namehillsoftware.handoff.promises.Promise
66
interface NowPlayingFileDetailsState {
77
val isInPosition: InteractionState<Boolean>
88
fun removeFile(): Promise<Unit>
9-
val isRemoving: InteractionState<Boolean>
109
}

projectBlueWater/src/main/java/com/lasthopesoftware/bluewater/client/browsing/files/details/NowPlayingFileDetailsViewModel.kt

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import com.lasthopesoftware.bluewater.shared.observables.LiftedInteractionState
1313
import com.lasthopesoftware.bluewater.shared.observables.MutableInteractionState
1414
import com.lasthopesoftware.bluewater.shared.observables.asInteractionState
1515
import com.lasthopesoftware.bluewater.shared.observables.mapNotNull
16+
import com.lasthopesoftware.promises.extensions.keepPromise
1617
import com.lasthopesoftware.promises.extensions.toPromise
1718
import com.lasthopesoftware.resources.closables.AutoCloseableManager
1819
import com.namehillsoftware.handoff.promises.Promise
20+
import com.namehillsoftware.handoff.promises.response.EventualAction
1921
import com.namehillsoftware.handoff.promises.response.ImmediateAction
2022
import com.namehillsoftware.handoff.promises.response.ImmediateResponse
21-
import com.namehillsoftware.handoff.promises.response.PromisedResponse
2223
import io.reactivex.rxjava3.core.Observable
2324

2425
class NowPlayingFileDetailsViewModel(
@@ -32,21 +33,19 @@ class NowPlayingFileDetailsViewModel(
3233
NowPlayingFileDetailsState,
3334
PlayableFileDetailsState,
3435
FileDetailsState by fileDetailsState,
36+
EventualAction,
3537
ImmediateAction,
36-
ImmediateResponse<NowPlaying?, Unit>,
37-
PromisedResponse<Unit, Unit>
38+
ImmediateResponse<NowPlaying?, Unit>
3839
{
3940
private var activePositionedFile: PositionedFile? = null
4041

4142
private val autoCloseableManager by lazy {
4243
AutoCloseableManager().also(::addCloseable)
4344
}
4445

45-
private val mutableIsRemoving = MutableInteractionState(false)
4646
private val mutableIsLoading = MutableInteractionState(false)
4747
private val mutableIsInPosition = MutableInteractionState(false)
4848

49-
override val isRemoving = mutableIsRemoving.asInteractionState()
5049
override val isInPosition = mutableIsInPosition.asInteractionState()
5150
override val isLoading = autoCloseableManager.manage(LiftedInteractionState(
5251
Observable.combineLatest(listOf(mutableIsLoading.mapNotNull(), fileDetailsState.isLoading.mapNotNull())) { source -> source.any { loading -> loading as Boolean } },
@@ -64,18 +63,18 @@ class NowPlayingFileDetailsViewModel(
6463
activePositionedFile = positionedFile
6564
return loadFileDetailsState
6665
.load(libraryId, positionedFile.serviceFile)
67-
.eventually(this)
66+
.inevitably(this)
6867
.must(this)
6968
}
7069

7170
override fun removeFile(): Promise<Unit> {
7271
val libraryId = activeLibraryId ?: return Unit.toPromise()
7372
val positionedFile = activePositionedFile ?: return Unit.toPromise()
7473

75-
mutableIsRemoving.value = true
74+
mutableIsInPosition.value = false
7675
return controlPlayback
7776
.removeFromPlaylistAtPosition(libraryId, positionedFile.playlistPosition)
78-
.must { _ -> mutableIsRemoving.value = false }
77+
.inevitably(this)
7978
}
8079

8180
override fun play() {
@@ -89,10 +88,8 @@ class NowPlayingFileDetailsViewModel(
8988
mutableIsLoading.value = false
9089
}
9190

92-
override fun promiseResponse(resolution: Unit): Promise<Unit> {
93-
val libraryId = activeLibraryId ?: return Unit.toPromise()
94-
return loadIsInPosition(libraryId)
95-
}
91+
override fun promiseAction(): Promise<*>? =
92+
activeLibraryId?.let(::loadIsInPosition).keepPromise()
9693

9794
override fun respond(nowPlaying: NowPlaying?) {
9895
val currentLibraryId = activeLibraryId

projectBlueWater/src/test/java/com/lasthopesoftware/bluewater/client/browsing/files/details/GivenAFile/When removing the file from now playing.kt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class `When removing the file from now playing` {
5252
mockk {
5353
every { promiseNowPlaying(LibraryId(libraryId)) } returns NowPlaying(
5454
libraryId = LibraryId(libraryId),
55-
playlist = emptyList(),
55+
playlist = listOf(ServiceFile(serviceFileId)),
5656
playlistPosition = 0,
5757
filePosition = 0,
5858
isRepeating = false,
@@ -63,20 +63,17 @@ class `When removing the file from now playing` {
6363
}
6464

6565
private var isLoadingStates = mutableListOf<Boolean>()
66-
private var isRemovingStates = mutableListOf<Boolean>()
6766
private var isInPositionStates = mutableListOf<Boolean>()
6867

6968
@BeforeAll
7069
fun act() {
7170
viewModel.isLoading.mapNotNull().subscribe(isLoadingStates::add).toCloseable().use {
72-
viewModel.isRemoving.mapNotNull().subscribe(isRemovingStates::add).toCloseable().use {
73-
viewModel.isInPosition.mapNotNull().subscribe(isInPositionStates::add).toCloseable().use {
74-
viewModel
75-
.load(LibraryId(libraryId), PositionedFile(501, ServiceFile(serviceFileId)))
76-
.toExpiringFuture()
77-
.get()
78-
viewModel.removeFile().toExpiringFuture().get()
79-
}
71+
viewModel.isInPosition.mapNotNull().subscribe(isInPositionStates::add).toCloseable().use {
72+
viewModel
73+
.load(LibraryId(libraryId), PositionedFile(0, ServiceFile(serviceFileId)))
74+
.toExpiringFuture()
75+
.get()
76+
viewModel.removeFile().toExpiringFuture().get()
8077
}
8178
}
8279
}
@@ -87,28 +84,24 @@ class `When removing the file from now playing` {
8784
}
8885

8986
@Test
90-
fun `then is removing changes correctly`() {
91-
assertThat(isRemovingStates).isEqualTo(
87+
fun `then the file is in position changes correctly`() {
88+
assertThat(isInPositionStates).isEqualTo(
9289
listOf(
9390
false,
9491
true,
9592
false,
93+
true,
9694
)
9795
)
9896
}
9997

100-
@Test
101-
fun `then the file is in position changes correctly`() {
102-
assertThat(isInPositionStates).isEqualTo(listOf(false))
103-
}
104-
10598
@Test
10699
fun `then the file is removed with the correct library id`() {
107100
assertThat(removedLibraryId).isEqualTo(LibraryId(libraryId))
108101
}
109102

110103
@Test
111104
fun `then the file is removed to now playing`() {
112-
assertThat(removedPosition).isEqualTo(501)
105+
assertThat(removedPosition).isEqualTo(0)
113106
}
114107
}

0 commit comments

Comments
 (0)