Created
April 7, 2018 18:48
-
-
Save AOrobator/1529d776d5e1c7d18adf2e57300f0f00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RealmSongRepository : SongRepository { | |
override fun addSongToLibrary(filePath: String): Single<SongId> { | |
return Single.fromCallable { | |
scanSongIntoLibrary(filePath) | |
} | |
.subscribeOn(io()) | |
.observeOn(mainThread()) | |
} | |
override fun scanSongIntoLibrary(filePath: String): SongId { | |
var newSongId: SongId = InvalidSongId | |
realmTransaction { | |
if (getSongForFilepath(it, filePath) == null) { | |
val song = Song { | |
id = Database.getNextId(it, Song::class.java) | |
newSongId = // get next ValidSongId | |
// Initialize title, artist, and album for the song | |
} | |
it.copyToRealm(song) | |
} | |
} | |
return newSongId | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment