Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visible offline 2.0 #129

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/src/main/java/com/dd3boh/outertune/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class MainActivity : ComponentActivity() {

setContent {
val connectivityObserver = NetworkConnectivityObserver(this)
val isInternetConnected by connectivityObserver.networkStatus.collectAsState(false)
val isNetworkConnected by connectivityObserver.networkStatus.collectAsState(false)

val enableDynamicTheme by rememberPreference(DynamicThemeKey, defaultValue = true)
val darkTheme by rememberEnumPreference(DarkModeKey, defaultValue = DarkMode.AUTO)
Expand Down Expand Up @@ -692,7 +692,7 @@ class MainActivity : ComponentActivity() {
LocalDownloadUtil provides downloadUtil,
LocalShimmerTheme provides ShimmerTheme,
LocalSyncUtils provides syncUtils,
LocalIsInternetConnected provides isInternetConnected
LocalIsNetworkConnected provides isNetworkConnected
) {
Scaffold(
topBar = {
Expand Down Expand Up @@ -1269,4 +1269,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 @@ -113,7 +113,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 @@ -134,15 +134,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 @@ -154,19 +154,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 @@ -199,7 +199,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 @@ -178,9 +181,9 @@ fun SwipeToQueueBox(
)
}

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

}
Loading
Loading