This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not override an existing collection with an empty one - except whe…
…n last podcast is deleted
- Loading branch information
Showing
11 changed files
with
156 additions
and
53 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
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
43 changes: 32 additions & 11 deletions
43
app/src/main/java/org/y20k/escapepod/database/EpisodeDao.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,30 +1,51 @@ | ||
package org.y20k.escapepod.database | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.room.* | ||
|
||
@Dao | ||
interface EpisodeDao { | ||
@Query("SELECT * FROM episode") | ||
fun getAll(): List<EpisodeEntity> | ||
@Query("SELECT COUNT(*) FROM episodes") | ||
fun getSize(): Int | ||
|
||
@Query("SELECT * FROM episode WHERE eid IN (:eids)") | ||
@Query("SELECT * FROM episodes") | ||
fun getAll(): LiveData<List<EpisodeEntity>> | ||
|
||
@Query("SELECT * FROM episodes WHERE eid IN (:eids)") | ||
fun loadAllByIds(eids: IntArray): List<EpisodeEntity> | ||
|
||
@Query("SELECT * FROM episode WHERE episode_title LIKE :title LIMIT 1") | ||
@Query("SELECT * FROM episodes WHERE episode_title LIKE :title LIMIT 1") | ||
fun findByTitle(title: String): EpisodeEntity | ||
|
||
@Query("SELECT * FROM episode WHERE episode_guid IS :guid LIMIT 1") | ||
@Query("SELECT * FROM episodes WHERE episode_guid IS :guid LIMIT 1") | ||
fun findByGuid(guid: String): EpisodeEntity | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insert(episode: EpisodeEntity) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insert(episode: EpisodeEntity): Long | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun insertAll(vararg episodes: EpisodeEntity) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insertAll(episodes: List<EpisodeEntity>): List< Long> | ||
|
||
@Update | ||
fun add(episode: EpisodeEntity) | ||
@Update(onConflict = OnConflictStrategy.REPLACE) | ||
fun update(episode: EpisodeEntity) | ||
|
||
@Delete | ||
fun delete(episode: EpisodeEntity) | ||
|
||
@Transaction | ||
fun upsert(episode: EpisodeEntity) { | ||
val rowId = insert(episode) | ||
if (rowId == -1L) { | ||
update(episode) | ||
} | ||
} | ||
|
||
@Transaction | ||
fun upsertAll(episodes: List<EpisodeEntity>) { | ||
val rowIds = insertAll(episodes) | ||
val episodesToUpdate = rowIds.mapIndexedNotNull { index, rowId -> | ||
if (rowId == -1L) null else episodes[index] } | ||
episodesToUpdate.forEach { update(it) } | ||
} | ||
|
||
} |
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
48 changes: 37 additions & 11 deletions
48
app/src/main/java/org/y20k/escapepod/database/PodcastDao.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,32 +1,58 @@ | ||
package org.y20k.escapepod.database | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.room.* | ||
|
||
@Dao | ||
interface PodcastDao { | ||
@Query("SELECT * FROM podcast") | ||
fun getAll(): List<PodcastEntity> | ||
@Query("SELECT COUNT(*) FROM podcasts") | ||
fun getSize(): Int | ||
|
||
@Query("SELECT * FROM podcast WHERE pid IN (:pids)") | ||
@Query("SELECT * FROM podcasts") | ||
fun getAll(): LiveData<List<PodcastEntity>> | ||
|
||
@Query("SELECT * FROM podcasts WHERE pid IN (:pids)") | ||
fun loadAllByIds(pids: IntArray): List<PodcastEntity> | ||
|
||
@Query("SELECT * FROM podcast WHERE podcast_name LIKE :name LIMIT 1") | ||
@Query("SELECT * FROM podcasts WHERE podcast_name LIKE :name LIMIT 1") | ||
fun findByName(name: String): PodcastEntity | ||
|
||
@Insert | ||
fun insert(podcast: PodcastEntity) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insert(podcast: PodcastEntity): Long | ||
|
||
@Insert | ||
fun insertAll(podcasts: List<PodcastEntity>) | ||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insertAll(podcasts: List<PodcastEntity>): List<Long> | ||
|
||
@Update | ||
fun add(podcast: PodcastEntity) | ||
@Update(onConflict = OnConflictStrategy.REPLACE) | ||
fun update(podcast: PodcastEntity) | ||
|
||
@Delete | ||
fun delete(user: PodcastEntity) | ||
|
||
@Transaction | ||
@Query("SELECT * FROM podcast") | ||
fun upsert(podcast: PodcastEntity) { | ||
val rowId = insert(podcast) | ||
if (rowId == -1L) { | ||
update(podcast) | ||
} | ||
} | ||
|
||
@Transaction | ||
fun upsertAll(podcasts: List<PodcastEntity>) { | ||
val rowIds = insertAll(podcasts) | ||
val podcastsToUpdate = rowIds.mapIndexedNotNull { index, rowId -> | ||
if (rowId == -1L) null else podcasts[index] } | ||
podcastsToUpdate.forEach { update(it) } | ||
} | ||
|
||
|
||
/** | ||
* This query will tell Room to query both the Podcast and Episode tables and handle | ||
* the object mapping. | ||
*/ | ||
@Transaction | ||
//@Query("SELECT * FROM episodes WHERE podcast_id IN (SELECT DISTINCT(pid) FROM podcasts)") | ||
@Query("SELECT * FROM podcasts") | ||
fun getPodcastsWithEpisodes(): List<PodcastWithEpisodesEntity> | ||
|
||
} |
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