mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Basic requesting structure (doesn't work)
This commit is contained in:
parent
76c1fd4b15
commit
ac5f0aa367
5 changed files with 96 additions and 14 deletions
|
|
@ -41,6 +41,7 @@ import com.github.damontecres.wholphin.data.model.DiscoverRating
|
|||
import com.github.damontecres.wholphin.data.model.LocalTrailer
|
||||
import com.github.damontecres.wholphin.data.model.Person
|
||||
import com.github.damontecres.wholphin.data.model.RemoteTrailer
|
||||
import com.github.damontecres.wholphin.data.model.SeerrAvailability
|
||||
import com.github.damontecres.wholphin.data.model.Trailer
|
||||
import com.github.damontecres.wholphin.preferences.UserPreferences
|
||||
import com.github.damontecres.wholphin.services.TrailerService
|
||||
|
|
@ -122,7 +123,10 @@ fun DiscoverMovieDetails(
|
|||
similar = similar,
|
||||
recommended = recommended,
|
||||
requestOnClick = {
|
||||
// TODO seerr
|
||||
movie.id?.let { viewModel.request(it) }
|
||||
},
|
||||
cancelOnClick = {
|
||||
movie.id?.let { viewModel.cancelRequest(it) }
|
||||
},
|
||||
onClickItem = { index, item ->
|
||||
viewModel.navigateTo(Destination.DiscoveredItem(item))
|
||||
|
|
@ -207,6 +211,7 @@ fun DiscoverMovieDetailsContent(
|
|||
similar: List<DiscoverItem>,
|
||||
recommended: List<DiscoverItem>,
|
||||
requestOnClick: () -> Unit,
|
||||
cancelOnClick: () -> Unit,
|
||||
trailerOnClick: (Trailer) -> Unit,
|
||||
overviewOnClick: () -> Unit,
|
||||
moreOnClick: () -> Unit,
|
||||
|
|
@ -251,7 +256,11 @@ fun DiscoverMovieDetailsContent(
|
|||
.padding(top = 32.dp, bottom = 16.dp),
|
||||
)
|
||||
ExpandableDiscoverButtons(
|
||||
availability =
|
||||
SeerrAvailability.from(movie.mediaInfo?.status)
|
||||
?: SeerrAvailability.UNKNOWN,
|
||||
requestOnClick = requestOnClick,
|
||||
cancelOnClick = cancelOnClick,
|
||||
moreOnClick = moreOnClick,
|
||||
buttonOnFocusChanged = {
|
||||
if (it.isFocused) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.github.damontecres.wholphin.api.seerr.model.MovieDetails
|
||||
import com.github.damontecres.wholphin.api.seerr.model.RelatedVideo
|
||||
import com.github.damontecres.wholphin.api.seerr.model.RequestPostRequest
|
||||
import com.github.damontecres.wholphin.data.ServerRepository
|
||||
import com.github.damontecres.wholphin.data.model.DiscoverItem
|
||||
import com.github.damontecres.wholphin.data.model.DiscoverRating
|
||||
|
|
@ -157,4 +158,28 @@ class DiscoverMovieViewModel
|
|||
fun navigateTo(destination: Destination) {
|
||||
navigationManager.navigateTo(destination)
|
||||
}
|
||||
|
||||
fun request(id: Int) {
|
||||
viewModelScope.launchIO {
|
||||
val request =
|
||||
seerrService.api.requestApi.requestPost(
|
||||
RequestPostRequest(
|
||||
is4k = false,
|
||||
mediaid = id,
|
||||
mediaType = RequestPostRequest.MediaType.MOVIE,
|
||||
),
|
||||
)
|
||||
fetchAndSetItem().await()
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelRequest(id: Int) {
|
||||
viewModelScope.launchIO {
|
||||
movie.value?.mediaInfo?.requests?.firstOrNull()?.let {
|
||||
// TODO handle multiple requests? Or just delete self's request?
|
||||
seerrService.api.requestApi.requestRequestIdDelete(it.id.toString())
|
||||
fetchAndSetItem().await()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ import androidx.compose.foundation.layout.Arrangement
|
|||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
|
|
@ -16,13 +18,16 @@ import androidx.compose.ui.focus.focusRestorer
|
|||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.damontecres.wholphin.R
|
||||
import com.github.damontecres.wholphin.data.model.SeerrAvailability
|
||||
import com.github.damontecres.wholphin.ui.components.ExpandableFaButton
|
||||
import com.github.damontecres.wholphin.ui.components.ExpandablePlayButton
|
||||
import kotlin.time.Duration
|
||||
|
||||
@Composable
|
||||
fun ExpandableDiscoverButtons(
|
||||
availability: SeerrAvailability,
|
||||
requestOnClick: () -> Unit,
|
||||
cancelOnClick: () -> Unit,
|
||||
moreOnClick: () -> Unit,
|
||||
buttonOnFocusChanged: (FocusState) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
|
|
@ -36,17 +41,59 @@ fun ExpandableDiscoverButtons(
|
|||
.focusGroup()
|
||||
.focusRestorer(firstFocus),
|
||||
) {
|
||||
item("request") {
|
||||
ExpandableFaButton(
|
||||
title = R.string.request,
|
||||
iconStringRes = R.string.fa_download,
|
||||
onClick = requestOnClick,
|
||||
modifier =
|
||||
Modifier
|
||||
.focusRequester(firstFocus)
|
||||
.onFocusChanged(buttonOnFocusChanged)
|
||||
.animateItem(),
|
||||
)
|
||||
if (availability == SeerrAvailability.UNKNOWN) {
|
||||
item("request") {
|
||||
ExpandableFaButton(
|
||||
title = R.string.request,
|
||||
iconStringRes = R.string.fa_download,
|
||||
onClick = requestOnClick,
|
||||
modifier =
|
||||
Modifier
|
||||
.focusRequester(firstFocus)
|
||||
.onFocusChanged(buttonOnFocusChanged),
|
||||
)
|
||||
}
|
||||
} else if (availability == SeerrAvailability.PENDING || availability == SeerrAvailability.PROCESSING) {
|
||||
item("pending") {
|
||||
ExpandableFaButton(
|
||||
title = R.string.pending,
|
||||
iconStringRes = R.string.fa_clock,
|
||||
onClick = {
|
||||
// TODO show request dialog?
|
||||
},
|
||||
modifier =
|
||||
Modifier
|
||||
.focusRequester(firstFocus)
|
||||
.onFocusChanged(buttonOnFocusChanged),
|
||||
)
|
||||
}
|
||||
item("cancel") {
|
||||
ExpandablePlayButton(
|
||||
title = R.string.cancel,
|
||||
icon = Icons.Default.Delete,
|
||||
onClick = { cancelOnClick.invoke() },
|
||||
resume = Duration.ZERO,
|
||||
modifier =
|
||||
Modifier
|
||||
.focusRequester(firstFocus)
|
||||
.onFocusChanged(buttonOnFocusChanged),
|
||||
)
|
||||
}
|
||||
} else if (availability == SeerrAvailability.PARTIALLY_AVAILABLE || availability == SeerrAvailability.AVAILABLE) {
|
||||
item("goto") {
|
||||
ExpandablePlayButton(
|
||||
title = R.string.go_to,
|
||||
icon = Icons.Default.PlayArrow,
|
||||
onClick = {
|
||||
// TODO go to the item
|
||||
},
|
||||
resume = Duration.ZERO,
|
||||
modifier =
|
||||
Modifier
|
||||
.focusRequester(firstFocus)
|
||||
.onFocusChanged(buttonOnFocusChanged),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// More button
|
||||
|
|
@ -57,8 +104,7 @@ fun ExpandableDiscoverButtons(
|
|||
Icons.Default.MoreVert,
|
||||
{ moreOnClick.invoke() },
|
||||
Modifier
|
||||
.onFocusChanged(buttonOnFocusChanged)
|
||||
.animateItem(),
|
||||
.onFocusChanged(buttonOnFocusChanged),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,5 @@
|
|||
<string name="fa_filter" translatable="false"></string>
|
||||
<string name="fa_sliders" translatable="false"></string>
|
||||
<string name="fa_download" translatable="false"></string>
|
||||
<string name="fa_clock" translatable="false"></string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -401,6 +401,7 @@
|
|||
|
||||
<string name="discover">Discover</string>
|
||||
<string name="request">Request</string>
|
||||
<string name="pending">Pending</string>
|
||||
|
||||
<string-array name="theme_song_volume">
|
||||
<item>Disabled</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue