-
Notifications
You must be signed in to change notification settings - Fork 97
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
Showing
37 changed files
with
828 additions
and
388 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...le/src/main/java/com/google/android/horologist/mediasample/data/database/MediaDatabase.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.google.android.horologist.mediasample.data.database.dao.MediaDownloadDao | ||
import com.google.android.horologist.mediasample.data.database.dao.PlaylistDao | ||
import com.google.android.horologist.mediasample.data.database.model.MediaDownloadEntity | ||
import com.google.android.horologist.mediasample.data.database.model.MediaEntity | ||
import com.google.android.horologist.mediasample.data.database.model.PlaylistEntity | ||
import com.google.android.horologist.mediasample.data.database.model.PlaylistMediaEntity | ||
|
||
@Database( | ||
entities = [ | ||
MediaDownloadEntity::class, | ||
MediaEntity::class, | ||
PlaylistEntity::class, | ||
PlaylistMediaEntity::class, | ||
], | ||
version = 1, | ||
exportSchema = false | ||
) | ||
abstract class MediaDatabase : RoomDatabase() { | ||
|
||
abstract fun mediaDownloadDao(): MediaDownloadDao | ||
|
||
abstract fun playlistDao(): PlaylistDao | ||
} |
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
63 changes: 63 additions & 0 deletions
63
.../src/main/java/com/google/android/horologist/mediasample/data/database/dao/PlaylistDao.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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import com.google.android.horologist.mediasample.data.database.model.MediaEntity | ||
import com.google.android.horologist.mediasample.data.database.model.PlaylistEntity | ||
import com.google.android.horologist.mediasample.data.database.model.PlaylistMediaEntity | ||
import com.google.android.horologist.mediasample.data.database.model.PopulatedPlaylist | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface PlaylistDao { | ||
|
||
@Query( | ||
value = """ | ||
SELECT COUNT(*) FROM playlistentity | ||
""" | ||
) | ||
suspend fun getCount(): Int | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert( | ||
playlistEntity: PlaylistEntity, | ||
mediaEntityList: List<MediaEntity>, | ||
playlistMediaEntityList: List<PlaylistMediaEntity> | ||
) | ||
|
||
@Transaction | ||
@Query( | ||
value = """ | ||
SELECT * FROM playlistentity | ||
WHERE playlistId = :playlistId | ||
""" | ||
) | ||
fun getPopulated(playlistId: String): Flow<PopulatedPlaylist> | ||
|
||
@Transaction | ||
@Query( | ||
value = """ | ||
SELECT * FROM playlistentity | ||
""" | ||
) | ||
fun getAllPopulated(): Flow<List<PopulatedPlaylist>> | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...m/google/android/horologist/mediasample/data/database/mapper/PlaylistMediaEntityMapper.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database.mapper | ||
|
||
import com.google.android.horologist.media.model.Media | ||
import com.google.android.horologist.mediasample.data.database.model.PlaylistMediaEntity | ||
import com.google.android.horologist.mediasample.domain.model.Playlist | ||
|
||
object PlaylistMediaEntityMapper { | ||
|
||
fun map(playlist: Playlist, media: Media) = PlaylistMediaEntity( | ||
playlistId = playlist.id, | ||
mediaId = media.id | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
...java/com/google/android/horologist/mediasample/data/database/model/MediaDownloadEntity.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class MediaDownloadEntity( | ||
@PrimaryKey val mediaId: String, | ||
val status: MediaDownloadEntityStatus, | ||
) | ||
|
||
enum class MediaDownloadEntityStatus { | ||
NotDownloaded, Downloading, Downloaded, Failed | ||
} |
30 changes: 30 additions & 0 deletions
30
...rc/main/java/com/google/android/horologist/mediasample/data/database/model/MediaEntity.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database.model | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class MediaEntity( | ||
@PrimaryKey val mediaId: String, | ||
@ColumnInfo val mediaUrl: String, | ||
@ColumnInfo val artworkUrl: String, | ||
@ColumnInfo val title: String?, | ||
@ColumnInfo val artist: String?, | ||
) |
27 changes: 27 additions & 0 deletions
27
...main/java/com/google/android/horologist/mediasample/data/database/model/PlaylistEntity.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.mediasample.data.database.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class PlaylistEntity( | ||
@PrimaryKey val playlistId: String, | ||
val name: String, | ||
val artworkUri: String?, | ||
) |
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.