Skip to content

Commit

Permalink
[MERGE/#46] merge develop into ocr-feat-text-recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Jan 13, 2023
2 parents cd55655 + a8f488e commit 54c2dbc
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
</activity>
<activity
android:name="com.keyneez.presentation.login.LoginActivity"
android:exported="false"
android:exported="true"
android:screenOrientation="portrait" />
<activity
android:name="com.keyneez.presentation.signup.SignupActivity"
android:exported="true"
android:screenOrientation="portrait" />
<activity
android:name="com.keyneez.presentation.main.MainActivity"
android:exported="false"
android:exported="true"
android:screenOrientation="portrait" />
<activity
android:name="com.keyneez.presentation.main.detail.DetailActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.keyneez.data.model.request

import kotlinx.serialization.SerialName

@kotlinx.serialization.Serializable
data class RequestPostSaveDto(
@SerialName("content_id")
val contentId: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.keyneez.data.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@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<String>
) {
@Serializable
data class Category(
val category: String?
)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
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.ResponseGetContentDeatilDto
import com.keyneez.data.model.response.ResponseGetSearchDto
import com.keyneez.data.model.response.ResponseLikeDto
import com.keyneez.data.model.response.wrapper.BaseResponse

interface ContentRepository {
suspend fun getContent(): Result<BaseResponse<List<ResponseContentDto>>>
suspend fun postSave(
requestPostSaveDto: RequestPostSaveDto
): Result<BaseResponse<Unit>>

suspend fun getLike(): Result<BaseResponse<List<ResponseLikeDto>>>

suspend fun getDetail(contentId: Int): Result<BaseResponse<ResponseGetContentDeatilDto>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.ResponseGetContentDeatilDto
import com.keyneez.data.model.response.ResponseGetSearchDto
import com.keyneez.data.model.response.ResponseLikeDto
Expand All @@ -19,4 +21,12 @@ class ContentRepositoryImpl @Inject constructor(

override suspend fun getDetail(contentId: Int): Result<BaseResponse<ResponseGetContentDeatilDto>> =
kotlin.runCatching { contentDataSource.getDetail(contentId) }

override suspend fun getContent(): Result<BaseResponse<List<ResponseContentDto>>> =
kotlin.runCatching { contentDataSource.getContent() }

override suspend fun postSave(
requestPostSaveDto: RequestPostSaveDto
): Result<BaseResponse<Unit>> =
kotlin.runCatching { contentDataSource.postSave(requestPostSaveDto) }
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/keyneez/data/service/ContentService.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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.ResponseGetContentDeatilDto
import com.keyneez.data.model.response.ResponseGetSearchDto
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
import retrofit2.http.Query

Expand All @@ -21,4 +25,14 @@ interface ContentService {
suspend fun getSearch(
@Query("keyword") keyword: String
): BaseResponse<List<ResponseGetSearchDto>>

// ๊ฒŒ์‹œ๋ฌผ ์ „์ฒด ์กฐํšŒ API
@GET("content/")
suspend fun getContent(): BaseResponse<List<ResponseContentDto>>

// ๊ฒŒ์‹œ๋ฌผ ์ฐœ
@POST("content/save")
suspend fun postSave(
@Body requestBody: RequestPostSaveDto
): BaseResponse<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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.ResponseGetContentDeatilDto
import com.keyneez.data.model.response.ResponseGetSearchDto
import com.keyneez.data.model.response.ResponseLikeDto
Expand All @@ -10,6 +12,8 @@ import javax.inject.Inject
class ContentDataSource @Inject constructor(
private val contentService: ContentService
) {
suspend fun getContent(): BaseResponse<List<ResponseContentDto>> =
contentService.getContent()

suspend fun getLike(): BaseResponse<List<ResponseLikeDto>> = contentService.getLike()

Expand All @@ -18,4 +22,9 @@ class ContentDataSource @Inject constructor(

suspend fun getSearch(keyword: String): BaseResponse<List<ResponseGetSearchDto>> =
contentService.getSearch(keyword)

suspend fun postSave(
requestPostSaveDto: RequestPostSaveDto
): BaseResponse<Unit> =
contentService.postSave(requestPostSaveDto)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class DetailActivity :
BindingActivity<ActivityHomeDetailBinding>(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", 0) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -21,10 +23,11 @@ class DetailActivity :
initBackClickListener()
initShareClickListener()
initHeartClickListener()
initHeartActiveObserve()
}

private fun initContentId() {
detailViewModel.getDetail(2)
detailViewModel.getDetail(contentId)
}

private fun initBackClickListener() {
Expand All @@ -38,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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +27,10 @@ class DetailViewModel @Inject constructor(
val stateMessage: LiveData<UiState>
get() = _stateMessage

private val _saveState = MutableLiveData<Boolean>()
val saveState: LiveData<Boolean>
get() = _saveState

fun getDetail(contentId: Int) {
viewModelScope.launch {
contentRepository.getDetail(contentId)
Expand All @@ -37,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
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,6 +15,14 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package com.keyneez.presentation.main.home.recommend

import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.keyneez.data.entity.HomeData
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

class RecommendAdapter : RecyclerView.Adapter<RecommendAdapter.InfoViewHolder>() {
var data = listOf<HomeData>()
class RecommendAdapter : RecyclerView.Adapter<RecommendAdapter.HomeViewHolder>() {
var data = listOf<ResponseContentDto>()

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.btnHomeHeart.isSelected = item.liked
binding.root.setOnSingleClickListener {
val intent = Intent(binding.root.context, DetailActivity::class.java)
intent.putExtra("contentId", item.key)
ContextCompat.startActivity(binding.root.context, intent, null)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FragmentHomeRecommendBinding>(R.layout.fragment_home_recommend) {
private val viewModel: RecommendViewModel by viewModels()
val data = mutableListOf<HomeData>()
private lateinit var RecommendAdapter: RecommendAdapter
val data = mutableListOf<ResponseContentDto>()
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 = 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 {
Expand Down
Loading

0 comments on commit 54c2dbc

Please sign in to comment.