Skip to content

Commit

Permalink
[MERGE] #54 -> develop
Browse files Browse the repository at this point in the history
[UI/#54] MyTodo 조회 뷰 / UI 구현
  • Loading branch information
Marchbreeze authored Jan 9, 2024
2 parents 4f5d380 + 9475049 commit fc6c61f
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.todo.mytodo.detail.MyTodoDetailActivity"
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name="com.going.presentation.starttrip.finishtrip.FinishTripActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.going.presentation.todo.mytodo.detail

import android.os.Bundle
import androidx.activity.viewModels
import com.going.presentation.R
import com.going.presentation.databinding.ActivityMyTodoDetailBinding
import com.going.ui.base.BaseActivity
import com.going.ui.extension.setOnSingleClickListener
import com.going.ui.extension.toast

class MyTodoDetailActivity :
BaseActivity<ActivityMyTodoDetailBinding>(R.layout.activity_my_todo_detail) {

private val viewModel by viewModels<MyTodoDetailViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

initViewModel()
initBackBtnClickListener()
initDeleteBtnClickListener()
initModBtnClickListener()
setDetailData()
}

private fun initViewModel() {
binding.vm = viewModel
}

private fun initBackBtnClickListener() {
binding.btnMyTodoDetailBack.setOnSingleClickListener {
finish()
}
}

private fun initDeleteBtnClickListener() {
binding.btnMyTodoDetailDelete.setOnSingleClickListener {
// 삭제 서버 통신
finish()
}
}

private fun initModBtnClickListener() {
binding.btnMyTodoDetailMod.setOnSingleClickListener {
toast(getString(R.string.will_be_update))
}
}

private fun setDetailData() {
intent.getLongExtra(EXTRA_TODO_ID,0)
// 추후 todoId를 보내서 받는 서버통신으로 변경
viewModel.todo.value = "맛있는 밥 먹기"
viewModel.endDate.value = "2024.1.10"
viewModel.memo.value = "오늘 완전 완전 맛있는 파스타를 먹었는데 완전 아주 그냥 이게 말이지"
}

companion object {
const val EXTRA_TODO_ID = "EXTRA_TODO_ID"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.going.presentation.todo.mytodo.detail

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MyTodoDetailViewModel : ViewModel() {

val todo = MutableLiveData("")
val nowTodoLength = MutableLiveData(0)

val endDate = MutableLiveData("")

val memo = MutableLiveData("")
val nowMemoLength = MutableLiveData(0)

companion object {
const val MAX_TODO_LEN = 15
const val MAX_MEMO_LEN = 1000
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.going.presentation.todo.mytodo.todolist

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.going.presentation.R
import com.going.presentation.databinding.FragmentMyTodoCompleteBinding
import com.going.presentation.todo.mytodo.MyTodoViewModel
import com.going.presentation.todo.mytodo.detail.MyTodoDetailActivity
import com.going.ui.base.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -27,10 +29,18 @@ class MyTodoCompleteFragment() :
}

private fun initAdapterWithClickListener() {
_adapter = MyTodoListAdapter(true, { }, { position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
})
_adapter = MyTodoListAdapter(true,
{ },
{ position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
},
{ todoId ->
Intent(activity, MyTodoDetailActivity::class.java).apply {
putExtra(MyTodoDetailActivity.EXTRA_TODO_ID, todoId)
startActivity(this)
}
})
binding.rvMyTodoComplete.adapter = adapter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import com.going.presentation.databinding.ItemMyTodoBinding
class MyTodoListAdapter(
private val isCompleted: Boolean,
private val itemSelect: (Int) -> Unit,
private val itemUnselect: (Int) -> Unit
private val itemUnselect: (Int) -> Unit,
private val itemDetailClick: (Long) -> Unit
) : 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)
return MyTodoListViewHolder(binding, isCompleted, itemSelect, itemUnselect)
return MyTodoListViewHolder(binding, isCompleted, itemSelect, itemUnselect, itemDetailClick)
}

override fun onBindViewHolder(holder: MyTodoListViewHolder, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class MyTodoListViewHolder(
val binding: ItemMyTodoBinding,
private val isCompleted: Boolean,
private val itemSelect: (Int) -> Unit,
private val itemUnselect: (Int) -> Unit
private val itemUnselect: (Int) -> Unit,
private val itemDetailClick: (Long) -> Unit
) : RecyclerView.ViewHolder(binding.root) {

fun onBind(item: TodoModel, position: Int) {
Expand Down Expand Up @@ -52,6 +53,10 @@ class MyTodoListViewHolder(
cbMyTodoSelected.setOnSingleClickListener {
itemUnselect(position)
}

root.setOnSingleClickListener {
itemDetailClick(item.todoId)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.going.presentation.todo.mytodo.todolist

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.going.presentation.R
import com.going.presentation.databinding.FragmentMyTodoUncompleteBinding
import com.going.presentation.todo.mytodo.MyTodoViewModel
import com.going.presentation.todo.mytodo.detail.MyTodoDetailActivity
import com.going.presentation.todo.mytodo.detail.MyTodoDetailActivity.Companion.EXTRA_TODO_ID
import com.going.ui.base.BaseFragment
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -27,11 +30,19 @@ class MyTodoUncompleteFragment() :
}

private fun initAdapterWithClickListener() {
_adapter = MyTodoListAdapter(false, { position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
viewModel.decreaseTodoCount()
}, { })
_adapter = MyTodoListAdapter(false,
{ position ->
adapter.removeItem(position)
adapter.notifyDataSetChanged()
viewModel.decreaseTodoCount()
},
{ },
{ todoId ->
Intent(activity, MyTodoDetailActivity::class.java).apply {
putExtra(EXTRA_TODO_ID, todoId)
startActivity(this)
}
})
binding.rvMyTodoUncomplete.adapter = adapter
}

Expand Down
Loading

0 comments on commit fc6c61f

Please sign in to comment.