Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#93-image-download
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin committed Jan 14, 2024
2 parents 67db062 + f3de42f commit 9fa3b93
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ interface TodoDataSource {
tripId: Long
): BaseResponse<OurTripInfoResponseDto>

suspend fun getToFinishTodoData(
todoId: Long
): NonDataBaseResponse

suspend fun getToRedoTodoData(
todoId: Long
): NonDataBaseResponse

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ class TodoDataSourceImpl @Inject constructor(
): BaseResponse<OurTripInfoResponseDto> =
todoService.getOurTripInfo(tripId)

override suspend fun getToFinishTodoData(
todoId: Long
): NonDataBaseResponse =
todoService.getToFinishTodo(todoId)

override suspend fun getToRedoTodoData(
todoId: Long
): NonDataBaseResponse =
todoService.getToRedoTodo(todoId)

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ class TodoRepositoryImpl @Inject constructor(
todoDataSource.getOurTripInfo(tripId).data.toOurTripInfoModel()
}

override suspend fun getToFinishTodo(
todoId: Long
): Result<Unit> =
runCatching {
todoDataSource.getToFinishTodoData(todoId)
}

override suspend fun getToRedoTodo(
todoId: Long
): Result<Unit> =
runCatching {
todoDataSource.getToRedoTodoData(todoId)
}

}
10 changes: 10 additions & 0 deletions data/src/main/java/com/going/data/service/TodoService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ interface TodoService {
@Path("tripId") tripId: Long
): BaseResponse<OurTripInfoResponseDto>

@GET("api/trips/todos/{todoId}/complete")
suspend fun getToFinishTodo(
@Path("todoId") todoId: Long
): NonDataBaseResponse

@GET("api/trips/todos/{todoId}/incomplete")
suspend fun getToRedoTodo(
@Path("todoId") todoId: Long
): NonDataBaseResponse

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.going.domain.entity.response
data class TripParticipantModel(
val participantId: Long,
val name: String,
val result: Int
val result: Int,
var isSelected: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ interface TodoRepository {
tripId: Long
): Result<OurTripInfoModel>

suspend fun getToFinishTodo(
todoId: Long
): Result<Unit>

suspend fun getToRedoTodo(
todoId: Long
): Result<Unit>

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class TodoActivity() : BaseActivity<ActivityTodoBinding>(R.layout.activity_todo)
supportFragmentManager.findFragmentById(R.id.fcv_todo) ?: navigateTo<OurTodoFragment>()

binding.bnvTodo.setOnItemSelectedListener { menu ->
if (binding.bnvTodo.selectedItemId == menu.itemId) {
return@setOnItemSelectedListener false
}
when (menu.itemId) {
R.id.menu_our_todo -> navigateTo<OurTodoFragment>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.going.domain.entity.response.MyTripInfoModel
import com.going.domain.entity.response.TodoModel
import com.going.domain.repository.TodoRepository
import com.going.presentation.todo.ourtodo.OurTodoViewModel
import com.going.ui.extension.EnumUiState
import com.going.ui.extension.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -30,8 +30,14 @@ class MyTodoViewModel @Inject constructor(
private val _todoCompleteListState = MutableStateFlow<UiState<List<TodoModel>>>(UiState.Empty)
val todoCompleteListState: StateFlow<UiState<List<TodoModel>>> = _todoCompleteListState

fun decreaseTodoCount() {
_totalUncompletedTodoCount.value = _totalUncompletedTodoCount.value - 1
private val _todoFinishState = MutableStateFlow<EnumUiState>(EnumUiState.EMPTY)
val todoFinishState: StateFlow<EnumUiState> = _todoFinishState

private val _todoRedoState = MutableStateFlow<EnumUiState>(EnumUiState.EMPTY)
val todoRedoState: StateFlow<EnumUiState> = _todoRedoState

fun increaseTodoCount() {
_totalUncompletedTodoCount.value += 1
}

fun getMyTripInfoFromServer(tripId: Long) {
Expand Down Expand Up @@ -74,6 +80,32 @@ class MyTodoViewModel @Inject constructor(
}
}

fun getToFinishTodoFromServer(todoId: Long) {
_todoFinishState.value = EnumUiState.LOADING
viewModelScope.launch {
todoRepository.getToFinishTodo(todoId)
.onSuccess {
_todoFinishState.value = EnumUiState.SUCCESS
}
.onFailure {
_todoFinishState.value = EnumUiState.FAILURE
}
}
}

fun getToRedoTodoFromServer(todoId: Long) {
_todoRedoState.value = EnumUiState.LOADING
viewModelScope.launch {
todoRepository.getToRedoTodo(todoId)
.onSuccess {
_todoRedoState.value = EnumUiState.SUCCESS
}
.onFailure {
_todoRedoState.value = EnumUiState.FAILURE
}
}
}

companion object {
const val MY_TODO = "my"
const val UNCOMPLETE = "incomplete"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.going.presentation.todo.mytodo.todolist

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
Expand All @@ -16,6 +15,7 @@ import com.going.presentation.todo.mytodo.MyTodoViewModel
import com.going.presentation.todo.mytodo.MyTodoViewModel.Companion.COMPLETE
import com.going.presentation.todo.mytodo.MyTodoViewModel.Companion.MY_TODO
import com.going.ui.base.BaseFragment
import com.going.ui.extension.EnumUiState
import com.going.ui.extension.UiState
import com.going.ui.extension.toast
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -36,16 +36,21 @@ class MyTodoCompleteFragment() :
super.onViewCreated(view, savedInstanceState)

initAdapterWithClickListener()
setTodoList()
observeTodoListState()
observeTodoRedoState()
}

override fun onResume() {
super.onResume()

setTodoList()
}

private fun initAdapterWithClickListener() {
_adapter = MyTodoListAdapter(true,
{ },
{ position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
{ todoId ->
viewModel.getToRedoTodoFromServer(todoId)
},
{ todoModel ->
if (todoModel.allocators.size <= 1) {
Expand Down Expand Up @@ -84,6 +89,23 @@ class MyTodoCompleteFragment() :
}.launchIn(lifecycleScope)
}

private fun observeTodoRedoState() {
viewModel.todoRedoState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
EnumUiState.LOADING -> return@onEach

EnumUiState.SUCCESS -> {
setTodoList()
viewModel.increaseTodoCount()
}

EnumUiState.FAILURE -> toast(getString(R.string.server_error))

EnumUiState.EMPTY -> return@onEach
}
}.launchIn(lifecycleScope)
}

override fun onDestroyView() {
super.onDestroyView()
_adapter = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.going.ui.extension.ItemDiffCallback

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

Expand All @@ -21,12 +21,7 @@ class MyTodoListAdapter(
}

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

fun removeItem(position: Int) {
// itemList.removeAt(position)
notifyDataSetChanged()
holder.onBind(getItem(position))
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import com.going.ui.extension.setOnSingleClickListener
class MyTodoListViewHolder(
val binding: ItemMyTodoBinding,
private val isCompleted: Boolean,
private val itemSelect: (Int) -> Unit,
private val itemUnselect: (Int) -> Unit,
private val itemSelect: (Long) -> Unit,
private val itemUnselect: (Long) -> Unit,
private val itemDetailClick: (TodoModel) -> Unit
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(item: TodoModel, position: Int) {
fun onBind(item: TodoModel) {
binding.run {
tvMyTodoItemTitle.text = item.title
tvMyTodoItemDate.text = item.endDate.replace("-", ".") + "까지"
Expand Down Expand Up @@ -47,11 +47,11 @@ class MyTodoListViewHolder(
}

cbMyTodoUnselected.setOnSingleClickListener {
itemSelect(position)
itemSelect(item.todoId)
}

cbMyTodoSelected.setOnSingleClickListener {
itemUnselect(position)
itemUnselect(item.todoId)
}

root.setOnSingleClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.going.presentation.todo.detail.PrivateDetailActivity
import com.going.presentation.todo.detail.PublicDetailActivity
import com.going.presentation.todo.detail.PublicDetailActivity.Companion.EXTRA_TODO_ID
import com.going.ui.base.BaseFragment
import com.going.ui.extension.EnumUiState
import com.going.ui.extension.UiState
import com.going.ui.extension.toast
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -37,6 +38,7 @@ class MyTodoUncompleteFragment() :

initAdapterWithClickListener()
observeTodoListState()
observeTodoFinishState()
}

override fun onResume() {
Expand All @@ -47,10 +49,8 @@ class MyTodoUncompleteFragment() :

private fun initAdapterWithClickListener() {
_adapter = MyTodoListAdapter(false,
{ position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
viewModel.decreaseTodoCount()
{ todoId ->
viewModel.getToFinishTodoFromServer(todoId)
},
{ },
{ todoModel ->
Expand Down Expand Up @@ -90,6 +90,20 @@ class MyTodoUncompleteFragment() :
}.launchIn(lifecycleScope)
}

private fun observeTodoFinishState() {
viewModel.todoFinishState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
EnumUiState.LOADING -> return@onEach

EnumUiState.SUCCESS -> setTodoList()

EnumUiState.FAILURE -> toast(getString(R.string.server_error))

EnumUiState.EMPTY -> return@onEach
}
}.launchIn(lifecycleScope)
}

override fun onDestroyView() {
super.onDestroyView()
_adapter = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.going.domain.entity.response.TripParticipantModel
import com.going.presentation.R
import com.going.presentation.databinding.FragmentOurTodoBinding
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.todolist.OurTodoViewPagerAdapter
import com.going.ui.base.BaseFragment
import com.going.ui.extension.UiState
Expand All @@ -34,6 +38,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment

private val viewModel by activityViewModels<OurTodoViewModel>()

private var participantList = listOf<TripParticipantModel>()

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

Expand All @@ -53,7 +59,13 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment

private fun initAddTodoBtnListener() {
binding.btnOurTodoAddTodo.setOnSingleClickListener {
val idList: ArrayList<Int> = ArrayList(participantList.map { it.participantId.toInt() })
val nameList: ArrayList<String> = ArrayList(participantList.map { it.name })
val resultList: ArrayList<Int> = ArrayList(participantList.map { it.result })
Intent(activity, OurTodoCreateActivity::class.java).apply {
putIntegerArrayListExtra(EXTRA_PARTICIPANT_ID, idList)
putStringArrayListExtra(EXTRA_NAME, nameList)
putIntegerArrayListExtra(EXTRA_RESULT, resultList)
startActivity(this)
}
}
Expand Down Expand Up @@ -103,6 +115,7 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
)
progressBarOurTodo.progress = state.data.progress
tvOurTripInfoPercent.text = state.data.progress.toString() + "%"
participantList = state.data.participants
adapter.submitList(state.data.participants)
}
}
Expand All @@ -122,7 +135,8 @@ class OurTodoFragment() : BaseFragment<FragmentOurTodoBinding>(R.layout.fragment
private fun setTitleTextWithDay(day: Int) {
when {
day > 0 -> {
binding.tvOurTodoTitleDown.text = getString(R.string.our_todo_title_down_before).format(day)
binding.tvOurTodoTitleDown.text =
getString(R.string.our_todo_title_down_before).format(day)
setDateTextColor(6, 6)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.going.domain.entity.response.OurTripInfoModel
import com.going.domain.entity.response.TodoModel
import com.going.domain.entity.response.TripParticipantModel
import com.going.domain.repository.TodoRepository
import com.going.ui.extension.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down
Loading

0 comments on commit 9fa3b93

Please sign in to comment.