Skip to content

Commit

Permalink
Done Album Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Dec 4, 2024
1 parent c2440fb commit 08d81a8
Show file tree
Hide file tree
Showing 16 changed files with 777 additions and 1,510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,14 @@ interface DatabaseDao {
@Query("SELECT * FROM album WHERE browseId = :browseId")
suspend fun getAlbum(browseId: String): AlbumEntity

@Query("SELECT * FROM album WHERE browseId = :browseId")
fun getAlbumAsFlow(browseId: String): Flow<AlbumEntity?>

@Query("SELECT * FROM album WHERE liked = 1")
suspend fun getLikedAlbums(): List<AlbumEntity>

@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertAlbum(album: AlbumEntity)
suspend fun insertAlbum(album: AlbumEntity): Long

@Query("UPDATE album SET liked = :liked WHERE browseId = :browseId")
suspend fun updateAlbumLiked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class LocalDataSource(

suspend fun getAlbum(albumId: String) = databaseDao.getAlbum(albumId)

fun getAlbumAsFlow(albumId: String) = databaseDao.getAlbumAsFlow(albumId)

suspend fun getLikedAlbums() = databaseDao.getLikedAlbums()

suspend fun updateAlbumInLibrary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,16 @@ class MainRepository(
emit(localDataSource.getAlbum(id))
}.flowOn(Dispatchers.IO)

fun getAlbumAsFlow(id: String) = localDataSource.getAlbumAsFlow(id)

fun getLikedAlbums(): Flow<List<AlbumEntity>> =
flow {
emit(localDataSource.getLikedAlbums())
}.flowOn(Dispatchers.IO)

suspend fun insertAlbum(albumEntity: AlbumEntity) =
withContext(Dispatchers.IO) {
localDataSource.insertAlbum(albumEntity)
}
fun insertAlbum(albumEntity: AlbumEntity) = flow {
emit(localDataSource.insertAlbum(albumEntity))
}.flowOn(Dispatchers.IO)

suspend fun updateAlbumLiked(
albumId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.media3.exoplayer.audio.AudioSink
import androidx.media3.exoplayer.audio.DefaultAudioSink
import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.util.EventLogger
import androidx.media3.extractor.ExtractorsFactory
import androidx.media3.extractor.mkv.MatroskaExtractor
import androidx.media3.extractor.mp4.FragmentedMp4Extractor
Expand Down Expand Up @@ -135,7 +136,9 @@ val mediaServiceModule =
get(),
),
).setRenderersFactory(provideRendererFactory(androidContext()))
.build()
.build().also {
it.addAnalyticsListener(EventLogger())
}
}
// CoilBitmapLoader
single<CoilBitmapLoader>(createdAtStart = true) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/di/ViewModelModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxrave.simpmusic.di

import androidx.media3.common.util.UnstableApi
import com.maxrave.simpmusic.viewModel.AlbumViewModel
import com.maxrave.simpmusic.viewModel.LibraryDynamicPlaylistViewModel
import com.maxrave.simpmusic.viewModel.LibraryViewModel
import com.maxrave.simpmusic.viewModel.NowPlayingBottomSheetViewModel
Expand All @@ -25,4 +26,9 @@ val viewModelModule = module {
application = androidApplication()
)
}
viewModel {
AlbumViewModel(
application = androidApplication()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -41,11 +42,21 @@ fun DescriptionView(
var expanded by rememberSaveable {
mutableStateOf(false)
}
var shouldHideExpandButton by rememberSaveable {
mutableStateOf(false)
}
val maxLineAnimated by animateIntAsState(
targetValue = if (expanded) 1000 else limitLine
)
var layoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }

LaunchedEffect(layoutResult) {
val lineCount = layoutResult?.lineCount ?: 0
if (lineCount < limitLine ) {
shouldHideExpandButton = true
}
}


val timeRegex = Regex("""(\d+):(\d+)(?::(\d+))?""")
val urlRegex = Regex("""https?://\S+""")
Expand Down Expand Up @@ -126,14 +137,16 @@ fun DescriptionView(
onTextLayout = { layoutResult = it },
style = typo.bodyMedium
)
Spacer(modifier = Modifier.height(5.dp))
Text(
text = if (expanded) stringResource(id = R.string.less) else stringResource(id = R.string.more),
color = Color.LightGray,
modifier = Modifier.clickable {
expanded = !expanded
},
style = typo.labelSmall
)
Spacer(modifier = Modifier.height(8.dp))
androidx.compose.animation.AnimatedVisibility(!shouldHideExpandButton) {
Text(
text = if (expanded) stringResource(id = R.string.less) else stringResource(id = R.string.more),
color = Color.LightGray,
modifier = Modifier.clickable {
expanded = !expanded
},
style = typo.labelSmall
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import org.koin.compose.koinInject
@Composable
fun SongFullWidthItems(
track: Track? = null,
index: Int? = null,
songEntity: SongEntity? = null,
isPlaying: Boolean,
onMoreClickListener: ((videoId: String) -> Unit)? = null,
Expand All @@ -88,11 +89,14 @@ fun SongFullWidthItems(
.fillMaxWidth(),
) {
Spacer(modifier = Modifier.width(10.dp))
Box(modifier = Modifier.size(50.dp)) {
Box(
modifier = Modifier.size(50.dp),
contentAlignment = Alignment.Center
) {
Crossfade(isPlaying) {
if (it) {
LottieAnimation(composition, iterations = LottieConstants.IterateForever)
} else {
} else if (index == null) {
val thumb = track?.thumbnails?.lastOrNull()?.url ?: songEntity?.thumbnails
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
Expand All @@ -109,6 +113,11 @@ fun SongFullWidthItems(
Modifier
.fillMaxSize(),
)
} else {
Text(
text = ((index ?: 0) + 1).toString(), color = Color.White, style = typo.titleMedium,
modifier = Modifier.align(Alignment.Center)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fun LibraryItem(
R.id.action_global_playlistFragment,
Bundle().apply {
putString("id", item.browseId)
putBoolean("youtube", true)
}
)
}
Expand Down
Loading

0 comments on commit 08d81a8

Please sign in to comment.