-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#42 [feat] 데일리 루틴
- Loading branch information
Showing
17 changed files
with
469 additions
and
596 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/sopetit/softie/domain/entity/DailyRoutine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
165 changes: 155 additions & 10 deletions
165
app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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) | ||
} | ||
} | ||
} | ||
} | ||
} |
79 changes: 78 additions & 1 deletion
79
app/src/main/java/com/sopetit/softie/ui/dailyroutine/DailyRoutineViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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 | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
...main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineedit/DailyRoutineEditActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
7 changes: 0 additions & 7 deletions
7
...ain/java/com/sopetit/softie/ui/dailyroutine/dailyroutineedit/DailyRoutineEditViewModel.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.