Skip to content

Commit

Permalink
Merge pull request #14 from shadow578/fix/quality-of-life
Browse files Browse the repository at this point in the history
Quality-of-Life fixes for 1.3
  • Loading branch information
shadow578 authored Oct 3, 2022
2 parents b2b60bb + 7b1d0b5 commit c27c2b1
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 189 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ android {
signingConfig = signingConfigs.getByName("from_props")
}
}
getByName("debug") {
applicationIdSuffix = ".dev"
}
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
Expand Down
4 changes: 4 additions & 0 deletions app/src/debug/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FF69B4</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.content.Context
import androidx.documentfile.provider.DocumentFile
import com.google.gson.*
import io.github.shadow578.yodel.db.TracksDB
import io.github.shadow578.yodel.db.model.TrackInfo
import timber.log.Timber
import java.io.*
import java.time.*
import java.time.LocalDate
import java.time.LocalDateTime

/**
* tracks db backup helper class.
Expand Down Expand Up @@ -87,15 +89,19 @@ class BackupHelper(
*
* @param data the data to restore
* @param replaceExisting if true, existing entries are overwritten. if false, existing entries are not added
* @param transform transformation function, applied to all restored tracks
*/
fun restoreBackup(data: BackupData, replaceExisting: Boolean) {
fun restoreBackup(data: BackupData, replaceExisting: Boolean, transform: TrackInfo.() -> Unit = {}) {
// check there are tracks to import
if (data.tracks.isEmpty()) return

// apply transform to all tracks
val tracks = data.tracks.map { it.transform(); it }

// insert the tracks
if (replaceExisting)
db.tracks().insertAll(data.tracks)
db.tracks().insertAll(tracks)
else
db.tracks().insertAllNew(data.tracks)
db.tracks().insertAllNew(tracks)
}
}
16 changes: 8 additions & 8 deletions app/src/main/kotlin/io/github/shadow578/yodel/db/TracksDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ interface TracksDao {
@Query("SELECT * FROM tracks ORDER BY first_added_at ASC")
fun observe(): LiveData<List<TrackInfo>>

/**
* observe all tracks that have to be downloaded
*
* @return the tracks that can be observed
*/
@Query("SELECT * FROM tracks WHERE status = 'pending'")
fun observePending(): LiveData<List<TrackInfo>>

/**
* get a list of all tracks
*
Expand All @@ -33,6 +25,14 @@ interface TracksDao {
@get:Query("SELECT * FROM tracks")
val all: List<TrackInfo>

/**
* get a list of all tracks that are marked as pending download
*
* @return a list of all downloaded tracks
*/
@get:Query("SELECT * FROM tracks WHERE status = 'pending'")
val pending: List<TrackInfo>

/**
* get a list of all tracks that are marked as downloaded
*
Expand Down
Loading

0 comments on commit c27c2b1

Please sign in to comment.