Skip to content

Commit

Permalink
[LH-112] Change detail profile to Activity and linked #16
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Aug 11, 2023
1 parent 28fba1a commit 6691522
Show file tree
Hide file tree
Showing 11 changed files with 610 additions and 98 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.lighthouse.board.adapter

import android.content.res.Resources
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.lighthouse.android.common_ui.BR
import com.lighthouse.android.common_ui.R
import com.lighthouse.android.common_ui.base.adapter.ItemDiffCallBack
import com.lighthouse.android.common_ui.base.adapter.SimpleListAdapter
import com.lighthouse.android.common_ui.constant.Constant
import com.lighthouse.android.common_ui.databinding.QuestionTileBinding
import com.lighthouse.android.common_ui.util.Constant
import com.lighthouse.android.common_ui.util.calSize
import com.lighthouse.domain.response.vo.BoardQuestionVO

fun makeAdapter(
likeListener: (questionId: Int, memberId: Int) -> Unit,
navigateToProfile: (userId: Int) -> Unit,
) =
SimpleListAdapter<BoardQuestionVO, QuestionTileBinding>(
diffCallBack = ItemDiffCallBack(
Expand Down Expand Up @@ -55,13 +56,11 @@ fun makeAdapter(
}
}

binding.ivProfile.setOnClickListener {
navigateToProfile(item.memberId)
}

binding.setVariable(BR.item, item)

}
)

private fun calSize(size: Float?): Int {
val density = Resources.getSystem().displayMetrics.density

return (size?.times(density) ?: 0).toInt()
}
Original file line number Diff line number Diff line change
@@ -1,64 +1,54 @@
package com.lighthouse.board.view

import android.os.Bundle
import android.view.LayoutInflater
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import com.lighthouse.android.common_ui.base.BindingFragment
import com.lighthouse.android.common_ui.base.adapter.ScrollSpeedLinearLayoutManager
import com.lighthouse.android.common_ui.base.adapter.SimpleListAdapter
import com.lighthouse.android.common_ui.constant.setGone
import com.lighthouse.android.common_ui.constant.setVisible
import com.lighthouse.android.common_ui.constant.toast
import com.lighthouse.android.common_ui.databinding.QuestionTileBinding
import com.lighthouse.android.common_ui.util.UiState
import com.lighthouse.android.common_ui.util.setGone
import com.lighthouse.android.common_ui.util.setVisible
import com.lighthouse.android.common_ui.util.toast
import com.lighthouse.board.R
import com.lighthouse.board.adapter.makeAdapter
import com.lighthouse.board.databinding.FragmentTabContentBinding
import com.lighthouse.board.util.UiState
import com.lighthouse.board.util.UiState.Error
import com.lighthouse.board.util.UiState.Loading
import com.lighthouse.board.util.UiState.Success
import com.lighthouse.board.viewmodel.BoardViewModel
import com.lighthouse.domain.request.UpdateLikeVO
import com.lighthouse.domain.response.vo.BoardQuestionVO
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class TabContentFragment : Fragment() {
class TabContentFragment :
BindingFragment<FragmentTabContentBinding>(R.layout.fragment_tab_content) {
private val viewModel: BoardViewModel by viewModels(
ownerProducer = { requireParentFragment() }
)
private lateinit var binding: FragmentTabContentBinding
private lateinit var adapter: SimpleListAdapter<BoardQuestionVO, QuestionTileBinding>

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_tab_content, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initAdapter()
initRefresh()

val curPos = arguments?.getInt("tab_pos") ?: "Default Content"
val order = arguments?.getString("order") ?: "date"
// val order = arguments?.getString("order") ?: "date"

viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
viewModel.fetchState(curPos as Int, "latest").collect {
viewModel.fetchState(curPos as Int, null).collect {
render(it)
}
}
}


return binding.root
}

private fun initRefresh() {
Expand All @@ -69,9 +59,21 @@ class TabContentFragment : Fragment() {
}

private fun initAdapter() {
adapter = makeAdapter() { questionId, memberId ->
viewModel.updateLike(questionId, memberId)
}
adapter = makeAdapter({ questionId, memberId ->
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) {
viewModel.updateLike(questionId, UpdateLikeVO(memberId)).collect {
Log.d("UPDATE", it.toString())
}
}
}
}, { userId ->
mainNavigator.navigateToProfile(
requireContext(),
Pair("userId", userId),
Pair("isMe", false)
)
})

val linearLayoutManager = ScrollSpeedLinearLayoutManager(requireContext(), 8f)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
Expand All @@ -82,19 +84,19 @@ class TabContentFragment : Fragment() {

private fun render(uiState: UiState) {
when (uiState) {
is Loading -> {
is UiState.Loading -> {
binding.pbBoardLoading.setVisible()
binding.srBoard.setGone()

}

is Success<*> -> {
is UiState.Success<*> -> {
binding.srBoard.setVisible()
adapter.submitList(uiState.data as List<BoardQuestionVO>)
binding.pbBoardLoading.setGone()
}

is Error -> {
is UiState.Error -> {
context.toast(uiState.message)
binding.pbBoardLoading.setGone()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.lighthouse.profile.adapter

import android.view.LayoutInflater
import com.google.android.material.chip.Chip
import com.lighthouse.android.common_ui.base.adapter.ItemDiffCallBack
import com.lighthouse.android.common_ui.base.adapter.SimpleListAdapter
import com.lighthouse.domain.response.vo.InterestVO
import com.lighthouse.profile.R
import com.lighthouse.profile.databinding.InterestTileBinding

fun makeAdapter() =
SimpleListAdapter<InterestVO, InterestTileBinding>(
diffCallBack = ItemDiffCallBack(
onContentsTheSame = { old, new -> old == new },
onItemsTheSame = { old, new -> old.interest == new.interest }
),
layoutId = R.layout.interest_tile,
onBindCallback = { viewHolder, item ->
val binding = viewHolder.binding
binding.tvInterestTitle.text = item.category

val inflator = LayoutInflater.from(binding.root.context)
item.interest.forEach {
val chip = inflator.inflate(
com.lighthouse.android.common_ui.R.layout.chip,
binding.chipInterest,
false
) as Chip

chip.text = it
chip.isCloseIconVisible = false
chip.isCheckable = false

binding.chipInterest.addView(chip)
}

}
)
Loading

0 comments on commit 6691522

Please sign in to comment.