Mark item as played
This commit is contained in:
parent
6cf1f5cc49
commit
dbc2582724
8 changed files with 101 additions and 4 deletions
|
@ -34,7 +34,7 @@ class JellyfinApi(context: Context, baseUrl: String) {
|
|||
val sessionApi = SessionApi(api)
|
||||
val videosApi = VideosApi(api)
|
||||
val mediaInfoApi = MediaInfoApi(api)
|
||||
val playstateApi = PlayStateApi(api)
|
||||
val playStateApi = PlayStateApi(api)
|
||||
|
||||
companion object {
|
||||
@Volatile
|
||||
|
|
|
@ -41,6 +41,13 @@ class EpisodeBottomSheetFragment : BottomSheetDialogFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
binding.checkButton.setOnClickListener {
|
||||
when (viewModel.played.value) {
|
||||
true -> viewModel.markAsUnplayed(args.episodeId)
|
||||
false -> viewModel.markAsPlayed(args.episodeId)
|
||||
}
|
||||
}
|
||||
|
||||
binding.favoriteButton.setOnClickListener {
|
||||
when (viewModel.favorite.value) {
|
||||
true -> viewModel.unmarkAsFavorite(args.episodeId)
|
||||
|
@ -59,6 +66,15 @@ class EpisodeBottomSheetFragment : BottomSheetDialogFragment() {
|
|||
}
|
||||
})
|
||||
|
||||
viewModel.played.observe(viewLifecycleOwner, {
|
||||
val drawable = when (it) {
|
||||
true -> R.drawable.ic_check_filled
|
||||
false -> R.drawable.ic_check
|
||||
}
|
||||
|
||||
binding.checkButton.setImageResource(drawable)
|
||||
})
|
||||
|
||||
viewModel.favorite.observe(viewLifecycleOwner, {
|
||||
val drawable = when (it) {
|
||||
true -> R.drawable.ic_heart_filled
|
||||
|
|
|
@ -65,6 +65,15 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
})
|
||||
|
||||
viewModel.played.observe(viewLifecycleOwner, {
|
||||
val drawable = when (it) {
|
||||
true -> R.drawable.ic_check_filled
|
||||
false -> R.drawable.ic_check
|
||||
}
|
||||
|
||||
binding.checkButton.setImageResource(drawable)
|
||||
})
|
||||
|
||||
viewModel.favorite.observe(viewLifecycleOwner, {
|
||||
val drawable = when (it) {
|
||||
true -> R.drawable.ic_heart_filled
|
||||
|
@ -111,6 +120,13 @@ class MediaInfoFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
binding.checkButton.setOnClickListener {
|
||||
when (viewModel.played.value) {
|
||||
true -> viewModel.markAsUnplayed(args.itemId)
|
||||
false -> viewModel.markAsPlayed(args.itemId)
|
||||
}
|
||||
}
|
||||
|
||||
binding.favoriteButton.setOnClickListener {
|
||||
when (viewModel.favorite.value) {
|
||||
true -> viewModel.unmarkAsFavorite(args.itemId)
|
||||
|
|
|
@ -29,4 +29,8 @@ interface JellyfinRepository {
|
|||
suspend fun markAsFavorite(itemId: UUID)
|
||||
|
||||
suspend fun unmarkAsFavorite(itemId: UUID)
|
||||
|
||||
suspend fun markAsPlayed(itemId: UUID)
|
||||
|
||||
suspend fun markAsUnplayed(itemId: UUID)
|
||||
}
|
|
@ -119,20 +119,20 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
override suspend fun postPlaybackStart(itemId: UUID) {
|
||||
Log.d("PlayerActivity", "Sending start $itemId")
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.playstateApi.onPlaybackStart(jellyfinApi.userId!!, itemId)
|
||||
jellyfinApi.playStateApi.onPlaybackStart(jellyfinApi.userId!!, itemId)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun postPlaybackStop(itemId: UUID, positionTicks: Long) {
|
||||
Log.d("PlayerActivity", "Sending stop $itemId")
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.playstateApi.onPlaybackStopped(jellyfinApi.userId!!, itemId, positionTicks = positionTicks)
|
||||
jellyfinApi.playStateApi.onPlaybackStopped(jellyfinApi.userId!!, itemId, positionTicks = positionTicks)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun postPlaybackProgress(itemId: UUID, positionTicks: Long, isPaused: Boolean) {
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.playstateApi.onPlaybackProgress(jellyfinApi.userId!!, itemId, positionTicks = positionTicks, isPaused = isPaused)
|
||||
jellyfinApi.playStateApi.onPlaybackProgress(jellyfinApi.userId!!, itemId, positionTicks = positionTicks, isPaused = isPaused)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,4 +147,16 @@ class JellyfinRepositoryImpl(private val jellyfinApi: JellyfinApi) : JellyfinRep
|
|||
jellyfinApi.userLibraryApi.unmarkFavoriteItem(jellyfinApi.userId!!, itemId)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun markAsPlayed(itemId: UUID) {
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.playStateApi.markPlayedItem(jellyfinApi.userId!!, itemId)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun markAsUnplayed(itemId: UUID) {
|
||||
withContext(Dispatchers.IO) {
|
||||
jellyfinApi.playStateApi.markUnplayedItem(jellyfinApi.userId!!, itemId)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,9 @@ constructor(
|
|||
private val _mediaSources = MutableLiveData<List<MediaSourceInfo>>()
|
||||
val mediaSources: LiveData<List<MediaSourceInfo>> = _mediaSources
|
||||
|
||||
private val _played = MutableLiveData<Boolean>()
|
||||
val played: LiveData<Boolean> = _played
|
||||
|
||||
private val _favorite = MutableLiveData<Boolean>()
|
||||
val favorite: LiveData<Boolean> = _favorite
|
||||
|
||||
|
@ -43,10 +46,25 @@ constructor(
|
|||
_runTime.value = "${_item.value?.runTimeTicks?.div(600000000)} min"
|
||||
_dateString.value = getDateString(_item.value!!)
|
||||
_mediaSources.value = jellyfinRepository.getMediaSources(episodeId)
|
||||
_played.value = _item.value?.userData?.played
|
||||
_favorite.value = _item.value?.userData?.isFavorite
|
||||
}
|
||||
}
|
||||
|
||||
fun markAsPlayed(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsPlayed(itemId)
|
||||
}
|
||||
_played.value = true
|
||||
}
|
||||
|
||||
fun markAsUnplayed(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsUnplayed(itemId)
|
||||
}
|
||||
_played.value = false
|
||||
}
|
||||
|
||||
fun markAsFavorite(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsFavorite(itemId)
|
||||
|
|
|
@ -56,6 +56,9 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
private val _navigateToPlayer = MutableLiveData<MediaSourceInfo>()
|
||||
val navigateToPlayer: LiveData<MediaSourceInfo> = _navigateToPlayer
|
||||
|
||||
private val _played = MutableLiveData<Boolean>()
|
||||
val played: LiveData<Boolean> = _played
|
||||
|
||||
private val _favorite = MutableLiveData<Boolean>()
|
||||
val favorite: LiveData<Boolean> = _favorite
|
||||
|
||||
|
@ -70,6 +73,7 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
_genresString.value = _item.value?.genres?.joinToString(separator = ", ")
|
||||
_runTime.value = "${_item.value?.runTimeTicks?.div(600000000)} min"
|
||||
_dateString.value = getDateString(_item.value!!)
|
||||
_played.value = _item.value?.userData?.played
|
||||
_favorite.value = _item.value?.userData?.isFavorite
|
||||
if (itemType == "Series") {
|
||||
_nextUp.value = getNextUp(itemId)
|
||||
|
@ -114,6 +118,20 @@ constructor(private val jellyfinRepository: JellyfinRepository) : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
fun markAsPlayed(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsPlayed(itemId)
|
||||
}
|
||||
_played.value = true
|
||||
}
|
||||
|
||||
fun markAsUnplayed(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsUnplayed(itemId)
|
||||
}
|
||||
_played.value = false
|
||||
}
|
||||
|
||||
fun markAsFavorite(itemId: UUID) {
|
||||
viewModelScope.launch {
|
||||
jellyfinRepository.markAsFavorite(itemId)
|
||||
|
|
13
app/src/main/res/drawable/ic_check_filled.xml
Normal file
13
app/src/main/res/drawable/ic_check_filled.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M20,6l-11,11l-5,-5"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="@color/red"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
Loading…
Reference in a new issue