From 511ce6c85267378bcd59a6ca7761e8eaf87a0ee4 Mon Sep 17 00:00:00 2001 From: tama Date: Wed, 11 Jan 2023 15:23:29 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[ADD/#38]=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/wrapper/ResponseContentDto.kt | 21 +++++++++++++++++++ .../data/repository/ContentRepository.kt | 4 +++- .../data/repository/ContentRepositoryImpl.kt | 6 +++++- .../keyneez/data/service/ContentService.kt | 11 +++++++++- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt diff --git a/app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt b/app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt new file mode 100644 index 0000000..8063435 --- /dev/null +++ b/app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt @@ -0,0 +1,21 @@ +package com.keyneez.data.model.response.wrapper + +import kotlinx.serialization.SerialName + +@kotlinx.serialization.Serializable +data class ResponseContentDto( + @SerialName("content_key") + val key: Int, + @SerialName("content_title") + val title: String, + @SerialName("content_img") + val img: String, + val introduction: String, + val usage: String, + @SerialName("start_at") + val start: String, + @SerialName("end_at") + val end: String, + val liked: Boolean, + val category: List +) diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt index 23b6aa3..a4468dc 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt @@ -1,3 +1,5 @@ package com.keyneez.data.repository -interface ContentRepository +interface ContentRepository { + suspend fun getContent() +} diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt index f9e50fc..1a4ed2d 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt @@ -5,4 +5,8 @@ import javax.inject.Inject class ContentRepositoryImpl @Inject constructor( private val contentDataSource: ContentDataSource -) : ContentRepository +) : ContentRepository{ + override suspend fun getContent() { + TODO("Not yet implemented") + } +} diff --git a/app/src/main/java/com/keyneez/data/service/ContentService.kt b/app/src/main/java/com/keyneez/data/service/ContentService.kt index 82e94e5..2348b92 100644 --- a/app/src/main/java/com/keyneez/data/service/ContentService.kt +++ b/app/src/main/java/com/keyneez/data/service/ContentService.kt @@ -1,3 +1,12 @@ package com.keyneez.data.service -interface ContentService +import com.keyneez.data.model.response.wrapper.BaseResponse +import com.keyneez.data.model.response.wrapper.ResponseContentDto +import retrofit2.http.GET + +interface ContentService { + + // 게시물 전체 조회 API + @GET("content/") + suspend fun getContent(): BaseResponse +} From 0e0b36c83f40b5219b4e8cdf59d0d2e7db4a8211 Mon Sep 17 00:00:00 2001 From: tama Date: Wed, 11 Jan 2023 15:51:14 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[ADD/#38]=20=EA=B2=8C=EC=8B=9C=EB=AC=BC?= =?UTF-8?q?=20=EC=B0=9C=20dto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keyneez/data/model/request/RequestPostSaveDto.kt | 12 ++++++++++++ .../response/{wrapper => }/ResponseContentDto.kt | 2 +- .../data/model/response/ResponsePostSaveDto.kt | 7 +++++++ .../java/com/keyneez/data/service/ContentService.kt | 12 +++++++++++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt rename app/src/main/java/com/keyneez/data/model/response/{wrapper => }/ResponseContentDto.kt (90%) create mode 100644 app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt diff --git a/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt b/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt new file mode 100644 index 0000000..6c3257f --- /dev/null +++ b/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt @@ -0,0 +1,12 @@ +package com.keyneez.data.model.request + +import kotlinx.serialization.SerialName + +@kotlinx.serialization.Serializable +data class RequestPostSaveDto( + @SerialName("user_key") + val key: Int, + @SerialName("content_id") + val content: Int + +) diff --git a/app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt b/app/src/main/java/com/keyneez/data/model/response/ResponseContentDto.kt similarity index 90% rename from app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt rename to app/src/main/java/com/keyneez/data/model/response/ResponseContentDto.kt index 8063435..3baf4b2 100644 --- a/app/src/main/java/com/keyneez/data/model/response/wrapper/ResponseContentDto.kt +++ b/app/src/main/java/com/keyneez/data/model/response/ResponseContentDto.kt @@ -1,4 +1,4 @@ -package com.keyneez.data.model.response.wrapper +package com.keyneez.data.model.response import kotlinx.serialization.SerialName diff --git a/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt b/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt new file mode 100644 index 0000000..8f02160 --- /dev/null +++ b/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt @@ -0,0 +1,7 @@ +package com.keyneez.data.model.response + +@kotlinx.serialization.Serializable +data class ResponsePostSaveDto( + val status: Int, + val message: String +) diff --git a/app/src/main/java/com/keyneez/data/service/ContentService.kt b/app/src/main/java/com/keyneez/data/service/ContentService.kt index 2348b92..0da6505 100644 --- a/app/src/main/java/com/keyneez/data/service/ContentService.kt +++ b/app/src/main/java/com/keyneez/data/service/ContentService.kt @@ -1,12 +1,22 @@ package com.keyneez.data.service +import com.keyneez.data.model.request.RequestPostSaveDto +import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.ResponsePostSaveDto import com.keyneez.data.model.response.wrapper.BaseResponse -import com.keyneez.data.model.response.wrapper.ResponseContentDto +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST interface ContentService { // 게시물 전체 조회 API @GET("content/") suspend fun getContent(): BaseResponse + + // 게시물 찜 + @POST("content/save") + suspend fun postLike( + @Body requestBody: RequestPostSaveDto + ): ResponsePostSaveDto } From 032643eea3277e65ce422e49bf4a3ee10c7cd351 Mon Sep 17 00:00:00 2001 From: tama Date: Thu, 12 Jan 2023 03:30:21 +0900 Subject: [PATCH 03/16] =?UTF-8?q?[FEAT/#38]=20=EC=A0=84=EC=B2=B4=20content?= =?UTF-8?q?=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0=20api=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../data/model/response/ResponseContentDto.kt | 9 +- .../model/response/ResponsePostSaveDto.kt | 7 -- .../data/repository/ContentRepository.kt | 9 +- .../data/repository/ContentRepositoryImpl.kt | 16 +++- .../keyneez/data/service/ContentService.kt | 5 +- .../keyneez/data/source/ContentDataSource.kt | 13 ++- .../main/home/recommend/RecommendAdapter.kt | 36 +++---- .../main/home/recommend/RecommendFragment.kt | 21 +++-- .../main/home/recommend/RecommendViewModel.kt | 94 ++++++++++++++----- .../keyneez/util/binding/BindingAdapter.kt | 41 ++++++++ ...hape_gray050_80_fill_gray050_line_rect.xml | 9 ++ app/src/main/res/layout/activity_id_photo.xml | 4 +- app/src/main/res/layout/activity_ocr.xml | 6 +- .../res/layout/fragment_home_recommend.xml | 3 + app/src/main/res/layout/item_home.xml | 24 ++++- app/src/main/res/values/colors.xml | 3 +- 17 files changed, 222 insertions(+), 80 deletions(-) delete mode 100644 app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt create mode 100644 app/src/main/res/drawable/shape_gray050_80_fill_gray050_line_rect.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 47a336f..54a8c24 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,7 @@ android:screenOrientation="portrait" /> -) + val category: Category +) { + @kotlinx.serialization.Serializable + data class Category( + val category: String + ) +} diff --git a/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt b/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt deleted file mode 100644 index 8f02160..0000000 --- a/app/src/main/java/com/keyneez/data/model/response/ResponsePostSaveDto.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.keyneez.data.model.response - -@kotlinx.serialization.Serializable -data class ResponsePostSaveDto( - val status: Int, - val message: String -) diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt index a4468dc..69ee15e 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt @@ -1,5 +1,12 @@ package com.keyneez.data.repository +import com.keyneez.data.model.request.RequestPostSaveDto +import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.wrapper.BaseResponse + interface ContentRepository { - suspend fun getContent() + suspend fun getContent(): Result> + suspend fun postSave( + requestPostSaveDto: RequestPostSaveDto + ): Result> } diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt index 1a4ed2d..8d12c0e 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt @@ -1,12 +1,20 @@ package com.keyneez.data.repository +import com.keyneez.data.model.request.RequestPostSaveDto +import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.source.ContentDataSource import javax.inject.Inject class ContentRepositoryImpl @Inject constructor( private val contentDataSource: ContentDataSource -) : ContentRepository{ - override suspend fun getContent() { - TODO("Not yet implemented") - } +) : ContentRepository { + + override suspend fun getContent(): Result> = + kotlin.runCatching { contentDataSource.getContent() } + + override suspend fun postSave( + requestPostSaveDto: RequestPostSaveDto + ): Result> = + kotlin.runCatching { contentDataSource.postSave(requestPostSaveDto) } } diff --git a/app/src/main/java/com/keyneez/data/service/ContentService.kt b/app/src/main/java/com/keyneez/data/service/ContentService.kt index 0da6505..3393137 100644 --- a/app/src/main/java/com/keyneez/data/service/ContentService.kt +++ b/app/src/main/java/com/keyneez/data/service/ContentService.kt @@ -2,7 +2,6 @@ package com.keyneez.data.service import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseContentDto -import com.keyneez.data.model.response.ResponsePostSaveDto import com.keyneez.data.model.response.wrapper.BaseResponse import retrofit2.http.Body import retrofit2.http.GET @@ -16,7 +15,7 @@ interface ContentService { // 게시물 찜 @POST("content/save") - suspend fun postLike( + suspend fun postSave( @Body requestBody: RequestPostSaveDto - ): ResponsePostSaveDto + ): BaseResponse } diff --git a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt index 8314096..eca4350 100644 --- a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt +++ b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt @@ -1,8 +1,19 @@ package com.keyneez.data.source +import com.keyneez.data.model.request.RequestPostSaveDto +import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.service.ContentService import javax.inject.Inject class ContentDataSource @Inject constructor( private val contentService: ContentService -) +) { + suspend fun getContent(): BaseResponse = + contentService.getContent() + + suspend fun postSave( + requestPostSaveDto: RequestPostSaveDto + ): BaseResponse = + contentService.postSave(requestPostSaveDto) +} diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt index 0230e1e..f76f6b0 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt @@ -3,32 +3,32 @@ package com.keyneez.presentation.main.home.recommend import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import coil.load -import com.keyneez.data.entity.HomeData +import com.keyneez.data.model.response.ResponseContentDto import com.keyneez.util.extension.setOnSingleClickListener import com.lab.keyneez.databinding.ItemHomeBinding -class RecommendAdapter : RecyclerView.Adapter() { - var data = listOf() +class RecommendAdapter : RecyclerView.Adapter() { + var data = listOf() - class InfoViewHolder(private val binding: ItemHomeBinding) : - RecyclerView.ViewHolder(binding.root) { - fun bind(item: HomeData) { - binding.ivHomeItem.load(item.background) - binding.tvHomeTitle.text = item.title - binding.ivHomeCard.setOnSingleClickListener { - } - } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewHolder { + val binding = ItemHomeBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return HomeViewHolder(binding) } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): InfoViewHolder { - val binding = ItemHomeBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return InfoViewHolder(binding) + override fun getItemCount(): Int { + return data.size } - override fun getItemCount(): Int = data.size + override fun onBindViewHolder(holder: HomeViewHolder, position: Int) { + holder.onBind(data[position]) + } - override fun onBindViewHolder(holder: InfoViewHolder, position: Int) { - holder.bind(data[position]) + class HomeViewHolder(private val binding: ItemHomeBinding) : + RecyclerView.ViewHolder(binding.root) { + fun onBind(item: ResponseContentDto) { + binding.content = item + binding.root.setOnSingleClickListener { + } + } } } diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt index 04f5f12..bce4e29 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt @@ -3,34 +3,39 @@ package com.keyneez.presentation.main.home.recommend import android.os.Bundle import android.view.View import androidx.fragment.app.viewModels -import com.keyneez.data.entity.HomeData +import androidx.recyclerview.widget.LinearLayoutManager +import com.keyneez.data.model.response.ResponseContentDto import com.keyneez.util.binding.BindingFragment import com.lab.keyneez.R import com.lab.keyneez.databinding.FragmentHomeRecommendBinding +import dagger.hilt.android.AndroidEntryPoint +@AndroidEntryPoint class RecommendFragment : BindingFragment(R.layout.fragment_home_recommend) { private val viewModel: RecommendViewModel by viewModels() - val data = mutableListOf() - private lateinit var RecommendAdapter: RecommendAdapter + val data = mutableListOf() + private lateinit var recommendAdapter: RecommendAdapter override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + binding.vm = viewModel setupHomeData() initRecommendAdapter() } private fun setupHomeData() { - viewModel.itemList.observe(viewLifecycleOwner) { - RecommendAdapter.data = it - RecommendAdapter.notifyDataSetChanged() + viewModel.contentList.observe(viewLifecycleOwner) { + recommendAdapter.data = listOf(it) + recommendAdapter.notifyDataSetChanged() } } private fun initRecommendAdapter() { - RecommendAdapter = RecommendAdapter() - binding.rvRecommend.adapter = RecommendAdapter + recommendAdapter = RecommendAdapter() + binding.rvRecommend.adapter = recommendAdapter + binding.rvRecommend.layoutManager = LinearLayoutManager(requireContext()) } companion object { diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt index 8901de3..99b75f9 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt @@ -3,37 +3,79 @@ package com.keyneez.presentation.main.home.recommend import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel -import com.keyneez.data.entity.HomeData -import com.lab.keyneez.R +import androidx.lifecycle.viewModelScope +import com.keyneez.data.model.request.RequestPostSaveDto +import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.repository.ContentRepository +import com.keyneez.util.UiState +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.launch +import retrofit2.HttpException +import timber.log.Timber +import javax.inject.Inject -class RecommendViewModel : ViewModel() { - private val _itemList = MutableLiveData>() - val itemList: LiveData> - get() = _itemList +@HiltViewModel +class RecommendViewModel @Inject constructor( + private val contentRepository: ContentRepository +) : ViewModel() { + + private val _stateMessage = MutableLiveData() + val stateMessage: LiveData + get() = _stateMessage + + private val _contentList = MutableLiveData() + val contentList: LiveData + get() = _contentList + + private val _saveState = MutableLiveData() + val saveState: LiveData + get() = _saveState init { - getItemList() + getContent() } - private fun getItemList() { - val mainList = listOf( - HomeData( - background = R.drawable.img_home_item_background, - title = "청소년 미술관 할인" - ), - HomeData( - background = R.drawable.img_home_item_background, - title = "청소년 미술관 할인" - ), - HomeData( - background = R.drawable.img_home_item_background, - title = "청소년 미술관 할인" - ), - HomeData( - background = R.drawable.img_home_item_background, - title = "청소년 미술관 할인" + fun getContent() { + viewModelScope.launch { + contentRepository.getContent() + .onSuccess { response -> + Timber.tag(successTag).d("response : $response") + + if (response.data == null) { + Timber.d("GET CONTENT IS NULL") + _stateMessage.value = UiState.Failure(CONTENT_DATA_NULL_CODE) + } + _contentList.value = response.data!! + _stateMessage.value = UiState.Success + } + .onFailure { + Timber.tag(failTag).e("throwable : $it") + if (it is HttpException) { + Timber.tag(failTag).e("code : ${it.code()}") + Timber.tag(failTag).e("message : ${it.message()}") + } + } + } + } + + fun postSave() { + viewModelScope.launch { + contentRepository.postSave( + RequestPostSaveDto(key = 1, content = 1) ) - ) - _itemList.value = mainList + .onSuccess { response -> + Timber.tag(successTag).d("response : $response") + _saveState.value = true + }.onFailure { + Timber.tag(failTag).e("throwable : $it") + } + } + } + + companion object { + const val CONTENT_DATA_NULL_CODE = 100 + + private const val successTag = "GET_CONTENT_SUCCESS" + private const val failTag = "GET_CONTENT_FAIL" } } diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index 61bccaf..12c201c 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -2,9 +2,12 @@ package com.keyneez.util.binding import android.view.View import android.view.ViewGroup +import android.widget.ImageView import android.widget.TextView import androidx.databinding.BindingAdapter import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import com.lab.keyneez.R object BindingAdapter { @JvmStatic @@ -36,4 +39,42 @@ object BindingAdapter { this.layoutParams = it } } + + @JvmStatic + @BindingAdapter("url") + fun setImage(view: ImageView, url: MutableLiveData) { + url?.let { + } + } + + @JvmStatic + @BindingAdapter("keywordColor") + fun TextView.setKeywordColor(txt: String?) { + txt?.let { + when (txt) { + "문화" -> { + this.setTextColor(this.context.getColor(R.color.mint500)) + this.background = this.context.getDrawable(R.drawable.shape_mint500_line_rect) + } + "진로" -> { + this.setTextColor(this.context.getColor(R.color.green600)) + this.background = this.context.getDrawable(R.drawable.shape_green600_line_rect) + } + "봉사" -> { + this.setTextColor(this.context.getColor(R.color.purple500)) + this.background = this.context.getDrawable(R.drawable.shape_purple500_line_rect) + } + + "여행" -> { + this.setTextColor(this.context.getColor(R.color.pink500)) + this.background = this.context.getDrawable(R.drawable.shape_pink500_line_rect) + } + + "진로" -> { + this.setTextColor(this.context.getColor(R.color.red500)) + this.background = this.context.getDrawable(R.drawable.shape_red500_line_rect) + } + } + } + } } diff --git a/app/src/main/res/drawable/shape_gray050_80_fill_gray050_line_rect.xml b/app/src/main/res/drawable/shape_gray050_80_fill_gray050_line_rect.xml new file mode 100644 index 0000000..3e5c51b --- /dev/null +++ b/app/src/main/res/drawable/shape_gray050_80_fill_gray050_line_rect.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_id_photo.xml b/app/src/main/res/layout/activity_id_photo.xml index 9be30c4..c589e3b 100644 --- a/app/src/main/res/layout/activity_id_photo.xml +++ b/app/src/main/res/layout/activity_id_photo.xml @@ -28,14 +28,14 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="28dp" - android:background="@color/gray050_80" /> + android:background="@color/gray900_80" /> + android:background="@color/gray900_80" /> @@ -36,7 +36,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="28dp" - android:background="@color/gray050_80" + android:background="@color/gray900_80" android:visibility="@{vm.isVertical() ? View.INVISIBLE : View.VISIBLE}" /> diff --git a/app/src/main/res/layout/fragment_home_recommend.xml b/app/src/main/res/layout/fragment_home_recommend.xml index ac02bcd..d7bc811 100644 --- a/app/src/main/res/layout/fragment_home_recommend.xml +++ b/app/src/main/res/layout/fragment_home_recommend.xml @@ -3,6 +3,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index 7733345..218fbc8 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -3,6 +3,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> + @@ -26,7 +29,7 @@ android:layout_height="240dp" android:layout_marginBottom="160dp" android:scaleType="centerCrop" - android:src="@drawable/img_home_item_background" + android:src="@{content.img}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -39,7 +42,7 @@ android:layout_height="wrap_content" android:layout_marginTop="72dp" android:paddingHorizontal="21dp" - android:text="@string/home_title" + android:text="@{content.title}" android:textColor="@color/gray900" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/iv_home_item" /> @@ -52,7 +55,7 @@ android:layout_marginTop="4dp" android:layout_marginBottom="34dp" android:paddingHorizontal="21dp" - android:text="@string/home_sub" + android:text="@{content.introduction}" android:textColor="@color/gary600" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" @@ -82,6 +85,7 @@ + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5241ae1..bcb8ad2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -49,5 +49,6 @@ #FFFFFF - #CC000000 + #CC000000 + #CCFFFFFF \ No newline at end of file From 6e4424f267fa9fef3ecfa7c33400d60eb03abb00 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 05:11:13 +0900 Subject: [PATCH 04/16] =?UTF-8?q?[ADD/#38]=20postSave=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/request/RequestPostSaveDto.kt | 5 +---- .../keyneez/data/repository/ContentRepository.kt | 2 +- .../data/repository/ContentRepositoryImpl.kt | 8 +++----- .../java/com/keyneez/data/service/ContentService.kt | 13 ++++--------- .../com/keyneez/data/source/ContentDataSource.kt | 9 +++------ 5 files changed, 12 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt b/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt index 6c3257f..0f30feb 100644 --- a/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt +++ b/app/src/main/java/com/keyneez/data/model/request/RequestPostSaveDto.kt @@ -4,9 +4,6 @@ import kotlinx.serialization.SerialName @kotlinx.serialization.Serializable data class RequestPostSaveDto( - @SerialName("user_key") - val key: Int, @SerialName("content_id") - val content: Int - + val contentId: Int ) diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt index a4d0464..05d0dbc 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt @@ -10,7 +10,7 @@ interface ContentRepository { suspend fun getContent(): Result> suspend fun postSave( requestPostSaveDto: RequestPostSaveDto - ): Result> + ): Result> suspend fun getLike(): Result>> diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt index 7845b2d..7dbf73f 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt @@ -1,10 +1,9 @@ package com.keyneez.data.repository -import com.keyneez.data.model.response.ResponseGetContentDeatilDto -import com.keyneez.data.model.response.ResponseLikeDto -import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.ResponseGetContentDeatilDto +import com.keyneez.data.model.response.ResponseLikeDto import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.source.ContentDataSource import javax.inject.Inject @@ -18,13 +17,12 @@ class ContentRepositoryImpl @Inject constructor( override suspend fun getDetail(contentId: Int): Result> = kotlin.runCatching { contentDataSource.getDetail(contentId) } -} override suspend fun getContent(): Result> = kotlin.runCatching { contentDataSource.getContent() } override suspend fun postSave( requestPostSaveDto: RequestPostSaveDto - ): Result> = + ): Result> = kotlin.runCatching { contentDataSource.postSave(requestPostSaveDto) } } diff --git a/app/src/main/java/com/keyneez/data/service/ContentService.kt b/app/src/main/java/com/keyneez/data/service/ContentService.kt index badef86..2e1e3b8 100644 --- a/app/src/main/java/com/keyneez/data/service/ContentService.kt +++ b/app/src/main/java/com/keyneez/data/service/ContentService.kt @@ -1,16 +1,14 @@ package com.keyneez.data.service -import com.keyneez.data.model.response.ResponseGetContentDeatilDto -import com.keyneez.data.model.response.ResponseLikeDto -import com.keyneez.data.model.response.wrapper.BaseResponse -import retrofit2.http.GET -import retrofit2.http.Path import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.ResponseGetContentDeatilDto +import com.keyneez.data.model.response.ResponseLikeDto import com.keyneez.data.model.response.wrapper.BaseResponse import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST +import retrofit2.http.Path interface ContentService { @GET("content/liked") @@ -20,9 +18,6 @@ interface ContentService { suspend fun getDetail( @Path("content_id") contentId: Int ): BaseResponse -} - -interface ContentService { // 게시물 전체 조회 API @GET("content/") @@ -32,5 +27,5 @@ interface ContentService { @POST("content/save") suspend fun postSave( @Body requestBody: RequestPostSaveDto - ): BaseResponse + ): BaseResponse } diff --git a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt index d14eae8..aa8f810 100644 --- a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt +++ b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt @@ -1,17 +1,15 @@ package com.keyneez.data.source -import com.keyneez.data.model.response.ResponseGetContentDeatilDto -import com.keyneez.data.model.response.ResponseLikeDto -import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.data.model.response.ResponseGetContentDeatilDto +import com.keyneez.data.model.response.ResponseLikeDto import com.keyneez.data.model.response.wrapper.BaseResponse import com.keyneez.data.service.ContentService import javax.inject.Inject class ContentDataSource @Inject constructor( private val contentService: ContentService -) { ) { suspend fun getContent(): BaseResponse = contentService.getContent() @@ -20,10 +18,9 @@ class ContentDataSource @Inject constructor( suspend fun getDetail(contentId: Int): BaseResponse = contentService.getDetail(contentId) -} suspend fun postSave( requestPostSaveDto: RequestPostSaveDto - ): BaseResponse = + ): BaseResponse = contentService.postSave(requestPostSaveDto) } From 0ef51eefc92461dd09395cf3109bf92a5622570c Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 05:54:52 +0900 Subject: [PATCH 05/16] =?UTF-8?q?[FEAT/#38]=20SearchActivity=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keyneez/presentation/main/home/HomeFragment.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/keyneez/presentation/main/home/HomeFragment.kt b/app/src/main/java/com/keyneez/presentation/main/home/HomeFragment.kt index 6fef642..90bd8a0 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/HomeFragment.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/HomeFragment.kt @@ -1,9 +1,12 @@ package com.keyneez.presentation.main.home +import android.content.Intent import android.os.Bundle import android.view.View import com.google.android.material.tabs.TabLayoutMediator +import com.keyneez.presentation.main.search.SearchActivity import com.keyneez.util.binding.BindingFragment +import com.keyneez.util.extension.setOnSingleClickListener import com.lab.keyneez.R import com.lab.keyneez.databinding.FragmentHomeBinding @@ -12,6 +15,14 @@ class HomeFragment : BindingFragment(R.layout.fragment_home super.onViewCreated(view, savedInstanceState) initHomeViewPagerAdapter() + initSearchClickListener() + } + + private fun initSearchClickListener() { + binding.btnHomeSearch.setOnSingleClickListener { + val intent = Intent(getActivity(), SearchActivity::class.java) + startActivity(intent) + } } private fun initHomeViewPagerAdapter() { From 4b01ab534ae335e7735a586c77c4b96aaeb4dac7 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 06:20:43 +0900 Subject: [PATCH 06/16] =?UTF-8?q?[ADD/#38]=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=94=EC=9D=B8=EB=94=A9=20?= =?UTF-8?q?=EC=96=B4=EB=8C=91=ED=84=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_home.xml | 9 ++++++--- app/src/main/res/values/strings.xml | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index 218fbc8..a21614b 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> @@ -103,7 +104,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shape_gray050_80_fill_gray050_line_rect" - android:text="11.24 - 11.25" + putStartDate="@{content.start}" + putEndDate="@{content.end}" + android:text="@{@string/home_period(content.start,content.end)}" style="@style/PretendardSemibold12" android:textColor="@color/gray900" android:paddingVertical="8dp" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8955600..b2aa93e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -118,6 +118,7 @@ 인기 최신 문화 + %s–%s 유적 탐방부터 미술품까지! 청소년 미술관 할인 From 474d034285a1b3356e522eb68c1c1f1ae91077c6 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 06:21:26 +0900 Subject: [PATCH 07/16] =?UTF-8?q?[FEAT/#38]=20=EC=83=81=EC=84=B8=EB=B7=B0?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/main/home/recommend/RecommendAdapter.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt index f76f6b0..7c377ac 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt @@ -1,9 +1,13 @@ package com.keyneez.presentation.main.home.recommend +import android.content.Intent import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup +import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.keyneez.data.model.response.ResponseContentDto +import com.keyneez.presentation.main.detail.DetailActivity import com.keyneez.util.extension.setOnSingleClickListener import com.lab.keyneez.databinding.ItemHomeBinding @@ -28,6 +32,9 @@ class RecommendAdapter : RecyclerView.Adapter() fun onBind(item: ResponseContentDto) { binding.content = item binding.root.setOnSingleClickListener { + val intent = Intent(binding.root.context, DetailActivity::class.java) + intent.putExtra("contentId", item.key) + ContextCompat.startActivity(binding.root.context, intent, null) } } } From e8edd4429bdf942136431a9a6dba2576395e4a2a Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 11:17:14 +0900 Subject: [PATCH 08/16] =?UTF-8?q?[CHORE/#38]=20=EC=83=81=EC=84=B8=EB=B7=B0?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/detail/DetailActivity.kt | 4 ++- .../main/detail/DetailViewModel.kt | 4 +++ .../main/home/recommend/RecommendViewModel.kt | 26 +++++++++---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt index abe9670..3bd1d8a 100644 --- a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt +++ b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt @@ -13,6 +13,8 @@ class DetailActivity : BindingActivity(R.layout.activity_home_detail) { val detailViewModel: DetailViewModel by viewModels() + private val contentId: Int by lazy { intent.getIntExtra("contentId", 2) } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding.vm = detailViewModel @@ -24,7 +26,7 @@ class DetailActivity : } private fun initContentId() { - detailViewModel.getDetail(2) + detailViewModel.getDetail(contentId) } private fun initBackClickListener() { diff --git a/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt index d7aad5b..0db9eac 100644 --- a/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt @@ -25,6 +25,10 @@ class DetailViewModel @Inject constructor( val stateMessage: LiveData get() = _stateMessage + private val _saveState = MutableLiveData() + val saveState: LiveData + get() = _saveState + fun getDetail(contentId: Int) { viewModelScope.launch { contentRepository.getDetail(contentId) diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt index 99b75f9..d75c57d 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt @@ -58,19 +58,19 @@ class RecommendViewModel @Inject constructor( } } - fun postSave() { - viewModelScope.launch { - contentRepository.postSave( - RequestPostSaveDto(key = 1, content = 1) - ) - .onSuccess { response -> - Timber.tag(successTag).d("response : $response") - _saveState.value = true - }.onFailure { - Timber.tag(failTag).e("throwable : $it") - } - } - } +// fun postSave() { +// viewModelScope.launch { +// contentRepository.postSave( +// RequestPostSaveDto(contentId) +// ) +// .onSuccess { response -> +// Timber.tag(successTag).d("response : $response") +// _saveState.value = true +// }.onFailure { +// Timber.tag(failTag).e("throwable : $it") +// } +// } +// } companion object { const val CONTENT_DATA_NULL_CODE = 100 From 589ec683b315b54cb7a9b7fdb56dd7b8650c5421 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 12:14:22 +0900 Subject: [PATCH 09/16] =?UTF-8?q?[FEAT/#38]=20=ED=99=88=ED=99=94=EB=A9=B4?= =?UTF-8?q?=20=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 +- .../data/model/response/ResponseContentDto.kt | 15 ++++++++------- .../keyneez/data/repository/ContentRepository.kt | 2 +- .../data/repository/ContentRepositoryImpl.kt | 2 +- .../com/keyneez/data/service/ContentService.kt | 2 +- .../com/keyneez/data/source/ContentDataSource.kt | 2 +- .../main/home/recommend/RecommendFragment.kt | 2 +- .../main/home/recommend/RecommendViewModel.kt | 4 ++-- .../com/keyneez/util/binding/BindingAdapter.kt | 14 +++++++++++++- app/src/main/res/layout/item_home.xml | 11 +++++++---- 10 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c66c4b6..6a147cd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,7 +30,7 @@ ) { - @kotlinx.serialization.Serializable + @Serializable data class Category( - val category: String + val category: String? ) } diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt index 05d0dbc..8987bfc 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepository.kt @@ -7,7 +7,7 @@ import com.keyneez.data.model.response.ResponseLikeDto import com.keyneez.data.model.response.wrapper.BaseResponse interface ContentRepository { - suspend fun getContent(): Result> + suspend fun getContent(): Result>> suspend fun postSave( requestPostSaveDto: RequestPostSaveDto ): Result> diff --git a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt index 7dbf73f..3f66e7c 100644 --- a/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt +++ b/app/src/main/java/com/keyneez/data/repository/ContentRepositoryImpl.kt @@ -18,7 +18,7 @@ class ContentRepositoryImpl @Inject constructor( override suspend fun getDetail(contentId: Int): Result> = kotlin.runCatching { contentDataSource.getDetail(contentId) } - override suspend fun getContent(): Result> = + override suspend fun getContent(): Result>> = kotlin.runCatching { contentDataSource.getContent() } override suspend fun postSave( diff --git a/app/src/main/java/com/keyneez/data/service/ContentService.kt b/app/src/main/java/com/keyneez/data/service/ContentService.kt index 2e1e3b8..b4877b4 100644 --- a/app/src/main/java/com/keyneez/data/service/ContentService.kt +++ b/app/src/main/java/com/keyneez/data/service/ContentService.kt @@ -21,7 +21,7 @@ interface ContentService { // 게시물 전체 조회 API @GET("content/") - suspend fun getContent(): BaseResponse + suspend fun getContent(): BaseResponse> // 게시물 찜 @POST("content/save") diff --git a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt index aa8f810..406cc7f 100644 --- a/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt +++ b/app/src/main/java/com/keyneez/data/source/ContentDataSource.kt @@ -11,7 +11,7 @@ import javax.inject.Inject class ContentDataSource @Inject constructor( private val contentService: ContentService ) { - suspend fun getContent(): BaseResponse = + suspend fun getContent(): BaseResponse> = contentService.getContent() suspend fun getLike(): BaseResponse> = contentService.getLike() diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt index bce4e29..d769f0c 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendFragment.kt @@ -27,7 +27,7 @@ class RecommendFragment : private fun setupHomeData() { viewModel.contentList.observe(viewLifecycleOwner) { - recommendAdapter.data = listOf(it) + recommendAdapter.data = it recommendAdapter.notifyDataSetChanged() } } diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt index d75c57d..18ce08c 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt @@ -23,8 +23,8 @@ class RecommendViewModel @Inject constructor( val stateMessage: LiveData get() = _stateMessage - private val _contentList = MutableLiveData() - val contentList: LiveData + private val _contentList = MutableLiveData>() + val contentList: LiveData> get() = _contentList private val _saveState = MutableLiveData() diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index d2dbef4..818c70b 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -123,11 +123,23 @@ object BindingAdapter { this.background = this.context.getDrawable(R.drawable.shape_pink500_line_rect) } - "진로" -> { + "경제" -> { this.setTextColor(this.context.getColor(R.color.red500)) this.background = this.context.getDrawable(R.drawable.shape_red500_line_rect) } } } } + + @JvmStatic + @BindingAdapter("keywordColorCard") + fun ImageView.keywordColorCard(txt: String?) { + when (txt) { + "문화" -> this.context.getDrawable(R.drawable.ic_home_card_mint) + "진로" -> this.context.getDrawable(R.drawable.ic_home_card_green) + "봉사" -> this.context.getDrawable(R.drawable.ic_home_card_purple) + "여행" -> this.context.getDrawable(R.drawable.ic_home_card_pink) + "경제" -> this.context.getDrawable(R.drawable.ic_home_card_red) + } + } } diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index a21614b..26aa1e0 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -30,7 +30,7 @@ android:layout_height="240dp" android:layout_marginBottom="160dp" android:scaleType="centerCrop" - android:src="@{content.img}" + setImage="@{content.img}" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -39,7 +39,7 @@ @@ -86,7 +88,8 @@ Date: Fri, 13 Jan 2023 17:32:55 +0900 Subject: [PATCH 10/16] =?UTF-8?q?[FEAT/#38]=20postSave=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/response/ResponseIdDto.kt | 2 +- .../main/detail/DetailActivity.kt | 16 ++++++++-- .../main/detail/DetailViewModel.kt | 24 +++++++++++++++ .../main/home/recommend/RecommendAdapter.kt | 29 ++++++++++++++++++- .../main/home/recommend/RecommendViewModel.kt | 1 - .../keyneez/util/binding/BindingAdapter.kt | 12 -------- .../main/res/layout/activity_home_detail.xml | 2 ++ app/src/main/res/layout/item_home.xml | 5 ++-- 8 files changed, 72 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/keyneez/data/model/response/ResponseIdDto.kt b/app/src/main/java/com/keyneez/data/model/response/ResponseIdDto.kt index c1ba252..061058e 100644 --- a/app/src/main/java/com/keyneez/data/model/response/ResponseIdDto.kt +++ b/app/src/main/java/com/keyneez/data/model/response/ResponseIdDto.kt @@ -21,7 +21,7 @@ data class ResponseIdDto( ) { @Serializable data class Character( - val character: String?, + val character: String? // @SerialName("character_img") val characterImg: String? ) } diff --git a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt index 3bd1d8a..bf8f5b9 100644 --- a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt +++ b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt @@ -11,7 +11,7 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class DetailActivity : BindingActivity(R.layout.activity_home_detail) { - val detailViewModel: DetailViewModel by viewModels() + private val detailViewModel: DetailViewModel by viewModels() private val contentId: Int by lazy { intent.getIntExtra("contentId", 2) } @@ -23,6 +23,7 @@ class DetailActivity : initBackClickListener() initShareClickListener() initHeartClickListener() + initHeartActiveObserve() } private fun initContentId() { @@ -40,6 +41,17 @@ class DetailActivity : } private fun initHeartClickListener() { - binding.btnDetailHeart.setOnSingleClickListener { } + binding.btnDetailHeart.setOnSingleClickListener { + detailViewModel.postSave(contentId) + } + } + + private fun initHeartActiveObserve() { + detailViewModel.saveState.observe(this) { + binding.btnDetailHeart.isSelected = it + } + detailViewModel.detailContent.observe(this) { + binding.btnDetailHeart.isSelected = it.liked + } } } diff --git a/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt index 0db9eac..77ff6a7 100644 --- a/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/detail/DetailViewModel.kt @@ -4,8 +4,10 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseGetContentDeatilDto import com.keyneez.data.repository.ContentRepository +import com.keyneez.presentation.main.like.LikeViewModel import com.keyneez.util.UiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.launch @@ -41,10 +43,32 @@ class DetailViewModel @Inject constructor( Timber.d("GET DETAIL LIST SUCCESS") Timber.d("response : $response") _detailContent.value = response.data!! + _saveState.value = response.data.liked _stateMessage.value = UiState.Success }.onFailure { throwable -> Timber.e("$throwable") } } } + + fun postSave(contentId: Int) { + viewModelScope.launch { + contentRepository.postSave(RequestPostSaveDto(contentId)).onSuccess { response -> + if (response.data == null) { + Timber.d("GET LIKE LIST IS NULL") + _stateMessage.value = UiState.Failure(LikeViewModel.LIKE_NULL_CODE) + return@onSuccess + } + Timber.d("POST SAVE STATE SUCCESS") + Timber.d("response : $response") + + _saveState.value = true + _stateMessage.value = UiState.Success + } + .onFailure { + Timber.d("throwable : $it") + _stateMessage.value = UiState.Error + } + } + } } diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt index 7c377ac..551ff56 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt @@ -2,7 +2,6 @@ package com.keyneez.presentation.main.home.recommend import android.content.Intent import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView @@ -31,6 +30,8 @@ class RecommendAdapter : RecyclerView.Adapter() RecyclerView.ViewHolder(binding.root) { fun onBind(item: ResponseContentDto) { binding.content = item + binding.ivHomeCard + binding.btnHomeHeart.isSelected = item.liked binding.root.setOnSingleClickListener { val intent = Intent(binding.root.context, DetailActivity::class.java) intent.putExtra("contentId", item.key) @@ -38,4 +39,30 @@ class RecommendAdapter : RecyclerView.Adapter() } } } +// private fun initIdBackGround() { +// when (data.) { +// // 문화인-파란색 +// "문화" -> { +// binding.ivsetImageDrawable(R.mipmap.card_bg_mint) +// } +// // 진로탐색러-초록색 +// 2 -> { +// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_green) +// } +// // 탐험가-핑크색 +// 3 -> { +// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_pink) +// } +// // 경제인-빨간색 +// 4 -> { +// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_red) +// } +// // 봉사자-보라색 +// else -> { +// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_purple) +// } +// } +// +// fun ImageView.setImageDrawable(img: Int) { +// } } diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt index 18ce08c..6a2422f 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendViewModel.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.keyneez.data.model.request.RequestPostSaveDto import com.keyneez.data.model.response.ResponseContentDto import com.keyneez.data.repository.ContentRepository import com.keyneez.util.UiState diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index b2d69e2..830a1dd 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -128,16 +128,4 @@ object BindingAdapter { } } } - - @JvmStatic - @BindingAdapter("keywordColorCard") - fun ImageView.keywordColorCard(txt: String?) { - when (txt) { - "문화" -> this.context.getDrawable(R.drawable.ic_home_card_mint) - "진로" -> this.context.getDrawable(R.drawable.ic_home_card_green) - "봉사" -> this.context.getDrawable(R.drawable.ic_home_card_purple) - "여행" -> this.context.getDrawable(R.drawable.ic_home_card_pink) - "경제" -> this.context.getDrawable(R.drawable.ic_home_card_red) - } - } } diff --git a/app/src/main/res/layout/activity_home_detail.xml b/app/src/main/res/layout/activity_home_detail.xml index 28b115b..fc05dc2 100644 --- a/app/src/main/res/layout/activity_home_detail.xml +++ b/app/src/main/res/layout/activity_home_detail.xml @@ -51,6 +51,8 @@ android:layout_height="wrap_content" android:layout_marginTop="48dp" android:layout_marginEnd="12dp" + isSelected="@{vm.saveState}" + android:onClick="@{()->vm.postSave(vm.detailContent.key)}" android:background="@null" android:padding="12dp" android:src="@drawable/sel_detail_heart" diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index 26aa1e0..5e24861 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -39,8 +39,9 @@ From 2fbb6b4999c90a1b7c67d6000b359cf320794348 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 17:56:10 +0900 Subject: [PATCH 11/16] =?UTF-8?q?[FEAT/#38]=20=EC=A4=84=EB=B0=94=EA=BF=88?= =?UTF-8?q?=20=EC=97=86=EC=95=A0=EB=8A=94=20=EB=B0=94=EC=9D=B8=EB=94=A9=20?= =?UTF-8?q?=EC=96=B4=EB=8C=91=ED=84=B0=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/keyneez/util/binding/BindingAdapter.kt | 6 ++++++ app/src/main/res/layout/item_home.xml | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index 830a1dd..f4f26d3 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -128,4 +128,10 @@ object BindingAdapter { } } } + + @JvmStatic + @BindingAdapter("replaceNewline") + fun TextView.replaceNewline(string: String) { + this.text = string.replace(" ", "\u00A0") + } } diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index 5e24861..0ef1640 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -39,12 +39,11 @@ From 42d5ce77395f4588a1b4b9432791eb243a1993d6 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 17:58:50 +0900 Subject: [PATCH 12/16] =?UTF-8?q?[FIX/#38]=20=EC=96=B4=EB=8C=91=ED=84=B0?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index f4f26d3..b616ae7 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -132,6 +132,6 @@ object BindingAdapter { @JvmStatic @BindingAdapter("replaceNewline") fun TextView.replaceNewline(string: String) { - this.text = string.replace(" ", "\u00A0") + this.text = string.replace("\n", " ") } } From 8d35d843899556928bfc554aec97626b6c844c78 Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 18:44:51 +0900 Subject: [PATCH 13/16] =?UTF-8?q?[ADD/#38]=20=EB=B0=94=EC=9D=B8=EB=94=A9?= =?UTF-8?q?=20=EC=96=B4=EB=8C=91=ED=84=B0=20=EC=B6=94=EA=B0=80=ED=95=B4?= =?UTF-8?q?=EB=B4=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/home/recommend/RecommendAdapter.kt | 3 --- .../com/keyneez/util/binding/BindingAdapter.kt | 15 +++++++++++++++ app/src/main/res/layout/item_home.xml | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt index 551ff56..fa8d539 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt @@ -30,7 +30,6 @@ class RecommendAdapter : RecyclerView.Adapter() RecyclerView.ViewHolder(binding.root) { fun onBind(item: ResponseContentDto) { binding.content = item - binding.ivHomeCard binding.btnHomeHeart.isSelected = item.liked binding.root.setOnSingleClickListener { val intent = Intent(binding.root.context, DetailActivity::class.java) @@ -63,6 +62,4 @@ class RecommendAdapter : RecyclerView.Adapter() // } // } // -// fun ImageView.setImageDrawable(img: Int) { -// } } diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index b616ae7..febbfb1 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -134,4 +134,19 @@ object BindingAdapter { fun TextView.replaceNewline(string: String) { this.text = string.replace("\n", " ") } + + @JvmStatic + @BindingAdapter("card") + fun ImageView.card(string: String) { + when (string) { + "문화" -> this.setImageDrawable(R.drawable.ic_home_card_mint) + "진로" -> this.setImageDrawable(R.drawable.ic_home_card_green) + "봉사" -> this.setImageDrawable(R.drawable.ic_home_card_purple) + "여행" -> this.setImageDrawable(R.drawable.ic_home_card_pink) + "경제" -> this.setImageDrawable(R.drawable.ic_home_card_red) + } + } +} + +private fun ImageView.setImageDrawable(drawable: Int) { } diff --git a/app/src/main/res/layout/item_home.xml b/app/src/main/res/layout/item_home.xml index 0ef1640..11cad6b 100644 --- a/app/src/main/res/layout/item_home.xml +++ b/app/src/main/res/layout/item_home.xml @@ -70,7 +70,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="24dp" android:layout_marginTop="204dp" - android:src="@drawable/ic_home_card_mint" + card="@{content.category.get(0)}" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> From 7fe60fc26d81dfbe3eed5beb9b265a20bf4ff0aa Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 18:51:03 +0900 Subject: [PATCH 14/16] =?UTF-8?q?[DELETE/#38]=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/home/recommend/RecommendAdapter.kt | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt index fa8d539..7e13215 100644 --- a/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/home/recommend/RecommendAdapter.kt @@ -38,28 +38,4 @@ class RecommendAdapter : RecyclerView.Adapter() } } } -// private fun initIdBackGround() { -// when (data.) { -// // 문화인-파란색 -// "문화" -> { -// binding.ivsetImageDrawable(R.mipmap.card_bg_mint) -// } -// // 진로탐색러-초록색 -// 2 -> { -// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_green) -// } -// // 탐험가-핑크색 -// 3 -> { -// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_pink) -// } -// // 경제인-빨간색 -// 4 -> { -// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_red) -// } -// // 봉사자-보라색 -// else -> { -// binding.ivIdMainBackground.setImageDrawable(R.mipmap.card_bg_purple) -// } -// } -// } From 698d64349dfe4600fb52941f8238ea15c89f751a Mon Sep 17 00:00:00 2001 From: tama Date: Fri, 13 Jan 2023 20:11:52 +0900 Subject: [PATCH 15/16] =?UTF-8?q?[FEAT/#38]=20home=20detail=20=EB=B7=B0=20?= =?UTF-8?q?title=20=EB=B0=94=EC=9D=B8=EB=94=A9=EC=96=B4=EB=8C=91=ED=84=B0?= =?UTF-8?q?=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/activity_home_detail.xml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/res/layout/activity_home_detail.xml b/app/src/main/res/layout/activity_home_detail.xml index fc05dc2..4b96cf0 100644 --- a/app/src/main/res/layout/activity_home_detail.xml +++ b/app/src/main/res/layout/activity_home_detail.xml @@ -1,9 +1,9 @@ + xmlns:app="http://schemas.android.com/apk/res-auto"> + @@ -47,13 +47,13 @@ @@ -123,11 +123,11 @@ + app:layout_constraintTop_toBottomOf="@id/btn_detail_link" /> Date: Fri, 13 Jan 2023 21:05:59 +0900 Subject: [PATCH 16/16] [FEAT/#38] like, search -> detail --- .../keyneez/presentation/main/detail/DetailActivity.kt | 2 +- .../com/keyneez/presentation/main/like/LikeAdapter.kt | 2 +- .../com/keyneez/presentation/main/search/SearchAdapter.kt | 8 ++++++++ .../main/java/com/keyneez/util/binding/BindingAdapter.kt | 8 ++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt index bf8f5b9..ac8cd18 100644 --- a/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt +++ b/app/src/main/java/com/keyneez/presentation/main/detail/DetailActivity.kt @@ -13,7 +13,7 @@ class DetailActivity : BindingActivity(R.layout.activity_home_detail) { private val detailViewModel: DetailViewModel by viewModels() - private val contentId: Int by lazy { intent.getIntExtra("contentId", 2) } + private val contentId: Int by lazy { intent.getIntExtra("contentId", 0) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/com/keyneez/presentation/main/like/LikeAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/like/LikeAdapter.kt index f366a8e..727e67c 100644 --- a/app/src/main/java/com/keyneez/presentation/main/like/LikeAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/like/LikeAdapter.kt @@ -28,7 +28,7 @@ class LikeAdapter : RecyclerView.Adapter() { binding.data = item binding.root.setOnClickListener { val intent = Intent(binding.root.context, DetailActivity::class.java) - intent.putExtra("key", item.key) + intent.putExtra("contentId", item.key) ContextCompat.startActivity(binding.root.context, intent, null) } } diff --git a/app/src/main/java/com/keyneez/presentation/main/search/SearchAdapter.kt b/app/src/main/java/com/keyneez/presentation/main/search/SearchAdapter.kt index fea906b..069380e 100644 --- a/app/src/main/java/com/keyneez/presentation/main/search/SearchAdapter.kt +++ b/app/src/main/java/com/keyneez/presentation/main/search/SearchAdapter.kt @@ -1,9 +1,12 @@ package com.keyneez.presentation.main.search +import android.content.Intent import android.view.LayoutInflater import android.view.ViewGroup +import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.keyneez.data.model.response.ResponseGetSearchDto +import com.keyneez.presentation.main.detail.DetailActivity import com.lab.keyneez.databinding.ItemSearchContentBinding class SearchAdapter : RecyclerView.Adapter() { @@ -25,6 +28,11 @@ class SearchAdapter : RecyclerView.Adapter() { RecyclerView.ViewHolder(binding.root) { fun bind(item: ResponseGetSearchDto) { binding.data = item + binding.root.setOnClickListener { + val intent = Intent(binding.root.context, DetailActivity::class.java) + intent.putExtra("contentId", item.key) + ContextCompat.startActivity(binding.root.context, intent, null) + } } } } diff --git a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt index d7ab90f..f036574 100644 --- a/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt +++ b/app/src/main/java/com/keyneez/util/binding/BindingAdapter.kt @@ -50,7 +50,7 @@ object BindingAdapter { @BindingAdapter("putStartDate", "putEndDate") fun TextView.setDuration(start: String?, end: String?) { if (start == null || end == null) { - this.text = "2023-" + this.text = "2023 -" return } @@ -129,13 +129,13 @@ object BindingAdapter { @JvmStatic @BindingAdapter("replaceNewline") - fun TextView.replaceNewline(string: String) { - this.text = string.replace("\n", " ") + fun TextView.replaceNewline(string: String?) { + this.text = string?.replace("\n", " ") } @JvmStatic @BindingAdapter("card") - fun ImageView.card(string: String) { + fun ImageView.card(string: String?) { when (string) { "문화" -> this.setImageDrawable(R.drawable.ic_home_card_mint) "진로" -> this.setImageDrawable(R.drawable.ic_home_card_green)