-
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
38 changed files
with
743 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ | |
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
app/google-services.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/easyhz/pico/data/entity/album/Album.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,25 @@ | ||
package com.easyhz.pico.data.entity.album | ||
|
||
import com.google.firebase.Timestamp | ||
import com.google.firebase.firestore.PropertyName | ||
|
||
data class Album( | ||
@PropertyName("creationTime") | ||
val creationTime: Timestamp = Timestamp.now(), | ||
@PropertyName("expireTime") | ||
val expireTime: Timestamp = Timestamp.now(), | ||
@PropertyName("imageCount") | ||
val imageCount: Int = 0, | ||
@PropertyName("imageSizes") | ||
val imageSizes: List<ImageSize> = listOf(), | ||
@PropertyName("imageURLs") | ||
val imageUrls: List<String> = listOf(), | ||
@PropertyName("ownerID") | ||
val ownerId: String = "", | ||
@PropertyName("tags") | ||
val tags: List<String> = listOf(), | ||
@PropertyName("thumbnailURL") | ||
val thumbnailUrl: String = "", | ||
@PropertyName("viewCount") | ||
val viewCount: Int = 0 | ||
) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/easyhz/pico/data/entity/album/ImageSize.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,6 @@ | ||
package com.easyhz.pico.data.entity.album | ||
|
||
data class ImageSize( | ||
val height: Int = 0, | ||
val width: Int = 0 | ||
) |
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,8 @@ | ||
package com.easyhz.pico.data.firebase | ||
|
||
object Constants { | ||
const val ALBUMS = "Albums" | ||
|
||
const val OWNER_ID = "ownerID" | ||
const val CREATION_TIME = "creationTime" | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/easyhz/pico/data/mapper/AlbumMapper.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,15 @@ | ||
package com.easyhz.pico.data.mapper | ||
|
||
import com.easyhz.pico.data.entity.album.Album | ||
import com.easyhz.pico.domain.model.AlbumItem | ||
import com.easyhz.pico.util.toDateFormat | ||
import com.easyhz.pico.util.toDay | ||
|
||
fun List<Album>.toAlbumItem(): List<AlbumItem> = this.map { | ||
AlbumItem( | ||
regDate = it.creationTime.toDateFormat(), | ||
expireDate = it.expireTime.toDay(), | ||
tag = it.tags[0], | ||
thumbnailUrl = it.thumbnailUrl | ||
) | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/easyhz/pico/data/repository/album/AlbumRepositoryImpl.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,37 @@ | ||
package com.easyhz.pico.data.repository.album | ||
|
||
import com.easyhz.pico.data.entity.album.Album | ||
import com.easyhz.pico.data.firebase.Constants.ALBUMS | ||
import com.easyhz.pico.data.firebase.Constants.CREATION_TIME | ||
import com.easyhz.pico.data.firebase.Constants.OWNER_ID | ||
import com.easyhz.pico.domain.repository.album.AlbumRepository | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.google.firebase.firestore.Query | ||
import com.google.firebase.firestore.toObjects | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.tasks.await | ||
import javax.inject.Inject | ||
|
||
class AlbumRepositoryImpl | ||
@Inject constructor( | ||
private val fireStore: FirebaseFirestore, | ||
): AlbumRepository { | ||
override fun fetchAlbums() : Flow<List<Album>> = flow { | ||
try { | ||
// TODO: OWNER_ID 관리 | ||
val result = fireStore.collection(ALBUMS) | ||
.whereEqualTo(OWNER_ID, "19bIo1GzbzPmZsjoHEeOTKf8WAm1") | ||
.orderBy(CREATION_TIME, Query.Direction.DESCENDING) | ||
.get() | ||
.await() | ||
|
||
val albums = result.toObjects<Album>() | ||
emit(albums) | ||
} catch (e: Exception) { | ||
// 예외 처리 | ||
println("Error fetching albums: ${e.message}") | ||
} | ||
} | ||
|
||
} |
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,22 @@ | ||
package com.easyhz.pico.di | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object FirebaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideFireStore(): FirebaseFirestore { | ||
return FirebaseFirestore.getInstance() | ||
} | ||
|
||
|
||
} |
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.easyhz.pico.di | ||
|
||
import com.easyhz.pico.data.repository.album.AlbumRepositoryImpl | ||
import com.easyhz.pico.domain.repository.album.AlbumRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindAlbumRepository( | ||
albumRepositoryImpl: AlbumRepositoryImpl | ||
): AlbumRepository | ||
} |
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,21 @@ | ||
package com.easyhz.pico.di | ||
|
||
import com.easyhz.pico.domain.repository.album.AlbumRepository | ||
import com.easyhz.pico.domain.usecase.album.AlbumUseCase | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object UseCaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAlbumUseCase( | ||
albumRepository: AlbumRepository | ||
): AlbumUseCase = AlbumUseCase(albumRepository) | ||
|
||
} |
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,8 @@ | ||
package com.easyhz.pico.domain.model | ||
|
||
data class AlbumItem( | ||
val regDate: String, | ||
val tag: String, | ||
val expireDate: Long, | ||
val thumbnailUrl: String, | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/easyhz/pico/domain/repository/album/AlbumRepository.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,9 @@ | ||
package com.easyhz.pico.domain.repository.album | ||
|
||
import com.easyhz.pico.data.entity.album.Album | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface AlbumRepository { | ||
fun fetchAlbums() : Flow<List<Album>> | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/easyhz/pico/domain/usecase/album/AlbumUseCase.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,14 @@ | ||
package com.easyhz.pico.domain.usecase.album | ||
|
||
import com.easyhz.pico.data.entity.album.Album | ||
import com.easyhz.pico.domain.repository.album.AlbumRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class AlbumUseCase | ||
@Inject constructor( | ||
private val repository: AlbumRepository | ||
) { | ||
operator fun invoke() : Flow<List<Album>> = repository.fetchAlbums() | ||
|
||
} |
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,19 @@ | ||
package com.easyhz.pico.util | ||
|
||
import com.google.firebase.Timestamp | ||
import java.time.Duration | ||
import java.time.LocalDateTime | ||
import java.time.ZoneId | ||
import java.time.format.DateTimeFormatter | ||
import java.util.Locale | ||
|
||
fun Timestamp.toDateFormat(): String = | ||
LocalDateTime.ofInstant(this.toDate().toInstant(), ZoneId.systemDefault()) | ||
.format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm", Locale.getDefault())) | ||
|
||
fun Timestamp.toDay(): Long { | ||
val expireDateTime = this.toDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime() | ||
val currentDateTime = LocalDateTime.now() | ||
|
||
return Duration.between(currentDateTime, expireDateTime).toDays() | ||
} |
Oops, something went wrong.