Skip to content

Commit

Permalink
Merge branch 'develop' into fix/#139-font-react
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Jan 16, 2024
2 parents c4e547e + bf8adcf commit ce28029
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.going.presentation.todo.mytodo

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
Expand All @@ -11,18 +13,22 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.ViewPager2
import com.going.presentation.R
import com.going.presentation.databinding.FragmentMyTodoBinding
import com.going.presentation.profile.ProfileActivity
import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID
import com.going.presentation.todo.mytodo.create.MyTodoCreateActivity
import com.going.presentation.todo.mytodo.todolist.MyTodoViewPagerAdapter
import com.going.presentation.todo.ourtodo.OurTodoFragment
import com.going.presentation.todo.ourtodo.OurTodoFragment.Companion.debounceTime
import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_PARTICIPANT_ID
import com.going.ui.base.BaseFragment
import com.going.ui.extension.UiState
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand All @@ -44,6 +50,8 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
setMyTripInfo()
setTabLayout()
setViewPager()
setViewPagerChangeListener()
setViewPagerDebounce()
setTodoCountText()
observeMyTripInfoState()
observeTotalUncompletedTodoCount()
Expand Down Expand Up @@ -100,6 +108,40 @@ class MyTodoFragment() : BaseFragment<FragmentMyTodoBinding>(R.layout.fragment_m
}.attach()
}

private fun setViewPagerChangeListener() {
binding.vpMyTodo.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)

viewModel.resetListState()
}
})
}

private fun setViewPagerDebounce() {
binding.tabMyTodo.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
binding.vpMyTodo.currentItem = tab.position
disableTabClick()
}

override fun onTabUnselected(tab: TabLayout.Tab) {}

override fun onTabReselected(tab: TabLayout.Tab) {}
})
}

private fun disableTabClick() {
for (i in tabTextList.indices) {
binding.tabMyTodo.getTabAt(i)?.view?.isClickable = false
}
Handler(Looper.getMainLooper()).postDelayed({
for (i in tabTextList.indices) {
binding.tabMyTodo.getTabAt(i)?.view?.isClickable = true
}
}, debounceTime)
}

private fun setTodoCountText() {
setTodoCount(viewModel.totalUncompletedTodoCount.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class MyTodoViewModel @Inject constructor(
}
}

fun resetListState() {
_todoCompleteListState.value = UiState.Empty
_todoUncompleteListState.value = UiState.Empty
}

fun getToFinishTodoFromServer(todoId: Long) {
_todoFinishState.value = EnumUiState.LOADING
viewModelScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@ package com.going.presentation.todo.mytodo.todolist

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.going.domain.entity.response.TodoModel
import com.going.presentation.databinding.ItemMyTodoBinding
import com.going.ui.extension.ItemDiffCallback

class MyTodoListAdapter(
private val isCompleted: Boolean,
private val itemSelect: (Long) -> Unit,
private val itemUnselect: (Long) -> Unit,
private val itemDetailClick: (TodoModel) -> Unit
) : ListAdapter<TodoModel, MyTodoListViewHolder>(diffUtil) {
) : RecyclerView.Adapter<MyTodoListViewHolder>() {

private var itemList = mutableListOf<TodoModel>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyTodoListViewHolder {
val binding: ItemMyTodoBinding =
ItemMyTodoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemMyTodoBinding = ItemMyTodoBinding.inflate(inflater, parent, false)
return MyTodoListViewHolder(binding, isCompleted, itemSelect, itemUnselect, itemDetailClick)
}

override fun onBindViewHolder(holder: MyTodoListViewHolder, position: Int) {
holder.onBind(getItem(position))
holder.onBind(itemList[position])
}

companion object {
private val diffUtil = ItemDiffCallback<TodoModel>(
onItemsTheSame = { old, new -> old.todoId == new.todoId },
onContentsTheSame = { old, new -> old == new },
)
override fun getItemCount(): Int = itemList.size

fun submitList(newItems: List<TodoModel>) {
this.itemList.clear()
this.itemList.addAll(newItems)
notifyDataSetChanged()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MyTodoUncompleteFragment() :
super.onViewCreated(view, savedInstanceState)

initAdapterWithClickListener()
initItemDecoration()
observeTodoListState()
observeTodoFinishState()
}
Expand Down Expand Up @@ -81,6 +82,11 @@ class MyTodoUncompleteFragment() :
}
}

private fun initItemDecoration() {
val itemDeco = TodoDecoration(requireContext(),0,0,0,30)
binding.rvMyTodoUncomplete.addItemDecoration(itemDeco)
}

private fun setTodoList() {
viewModel.getUncompleteTodoListFromServer(MY_TODO, UNCOMPLETE)
}
Expand All @@ -91,7 +97,6 @@ class MyTodoUncompleteFragment() :
is UiState.Success -> {
setLayoutEmpty(false)
adapter.submitList(state.data)
setItemDecoration()
}

is UiState.Failure -> {
Expand All @@ -112,12 +117,6 @@ class MyTodoUncompleteFragment() :
(parentFragment as MyTodoFragment).setAppbarDragAvailable(!isEmpty)
}

private fun setItemDecoration() {
val itemDeco = TodoDecoration(requireContext(),0,0,0,30)
if (binding.rvMyTodoUncomplete.itemDecorationCount > 0) binding.rvMyTodoUncomplete.removeItemDecoration(itemDeco)
binding.rvMyTodoUncomplete.addItemDecoration(itemDeco)
}

private fun observeTodoFinishState() {
viewModel.todoFinishState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.going.presentation.todo.ourtodo

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
Expand All @@ -11,11 +13,12 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.widget.ViewPager2
import com.going.domain.entity.response.TripParticipantModel
import com.going.presentation.R
import com.going.presentation.databinding.FragmentOurTodoBinding
import com.going.presentation.todo.TodoDecoration
import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID
import com.going.presentation.todo.TodoDecoration
import com.going.presentation.todo.ourtodo.checkfriends.CheckFriendsActivity
import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity
import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_NAME
Expand All @@ -28,6 +31,7 @@ import com.going.ui.extension.UiState
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand All @@ -48,6 +52,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment

private var participantList = listOf<TripParticipantModel>()

private var lastClickTime = 0L

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand All @@ -60,6 +66,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
setMyTripInfo()
setTabLayout()
setViewPager()
setViewPagerChangeListener()
setViewPagerDebounce()
observeOurTripInfoState()
}

Expand All @@ -84,7 +92,7 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
}

private fun initItemDecoration() {
val itemDeco = TodoDecoration(requireContext(),0,0,150,0)
val itemDeco = TodoDecoration(requireContext(), 0, 0, 150, 0)
binding.rvOurTripFriend.addItemDecoration(itemDeco)
}

Expand Down Expand Up @@ -136,6 +144,40 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
}.attach()
}

private fun setViewPagerChangeListener() {
binding.vpOurTodo.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)

viewModel.resetListState()
}
})
}

private fun setViewPagerDebounce() {
binding.tabOurTodo.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
binding.vpOurTodo.currentItem = tab.position
disableTabClick()
}

override fun onTabUnselected(tab: TabLayout.Tab) {}

override fun onTabReselected(tab: TabLayout.Tab) {}
})
}

private fun disableTabClick() {
for (i in tabTextList.indices) {
binding.tabOurTodo.getTabAt(i)?.view?.isClickable = false
}
Handler(Looper.getMainLooper()).postDelayed({
for (i in tabTextList.indices) {
binding.tabOurTodo.getTabAt(i)?.view?.isClickable = true
}
}, debounceTime)
}

private fun observeOurTripInfoState() {
viewModel.ourTripInfoState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
Expand Down Expand Up @@ -222,6 +264,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
const val TAB_UNCOMPLETE = "해야 해요"
const val TAB_COMPLETE = "완료했어요"
const val INVITE_DIALOG = "inviteDialog"

const val debounceTime = 300L
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class OurTodoViewModel @Inject constructor(
}
}

fun resetListState() {
_todoCompleteListState.value = UiState.Empty
_todoUncompleteListState.value = UiState.Empty
}

companion object {
const val OUR_TODO = "our"
const val UNCOMPLETE = "incomplete"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ class OurTodoCompleteFragment() :

initAdapterWithClickListener()
initItemDecoration()
setTodoList()
observeTodoListState()
}

override fun onResume() {
super.onResume()

setTodoList()
}

private fun initAdapterWithClickListener() {
_adapter = OurTodoListAdapter(
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@ package com.going.presentation.todo.ourtodo.todolist

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.going.domain.entity.response.TodoModel
import com.going.presentation.databinding.ItemOurTodoBinding
import com.going.ui.extension.ItemDiffCallback

class OurTodoListAdapter(
private val isCompleted: Boolean,
private val itemDetailClick: (Long) -> Unit
) : ListAdapter<TodoModel, OurTodoListViewHolder>(diffUtil) {
private val isCompleted: Boolean, private val itemDetailClick: (Long) -> Unit
) : RecyclerView.Adapter<OurTodoListViewHolder>() {

private var itemList = mutableListOf<TodoModel>()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OurTodoListViewHolder {
val binding: ItemOurTodoBinding =
ItemOurTodoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
val inflater by lazy { LayoutInflater.from(parent.context) }
val binding: ItemOurTodoBinding = ItemOurTodoBinding.inflate(inflater, parent, false)
return OurTodoListViewHolder(binding, isCompleted, itemDetailClick)
}

override fun onBindViewHolder(holder: OurTodoListViewHolder, position: Int) {
holder.onBind(getItem(position))
holder.onBind(itemList[position])
}

companion object {
private val diffUtil = ItemDiffCallback<TodoModel>(
onItemsTheSame = { old, new -> old.todoId == new.todoId },
onContentsTheSame = { old, new -> old == new },
)
override fun getItemCount(): Int = itemList.size

fun submitList(newItems: List<TodoModel>) {
this.itemList.clear()
this.itemList.addAll(newItems)
notifyDataSetChanged()
}

}

0 comments on commit ce28029

Please sign in to comment.