From a97c3c931086ad238c34e3e10e5eabd02f13e663 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 13:28:15 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[FIX/#185]=20OurTodo=20colorOf=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95,=20when=20=ED=99=9C=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ourtodo/OurTodoFragment.kt | 51 +++++++++---------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index 53ef09de..e34d19d5 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -8,7 +8,6 @@ import android.text.SpannableStringBuilder import android.text.Spanned import android.text.style.ForegroundColorSpan import android.view.View -import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.lifecycle.flowWithLifecycle @@ -28,6 +27,7 @@ import com.going.presentation.todo.ourtodo.invite.FriendInviteDialog import com.going.presentation.todo.ourtodo.todolist.OurTodoViewPagerAdapter import com.going.ui.base.BaseFragment import com.going.ui.extension.UiState +import com.going.ui.extension.colorOf import com.going.ui.extension.getWindowHeight import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.setStatusBarColor @@ -193,18 +193,10 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment binding.appbarOurTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> if (abs(verticalOffset) == appBarLayout.totalScrollRange) { setStatusBarColor(R.color.white_000) - binding.toolbarOurTodo.setBackgroundColor( - ContextCompat.getColor( - requireContext(), R.color.white_000 - ) - ) + binding.toolbarOurTodo.setBackgroundColor(colorOf(R.color.white_000)) } else { setStatusBarColor(R.color.gray_50) - binding.toolbarOurTodo.setBackgroundColor( - ContextCompat.getColor( - requireContext(), R.color.gray_50 - ) - ) + binding.toolbarOurTodo.setBackgroundColor(colorOf(R.color.gray_50)) } } } @@ -250,22 +242,27 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment }.launchIn(lifecycleScope) } - private fun convertDate(date: String): String { - val splitDate = date.split(".") - return getString(R.string.our_todo_day_form).format(splitDate[1], splitDate[2]) - } + private fun convertDate(date: String) = + date.split(".").let { splitDate -> + getString(R.string.our_todo_day_form).format(splitDate[1], splitDate[2]) + } private fun setTitleTextWithDay(day: Int, isComplete: Boolean) { - if (day > 0) { - binding.tvOurTodoTitleDown.text = - getString(R.string.our_todo_title_down_before).format(day) - setDateTextColor(6, 6) - } else if (!isComplete) { - binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_during) - setDateTextColor(0, 4) - } else { - binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_end) - setDateTextColor(4, 5) + when { + day > 0 -> { + binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_before).format(day) + setDateTextColor(6, 6) + } + + !isComplete -> { + binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_during) + setDateTextColor(0, 4) + } + + else -> { + binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_end) + setDateTextColor(4, 5) + } } } @@ -274,9 +271,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment text = SpannableStringBuilder(text).apply { setSpan( ForegroundColorSpan( - ContextCompat.getColor( - requireContext(), R.color.red_500 - ) + colorOf(R.color.red_500) ), start, length - end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ) } From c8bd0ec156dcb9b77ce75e6b8d01c19e674a24ca Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 13:34:50 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[FIX/#185]=20=EC=B9=9C=EA=B5=AC=EC=B4=88?= =?UTF-8?q?=EB=8C=80=20dialog=20intent=20=ED=95=B4=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ourtodo/OurTodoFragment.kt | 2 +- .../todo/ourtodo/OurTodoFriendAdapter.kt | 3 ++- .../todo/ourtodo/OurTodoViewModel.kt | 2 +- .../todo/ourtodo/invite/FriendInviteDialog.kt | 24 ++++++------------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index e34d19d5..a4ae8978 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -109,7 +109,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun initInviteBtnListener() { binding.btnOurTodoAddFriend.setOnSingleClickListener { - friendInviteDialog = FriendInviteDialog.newInstance(viewModel.inviteCode) + friendInviteDialog = FriendInviteDialog() friendInviteDialog?.show(parentFragmentManager, INVITE_DIALOG) } } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFriendAdapter.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFriendAdapter.kt index b97e9605..de773caf 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFriendAdapter.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFriendAdapter.kt @@ -11,8 +11,9 @@ class OurTodoFriendAdapter : RecyclerView.Adapter() { private var itemList = mutableListOf() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OurTodoFriendViewHolder { + val inflater by lazy { LayoutInflater.from(parent.context) } val binding: ItemTodoFriendsBinding = - ItemTodoFriendsBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ItemTodoFriendsBinding.inflate(inflater, parent, false) return OurTodoFriendViewHolder(binding) } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt index 5915a9eb..02b826bb 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoViewModel.kt @@ -38,7 +38,7 @@ class OurTodoViewModel @Inject constructor( _ourTripInfoState.value = UiState.Success(response) } .onFailure { - _ourTripInfoState.value = UiState.Failure(it.message.toString()) + _ourTripInfoState.value = UiState.Failure(it.message.orEmpty()) } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/invite/FriendInviteDialog.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/invite/FriendInviteDialog.kt index e06daa08..3daa9214 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/invite/FriendInviteDialog.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/invite/FriendInviteDialog.kt @@ -7,9 +7,10 @@ import android.os.Build import android.os.Bundle import android.view.View import android.view.WindowManager -import androidx.core.os.bundleOf +import androidx.fragment.app.activityViewModels import com.going.presentation.R import com.going.presentation.databinding.FragmentFriendInviteDialogBinding +import com.going.presentation.todo.ourtodo.OurTodoViewModel import com.going.ui.base.BaseDialog import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast @@ -17,7 +18,7 @@ import com.going.ui.extension.toast class FriendInviteDialog : BaseDialog(R.layout.fragment_friend_invite_dialog) { - private var inviteCode = "" + private val viewModel by activityViewModels() override fun onStart() { super.onStart() @@ -33,15 +34,13 @@ class FriendInviteDialog : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - getBundleArgs() + setInviteCode() initExitBtnListener() initLinkInviteBtnListener() } - private fun getBundleArgs() { - arguments ?: return - inviteCode = arguments?.getString(ARGS_CODE) ?: "" - binding.tvTodoInviteCode.text =inviteCode + private fun setInviteCode() { + binding.tvTodoInviteCode.text = viewModel.inviteCode } private fun initExitBtnListener() { @@ -54,22 +53,13 @@ class FriendInviteDialog : binding.tvTodoInviteTermsText.setOnSingleClickListener { val clipboardManager = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clipData = ClipData.newPlainText(CLIP_LABEL, inviteCode) + val clipData = ClipData.newPlainText(CLIP_LABEL, viewModel.inviteCode) clipboardManager.setPrimaryClip(clipData) if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) toast(getString(R.string.finish_trip_tv_copy_code_complete)) } } companion object { - const val ARGS_CODE = "code" const val CLIP_LABEL = "RECOMMEND_LINK" - - @JvmStatic - fun newInstance(code: String) = FriendInviteDialog().apply { - val args = bundleOf( - ARGS_CODE to code - ) - arguments = args - } } } From 6f33bc04a74a316bb3f8b0d767ac7f17d5e5812f Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 13:38:55 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[FIX/#185]=20initOffsetChangedListener=20?= =?UTF-8?q?=ED=95=A9=EC=B9=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/mytodo/MyTodoFragment.kt | 34 ++++++------------- .../todo/ourtodo/OurTodoFragment.kt | 23 +++++-------- 2 files changed, 20 insertions(+), 37 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt index 6764274e..1f4552d6 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt @@ -25,6 +25,7 @@ import com.going.presentation.todo.ourtodo.OurTodoFragment.Companion.debounceTim 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.colorOf import com.going.ui.extension.getWindowHeight import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.setStatusBarColor @@ -58,9 +59,8 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m setViewPagerChangeListener() setViewPagerDebounce() setTodoCountText() - setToolbarColor() initEmptyViewHeight() - setEmptyViewHeight() + initOffsetChangedListener() observeMyTripInfoState() observeTotalUncompletedTodoCount() @@ -154,26 +154,6 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m setTodoCount(viewModel.totalUncompletedTodoCount.value) } - private fun setToolbarColor() { - binding.appbarMyTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> - if (abs(verticalOffset) == appBarLayout.totalScrollRange) { - setStatusBarColor(R.color.white_000) - binding.toolbarMyTodo.setBackgroundColor( - ContextCompat.getColor( - requireContext(), R.color.white_000 - ) - ) - } else { - setStatusBarColor(R.color.gray_50) - binding.toolbarMyTodo.setBackgroundColor( - ContextCompat.getColor( - requireContext(), R.color.gray_50 - ) - ) - } - } - } - private fun initEmptyViewHeight() { binding.appbarMyTodo.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { @@ -189,7 +169,7 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m }) } - private fun setEmptyViewHeight() { + private fun initOffsetChangedListener() { binding.appbarMyTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener val toolbarHeight = binding.toolbarMyTodo.height @@ -197,6 +177,14 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m binding.layoutMyTodoEmpty.layoutParams = (binding.layoutMyTodoEmpty.layoutParams).also { it.height = displayHeight - toolbarHeight - appBarHeight - 300 } + + if (abs(verticalOffset) == appBarLayout.totalScrollRange) { + setStatusBarColor(R.color.white_000) + binding.toolbarMyTodo.setBackgroundColor(colorOf(R.color.white_000)) + } else { + setStatusBarColor(R.color.gray_50) + binding.toolbarMyTodo.setBackgroundColor(colorOf(R.color.gray_50)) + } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index a4ae8978..006508cf 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -70,8 +70,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment setViewPager() setViewPagerChangeListener() setViewPagerDebounce() - setToolbarColor() - setEmptyViewHeight() + initOffsetChangedListener() observeOurTripInfoState() } @@ -189,8 +188,15 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment handler.postDelayed(enableClickRunnable, debounceTime) } - private fun setToolbarColor() { + private fun initOffsetChangedListener() { binding.appbarOurTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> + val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener + val toolbarHeight = binding.toolbarOurTodo.height + val appBarHeight = appBarLayout.totalScrollRange + verticalOffset + binding.layoutOurTodoEmpty.layoutParams = (binding.layoutOurTodoEmpty.layoutParams).also { + it.height = displayHeight - toolbarHeight - appBarHeight - 300 + } + if (abs(verticalOffset) == appBarLayout.totalScrollRange) { setStatusBarColor(R.color.white_000) binding.toolbarOurTodo.setBackgroundColor(colorOf(R.color.white_000)) @@ -201,17 +207,6 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment } } - private fun setEmptyViewHeight() { - binding.appbarOurTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> - val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener - val toolbarHeight = binding.toolbarOurTodo.height - val appBarHeight = appBarLayout.totalScrollRange + verticalOffset - binding.layoutOurTodoEmpty.layoutParams = (binding.layoutOurTodoEmpty.layoutParams).also { - it.height = displayHeight - toolbarHeight - appBarHeight - 300 - } - } - } - fun showEmptyView(show: Boolean) { binding.layoutOurTodoEmpty.isVisible = show } From 1d841b8eeb6850893001e1adeaddb40f04c8cae6 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 16:37:31 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[FIX/#185]=20OurTodo=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=B7=B0=20intent=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/mytodo/MyTodoFragment.kt | 2 +- .../todo/ourtodo/OurTodoFragment.kt | 18 +++++++----------- .../ourtodo/create/OurTodoCreateActivity.kt | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt index 1f4552d6..c251af16 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt @@ -169,7 +169,7 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m }) } - private fun initOffsetChangedListener() { + private fun initOffsetChangedListener() { binding.appbarMyTodo.addOnOffsetChangedListener { appBarLayout, verticalOffset -> val displayHeight = activity?.getWindowHeight() ?: return@addOnOffsetChangedListener val toolbarHeight = binding.toolbarMyTodo.height diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index 006508cf..595ba2a9 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -20,9 +20,6 @@ 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 -import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_PARTICIPANT_ID -import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_RESULT import com.going.presentation.todo.ourtodo.invite.FriendInviteDialog import com.going.presentation.todo.ourtodo.todolist.OurTodoViewPagerAdapter import com.going.ui.base.BaseFragment @@ -88,14 +85,13 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment private fun initAddTodoBtnListener() { binding.btnOurTodoAddTodo.setOnSingleClickListener { - val idList: ArrayList = ArrayList(participantList.map { it.participantId.toInt() }) - val nameList: ArrayList = ArrayList(participantList.map { it.name }) - val resultList: ArrayList = ArrayList(participantList.map { it.result }) - Intent(activity, OurTodoCreateActivity::class.java).apply { - putIntegerArrayListExtra(EXTRA_PARTICIPANT_ID, idList) - putStringArrayListExtra(EXTRA_NAME, nameList) - putIntegerArrayListExtra(EXTRA_RESULT, resultList) - putExtra(EXTRA_TRIP_ID, viewModel.tripId) + OurTodoCreateActivity.createIntent( + requireContext(), + viewModel.tripId, + ArrayList(participantList.map { it.participantId.toInt() }), + ArrayList(participantList.map { it.name }), + ArrayList(participantList.map { it.result }) + ).apply { startActivity(this) } } diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateActivity.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateActivity.kt index a4dbaefb..791c9907 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateActivity.kt @@ -1,5 +1,7 @@ package com.going.presentation.todo.ourtodo.create +import android.content.Context +import android.content.Intent import android.graphics.drawable.Drawable import android.os.Bundle import android.widget.TextView @@ -54,8 +56,7 @@ class OurTodoCreateActivity : private fun initNameListAdapter() { _adapter = TodoCreateNameAdapter(false) { position -> - viewModel.participantList[position].isSelected = - !viewModel.participantList[position].isSelected + viewModel.participantList[position].also { it.isSelected = !it.isSelected } viewModel.checkIsFinishAvailable() } binding.rvOurTodoCreatePerson.adapter = adapter @@ -186,5 +187,19 @@ class OurTodoCreateActivity : const val EXTRA_PARTICIPANT_ID = "EXTRA_PARTICIPANT_ID" const val EXTRA_NAME = "EXTRA_NAME" const val EXTRA_RESULT = "EXTRA_RESULT" + + @JvmStatic + fun createIntent( + context: Context, + tripId: Long, + idList: ArrayList, + nameList: ArrayList, + resultList: ArrayList + ): Intent = Intent(context, OurTodoCreateActivity::class.java).apply { + putExtra(EXTRA_TRIP_ID, tripId) + putIntegerArrayListExtra(EXTRA_PARTICIPANT_ID, idList) + putStringArrayListExtra(EXTRA_NAME, nameList) + putIntegerArrayListExtra(EXTRA_RESULT, resultList) + } } } From a779de418c840e75661ffba75438a5bf11cf67b4 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 16:50:05 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[FIX/#185]=20nameList=20=EB=B7=B0=ED=99=80?= =?UTF-8?q?=EB=8D=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/ourtodo/create/OurTodoCreateBottomSheet.kt | 6 +++--- .../todo/ourtodo/create/OurTodoCreateViewModel.kt | 7 +++---- .../todo/ourtodo/create/TodoCreateNameViewHolder.kt | 6 +++--- .../todo/ourtodo/todolist/OurTodoListViewHolder.kt | 10 +++++----- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateBottomSheet.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateBottomSheet.kt index 600c5221..5e46c517 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateBottomSheet.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateBottomSheet.kt @@ -5,7 +5,7 @@ import android.view.View import androidx.fragment.app.activityViewModels import com.going.presentation.R import com.going.presentation.databinding.FragmentOurTodoCreateBottomSheetBinding -import com.going.presentation.todo.mytodo.create.MyTodoCreateBottomSheet +import com.going.presentation.todo.mytodo.create.MyTodoCreateBottomSheet.Companion.TWO_DIGIT_FORMAT import com.going.ui.base.BaseBottomSheet import com.going.ui.extension.setOnSingleClickListener @@ -27,8 +27,8 @@ class OurTodoCreateBottomSheet() : private fun initFinishBtnClickListener() { binding.btnCreateTripFinish.setOnSingleClickListener { - val createdMonth = String.format(MyTodoCreateBottomSheet.TWO_DIGIT_FORMAT, binding.dpCreateTripDate.month + 1) - val createdDay = String.format(MyTodoCreateBottomSheet.TWO_DIGIT_FORMAT, binding.dpCreateTripDate.dayOfMonth) + val createdMonth = String.format(TWO_DIGIT_FORMAT, binding.dpCreateTripDate.month + 1) + val createdDay = String.format(TWO_DIGIT_FORMAT, binding.dpCreateTripDate.dayOfMonth) viewModel.endDate.value = binding.dpCreateTripDate.year.toString() + "." + createdMonth + "." + createdDay viewModel.checkIsFinishAvailable() diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateViewModel.kt index 237dcfcd..1d20749d 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/OurTodoCreateViewModel.kt @@ -1,6 +1,5 @@ package com.going.presentation.todo.ourtodo.create -import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -58,7 +57,7 @@ class OurTodoCreateViewModel @Inject constructor( } isFinishAvailable.value = - todo.value?.isNotEmpty() == true && endDate.value?.isNotEmpty() == true && participantList.any { it.isSelected } && isTodoAvailable.value == NameState.Success && isMemoAvailable.value != NameState.OVER + todo.value?.isNotEmpty() == true && endDate.value?.isNotEmpty() == true && participantList.any { it.isSelected } && isTodoAvailable.value == NameState.Success && isMemoAvailable.value != NameState.OVER } fun postToCreateTodoFromServer() { @@ -67,8 +66,8 @@ class OurTodoCreateViewModel @Inject constructor( todoRepository.postToCreateTodo( tripId = tripId, request = TodoCreateRequestModel( - title = todo.value ?: "", - endDate = endDate.value ?: "", + title = todo.value.orEmpty(), + endDate = endDate.value.orEmpty(), allocators = participantList.map { it.participantId }, memo = memo.value, secret = false, diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/TodoCreateNameViewHolder.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/TodoCreateNameViewHolder.kt index 84bddbd2..1d897d65 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/TodoCreateNameViewHolder.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/create/TodoCreateNameViewHolder.kt @@ -1,10 +1,10 @@ package com.going.presentation.todo.ourtodo.create -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.going.domain.entity.response.TripParticipantModel import com.going.presentation.R import com.going.presentation.databinding.ItemTodoCreateNameBinding +import com.going.ui.extension.colorOf class TodoCreateNameViewHolder( val binding: ItemTodoCreateNameBinding, @@ -12,8 +12,8 @@ class TodoCreateNameViewHolder( private val itemClick: (Int) -> Unit ) : RecyclerView.ViewHolder(binding.root) { - private val whiteColor = ContextCompat.getColor(binding.root.context, R.color.white_000) - private val grayColor = ContextCompat.getColor(binding.root.context, R.color.gray_300) + private val whiteColor = binding.root.context.colorOf(R.color.white_000) + private val grayColor = binding.root.context.colorOf(R.color.gray_300) fun onBind(item: TripParticipantModel, position: Int) { binding.run { diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/todolist/OurTodoListViewHolder.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/todolist/OurTodoListViewHolder.kt index bf90d66a..9f2d19d5 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/todolist/OurTodoListViewHolder.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/todolist/OurTodoListViewHolder.kt @@ -1,11 +1,11 @@ package com.going.presentation.todo.ourtodo.todolist -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.going.domain.entity.response.TodoModel import com.going.presentation.R import com.going.presentation.databinding.ItemOurTodoBinding import com.going.presentation.todo.name.TodoNameAdapter +import com.going.ui.extension.colorOf import com.going.ui.extension.setOnSingleClickListener class OurTodoListViewHolder( @@ -23,11 +23,11 @@ class OurTodoListViewHolder( } if (isCompleted) { - tvOurTodoItemTitle.setTextColor(ContextCompat.getColor(binding.root.context,R.color.gray_300)) - tvOurTodoItemDate.setTextColor(ContextCompat.getColor(binding.root.context,R.color.gray_200)) + tvOurTodoItemTitle.setTextColor(binding.root.context.colorOf(R.color.gray_300)) + tvOurTodoItemDate.setTextColor(binding.root.context.colorOf(R.color.gray_200)) } else { - tvOurTodoItemTitle.setTextColor(ContextCompat.getColor(binding.root.context,R.color.black_000)) - tvOurTodoItemDate.setTextColor(ContextCompat.getColor(binding.root.context,R.color.gray_300)) + tvOurTodoItemTitle.setTextColor(binding.root.context.colorOf(R.color.black_000)) + tvOurTodoItemDate.setTextColor(binding.root.context.colorOf(R.color.gray_300)) } root.setOnSingleClickListener { From a07cfcdc5b64e122d8da3a3394836b2d40229369 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 16:52:48 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[FIX/#185]=20nameList=20=EB=B7=B0=ED=99=80?= =?UTF-8?q?=EB=8D=94=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/detail/TodoDetailNameAdapter.kt | 3 +- .../presentation/todo/name/TodoNameAdapter.kt | 3 +- .../todo/name/TodoNameViewHolder.kt | 35 ++++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/detail/TodoDetailNameAdapter.kt b/presentation/src/main/java/com/going/presentation/todo/detail/TodoDetailNameAdapter.kt index fc6fda5e..bae08570 100644 --- a/presentation/src/main/java/com/going/presentation/todo/detail/TodoDetailNameAdapter.kt +++ b/presentation/src/main/java/com/going/presentation/todo/detail/TodoDetailNameAdapter.kt @@ -10,8 +10,9 @@ import com.going.ui.extension.ItemDiffCallback class TodoDetailNameAdapter : ListAdapter(diffUtil) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoDetailNameViewHolder { + val inflater by lazy { LayoutInflater.from(parent.context) } val binding: ItemTodoCreateNameBinding = - ItemTodoCreateNameBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ItemTodoCreateNameBinding.inflate(inflater, parent, false) return TodoDetailNameViewHolder(binding) } diff --git a/presentation/src/main/java/com/going/presentation/todo/name/TodoNameAdapter.kt b/presentation/src/main/java/com/going/presentation/todo/name/TodoNameAdapter.kt index 9023218e..8e95cb46 100644 --- a/presentation/src/main/java/com/going/presentation/todo/name/TodoNameAdapter.kt +++ b/presentation/src/main/java/com/going/presentation/todo/name/TodoNameAdapter.kt @@ -12,8 +12,9 @@ class TodoNameAdapter( ) : ListAdapter(diffUtil) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoNameViewHolder { + val inflater by lazy { LayoutInflater.from(parent.context) } val binding: ItemTodoNameBinding = - ItemTodoNameBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ItemTodoNameBinding.inflate(inflater, parent, false) return TodoNameViewHolder(binding, isCompleted) } diff --git a/presentation/src/main/java/com/going/presentation/todo/name/TodoNameViewHolder.kt b/presentation/src/main/java/com/going/presentation/todo/name/TodoNameViewHolder.kt index 31dc6bf8..fbb437e2 100644 --- a/presentation/src/main/java/com/going/presentation/todo/name/TodoNameViewHolder.kt +++ b/presentation/src/main/java/com/going/presentation/todo/name/TodoNameViewHolder.kt @@ -1,31 +1,32 @@ package com.going.presentation.todo.name -import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import com.going.domain.entity.response.TodoAllocatorModel import com.going.presentation.R import com.going.presentation.databinding.ItemTodoNameBinding +import com.going.ui.extension.colorOf class TodoNameViewHolder( - val binding: ItemTodoNameBinding, private val isCompleted: Boolean + val binding: ItemTodoNameBinding, + private val isCompleted: Boolean ) : RecyclerView.ViewHolder(binding.root) { - private val redColor = ContextCompat.getColor(binding.root.context, R.color.red_500) - private val grayColor = ContextCompat.getColor(binding.root.context, R.color.gray_400) - private val completedColor = ContextCompat.getColor(binding.root.context, R.color.gray_300) - fun onBind(item: TodoAllocatorModel) { - binding.run { - tvTodoName.text = item.name - if (isCompleted) { - tvTodoName.setTextColor(completedColor) - tvTodoName.setBackgroundResource(R.drawable.shape_rect_2_gray300_line) - } else { - if (item.isOwner) { - tvTodoName.setTextColor(redColor) - tvTodoName.isSelected = true - } else { - tvTodoName.setTextColor(grayColor) + with(binding.tvTodoName) { + text = item.name + when { + isCompleted -> { + setTextColor(binding.root.context.colorOf(R.color.gray_300)) + setBackgroundResource(R.drawable.shape_rect_2_gray300_line) + } + + item.isOwner -> { + setTextColor(binding.root.context.colorOf(R.color.red_500)) + isSelected = true + } + + else -> { + setTextColor(binding.root.context.colorOf(R.color.gray_400)) } } } From e238172b2695d30f7ca3efe00cb91a1ae5937865 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Tue, 23 Jan 2024 17:15:08 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[FIX/#185]=20MyTodo=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=EC=A0=81=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../todo/mytodo/MyTodoFragment.kt | 15 +++++------ .../todo/mytodo/MyTodoViewModel.kt | 2 +- .../mytodo/create/MyTodoCreateActivity.kt | 27 ++++++++++--------- .../mytodo/create/MyTodoCreateViewModel.kt | 7 +++-- .../mytodo/todolist/MyTodoListViewHolder.kt | 16 +++++------ .../todo/ourtodo/OurTodoFragment.kt | 4 +-- 6 files changed, 34 insertions(+), 37 deletions(-) diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt index c251af16..bb011084 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoFragment.kt @@ -9,7 +9,6 @@ import android.text.Spanned import android.text.style.ForegroundColorSpan import android.view.View import android.view.ViewTreeObserver -import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.lifecycle.flowWithLifecycle @@ -68,11 +67,11 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m private fun initAddTodoListener() { binding.btnMyTodoAddTodo.setOnSingleClickListener { - Intent(activity, MyTodoCreateActivity::class.java).apply { - putExtra(EXTRA_TRIP_ID, viewModel.tripId) - putExtra(EXTRA_PARTICIPANT_ID, viewModel.participantId) - startActivity(this) - } + MyTodoCreateActivity.createIntent( + requireContext(), + viewModel.tripId, + viewModel.participantId + ).apply { startActivity(this) } } } @@ -219,9 +218,7 @@ class MyTodoFragment() : BaseFragment(R.layout.fragment_m ).apply { setSpan( ForegroundColorSpan( - ContextCompat.getColor( - requireContext(), R.color.red_500 - ) + colorOf(R.color.red_500) ), length - 3, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE ) } diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoViewModel.kt index 388a4773..d1834edf 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/MyTodoViewModel.kt @@ -52,7 +52,7 @@ class MyTodoViewModel @Inject constructor( _myTripInfoState.value = UiState.Success(response) } .onFailure { - _myTripInfoState.value = UiState.Failure(it.message.toString()) + _myTripInfoState.value = UiState.Failure(it.message.orEmpty()) } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateActivity.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateActivity.kt index 26039134..926bffe7 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateActivity.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateActivity.kt @@ -1,10 +1,10 @@ package com.going.presentation.todo.mytodo.create -import android.graphics.drawable.Drawable +import android.content.Context +import android.content.Intent import android.os.Bundle import android.widget.TextView import androidx.activity.viewModels -import androidx.core.content.res.ResourcesCompat import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import com.going.domain.entity.NameState @@ -14,6 +14,7 @@ import com.going.presentation.todo.TodoActivity.Companion.EXTRA_TRIP_ID import com.going.presentation.todo.ourtodo.create.OurTodoCreateActivity.Companion.EXTRA_PARTICIPANT_ID import com.going.ui.base.BaseActivity import com.going.ui.extension.UiState +import com.going.ui.extension.drawableOf import com.going.ui.extension.setOnSingleClickListener import com.going.ui.extension.toast import dagger.hilt.android.AndroidEntryPoint @@ -93,7 +94,7 @@ class MyTodoCreateActivity : state, binding.tvMyTodoTodoCounter, ) { background -> - binding.etMyTodoCreateTodo.background = setBackgroundColor(background) + binding.etMyTodoCreateTodo.background = drawableOf(background) } } } @@ -104,7 +105,7 @@ class MyTodoCreateActivity : state, binding.tvMyTodoMemoCounter, ) { background -> - binding.etMyTodoCreateMemo.background = setBackgroundColor(background) + binding.etMyTodoCreateMemo.background = drawableOf(background) } } } @@ -139,14 +140,6 @@ class MyTodoCreateActivity : counter.setTextColor(getColor(color)) } - private fun setBackgroundColor(background: Int): Drawable? { - return ResourcesCompat.getDrawable( - this.resources, - background, - theme, - ) - } - override fun onDestroy() { super.onDestroy() if (myTodoCreateBottomSheet?.isAdded == true) myTodoCreateBottomSheet?.dismiss() @@ -154,5 +147,15 @@ class MyTodoCreateActivity : companion object { private const val DATE_BOTTOM_SHEET = "DATE_BOTTOM_SHEET" + + @JvmStatic + fun createIntent( + context: Context, + tripId: Long, + participantId: Long + ): Intent = Intent(context, MyTodoCreateActivity::class.java).apply { + putExtra(EXTRA_TRIP_ID, tripId) + putExtra(EXTRA_PARTICIPANT_ID, participantId) + } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateViewModel.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateViewModel.kt index edcf9a9a..f54dab92 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateViewModel.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/create/MyTodoCreateViewModel.kt @@ -6,7 +6,6 @@ import androidx.lifecycle.viewModelScope import com.going.domain.entity.NameState import com.going.domain.entity.request.TodoCreateRequestModel import com.going.domain.repository.TodoRepository -import com.going.presentation.todo.ourtodo.create.OurTodoCreateViewModel import com.going.ui.extension.UiState import com.going.ui.extension.getGraphemeLength import dagger.hilt.android.lifecycle.HiltViewModel @@ -65,8 +64,8 @@ class MyTodoCreateViewModel @Inject constructor( todoRepository.postToCreateTodo( tripId = tripId, request = TodoCreateRequestModel( - title = todo.value ?: "", - endDate = endDate.value ?: "", + title = todo.value.orEmpty(), + endDate = endDate.value.orEmpty(), allocators = listOf(participantId), memo = memo.value, secret = true, @@ -76,7 +75,7 @@ class MyTodoCreateViewModel @Inject constructor( _todoCreateState.value = UiState.Success(response) } .onFailure { - _todoCreateState.value = UiState.Failure(it.message.toString()) + _todoCreateState.value = UiState.Failure(it.message.orEmpty()) } } } diff --git a/presentation/src/main/java/com/going/presentation/todo/mytodo/todolist/MyTodoListViewHolder.kt b/presentation/src/main/java/com/going/presentation/todo/mytodo/todolist/MyTodoListViewHolder.kt index d87369de..5e0d4a85 100644 --- a/presentation/src/main/java/com/going/presentation/todo/mytodo/todolist/MyTodoListViewHolder.kt +++ b/presentation/src/main/java/com/going/presentation/todo/mytodo/todolist/MyTodoListViewHolder.kt @@ -1,12 +1,12 @@ package com.going.presentation.todo.mytodo.todolist -import androidx.core.content.ContextCompat import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import com.going.domain.entity.response.TodoModel import com.going.presentation.R import com.going.presentation.databinding.ItemMyTodoBinding import com.going.presentation.todo.name.TodoNameAdapter +import com.going.ui.extension.colorOf import com.going.ui.extension.setOnSingleClickListener class MyTodoListViewHolder( @@ -20,7 +20,7 @@ class MyTodoListViewHolder( fun onBind(item: TodoModel) { binding.run { tvMyTodoItemTitle.text = item.title - tvMyTodoItemDate.text = item.endDate.replace("-", ".") + "까지" + tvMyTodoItemDate.text = item.endDate.replace("-", ".") + "까지" layoutMyTodoLock.isVisible = item.secret rvMyTodoName.isVisible = !item.secret @@ -33,17 +33,17 @@ class MyTodoListViewHolder( } if (isCompleted) { - tvMyTodoItemTitle.setTextColor(ContextCompat.getColor(binding.root.context, R.color.gray_300)) - tvMyTodoItemDate.setTextColor(ContextCompat.getColor(binding.root.context, R.color.gray_200)) + tvMyTodoItemTitle.setTextColor(binding.root.context.colorOf(R.color.gray_300)) + tvMyTodoItemDate.setTextColor(binding.root.context.colorOf(R.color.gray_200)) layoutMyTodoLock.setBackgroundResource(R.drawable.shape_rect_2_gray300_line) ivMyTodoLock.setImageResource(R.drawable.ic_lock_complete) - tvMyTodoLock.setTextColor(ContextCompat.getColor(binding.root.context, R.color.gray_300)) + tvMyTodoLock.setTextColor(binding.root.context.colorOf(R.color.gray_300)) } else { - tvMyTodoItemTitle.setTextColor(ContextCompat.getColor(binding.root.context, R.color.black_000)) - tvMyTodoItemDate.setTextColor(ContextCompat.getColor(binding.root.context, R.color.gray_300)) + tvMyTodoItemTitle.setTextColor(binding.root.context.colorOf(R.color.black_000)) + tvMyTodoItemDate.setTextColor(binding.root.context.colorOf(R.color.gray_300)) layoutMyTodoLock.setBackgroundResource(R.drawable.shape_rect_2_gray400_line) ivMyTodoLock.setImageResource(R.drawable.ic_lock_uncomplete) - tvMyTodoLock.setTextColor(ContextCompat.getColor(binding.root.context, R.color.gray_400)) + tvMyTodoLock.setTextColor(binding.root.context.colorOf(R.color.gray_400)) } cbMyTodoUnselected.setOnSingleClickListener { diff --git a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt index 595ba2a9..e2c5d72a 100644 --- a/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt +++ b/presentation/src/main/java/com/going/presentation/todo/ourtodo/OurTodoFragment.kt @@ -91,9 +91,7 @@ class OurTodoFragment() : BaseFragment(R.layout.fragment ArrayList(participantList.map { it.participantId.toInt() }), ArrayList(participantList.map { it.name }), ArrayList(participantList.map { it.result }) - ).apply { - startActivity(this) - } + ).apply { startActivity(this) } } }