-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#42 [feat] 데일리 루틴 #45
Changes from all commits
1a0c935
0aa97ec
525e7be
bf72621
f7af8f5
e73fe23
70a853d
1da0c81
72ed97c
517f3c3
eb4a269
62b4299
5b6f0ac
fbfa26b
b19d3fd
a649272
be616ae
76780a9
30f49d5
535652b
93f19a3
39f90c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class DailyRoutine( | ||
val routineId: Int, | ||
val content: String, | ||
val iconImageUrl: String, | ||
val achieveCount: Int, | ||
val isAchieve: Boolean | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,179 @@ | ||
package com.sopetit.softie.ui.dailyroutine | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.widget.TextView | ||
import androidx.fragment.app.viewModels | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentDailyRoutineBinding | ||
import com.sopetit.softie.ui.dailyroutine.dailyroutineedit.DailyRoutineEditActivity | ||
import com.sopetit.softie.util.OriginalBottomSheet.Companion.BOTTOM_SHEET_TAG | ||
import com.sopetit.softie.util.binding.BindingBottomSheet | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
import com.sopetit.softie.util.setStatusBarColor | ||
import com.sopetit.softie.util.snackBar | ||
import com.sopetit.softie.util.toast | ||
|
||
class DailyRoutineFragment : | ||
BindingFragment<FragmentDailyRoutineBinding>(R.layout.fragment_daily_routine) { | ||
|
||
private val dailyRoutineViewModel by viewModels<DailyRoutineViewModel>() | ||
private val viewModel by viewModels<DailyRoutineViewModel>() | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setStatusBarColor(R.color.background) | ||
|
||
binding.lifecycleOwner = this | ||
binding.dailyRoutineViewModel = dailyRoutineViewModel | ||
binding.viewModel = viewModel | ||
|
||
moveEdit() | ||
initSetDailyRoutineContent() | ||
initSetDeleteView() | ||
initSetRoutineDelete() | ||
} | ||
|
||
private fun moveEdit() { | ||
binding.tvDailyRoutineEdit.setOnClickListener { | ||
val intent = Intent(requireActivity(), DailyRoutineEditActivity::class.java) | ||
startActivity(intent) | ||
private fun initSetDailyRoutineContent() { | ||
with(binding) { | ||
routineItemView( | ||
tvDailyRoutineAddNameFirst, | ||
tvDailyRoutineIngFirst, | ||
btnDailyRoutineYetFinFirst, | ||
0 | ||
) | ||
routineItemView( | ||
tvDailyRoutineAddNameSecond, | ||
tvDailyRoutineIngSecond, | ||
btnDailyRoutineYetFinSecond, | ||
1 | ||
) | ||
routineItemView( | ||
tvDailyRoutineAddNameThird, | ||
tvDailyRoutineIngThird, | ||
btnDailyRoutineYetFinThird, | ||
2 | ||
) | ||
} | ||
} | ||
|
||
private fun routineItemView( | ||
routineTitle: TextView, | ||
achieveMsg: TextView, | ||
btn: View, | ||
index: Int | ||
) { | ||
viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { dailyRoutineList -> | ||
val achieveCountMsg = | ||
getString(R.string.daily_routine_ing).format(dailyRoutineList[index].achieveCount) | ||
achieveMsg.text = achieveCountMsg | ||
routineTitle.text = dailyRoutineList[index].content | ||
viewModel.setRoutineAchieve(dailyRoutineList[index].isAchieve, index) | ||
|
||
initSetDailyRoutineAchieve(btn, dailyRoutineList[index].routineId) | ||
} | ||
} | ||
|
||
private fun initSetDailyRoutineAchieve(btn: View, routineId: Int) { | ||
btn.setOnClickListener { | ||
// TODO 서버통신 구현 후 imageUri 버전으로 수정 | ||
|
||
BindingBottomSheet.Builder().build( | ||
isDrawable = true, | ||
imageDrawable = R.drawable.ic_bear_face_crying, | ||
imageUri = "", | ||
title = "데일리 루틴을 완료했나요?", | ||
content = "한 번 완료하면 이전으로 되돌릴 수 없어요", | ||
isContentVisible = true, | ||
contentColor = R.color.gray400, | ||
backBtnContent = "아니, 아직이야!", | ||
doBtnContent = "완료했어", | ||
doBtnColor = R.drawable.shape_main1_fill_12_rect, | ||
backBtnAction = {}, | ||
doBtnAction = { | ||
binding.root.context.toast("$routineId") | ||
} | ||
).show(parentFragmentManager, BOTTOM_SHEET_TAG) | ||
} | ||
} | ||
|
||
private fun initSetDeleteView() { | ||
viewModel.isDeleteView.observe(viewLifecycleOwner) { isDeleteView -> | ||
val isEditView = !isDeleteView | ||
if (isEditView) { | ||
binding.tvDailyRoutineEdit.setOnClickListener { | ||
viewModel.setDeleteView(true) | ||
} | ||
} | ||
} | ||
|
||
initSetBackOriginalView() | ||
} | ||
|
||
private fun initSetBackOriginalView() { | ||
viewModel.isDeleteView.observe(viewLifecycleOwner) { isDeleteView -> | ||
if (isDeleteView) { | ||
binding.tvDailyRoutineEdit.setOnClickListener { | ||
viewModel.setDeleteView(false) | ||
} | ||
clickEditRadioBtn() | ||
} | ||
} | ||
} | ||
|
||
private fun clickEditRadioBtn() { | ||
viewModel.mockDailyRoutineList.observe(viewLifecycleOwner) { routineList -> | ||
with(binding) { | ||
changeBtnSelectState(btnDailyRoutineRadioFirst, routineList[0].routineId) | ||
changeBtnSelectState(btnDailyRoutineRadioSecond, routineList[1].routineId) | ||
changeBtnSelectState(btnDailyRoutineRadioThird, routineList[2].routineId) | ||
} | ||
} | ||
} | ||
|
||
private fun changeBtnSelectState(button: View, itemId: Int) { | ||
button.setOnClickListener { | ||
it.isSelected = !it.isSelected | ||
viewModel.setEditRoutineIdArray(itemId) | ||
setDeleteRoutineBtnContent() | ||
} | ||
} | ||
|
||
private fun setDeleteRoutineBtnContent() { | ||
val editRoutineArraySize = viewModel.editRoutineIdArray.size | ||
val deleteBtnContent = | ||
getString(R.string.daily_routine_edit_delete).format(editRoutineArraySize) | ||
|
||
if (editRoutineArraySize > 0) { | ||
viewModel.setEditBtnEnabled(true) | ||
} else { | ||
viewModel.setEditBtnEnabled(false) | ||
} | ||
|
||
binding.btnDailyRoutineDelete.text = deleteBtnContent | ||
} | ||
|
||
private fun initSetRoutineDelete() { | ||
viewModel.isEditBtnEnabled.observe(viewLifecycleOwner) { isBtnEnabled -> | ||
if (isBtnEnabled) { | ||
binding.btnDailyRoutineDelete.setOnClickListener { | ||
BindingBottomSheet.Builder().build( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Builder( )함수는 어떤 역할을 하나요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. builder 패턴은 필요한 parameter만 설정해두면 build 메소드를 통해 객체를 생성할 수 있습니다..! 여기서 제가 공통 바텀시트를 만들어 두어서 이 builder 패턴을 통해서 각 뷰에서 커스텀되는 parameter만 넣어주면 바텀시트를 생성할 수 있습니다!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빌더 패턴까지 사용하시다니 정말 대단하군요 디자인패턴 공부 많이 한게 느껴졌어요. 저희꺼 바텀시트도 빌더로 만들어주세요 !! |
||
isDrawable = true, | ||
imageDrawable = R.drawable.ic_bear_face_crying, | ||
imageUri = "", | ||
title = "정말 삭제할까요?", | ||
content = "루틴을 삭제해도 달성 횟수는 저장돼요", | ||
isContentVisible = true, | ||
contentColor = R.color.red, | ||
backBtnContent = "취소", | ||
doBtnContent = "삭제할래", | ||
doBtnColor = R.drawable.shape_red_fill_12_rect, | ||
backBtnAction = {}, | ||
doBtnAction = { | ||
snackBar( | ||
binding.root.rootView, | ||
"데일리 루틴을 ${viewModel.editRoutineIdArray.size}개 삭제했어요" | ||
) | ||
viewModel.setDeleteView(false) | ||
} | ||
).show(parentFragmentManager, BOTTOM_SHEET_TAG) | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
package com.sopetit.softie.ui.dailyroutine | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.sopetit.softie.domain.entity.DailyRoutine | ||
|
||
class DailyRoutineViewModel : ViewModel() { | ||
val routineAddList = listOf<Int>(1, 2) | ||
|
||
private val _mockDailyRoutineList: MutableLiveData<List<DailyRoutine>> = MutableLiveData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 목데이터라도 잘 짜놓을껄... |
||
mutableListOf( | ||
DailyRoutine( | ||
1, | ||
"일찍 일어나기", | ||
"", | ||
3, | ||
true | ||
), | ||
DailyRoutine( | ||
2, | ||
"작업 끝내기", | ||
"", | ||
5, | ||
false | ||
), | ||
DailyRoutine( | ||
3, | ||
"이불 개기", | ||
"", | ||
10, | ||
true | ||
) | ||
) | ||
) | ||
|
||
val mockDailyRoutineList: LiveData<List<DailyRoutine>> | ||
get() = _mockDailyRoutineList | ||
|
||
private val _isRoutineAchieveFirst: MutableLiveData<Boolean> = MutableLiveData() | ||
val isRoutineAchieveFirst: LiveData<Boolean> | ||
get() = _isRoutineAchieveFirst | ||
|
||
private val _isRoutineAchieveSecond: MutableLiveData<Boolean> = MutableLiveData() | ||
val isRoutineAchieveSecond: LiveData<Boolean> | ||
get() = _isRoutineAchieveSecond | ||
|
||
private val _isRoutineAchieveThird: MutableLiveData<Boolean> = MutableLiveData() | ||
val isRoutineAchieveThird: LiveData<Boolean> | ||
get() = _isRoutineAchieveThird | ||
|
||
private val _isDeleteView: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val isDeleteView: LiveData<Boolean> | ||
get() = _isDeleteView | ||
|
||
val editRoutineIdArray = ArrayList<Int>() | ||
|
||
private val _isEditBtnEnabled: MutableLiveData<Boolean> = MutableLiveData() | ||
val isEditBtnEnabled: LiveData<Boolean> | ||
get() = _isEditBtnEnabled | ||
|
||
fun setRoutineAchieve(isAchieve: Boolean, index: Int) { | ||
when (index) { | ||
0 -> _isRoutineAchieveFirst.value = isAchieve | ||
1 -> _isRoutineAchieveSecond.value = isAchieve | ||
2 -> _isRoutineAchieveThird.value = isAchieve | ||
} | ||
} | ||
|
||
fun setDeleteView(deleteEnabled: Boolean) { | ||
_isDeleteView.value = deleteEnabled | ||
} | ||
|
||
fun setEditRoutineIdArray(routineId: Int) { | ||
if (editRoutineIdArray.contains(routineId)) { | ||
editRoutineIdArray.removeAt(editRoutineIdArray.indexOf(routineId)) | ||
} else { | ||
editRoutineIdArray.add(routineId) | ||
} | ||
} | ||
|
||
fun setEditBtnEnabled(enabled: Boolean) { | ||
_isEditBtnEnabled.value = enabled | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +0,0 @@ | ||
package com.sopetit.softie.ui.dailyroutine.dailyroutineedit | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.ActivityDailyRoutineEditBinding | ||
import com.sopetit.softie.util.binding.BindingActivity | ||
import com.sopetit.softie.util.setStatusBarColorFromResource | ||
|
||
class DailyRoutineEditActivity : | ||
BindingActivity<ActivityDailyRoutineEditBinding>(R.layout.activity_daily_routine_edit) { | ||
private val dailyRoutineEditViewModel by viewModels<DailyRoutineEditViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStatusBarColorFromResource(R.color.background) | ||
|
||
binding.lifecycleOwner = this | ||
binding.dailyRoutineEditViewModel = dailyRoutineEditViewModel | ||
|
||
setCancelBtnClickListener() | ||
clickEditRadioBtn() | ||
} | ||
|
||
private fun setCancelBtnClickListener() { | ||
binding.tvDailyRoutineEditCancel.setOnClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun clickEditRadioBtn() { | ||
with(binding) { | ||
changeBtnSelectState(btnDailyRoutineEditRadioEmptyFirst) | ||
changeBtnSelectState(btnDailyRoutineEditRadioEmptySecond) | ||
changeBtnSelectState(btnDailyRoutineEditRadioEmptyThird) | ||
} | ||
} | ||
|
||
private fun changeBtnSelectState(button: View) { | ||
button.setOnClickListener { | ||
it.isSelected = !it.isSelected | ||
} | ||
} | ||
} | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드가 직관적이여서 이해하기 쉽고 좋아요^^