Skip to content

Instantly share code, notes, and snippets.

@AOrobator
Created April 7, 2018 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AOrobator/1529d776d5e1c7d18adf2e57300f0f00 to your computer and use it in GitHub Desktop.
Save AOrobator/1529d776d5e1c7d18adf2e57300f0f00 to your computer and use it in GitHub Desktop.
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