-
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
Showing
27 changed files
with
335 additions
and
123 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
2 changes: 1 addition & 1 deletion
2
...b/deepsleep/data/entity/search/Results.kt → ...b/deepsleep/data/entity/photos/Results.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
2 changes: 1 addition & 1 deletion
2
...psleep/data/entity/search/SearchPhotos.kt → ...psleep/data/entity/photos/SearchPhotos.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
3 changes: 1 addition & 2 deletions
3
...eepsleep/data/entity/search/SearchUser.kt → ...eepsleep/data/entity/photos/SearchUser.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
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
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/flab/deepsleep/data/entity/room/AppDatabase.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,24 @@ | ||
package com.flab.deepsleep.data.entity.room | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
|
||
@Database(entities = [Photo::class], version = 2) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun photoDao(): PhotoDao | ||
|
||
companion object { | ||
@Volatile | ||
private var Instance: AppDatabase? = null | ||
|
||
fun getDatabase(context: Context): AppDatabase { | ||
return Instance ?: synchronized(this) { | ||
Room.databaseBuilder(context, AppDatabase::class.java, "photo_database") | ||
.build() | ||
.also { Instance = it } | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/flab/deepsleep/data/entity/room/Photo.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,16 @@ | ||
package com.flab.deepsleep.data.entity.room | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "photo") | ||
data class Photo( | ||
@PrimaryKey(autoGenerate = true) val pk: Int = 0, | ||
@ColumnInfo(name = "id") val id: Int, | ||
@ColumnInfo(name = "likes") val likes: Int, | ||
@ColumnInfo(name = "urls") val urls: String?, | ||
@ColumnInfo(name = "created_at") val createdAt: String?, | ||
@ColumnInfo(name = "username") val username: String?, | ||
@ColumnInfo(name = "is_like", defaultValue = "0") val isLike: Boolean = false, | ||
) |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/flab/deepsleep/data/entity/room/PhotoDao.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,20 @@ | ||
package com.flab.deepsleep.data.entity.room | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface PhotoDao { | ||
@Query("SELECT * FROM `photo` order by pk DESC") | ||
fun getAll(): Flow<List<Photo>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.IGNORE) | ||
fun insert(vararg like: Photo) | ||
|
||
@Delete | ||
suspend fun delete(like: Photo) | ||
} |
7 changes: 0 additions & 7 deletions
7
app/src/main/java/com/flab/deepsleep/data/repo/PhotoRepository.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
app/src/main/java/com/flab/deepsleep/data/repo/UnplashRepository.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/flab/deepsleep/data/repository/db/OffLinePhotoRepository.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,11 @@ | ||
package com.flab.deepsleep.data.repository.db | ||
|
||
import com.flab.deepsleep.data.entity.room.Photo | ||
import com.flab.deepsleep.data.entity.room.PhotoDao | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class OffLinePhotoRepository(private val photoDao: PhotoDao) : PhotoRepository { | ||
override fun getAllPhotos(): Flow<List<Photo>> = photoDao.getAll() | ||
override suspend fun insertPhoto(like: Photo) = photoDao.insert(like) | ||
override suspend fun deletePhoto(like: Photo) = photoDao.delete(like) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/flab/deepsleep/data/repository/db/PhotoRepository.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,10 @@ | ||
package com.flab.deepsleep.data.repository.db | ||
|
||
import com.flab.deepsleep.data.entity.room.Photo | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface PhotoRepository { | ||
fun getAllPhotos(): Flow<List<Photo>> | ||
suspend fun insertPhoto(like: Photo) | ||
suspend fun deletePhoto(like: Photo) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/flab/deepsleep/data/repository/photo/UnplashRepository.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,10 @@ | ||
package com.flab.deepsleep.data.repository.photo | ||
|
||
import com.flab.deepsleep.data.entity.photos.SinglePhoto | ||
import com.flab.deepsleep.data.entity.photos.SearchPhotos | ||
|
||
interface UnplashRepository { | ||
suspend fun getRandomPhotos(count: Int): List<SinglePhoto> | ||
suspend fun getSearchPhotos(query: String): SearchPhotos | ||
suspend fun getSinglePhotoById(photoId: String): SinglePhoto | ||
} |
4 changes: 2 additions & 2 deletions
4
...psleep/data/repo/UnplashRepositoryImpl.kt → ...repository/photo/UnplashRepositoryImpl.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
Oops, something went wrong.