Skip to content

Commit

Permalink
Visible offline 2.0 (DD3Boh#129)
Browse files Browse the repository at this point in the history
* songs: centralize SongListItem logic + select header also consider connection

* songs: add play when offline logic (only play offline items)

* songs: fix song selection when offline

* app: Fix codestyle

* refactor: move select logic to parent
  • Loading branch information
mattcarter11 authored and reocat committed Jan 8, 2025
1 parent 8b0e4ea commit 61629d3
Show file tree
Hide file tree
Showing 32 changed files with 921 additions and 1,187 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ class MainActivity : ComponentActivity() {
LocalDownloadUtil provides downloadUtil,
LocalShimmerTheme provides ShimmerTheme,
LocalSyncUtils provides syncUtils,
LocalIsInternetConnected provides isNetworkConnected
LocalIsNetworkConnected provides isNetworkConnected
) {
Scaffold(
topBar = {
Expand Down Expand Up @@ -1296,4 +1296,4 @@ val LocalPlayerConnection = staticCompositionLocalOf<PlayerConnection?> { error(
val LocalPlayerAwareWindowInsets = compositionLocalOf<WindowInsets> { error("No WindowInsets provided") }
val LocalDownloadUtil = staticCompositionLocalOf<DownloadUtil> { error("No DownloadUtil provided") }
val LocalSyncUtils = staticCompositionLocalOf<SyncUtils> { error("No SyncUtils provided") }
val LocalIsInternetConnected = staticCompositionLocalOf<Boolean> { error("No Network Status provided") }
val LocalIsNetworkConnected = staticCompositionLocalOf<Boolean> { error("No Network Status provided") }
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ interface ArtistsDao {
ArtistSortType.PLAY_TIME -> "SUM(totalPlayTime) ASC"
}

val where = when (filter){
val where = when (filter) {
ArtistFilter.DOWNLOADED -> "song.dateDownload IS NOT NULL"
ArtistFilter.LIBRARY -> "song.inLibrary IS NOT NULL"
ArtistFilter.LIKED -> "artist.bookmarkedAt IS NOT NULL"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/dd3boh/outertune/extensions/SongsExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dd3boh.outertune.extensions

import com.dd3boh.outertune.db.entities.Song

fun List<Song>.getAvailableSongs(isInternetConnected: Boolean): List<Song> {
if (isInternetConnected) {
return this
}
return filter { it.song.isAvailableOffline() }
}
16 changes: 8 additions & 8 deletions app/src/main/java/com/dd3boh/outertune/playback/DownloadUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ class DownloadUtil @Inject constructor(
songs.forEach { song -> downloadSong(song.id, song.title) }
}

fun download(song: MediaMetadata){
fun download(song: MediaMetadata) {
downloadSong(song.id, song.title)
}

fun download(song: SongEntity){
fun download(song: SongEntity) {
downloadSong(song.id, song.title)
}

private fun downloadSong(id: String, title: String){
private fun downloadSong(id: String, title: String) {
val downloadRequest = DownloadRequest.Builder(id, id.toUri())
.setCustomCacheKey(id)
.setData(title.toByteArray())
Expand All @@ -144,19 +144,19 @@ class DownloadUtil @Inject constructor(
false)
}

fun resumeDownloadsOnStart(){
fun resumeDownloadsOnStart() {
DownloadService.sendResumeDownloads(
context,
ExoDownloadService::class.java,
false)
}

fun autoDownloadIfLiked(songs: List<SongEntity>){
fun autoDownloadIfLiked(songs: List<SongEntity>) {
songs.forEach { song -> autoDownloadIfLiked(song) }
}

fun autoDownloadIfLiked(song: SongEntity){
if (!song.liked || song.dateDownload != null){
fun autoDownloadIfLiked(song: SongEntity) {
if (!song.liked || song.dateDownload != null) {
return
}

Expand Down Expand Up @@ -189,7 +189,7 @@ class DownloadUtil @Inject constructor(
}

CoroutineScope(Dispatchers.IO).launch {
if (download.state == Download.STATE_COMPLETED){
if (download.state == Download.STATE_COMPLETED) {
val updateTime = Instant.ofEpochMilli(download.updateTimeMs).atZone(ZoneOffset.UTC).toLocalDateTime()
database.updateDownloadStatus(download.request.id, updateTime)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ fun SwipeToQueueBox(

coroutineScope.launch {
snackbarHostState.showSnackbar(
message = context.getString(R.string.song_added_to_queue, item.mediaMetadata.title),
message = context.getString(
R.string.song_added_to_queue,
item.mediaMetadata.title
),
duration = SnackbarDuration.Short
)
}
Expand All @@ -179,16 +182,15 @@ fun SwipeToQueueBox(
)
}

LaunchedEffect(state.currentValue) {
if (state.currentValue == DragAnchors.Start && !state.isAnimationRunning) {
state.animateTo(DragAnchors.Center)
}
}

if (!enabled){
if (!enabled) {
Box { content() }
}
}
else {
LaunchedEffect(state.currentValue) {
if (state.currentValue == DragAnchors.Start && !state.isAnimationRunning) {
state.animateTo(DragAnchors.Center)
}
}
DraggableItem(
state = state,
content = {
Expand Down Expand Up @@ -217,5 +219,4 @@ fun SwipeToQueueBox(
}
)
}

}
Loading

0 comments on commit 61629d3

Please sign in to comment.