From f13ff602f0d43495c7a9d05087fced59a39a1c6f Mon Sep 17 00:00:00 2001 From: ChunBaee Date: Wed, 24 May 2023 18:37:40 +0900 Subject: [PATCH] =?UTF-8?q?#36=20feat:=20=ED=94=BC=EB=93=9C=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=EA=B8=B0=20API=20=EB=B0=8F=20=EC=9D=BC?= =?UTF-8?q?=EB=B0=98/=EA=B0=84=EB=8B=A8=EC=9D=BC=EA=B8=B0=20=EA=B5=AC?= =?UTF-8?q?=EB=B6=84=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chunbae/narchive/data/data/FeedData.kt | 4 +- .../chunbae/narchive/data/data/UserData.kt | 2 +- .../narchive/data/remote/api/FeedService.kt | 14 ++++ .../remote/repository/FeedRepositoryImpl.kt | 12 ++++ .../data/remote/response/ResponseFeedData.kt | 20 ++++++ .../data/remote/source/FeedRemoteSource.kt | 16 +++++ .../domain/repository/FeedRepository.kt | 8 +++ .../narchive/domain/source/FeedSource.kt | 9 +++ .../narchive/domain/usecase/DiaryUseCase.kt | 11 ++++ .../domain/usecase/DiaryUseCaseImpl.kt | 64 +++++++++++++++++++ .../domain/usecase/NormalDiaryUseCase.kt | 8 --- .../domain/usecase/NormalDiaryUseCaseImpl.kt | 24 ------- .../di/module/RepositoryModule.kt | 5 ++ .../presentation/di/module/ServiceModule.kt | 5 ++ .../presentation/di/module/SourceModule.kt | 5 ++ .../presentation/di/module/UseCaseModule.kt | 7 +- .../ui/comment/view/DiaryCommentActivity.kt | 25 ++------ .../detail/diary/view/DetailDiaryActivity.kt | 28 +++----- .../presentation/ui/main/MainActivity.kt | 2 + .../presentation/ui/main/MainViewModel.kt | 18 +++++- .../ui/main/feed/view/FeedFragment.kt | 30 ++++----- .../viewmodel/WriteNormalDiaryViewModel.kt | 6 +- .../main/res/layout/activity_detail_diary.xml | 2 +- .../res/layout/item_feed_normal_diary.xml | 13 ++-- .../res/layout/item_feed_simple_diary.xml | 14 ++-- 25 files changed, 245 insertions(+), 107 deletions(-) create mode 100644 app/src/main/java/com/chunbae/narchive/data/remote/api/FeedService.kt create mode 100644 app/src/main/java/com/chunbae/narchive/data/remote/repository/FeedRepositoryImpl.kt create mode 100644 app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseFeedData.kt create mode 100644 app/src/main/java/com/chunbae/narchive/data/remote/source/FeedRemoteSource.kt create mode 100644 app/src/main/java/com/chunbae/narchive/domain/repository/FeedRepository.kt create mode 100644 app/src/main/java/com/chunbae/narchive/domain/source/FeedSource.kt create mode 100644 app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCase.kt create mode 100644 app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCaseImpl.kt delete mode 100644 app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCase.kt delete mode 100644 app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCaseImpl.kt diff --git a/app/src/main/java/com/chunbae/narchive/data/data/FeedData.kt b/app/src/main/java/com/chunbae/narchive/data/data/FeedData.kt index f5728c4..c14fe37 100644 --- a/app/src/main/java/com/chunbae/narchive/data/data/FeedData.kt +++ b/app/src/main/java/com/chunbae/narchive/data/data/FeedData.kt @@ -5,9 +5,9 @@ data class FeedData( val user : UserData, val uploadedAt : String, val content : String?,/** 일반 일기 작성시 사용됨 */ - val thumbNail : String, //TODO: 추후 서버 연결시 String으로 변경할 것 + val thumbNail : String?, //TODO: 추후 서버 연결시 String으로 변경할 것 val imageCount : Int, - val locationAddress : String, + val locationAddress : String?, val commentCount : Int, val keywords : List?,/** 간단 일기 작성시 사용됨 */ val isSimple : String /** T / F */ diff --git a/app/src/main/java/com/chunbae/narchive/data/data/UserData.kt b/app/src/main/java/com/chunbae/narchive/data/data/UserData.kt index f1a27ad..4280a38 100644 --- a/app/src/main/java/com/chunbae/narchive/data/data/UserData.kt +++ b/app/src/main/java/com/chunbae/narchive/data/data/UserData.kt @@ -2,6 +2,6 @@ package com.chunbae.narchive.data.data data class UserData( val userIdx : Int, - val userProfileImage : Int, //TODO: 추후 서버 연결시 String으로 변경할 것 + val userProfileImage : String, val userNickName : String ) diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/api/FeedService.kt b/app/src/main/java/com/chunbae/narchive/data/remote/api/FeedService.kt new file mode 100644 index 0000000..ccfe8f6 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/api/FeedService.kt @@ -0,0 +1,14 @@ +package com.chunbae.narchive.data.remote.api + +import com.chunbae.narchive.data.remote.response.ResponseFeedData +import retrofit2.Response +import retrofit2.http.GET +import retrofit2.http.Query + +interface FeedService { + + @GET("/diaries") + suspend fun getDiaryFeedData( + @Query("page") page : Int + ) : Response +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/repository/FeedRepositoryImpl.kt b/app/src/main/java/com/chunbae/narchive/data/remote/repository/FeedRepositoryImpl.kt new file mode 100644 index 0000000..e9a9011 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/repository/FeedRepositoryImpl.kt @@ -0,0 +1,12 @@ +package com.chunbae.narchive.data.remote.repository + +import com.chunbae.narchive.data.remote.response.ResponseFeedData +import com.chunbae.narchive.domain.repository.FeedRepository +import com.chunbae.narchive.domain.source.FeedSource +import javax.inject.Inject + +class FeedRepositoryImpl @Inject constructor(private val feedSource: FeedSource): FeedRepository { + override suspend fun getFeedData(page: Int): Result> { + return feedSource.getFeedData(page) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseFeedData.kt b/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseFeedData.kt new file mode 100644 index 0000000..fd80267 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/response/ResponseFeedData.kt @@ -0,0 +1,20 @@ +package com.chunbae.narchive.data.remote.response + +import com.chunbae.narchive.presentation.util.BaseResponse + +data class ResponseFeedData ( + val result : List +) : BaseResponse() { + data class ResponseFeedResult( + val feedIdx : Int, + val nickName : String, + val profilePath : String, + val updatedAt : String, + val isSimple : String, + val content : String, + val thumbnailPath : String, + val imageCount : Int, + val locationName : String, + val commentCount : Int + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/data/remote/source/FeedRemoteSource.kt b/app/src/main/java/com/chunbae/narchive/data/remote/source/FeedRemoteSource.kt new file mode 100644 index 0000000..96e9ab6 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/data/remote/source/FeedRemoteSource.kt @@ -0,0 +1,16 @@ +package com.chunbae.narchive.data.remote.source + +import com.chunbae.narchive.data.remote.api.FeedService +import com.chunbae.narchive.data.remote.response.ResponseFeedData +import com.chunbae.narchive.domain.source.FeedSource +import javax.inject.Inject + +class FeedRemoteSource @Inject constructor(private val feedService: FeedService): FeedSource { + override suspend fun getFeedData(page: Int): Result> { + val res = feedService.getDiaryFeedData(page) + if (res.isSuccessful) { + return Result.success(res.body()!!.result as MutableList) + } + return Result.failure(IllegalArgumentException(res.message())) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/repository/FeedRepository.kt b/app/src/main/java/com/chunbae/narchive/domain/repository/FeedRepository.kt new file mode 100644 index 0000000..82b8ecf --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/domain/repository/FeedRepository.kt @@ -0,0 +1,8 @@ +package com.chunbae.narchive.domain.repository + +import com.chunbae.narchive.data.remote.response.ResponseFeedData + +interface FeedRepository { + + suspend fun getFeedData(page : Int) : Result> +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/source/FeedSource.kt b/app/src/main/java/com/chunbae/narchive/domain/source/FeedSource.kt new file mode 100644 index 0000000..c6edf97 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/domain/source/FeedSource.kt @@ -0,0 +1,9 @@ +package com.chunbae.narchive.domain.source + +import androidx.lifecycle.MutableLiveData +import com.chunbae.narchive.data.remote.response.ResponseFeedData + +interface FeedSource { + + suspend fun getFeedData(page : Int) : Result> +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCase.kt b/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCase.kt new file mode 100644 index 0000000..8730791 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCase.kt @@ -0,0 +1,11 @@ +package com.chunbae.narchive.domain.usecase + +import com.chunbae.narchive.data.data.FeedData +import com.chunbae.narchive.data.data.LocationData + +interface DiaryUseCase { + + suspend fun postMapping(content : String, locationData: LocationData?, images : MutableList?) : Result + + suspend fun getMapping(page : Int) : Result> +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCaseImpl.kt b/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCaseImpl.kt new file mode 100644 index 0000000..aef6483 --- /dev/null +++ b/app/src/main/java/com/chunbae/narchive/domain/usecase/DiaryUseCaseImpl.kt @@ -0,0 +1,64 @@ +package com.chunbae.narchive.domain.usecase + +import com.chunbae.narchive.data.data.FeedData +import com.chunbae.narchive.data.data.LocationData +import com.chunbae.narchive.data.data.UserData +import com.chunbae.narchive.data.remote.request.RequestNormalDiaryData +import com.chunbae.narchive.data.remote.response.ResponseFeedData +import com.chunbae.narchive.domain.repository.FeedRepository +import com.chunbae.narchive.domain.repository.NormalDiaryRepository +import javax.inject.Inject + +class DiaryUseCaseImpl @Inject constructor( + private val repo: NormalDiaryRepository, + private val feedRepo: FeedRepository +) : DiaryUseCase { + + override suspend fun postMapping( + content: String, + locationData: LocationData?, + images: MutableList? + ): Result { + return repo.postNormalDiary(content.mapToRequest(locationData, images)) + } + + override suspend fun getMapping(page: Int): Result> { + return feedRepo.getFeedData(page).map { it.mapToFeedData() } + } + + + private fun String.mapToRequest( + locationData: LocationData?, + images: MutableList? + ): RequestNormalDiaryData { + return RequestNormalDiaryData( + this, + locationData?.place_name, + locationData?.road_address_name, + locationData?.x?.toDouble(), + locationData?.y?.toDouble(), + images + ) + } + + private fun MutableList.mapToFeedData(): MutableList { + val returnList = mutableListOf() + this.forEach { + returnList.add( + FeedData( + feedIdx = it.feedIdx, + user = UserData(0, it.profilePath, it.nickName), + uploadedAt = it.updatedAt, + content = if(it.isSimple == "F") it.content else null, + keywords = if(it.isSimple == "T") it.content.split(",") else null, + thumbNail = it.thumbnailPath, + imageCount = it.imageCount, + locationAddress = it.locationName, + commentCount = it.commentCount, + isSimple = it.isSimple + ) + ) + } + return returnList + } +} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCase.kt b/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCase.kt deleted file mode 100644 index f6c043c..0000000 --- a/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCase.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.chunbae.narchive.domain.usecase - -import com.chunbae.narchive.data.data.LocationData - -interface NormalDiaryUseCase { - - suspend fun invoke(content : String, locationData: LocationData?, images : MutableList?) : Result -} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCaseImpl.kt b/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCaseImpl.kt deleted file mode 100644 index 8ddab21..0000000 --- a/app/src/main/java/com/chunbae/narchive/domain/usecase/NormalDiaryUseCaseImpl.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.chunbae.narchive.domain.usecase - -import com.chunbae.narchive.data.data.LocationData -import com.chunbae.narchive.data.remote.request.RequestNormalDiaryData -import com.chunbae.narchive.domain.repository.NormalDiaryRepository -import javax.inject.Inject - -class NormalDiaryUseCaseImpl @Inject constructor(private val repo : NormalDiaryRepository) : NormalDiaryUseCase{ - - override suspend fun invoke(content: String, locationData: LocationData?, images : MutableList?): Result { - return repo.postNormalDiary(content.mapToRequest(locationData, images)) - } - - private fun String.mapToRequest(locationData: LocationData?, images : MutableList?) : RequestNormalDiaryData { - return RequestNormalDiaryData( - this, - locationData?.place_name, - locationData?.road_address_name, - locationData?.x?.toDouble(), - locationData?.y?.toDouble(), - images - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/di/module/RepositoryModule.kt b/app/src/main/java/com/chunbae/narchive/presentation/di/module/RepositoryModule.kt index 98b2623..89c7f4c 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/di/module/RepositoryModule.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/di/module/RepositoryModule.kt @@ -1,6 +1,7 @@ package com.chunbae.narchive.presentation.di.module import com.chunbae.narchive.data.remote.repository.AuthRepositoryImpl +import com.chunbae.narchive.data.remote.repository.FeedRepositoryImpl import com.chunbae.narchive.data.remote.repository.FirebaseRepositoryImpl import com.chunbae.narchive.data.remote.repository.KakaoAiDiaryRepositoryImpl import com.chunbae.narchive.data.remote.repository.KakaoBookSearchRepositoryImpl @@ -8,6 +9,7 @@ import com.chunbae.narchive.data.remote.repository.KakaoLocationSearchRepository import com.chunbae.narchive.data.remote.repository.NormalDiaryRepositoryImpl import com.chunbae.narchive.data.remote.repository.ProfileRepositoryImpl import com.chunbae.narchive.domain.repository.AuthRepository +import com.chunbae.narchive.domain.repository.FeedRepository import com.chunbae.narchive.domain.repository.FirebaseRepository import com.chunbae.narchive.domain.repository.KakaoAiDiaryRepository import com.chunbae.narchive.domain.repository.KakaoBookSearchRepository @@ -43,4 +45,7 @@ abstract class RepositoryModule { @Binds abstract fun bindProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl) : ProfileRepository + + @Binds + abstract fun bindFeedRepository(feedRepositoryImpl: FeedRepositoryImpl) : FeedRepository } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/di/module/ServiceModule.kt b/app/src/main/java/com/chunbae/narchive/presentation/di/module/ServiceModule.kt index e02cbeb..395d6f9 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/di/module/ServiceModule.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/di/module/ServiceModule.kt @@ -1,6 +1,7 @@ package com.chunbae.narchive.presentation.di.module import com.chunbae.narchive.data.remote.api.AuthService +import com.chunbae.narchive.data.remote.api.FeedService import com.chunbae.narchive.data.remote.api.KakaoAiService import com.chunbae.narchive.data.remote.api.KakaoService import com.chunbae.narchive.data.remote.api.NormalDiaryService @@ -46,4 +47,8 @@ class ServiceModule { @Singleton fun provideProfileService(@NarchiveRetrofit retrofit : Retrofit) : ProfileService = retrofit.create(ProfileService::class.java) + @Provides + @Singleton + fun provideFeedService(@NarchiveRetrofit retrofit: Retrofit) : FeedService = retrofit.create(FeedService::class.java) + } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/di/module/SourceModule.kt b/app/src/main/java/com/chunbae/narchive/presentation/di/module/SourceModule.kt index 9729713..5373a3a 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/di/module/SourceModule.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/di/module/SourceModule.kt @@ -1,6 +1,7 @@ package com.chunbae.narchive.presentation.di.module import com.chunbae.narchive.data.remote.source.AuthRemoteSource +import com.chunbae.narchive.data.remote.source.FeedRemoteSource import com.chunbae.narchive.data.remote.source.FirebaseStorageRemoteSource import com.chunbae.narchive.data.remote.source.KakaoAiDiaryRemoteSource import com.chunbae.narchive.data.remote.source.KakaoBookSearchRemoteSource @@ -8,6 +9,7 @@ import com.chunbae.narchive.data.remote.source.KakaoLocationSearchRemoteSource import com.chunbae.narchive.data.remote.source.NormalDiaryRemoteSource import com.chunbae.narchive.data.remote.source.ProfileRemoteSource import com.chunbae.narchive.domain.source.AuthSource +import com.chunbae.narchive.domain.source.FeedSource import com.chunbae.narchive.domain.source.FirebaseStorageSource import com.chunbae.narchive.domain.source.KakaoAiDiarySource import com.chunbae.narchive.domain.source.KakaoBookSearchSource @@ -43,4 +45,7 @@ abstract class SourceModule { @Binds abstract fun bindProfileRemoteSource(profileRemoteSource: ProfileRemoteSource) : ProfileSource + + @Binds + abstract fun bindFeedRemoteSource(feedRemoteSource: FeedRemoteSource) : FeedSource } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/di/module/UseCaseModule.kt b/app/src/main/java/com/chunbae/narchive/presentation/di/module/UseCaseModule.kt index b6b46af..3c08ef3 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/di/module/UseCaseModule.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/di/module/UseCaseModule.kt @@ -1,10 +1,9 @@ package com.chunbae.narchive.presentation.di.module -import com.chunbae.narchive.domain.usecase.NormalDiaryUseCase -import com.chunbae.narchive.domain.usecase.NormalDiaryUseCaseImpl +import com.chunbae.narchive.domain.usecase.DiaryUseCase +import com.chunbae.narchive.domain.usecase.DiaryUseCaseImpl import dagger.Binds import dagger.Module -import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent @@ -12,5 +11,5 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) abstract class UseCaseModule { @Binds - abstract fun bindNormalDiaryUseCase(normalDiaryUseCaseImpl : NormalDiaryUseCaseImpl): NormalDiaryUseCase + abstract fun bindDiaryUseCase(diaryUseCaseImpl : DiaryUseCaseImpl): DiaryUseCase } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/comment/view/DiaryCommentActivity.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/comment/view/DiaryCommentActivity.kt index 738abf4..c468e5c 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/comment/view/DiaryCommentActivity.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/comment/view/DiaryCommentActivity.kt @@ -18,10 +18,11 @@ import com.chunbae.narchive.presentation.ui.comment.adapter.CommentAdapter class DiaryCommentActivity : AppCompatActivity() { - private lateinit var binding : ActivityDiaryCommentBinding + private lateinit var binding: ActivityDiaryCommentBinding private val commentAdapter by lazy { - CommentAdapter(getCommentDummies()) + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_diary_comment) @@ -31,29 +32,13 @@ class DiaryCommentActivity : AppCompatActivity() { } private fun initBinding() { - binding.commentData = getCommentDummy() + } private fun initComment() { val dividerItemDecoration = DividerItemDecoration(this, LinearLayoutManager.VERTICAL) binding.diaryCommentRvComments.addItemDecoration(dividerItemDecoration) - binding.diaryCommentRvComments.adapter = commentAdapter + // binding.diaryCommentRvComments.adapter = commentAdapter } - - - /** Dummy */ - - private fun getCommentDummy() : CommentData = - CommentData(UserData(0, R.drawable.ic_launcher_background, "춘배"), "3일 전", "어제는 지연이와 함께 찜질방에 다녀왔다!\n요근래 찜질방에 갔던적이 없었는데 역시 따뜻한 물에 들어가있으니까\n" + - "피로가 쫙 풀리는 기분이었다!\n근데 음식값이 생각보다 비싸서 그건 좀 아쉬웠다..\n" + - "계란이 개당 천원꼴에 치킨이 3만원이라니..\n" + - "그나마 식혜가 제일 합리적이었다\n그래도 음식 가격만 제외하면 정말 잘 놀다 왔다!\n대만족!", getCommentDummies()) - - private fun getCommentDummies() : MutableList = - mutableListOf().apply { - for(i in 0 until 10) { - add(Comment(i, UserData(0, R.drawable.ic_launcher_background, "춘배"), "$i 번째 댓글", "$i 일 전")) - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/detail/diary/view/DetailDiaryActivity.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/detail/diary/view/DetailDiaryActivity.kt index f80cb7e..85f3dbb 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/detail/diary/view/DetailDiaryActivity.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/detail/diary/view/DetailDiaryActivity.kt @@ -14,14 +14,13 @@ import com.chunbae.narchive.presentation.ui.comment.view.DiaryCommentActivity import com.chunbae.narchive.presentation.ui.detail.diary.adapter.DetailDiaryImageAdapter class DetailDiaryActivity : AppCompatActivity() { - private lateinit var binding : ActivityDetailDiaryBinding + private lateinit var binding: ActivityDetailDiaryBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_detail_diary) initBinding() - setUiDummy() initImages() } @@ -35,14 +34,14 @@ class DetailDiaryActivity : AppCompatActivity() { } private fun initImages() { - binding.detailDiaryVpImage.adapter = DetailDiaryImageAdapter(returnImageDummy()) - binding.detailDiaryTvImageIndicator.text = "1 / ${returnImageDummy().size}" - binding.detailDiaryVpImage.registerOnPageChangeCallback(object : OnPageChangeCallback() { - override fun onPageSelected(position: Int) { - super.onPageSelected(position) - binding.detailDiaryTvImageIndicator.text = "${position + 1} / ${returnImageDummy().size}" - } - }) +// binding.detailDiaryVpImage.adapter = DetailDiaryImageAdapter(returnImageDummy()) +// binding.detailDiaryTvImageIndicator.text = "1 / ${returnImageDummy().size}" +// binding.detailDiaryVpImage.registerOnPageChangeCallback(object : OnPageChangeCallback() { +// override fun onPageSelected(position: Int) { +// super.onPageSelected(position) +// binding.detailDiaryTvImageIndicator.text = "${position + 1} / ${returnImageDummy().size}" +// } +// }) } fun onCommentClick() { @@ -51,13 +50,4 @@ class DetailDiaryActivity : AppCompatActivity() { intent.putExtra("contentIdx", 0) startActivity(intent) } - - /** Dummy */ - - private fun setUiDummy() { - binding.diaryData = returnDiaryDummy() - } - - private fun returnDiaryDummy() : DiaryData = DiaryData(0, UserData(0, R.drawable.ic_launcher_background, "테스트1"), "1일전", "2023.03.1", "본문내용입니다!", "양천구 신정중앙로 1", null, returnImageDummy(), "F") - private fun returnImageDummy() = listOf(R.drawable.ic_launcher_background,R.drawable.ic_launcher_background,R.drawable.ic_launcher_background,R.drawable.ic_launcher_background) } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainActivity.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainActivity.kt index f37deeb..da77977 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainActivity.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainActivity.kt @@ -19,7 +19,9 @@ import com.chunbae.narchive.presentation.ui.search.book.view.SearchBookActivity import com.chunbae.narchive.presentation.ui.search.movie.view.SearchMovieActivity import com.chunbae.narchive.presentation.ui.write.diary.normal.view.WriteNormalDiaryActivity import com.chunbae.narchive.presentation.ui.write.diary.simple.view.WriteSimpleDiaryActivity +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class MainActivity : AppCompatActivity() { private lateinit var binding : ActivityMainBinding private val viewModel : MainViewModel by viewModels() diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainViewModel.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainViewModel.kt index af6c481..51d2871 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainViewModel.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/MainViewModel.kt @@ -4,9 +4,16 @@ import android.util.Log import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.chunbae.narchive.data.data.FeedData import com.chunbae.narchive.data.data.TodoData +import com.chunbae.narchive.domain.usecase.DiaryUseCase +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import javax.inject.Inject -class MainViewModel : ViewModel() { +@HiltViewModel +class MainViewModel @Inject constructor(private val diaryUseCase: DiaryUseCase): ViewModel() { private val _isBookOrMovie = MutableLiveData().apply { value = "Book" } //Book / Movie val isBookOrMovie: LiveData = _isBookOrMovie @@ -20,6 +27,9 @@ class MainViewModel : ViewModel() { private val _isCalClicked = MutableLiveData(false) val isCalClicked : LiveData = _isCalClicked + private val _feedDiaryData = MutableLiveData>() + val feedDiaryData : LiveData> = _feedDiaryData + fun setChangeBookOrMovie() { @@ -46,5 +56,11 @@ class MainViewModel : ViewModel() { _isCalClicked.value = true } + fun getFeedData(page : Int) { + viewModelScope.launch { + diaryUseCase.getMapping(page) + .onSuccess { _feedDiaryData.value = it } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/feed/view/FeedFragment.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/feed/view/FeedFragment.kt index 872a57b..19fc0e6 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/main/feed/view/FeedFragment.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/main/feed/view/FeedFragment.kt @@ -19,14 +19,16 @@ import com.chunbae.narchive.presentation.ui.detail.diary.view.DetailDiaryActivit import com.chunbae.narchive.presentation.ui.main.MainViewModel import com.chunbae.narchive.presentation.ui.main.feed.adapter.FeedAdapter import com.chunbae.narchive.presentation.util.ConvertUtil +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class FeedFragment : Fragment() { private lateinit var binding : FragmentFeedBinding private val viewModel : MainViewModel by activityViewModels() private val feedAdapter by lazy { FeedAdapter(::onFeedItemClicked) } - + val DEFAULT_PAGE = 0 override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -36,10 +38,16 @@ class FeedFragment : Fragment() { initBinding() initFeed() + observeFeed() return binding.root } + override fun onStart() { + super.onStart() + viewModel.getFeedData(DEFAULT_PAGE) + } + private fun initBinding() { binding.fragment = this binding.viewModel = viewModel @@ -49,8 +57,13 @@ class FeedFragment : Fragment() { binding.fgFeedRvFeed.adapter = feedAdapter binding.fgFeedRvFeed.itemAnimator = null binding.fgFeedRvFeed.addItemDecoration(FeedRVDecorUtil(requireActivity())) + } - feedAdapter.feedDatas = getFeedDummy() + private fun observeFeed() { + viewModel.feedDiaryData.observe(viewLifecycleOwner) { + feedAdapter.feedDatas = it + feedAdapter.notifyItemRangeChanged(0, it.size) + } } fun onSearchClicked() { @@ -76,17 +89,4 @@ class FeedFragment : Fragment() { outRect.bottom = ConvertUtil.dpToPx(context, 15) } } - - - /** Dummy */ - - private fun getFeedDummy() : MutableList = - mutableListOf().apply { - add(FeedData(0, UserData(0, R.drawable.ic_launcher_background, "테스트1"), "1일전", "본문내용입니다!", "!", 1, "양천구 신정중앙로 1", 1, null, "F")) - add(FeedData(1, UserData(1, R.drawable.ic_launcher_background, "테스트2"), "2일전", null, "!", 2, "양천구 신정중앙로 2", 2, getKeywordDummy(), "T")) - add(FeedData(2, UserData(2, R.drawable.ic_launcher_background, "테스트3"), "3일전", "본문내용입니다!", "!", 3, "양천구 신정중앙로 3", 3, null, "F")) - add(FeedData(3, UserData(3, R.drawable.ic_launcher_background, "테스트4"), "4일전", "본문내용입니다!", "!", 4, "양천구 신정중앙로 4", 4, getKeywordDummy(), "T")) - } - - private fun getKeywordDummy() : List = listOf("1","2","3","4","5") } \ No newline at end of file diff --git a/app/src/main/java/com/chunbae/narchive/presentation/ui/write/diary/normal/viewmodel/WriteNormalDiaryViewModel.kt b/app/src/main/java/com/chunbae/narchive/presentation/ui/write/diary/normal/viewmodel/WriteNormalDiaryViewModel.kt index 18e2181..aad7104 100644 --- a/app/src/main/java/com/chunbae/narchive/presentation/ui/write/diary/normal/viewmodel/WriteNormalDiaryViewModel.kt +++ b/app/src/main/java/com/chunbae/narchive/presentation/ui/write/diary/normal/viewmodel/WriteNormalDiaryViewModel.kt @@ -8,7 +8,7 @@ import androidx.lifecycle.viewModelScope import com.chunbae.narchive.data.data.LocationData import com.chunbae.narchive.domain.repository.FirebaseRepository import com.chunbae.narchive.domain.repository.KakaoAiDiaryRepository -import com.chunbae.narchive.domain.usecase.NormalDiaryUseCase +import com.chunbae.narchive.domain.usecase.DiaryUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.async import kotlinx.coroutines.launch @@ -17,7 +17,7 @@ import javax.inject.Inject @HiltViewModel class WriteNormalDiaryViewModel @Inject constructor( private val aiRepo: KakaoAiDiaryRepository, - private val normalUseCase: NormalDiaryUseCase, + private val normalUseCase: DiaryUseCase, private val firebaseRepo: FirebaseRepository ) : ViewModel() { @@ -77,7 +77,7 @@ class WriteNormalDiaryViewModel @Inject constructor( fun postNormalDiary() { viewModelScope.launch { userInputContent.value?.let { - normalUseCase.invoke( + normalUseCase.postMapping( it, selectedLocation.value, imageDownloadPath diff --git a/app/src/main/res/layout/activity_detail_diary.xml b/app/src/main/res/layout/activity_detail_diary.xml index 3e510e0..7f37867 100644 --- a/app/src/main/res/layout/activity_detail_diary.xml +++ b/app/src/main/res/layout/activity_detail_diary.xml @@ -84,7 +84,7 @@ + @@ -84,8 +86,9 @@ android:fontFamily="@font/pretendard_medium" android:includeFontPadding="false" android:text="@{@string/diary_thumbnail_count(feedData.imageCount)}" - android:textColor="@color/white" + android:textColor="@color/color_a4a4a4" android:textSize="20sp" + android:visibility='@{feedData.imageCount == 0 ? View.GONE : View.VISIBLE}' app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintEnd_toEndOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintStart_toStartOf="@id/item_feed_simple_diary_iv_thumbnail" @@ -98,6 +101,7 @@ android:layout_height="wrap_content" android:layout_marginVertical="@dimen/margin_15" android:src="@drawable/ic_common_marker" + android:visibility='@{feedData.locationAddress == null ? View.GONE : View.VISIBLE}' app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" /> @@ -111,6 +115,7 @@ android:text="@{feedData.locationAddress}" android:textColor="@color/color_a4a4a4" android:textSize="12sp" + android:visibility='@{feedData.locationAddress == null ? View.GONE : View.VISIBLE}' app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_marker" app:layout_constraintStart_toEndOf="@id/item_feed_simple_diary_iv_marker" app:layout_constraintTop_toTopOf="@id/item_feed_simple_diary_iv_marker" @@ -126,10 +131,10 @@ android:text="@{@string/convert_int_to_string(feedData.commentCount)}" android:textColor="@color/color_a4a4a4" android:textSize="12sp" - android:layout_marginEnd="@dimen/margin_15" - app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_marker" + android:layout_margin="@dimen/margin_15" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="@id/item_feed_simple_diary_iv_marker" + app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" tools:text="3" /> - + @@ -71,6 +71,7 @@ android:layout_width="55dp" android:layout_height="55dp" android:layout_marginTop="@dimen/margin_20" + android:visibility='@{feedData.imageCount == 0 ? View.GONE : View.VISIBLE}' app:layout_constraintStart_toStartOf="@id/item_feed_simple_diary_rv_keywords" app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_rv_keywords" /> @@ -80,8 +81,9 @@ android:fontFamily="@font/pretendard_medium" android:includeFontPadding="false" android:text="@{@string/diary_thumbnail_count(feedData.imageCount)}" - android:textColor="@color/white" + android:textColor="@color/color_a4a4a4" android:textSize="20sp" + android:visibility='@{feedData.imageCount == 0 ? View.GONE : View.VISIBLE}' app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintEnd_toEndOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintStart_toStartOf="@id/item_feed_simple_diary_iv_thumbnail" @@ -94,6 +96,7 @@ android:layout_height="wrap_content" android:layout_marginVertical="@dimen/margin_15" android:src="@drawable/ic_common_marker" + android:visibility='@{feedData.locationAddress == null ? View.GONE : View.VISIBLE}' app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@id/item_feed_simple_diary_iv_thumbnail" app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" /> @@ -105,6 +108,7 @@ android:fontFamily="@font/pretendard_medium" android:includeFontPadding="false" android:text="@{feedData.locationAddress}" + android:visibility='@{feedData.locationAddress == null ? View.GONE : View.VISIBLE}' android:textColor="@color/color_a4a4a4" android:textSize="12sp" app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_marker" @@ -122,10 +126,10 @@ android:text="@{@string/convert_int_to_string(feedData.commentCount)}" android:textColor="@color/color_a4a4a4" android:textSize="12sp" - android:layout_marginEnd="@dimen/margin_15" - app:layout_constraintBottom_toBottomOf="@id/item_feed_simple_diary_iv_marker" + android:layout_margin="@dimen/margin_15" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="@id/item_feed_simple_diary_iv_marker" + app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_iv_thumbnail" tools:text="3" />