Skip to content

Commit

Permalink
feat: add refetch album button
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang authored and Malopieds committed Aug 19, 2024
1 parent 43f183a commit 2b9db38
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/src/main/java/com/malopieds/innertune/ui/menu/AlbumMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.malopieds.innertune.ui.menu

import android.annotation.SuppressLint
import android.content.Intent
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -25,14 +27,17 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
Expand All @@ -49,6 +54,7 @@ import androidx.media3.exoplayer.offline.DownloadRequest
import androidx.media3.exoplayer.offline.DownloadService
import androidx.navigation.NavController
import coil.compose.AsyncImage
import com.malopieds.innertube.YouTube
import com.malopieds.innertune.LocalDatabase
import com.malopieds.innertune.LocalDownloadUtil
import com.malopieds.innertune.LocalPlayerConnection
Expand All @@ -67,6 +73,8 @@ import com.malopieds.innertune.ui.component.GridMenuItem
import com.malopieds.innertune.ui.component.ListDialog
import com.malopieds.innertune.ui.component.ListItem
import com.malopieds.innertune.ui.component.SongListItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.time.LocalDateTime

@SuppressLint("MutableCollectionMutableState")
Expand All @@ -81,6 +89,7 @@ fun AlbumMenu(
val database = LocalDatabase.current
val downloadUtil = LocalDownloadUtil.current
val playerConnection = LocalPlayerConnection.current ?: return
val scope = rememberCoroutineScope()
val libraryAlbum by database.album(originalAlbum.id).collectAsState(initial = originalAlbum)
val album = libraryAlbum ?: originalAlbum
var songs by remember {
Expand Down Expand Up @@ -116,6 +125,14 @@ fun AlbumMenu(
}
}

var refetchIconDegree by remember { mutableFloatStateOf(0f) }

val rotationAnimation by animateFloatAsState(
targetValue = refetchIconDegree,
animationSpec = tween(durationMillis = 800),
label = "",
)

var showChoosePlaylistDialog by rememberSaveable {
mutableStateOf(false)
}
Expand Down Expand Up @@ -331,6 +348,25 @@ fun AlbumMenu(
showSelectArtistDialog = true
}
}
GridMenuItem(
icon = {
Icon(
painter = painterResource(R.drawable.sync),
contentDescription = null,
modifier = Modifier.graphicsLayer(rotationZ = rotationAnimation),
)
},
title = R.string.refetch,
) {
refetchIconDegree -= 360
scope.launch(Dispatchers.IO) {
YouTube.album(album.id).onSuccess {
database.transaction {
update(album.album, it, album.artists)
}
}
}
}
GridMenuItem(
icon = R.drawable.share,
title = R.string.share,
Expand Down

0 comments on commit 2b9db38

Please sign in to comment.