-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e099c62
commit c9a2e1f
Showing
23 changed files
with
86 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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
10 changes: 5 additions & 5 deletions
10
app/src/main/java/app/suhasdissa/lyrics/backend/database/dao/ArtistsDao.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package app.suhasdissa.lyrics.backend.database.dao | ||
|
||
import androidx.room.* | ||
import app.suhasdissa.lyrics.backend.database.entities.ArtistEntity | ||
import app.suhasdissa.lyrics.backend.database.entities.Artist | ||
|
||
@Dao | ||
interface ArtistsDao { | ||
@Query("SELECT * FROM artists") | ||
fun getAll(): List<ArtistEntity> | ||
fun getAll(): List<Artist> | ||
|
||
@Query("SELECT * FROM artists WHERE artistID = :artist") | ||
fun getArtist(artist: Int): ArtistEntity | ||
fun getArtist(artist: Int): Artist | ||
|
||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insertAll(memes: List<ArtistEntity>) | ||
fun insertAll(memes: List<Artist>) | ||
|
||
@Delete | ||
fun delete(meme: ArtistEntity) | ||
fun delete(meme: Artist) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
49 changes: 13 additions & 36 deletions
49
app/src/main/java/app/suhasdissa/lyrics/backend/repositories/LocalSongRepository.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,35 @@ | ||
package app.suhasdissa.lyrics.backend.repositories | ||
|
||
import app.suhasdissa.lyrics.backend.database.dao.ArtistsDao | ||
import app.suhasdissa.lyrics.backend.database.dao.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.dao.SongsDao | ||
import app.suhasdissa.lyrics.backend.database.entities.ArtistEntity | ||
import app.suhasdissa.lyrics.backend.database.entities.SongEntity | ||
import app.suhasdissa.lyrics.backend.repositories.data.Artist | ||
import app.suhasdissa.lyrics.backend.repositories.data.Song | ||
import app.suhasdissa.lyrics.backend.repositories.data.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.entities.Artist | ||
import app.suhasdissa.lyrics.backend.database.entities.Song | ||
|
||
class LocalSongRepository(private val songsDao: SongsDao, private val artistsDao: ArtistsDao) : | ||
SongRepository { | ||
|
||
private fun SongEntity.toSong() = | ||
Song(artistID = artistID, song = song, lyric = lyric, artistName = artistName, _id = _id) | ||
|
||
private fun ArtistEntity.toArtist() = Artist(artistID = artistID, artistName = artistName) | ||
|
||
override suspend fun getSongs(): ArrayList<SongHeader> { | ||
return songsDao.getSongs().mapTo(ArrayList()) { | ||
SongHeader( | ||
_id = it._id, song = it.song, artistName = it.artistName | ||
) | ||
} | ||
override suspend fun getSongs(): List<SongHeader> { | ||
return songsDao.getSongs() | ||
} | ||
|
||
override suspend fun getArtists(): ArrayList<Artist> { | ||
return artistsDao.getAll().mapTo(ArrayList()) { | ||
Artist( | ||
artistID = it.artistID, artistName = it.artistName | ||
) | ||
} | ||
override suspend fun getArtists(): List<Artist> { | ||
return artistsDao.getAll() | ||
} | ||
|
||
override suspend fun getSong(id: Int): Song { | ||
return songsDao.getSong(id).toSong() | ||
return songsDao.getSong(id) | ||
} | ||
|
||
override suspend fun getArtist(id: Int): Artist { | ||
return artistsDao.getArtist(id).toArtist() | ||
return artistsDao.getArtist(id) | ||
} | ||
|
||
override suspend fun searchSongs(search: String): ArrayList<SongHeader> { | ||
return songsDao.searchSongs(search).mapTo(ArrayList()) { | ||
SongHeader( | ||
_id = it._id, song = it.song, artistName = it.artistName | ||
) | ||
} | ||
override suspend fun searchSongs(search: String): List<SongHeader> { | ||
return songsDao.searchSongs(search) | ||
} | ||
|
||
override suspend fun filterArtist(artist: Int): ArrayList<SongHeader> { | ||
return songsDao.filterArtist(artist).mapTo(ArrayList()) { | ||
SongHeader( | ||
_id = it._id, song = it.song, artistName = it.artistName | ||
) | ||
} | ||
override suspend fun filterArtist(artist: Int): List<SongHeader> { | ||
return songsDao.filterArtist(artist) | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
app/src/main/java/app/suhasdissa/lyrics/backend/repositories/SongRepository.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package app.suhasdissa.lyrics.backend.repositories | ||
|
||
import app.suhasdissa.lyrics.backend.repositories.data.Artist | ||
import app.suhasdissa.lyrics.backend.repositories.data.Song | ||
import app.suhasdissa.lyrics.backend.repositories.data.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.dao.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.entities.Artist | ||
import app.suhasdissa.lyrics.backend.database.entities.Song | ||
|
||
interface SongRepository { | ||
suspend fun getSongs(): ArrayList<SongHeader> | ||
suspend fun getArtists(): ArrayList<Artist> | ||
suspend fun getSongs(): List<SongHeader> | ||
suspend fun getArtists(): List<Artist> | ||
suspend fun getSong(id: Int): Song | ||
suspend fun getArtist(id: Int): Artist | ||
suspend fun searchSongs(search: String): ArrayList<SongHeader> | ||
suspend fun filterArtist(artist: Int): ArrayList<SongHeader> | ||
suspend fun searchSongs(search: String): List<SongHeader> | ||
suspend fun filterArtist(artist: Int): List<SongHeader> | ||
} |
5 changes: 0 additions & 5 deletions
5
app/src/main/java/app/suhasdissa/lyrics/backend/repositories/data/Artist.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/app/suhasdissa/lyrics/backend/repositories/data/Song.kt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
app/src/main/java/app/suhasdissa/lyrics/backend/repositories/data/SongHeader.kt
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
4 changes: 2 additions & 2 deletions
4
app/src/main/java/app/suhasdissa/lyrics/backend/viewmodels/states/FilterState.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package app.suhasdissa.lyrics.backend.viewmodels.states | ||
|
||
import app.suhasdissa.lyrics.backend.repositories.data.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.dao.SongHeader | ||
|
||
sealed interface FilterState { | ||
data class Success(val songs: ArrayList<SongHeader>) : FilterState | ||
data class Success(val songs: List<SongHeader>) : FilterState | ||
object Empty : FilterState | ||
} |
4 changes: 2 additions & 2 deletions
4
app/src/main/java/app/suhasdissa/lyrics/backend/viewmodels/states/SearchState.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package app.suhasdissa.lyrics.backend.viewmodels.states | ||
|
||
import app.suhasdissa.lyrics.backend.repositories.data.SongHeader | ||
import app.suhasdissa.lyrics.backend.database.dao.SongHeader | ||
|
||
sealed interface SearchState { | ||
data class Success(val songs: ArrayList<SongHeader>) : SearchState | ||
data class Success(val songs: List<SongHeader>) : SearchState | ||
object Empty : SearchState | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.