Skip to content

Commit

Permalink
#22 doneTodo 체크박스 이벤트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yellow-jam committed Sep 11, 2022
1 parent ca1a126 commit e497d28
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.example.shape_up_2022.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.shape_up_2022.databinding.TodoitemBinding
import com.example.shape_up_2022.data.TodoItem
import com.example.shape_up_2022.retrofit.DoneTodoReq
import com.example.shape_up_2022.retrofit.DoneTodoRes
import com.example.shape_up_2022.retrofit.MyApplication
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class TodoViewHolder(val binding: TodoitemBinding): RecyclerView.ViewHolder(binding.root)
class TodoAdapter (val datas: MutableList<TodoItem>?): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
Expand Down Expand Up @@ -49,5 +56,25 @@ class TodoAdapter (val datas: MutableList<TodoItem>?): RecyclerView.Adapter<Recy
// done: 체크 여부 다르게 표시
binding.tododone.isChecked = datas!![position].done == true

// doneTodo: 체크박스 클릭 이벤트
binding.tododone.setOnCheckedChangeListener { compoundButton, checked ->
//Log.d("mobileApp", "checkbox ${compoundButton.isChecked}, boolean $checked, position $position")

// DB에 doneTodo 요청
val call: Call<DoneTodoRes> = MyApplication.networkServiceTodo.doneTodo(
DoneTodoReq(_id = datas!![position]._id!!, done = checked)
)
call?.enqueue(object : Callback<DoneTodoRes> {
override fun onResponse(call: Call<DoneTodoRes>, response: Response<DoneTodoRes>) {
if(response.isSuccessful){
//Log.d("mobileApp", "doneTodo $response ${response.body()}")
}
}
override fun onFailure(call: Call<DoneTodoRes>, t: Throwable) {
Log.d("mobileApp", "doneTodo onFailure $t")
}
})
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.shape_up_2022.data

// DB의 모델 중 Todo에 해당
data class TodoItem (
val _id: String?="",
val todowork:String="할일",
val todorole:Todorole?=null,
val todotime:Int=17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ interface NetworkServiceTodo {
@Body user: RegisterTodoReq,
): Call<RegisterTodoRes>

@POST("doneTodo")
fun doneTodo(
@Body body: DoneTodoReq,
): Call<DoneTodoRes>

/*
@PUT("editTodo")
fun editTodo(
@Body body: EditTodoReq,
Expand All @@ -29,7 +35,7 @@ interface NetworkServiceTodo {
fun deleteTodo(
@Body body: DeleteTodoReq,
): Call<DeleteTodoRes>

*/
}


Expand All @@ -44,9 +50,12 @@ data class RegisterTodoReq(val familyID: String, val date: String,
)
data class RegisterTodoRes(val success: String)

data class EditTodoReq(val name: String, val email: String, val password: String)
data class EditTodoRes(val success: String)
data class DoneTodoReq(val _id: String, val done: Boolean)
data class DoneTodoRes(val success: String)

//data class EditTodoReq()
//data class EditTodoRes(val success: String)

data class DeleteTodoReq(val name: String, val email: String, val password: String)
data class DeleteTodoRes(val success: String)
//data class DeleteTodoReq()
//data class DeleteTodoRes(val success: String)

0 comments on commit e497d28

Please sign in to comment.