From 1c1ad0edf1b60960da5e38c38f324f3fcbb6bfce Mon Sep 17 00:00:00 2001 From: ramkid91 Date: Mon, 11 Apr 2022 16:57:29 +0900 Subject: [PATCH 01/18] fix: Modify refactor package structure --- .../src/main/java/com/example/todo/model/ActionLog.kt | 2 -- .../todo/{common/Common.kt => model/ActionType.kt} | 6 +----- .../main/java/com/example/todo/model/ProgressType.kt | 7 +++++++ .../src/main/java/com/example/todo/model/TodoItem.kt | 2 -- .../src/main/java/com/example/todo/network/JsonTodo.kt | 1 - .../example/todo/respository/ActionLogDataSource.kt | 1 - .../todo/respository/ActionLogRemoteDataSource.kt | 6 ------ .../example/todo/respository/ActionLogRepository.kt | 4 ++-- .../com/example/todo/respository/ToDoRepository.kt | 2 -- .../todo/{common => ui/action}/ActionDiffCallback.kt | 2 +- .../example/todo/{common => ui/action}/timeDiffUtil.kt | 0 .../todo/ui/{toDo => common}/ViewModelFactory.kt | 3 ++- .../example/todo/ui/common/actionLogBindingAdapter.kt | 1 - .../main/java/com/example/todo/ui/toDo/ToDoActivity.kt | 10 +++++----- .../todo/{common => ui/toDo}/TodoDiffCallback.kt | 2 +- 15 files changed, 19 insertions(+), 30 deletions(-) rename android/app/src/main/java/com/example/todo/{common/Common.kt => model/ActionType.kt} (54%) create mode 100644 android/app/src/main/java/com/example/todo/model/ProgressType.kt rename android/app/src/main/java/com/example/todo/{common => ui/action}/ActionDiffCallback.kt (93%) rename android/app/src/main/java/com/example/todo/{common => ui/action}/timeDiffUtil.kt (100%) rename android/app/src/main/java/com/example/todo/ui/{toDo => common}/ViewModelFactory.kt (90%) rename android/app/src/main/java/com/example/todo/{common => ui/toDo}/TodoDiffCallback.kt (92%) diff --git a/android/app/src/main/java/com/example/todo/model/ActionLog.kt b/android/app/src/main/java/com/example/todo/model/ActionLog.kt index 4c59c8902..98998b1fb 100644 --- a/android/app/src/main/java/com/example/todo/model/ActionLog.kt +++ b/android/app/src/main/java/com/example/todo/model/ActionLog.kt @@ -1,7 +1,5 @@ package com.example.todo.model -import com.example.todo.common.ActionType -import com.example.todo.common.ProgressType data class ActionLog( val title: String, diff --git a/android/app/src/main/java/com/example/todo/common/Common.kt b/android/app/src/main/java/com/example/todo/model/ActionType.kt similarity index 54% rename from android/app/src/main/java/com/example/todo/common/Common.kt rename to android/app/src/main/java/com/example/todo/model/ActionType.kt index 08684aa14..40c9c0bc6 100644 --- a/android/app/src/main/java/com/example/todo/common/Common.kt +++ b/android/app/src/main/java/com/example/todo/model/ActionType.kt @@ -1,11 +1,7 @@ -package com.example.todo.common +package com.example.todo.model import com.example.todo.R -enum class ProgressType(val value: Int) { - TO_DO(R.string.progress_todo), IN_PROGRESS(R.string.progress_ing), DONE(R.string.progress_done) -} - enum class ActionType(val value: Int) { ADD(R.string.action_add), REMOVE((R.string.action_remove)), MOVE((R.string.action_move)), UPDATE( R.string.action_update diff --git a/android/app/src/main/java/com/example/todo/model/ProgressType.kt b/android/app/src/main/java/com/example/todo/model/ProgressType.kt new file mode 100644 index 000000000..c0d5aa210 --- /dev/null +++ b/android/app/src/main/java/com/example/todo/model/ProgressType.kt @@ -0,0 +1,7 @@ +package com.example.todo.model + +import com.example.todo.R + +enum class ProgressType(val value: Int) { + TO_DO(R.string.progress_todo), IN_PROGRESS(R.string.progress_ing), DONE(R.string.progress_done) +} diff --git a/android/app/src/main/java/com/example/todo/model/TodoItem.kt b/android/app/src/main/java/com/example/todo/model/TodoItem.kt index 97bd1fc66..e918ed5bc 100644 --- a/android/app/src/main/java/com/example/todo/model/TodoItem.kt +++ b/android/app/src/main/java/com/example/todo/model/TodoItem.kt @@ -1,7 +1,5 @@ package com.example.todo.model -import com.example.todo.common.ProgressType - data class TodoItem(var itemId: String, val title: String, val content: String, val type: ProgressType) diff --git a/android/app/src/main/java/com/example/todo/network/JsonTodo.kt b/android/app/src/main/java/com/example/todo/network/JsonTodo.kt index 68ccc2581..74332106b 100644 --- a/android/app/src/main/java/com/example/todo/network/JsonTodo.kt +++ b/android/app/src/main/java/com/example/todo/network/JsonTodo.kt @@ -1,6 +1,5 @@ package com.example.todo.network -import android.icu.text.CaseMap import com.google.gson.annotations.SerializedName data class JsonTodo( diff --git a/android/app/src/main/java/com/example/todo/respository/ActionLogDataSource.kt b/android/app/src/main/java/com/example/todo/respository/ActionLogDataSource.kt index 0a74de4dc..4fbe19766 100644 --- a/android/app/src/main/java/com/example/todo/respository/ActionLogDataSource.kt +++ b/android/app/src/main/java/com/example/todo/respository/ActionLogDataSource.kt @@ -1,6 +1,5 @@ package com.example.todo.respository -import com.example.todo.model.ActionLog import com.example.todo.network.JsonActionLog interface ActionLogDataSource { diff --git a/android/app/src/main/java/com/example/todo/respository/ActionLogRemoteDataSource.kt b/android/app/src/main/java/com/example/todo/respository/ActionLogRemoteDataSource.kt index 82a48a042..dcbb83a28 100644 --- a/android/app/src/main/java/com/example/todo/respository/ActionLogRemoteDataSource.kt +++ b/android/app/src/main/java/com/example/todo/respository/ActionLogRemoteDataSource.kt @@ -1,11 +1,5 @@ package com.example.todo.respository -import android.content.Context -import android.util.Log -import com.example.todo.R -import com.example.todo.common.ActionType -import com.example.todo.common.ProgressType -import com.example.todo.model.ActionLog import com.example.todo.network.JsonActionLog import com.example.todo.network.RetrofitClient diff --git a/android/app/src/main/java/com/example/todo/respository/ActionLogRepository.kt b/android/app/src/main/java/com/example/todo/respository/ActionLogRepository.kt index 59d5e053e..3905e5d4e 100644 --- a/android/app/src/main/java/com/example/todo/respository/ActionLogRepository.kt +++ b/android/app/src/main/java/com/example/todo/respository/ActionLogRepository.kt @@ -2,9 +2,9 @@ package com.example.todo.respository import android.content.Context import com.example.todo.R -import com.example.todo.common.ActionType -import com.example.todo.common.ProgressType import com.example.todo.model.ActionLog +import com.example.todo.model.ActionType +import com.example.todo.model.ProgressType import com.example.todo.network.JsonActionLog class ActionLogRepository( diff --git a/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt b/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt index 7a71c1aae..3e847179b 100644 --- a/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt +++ b/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt @@ -1,6 +1,4 @@ package com.example.todo.respository -import android.content.Context - class ToDoRepository(private val toDoDataSource: ToDoDataSource) { } \ No newline at end of file diff --git a/android/app/src/main/java/com/example/todo/common/ActionDiffCallback.kt b/android/app/src/main/java/com/example/todo/ui/action/ActionDiffCallback.kt similarity index 93% rename from android/app/src/main/java/com/example/todo/common/ActionDiffCallback.kt rename to android/app/src/main/java/com/example/todo/ui/action/ActionDiffCallback.kt index 8dbe265ec..227e71c7a 100644 --- a/android/app/src/main/java/com/example/todo/common/ActionDiffCallback.kt +++ b/android/app/src/main/java/com/example/todo/ui/action/ActionDiffCallback.kt @@ -1,4 +1,4 @@ -package com.example.todo.common +package com.example.todo.ui.action import androidx.recyclerview.widget.DiffUtil import com.example.todo.model.ActionLog diff --git a/android/app/src/main/java/com/example/todo/common/timeDiffUtil.kt b/android/app/src/main/java/com/example/todo/ui/action/timeDiffUtil.kt similarity index 100% rename from android/app/src/main/java/com/example/todo/common/timeDiffUtil.kt rename to android/app/src/main/java/com/example/todo/ui/action/timeDiffUtil.kt diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ViewModelFactory.kt b/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt similarity index 90% rename from android/app/src/main/java/com/example/todo/ui/toDo/ViewModelFactory.kt rename to android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt index f4a575fd8..ca74ffcf4 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/ViewModelFactory.kt +++ b/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt @@ -1,4 +1,4 @@ -package com.example.todo.ui.toDo +package com.example.todo.ui.common import android.content.Context import androidx.lifecycle.ViewModel @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModelProvider import com.example.todo.network.RetrofitClient import com.example.todo.respository.ActionLogRemoteDataSource import com.example.todo.respository.ActionLogRepository +import com.example.todo.ui.toDo.ToDoViewModel import java.lang.IllegalArgumentException class ViewModelFactory(private val context: Context) : ViewModelProvider.Factory { diff --git a/android/app/src/main/java/com/example/todo/ui/common/actionLogBindingAdapter.kt b/android/app/src/main/java/com/example/todo/ui/common/actionLogBindingAdapter.kt index cbeffa221..83625bdd3 100644 --- a/android/app/src/main/java/com/example/todo/ui/common/actionLogBindingAdapter.kt +++ b/android/app/src/main/java/com/example/todo/ui/common/actionLogBindingAdapter.kt @@ -3,7 +3,6 @@ package com.example.todo.ui.common import android.widget.TextView import androidx.databinding.BindingAdapter import com.example.todo.common.getTimeDiff -import java.text.DecimalFormat @BindingAdapter("actionLogTime") fun getAfterTime(textView: TextView, time: String) { diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt index 902c45b3b..f0f80edb2 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt @@ -3,22 +3,22 @@ package com.example.todo.ui.toDo import android.os.Bundle import android.view.Menu import android.view.MenuItem -import android.view.View import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat import androidx.databinding.DataBindingUtil import androidx.recyclerview.widget.LinearLayoutManager import com.example.todo.R -import com.example.todo.common.ActionDiffCallback -import com.example.todo.common.ActionType -import com.example.todo.common.ProgressType -import com.example.todo.common.TodoDiffCallback +import com.example.todo.ui.action.ActionDiffCallback + import com.example.todo.databinding.ActivityTodoBinding import com.example.todo.model.ActionLog +import com.example.todo.model.ActionType +import com.example.todo.model.ProgressType import com.example.todo.model.TodoItem import com.example.todo.ui.action.ActionAdapter +import com.example.todo.ui.common.ViewModelFactory class ToDoActivity : AppCompatActivity() { diff --git a/android/app/src/main/java/com/example/todo/common/TodoDiffCallback.kt b/android/app/src/main/java/com/example/todo/ui/toDo/TodoDiffCallback.kt similarity index 92% rename from android/app/src/main/java/com/example/todo/common/TodoDiffCallback.kt rename to android/app/src/main/java/com/example/todo/ui/toDo/TodoDiffCallback.kt index c50d1105c..97504493c 100644 --- a/android/app/src/main/java/com/example/todo/common/TodoDiffCallback.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/TodoDiffCallback.kt @@ -1,4 +1,4 @@ -package com.example.todo.common +package com.example.todo.ui.toDo import androidx.recyclerview.widget.DiffUtil import com.example.todo.model.TodoItem From 2e0b4e6ad6ab0e66cf4a36497437eb069aed694d Mon Sep 17 00:00:00 2001 From: ramkid91 Date: Mon, 11 Apr 2022 22:32:14 +0900 Subject: [PATCH 02/18] feat: Add registerCard DialogFragment and closeBtn at Navigation Drawer --- android/app/build.gradle | 2 +- .../todo/respository/ToDoDataSource.kt | 2 +- .../todo/respository/ToDoRemoteDataSource.kt | 8 ++ .../todo/respository/ToDoRepository.kt | 22 ++++ .../todo/ui/common/ViewModelFactory.kt | 7 +- .../com/example/todo/ui/toDo/ToDoActivity.kt | 7 ++ .../com/example/todo/ui/toDo/ToDoDialog.kt | 103 ++++++++++++++++++ .../com/example/todo/ui/toDo/ToDoViewModel.kt | 23 +++- .../res/drawable/ic_baseline_close_24.xml | 10 ++ .../res/layout-sw720dp-land/activity_todo.xml | 10 ++ .../res/layout-sw720dp-land/dialog_card.xml | 83 ++++++++++++++ .../app/src/main/res/layout/activity_todo.xml | 9 ++ .../app/src/main/res/layout/dialog_card.xml | 83 ++++++++++++++ android/app/src/main/res/values/strings.xml | 7 ++ 14 files changed, 367 insertions(+), 9 deletions(-) create mode 100644 android/app/src/main/java/com/example/todo/respository/ToDoRemoteDataSource.kt create mode 100644 android/app/src/main/java/com/example/todo/ui/toDo/ToDoDialog.kt create mode 100644 android/app/src/main/res/drawable/ic_baseline_close_24.xml create mode 100644 android/app/src/main/res/layout-sw720dp-land/dialog_card.xml create mode 100644 android/app/src/main/res/layout/dialog_card.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index 83e4f8bc4..a2faf8d93 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -40,7 +40,7 @@ dependencies { implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.google.code.gson:gson:2.8.9' - + implementation 'androidx.fragment:fragment-ktx:1.4.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0' implementation 'joda-time:joda-time:2.10.10' implementation 'androidx.core:core-ktx:1.7.0' diff --git a/android/app/src/main/java/com/example/todo/respository/ToDoDataSource.kt b/android/app/src/main/java/com/example/todo/respository/ToDoDataSource.kt index 94611c64d..96a50e662 100644 --- a/android/app/src/main/java/com/example/todo/respository/ToDoDataSource.kt +++ b/android/app/src/main/java/com/example/todo/respository/ToDoDataSource.kt @@ -3,5 +3,5 @@ package com.example.todo.respository import com.example.todo.model.TodoItem interface ToDoDataSource { - fun getToDoItems(): List + } \ No newline at end of file diff --git a/android/app/src/main/java/com/example/todo/respository/ToDoRemoteDataSource.kt b/android/app/src/main/java/com/example/todo/respository/ToDoRemoteDataSource.kt new file mode 100644 index 000000000..94d9adea5 --- /dev/null +++ b/android/app/src/main/java/com/example/todo/respository/ToDoRemoteDataSource.kt @@ -0,0 +1,8 @@ +package com.example.todo.respository + +import com.example.todo.model.TodoItem +import com.example.todo.network.RetrofitClient + +class ToDoRemoteDataSource(private val retrofitClient: RetrofitClient,): ToDoDataSource { + +} \ No newline at end of file diff --git a/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt b/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt index 3e847179b..09ec6f001 100644 --- a/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt +++ b/android/app/src/main/java/com/example/todo/respository/ToDoRepository.kt @@ -1,4 +1,26 @@ package com.example.todo.respository +import com.example.todo.model.TodoItem + class ToDoRepository(private val toDoDataSource: ToDoDataSource) { + + + fun addToDoItem(toDoList:List, newItem:TodoItem): List { + val originList= toDoList.toMutableList() + originList.add(0, newItem) + return originList.toList() + } + + fun addInProgressItem(inProgressList:List, newItem:TodoItem): List { + val originList= inProgressList.toMutableList() + originList.add(0, newItem) + return originList.toList() + } + + fun addDoneItem(doneList:List, newItem:TodoItem): List { + val originList= doneList.toMutableList() + originList.add(0, newItem) + return originList.toList() + } + } \ No newline at end of file diff --git a/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt b/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt index ca74ffcf4..5aff38df8 100644 --- a/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt +++ b/android/app/src/main/java/com/example/todo/ui/common/ViewModelFactory.kt @@ -4,8 +4,7 @@ import android.content.Context import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.example.todo.network.RetrofitClient -import com.example.todo.respository.ActionLogRemoteDataSource -import com.example.todo.respository.ActionLogRepository +import com.example.todo.respository.* import com.example.todo.ui.toDo.ToDoViewModel import java.lang.IllegalArgumentException @@ -14,7 +13,9 @@ class ViewModelFactory(private val context: Context) : ViewModelProvider.Factory return if (modelClass.isAssignableFrom(ToDoViewModel::class.java)) { val repository = ActionLogRepository(context, ActionLogRemoteDataSource(RetrofitClient.create())) - ToDoViewModel(repository) as T + + val toDoRepository= ToDoRepository(ToDoRemoteDataSource(RetrofitClient.create())) + ToDoViewModel(repository, toDoRepository) as T } else { throw IllegalArgumentException() } diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt index f0f80edb2..d078499b6 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt @@ -34,10 +34,17 @@ class ToDoActivity : AppCompatActivity() { setContentView(R.layout.activity_todo) binding = DataBindingUtil.setContentView(this, R.layout.activity_todo) setToolBar() + setCloseDrawerBtn() initializeRecyclerViews() addDummyDataInRecyclerView() } + private fun setCloseDrawerBtn(){ + binding.ibtnCloseDrawer.setOnClickListener { + binding.draw.closeDrawer(GravityCompat.END) + } + } + private fun setToolBar() { setSupportActionBar(binding.tbMain) supportActionBar?.setDisplayShowTitleEnabled(false) diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoDialog.kt b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoDialog.kt new file mode 100644 index 000000000..23810a5cf --- /dev/null +++ b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoDialog.kt @@ -0,0 +1,103 @@ +package com.example.todo.ui.toDo + + +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.activityViewModels +import com.example.todo.databinding.DialogCardBinding +import com.example.todo.model.ProgressType +import com.example.todo.model.TodoItem + + +class ToDoDialog(private val progressType: ProgressType) : DialogFragment() { + + lateinit var binding: DialogCardBinding + private val viewModel :ToDoViewModel by activityViewModels() + private var titleValidationFlag = false + private var contentValidationFlag = false + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = DialogCardBinding.inflate(inflater, container, false) + dialog?.setCanceledOnTouchOutside(false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + binding.btnRegister.setOnClickListener { + when (progressType) { + + ProgressType.TO_DO -> { + val newToDoItem= TodoItem("test", binding.editCardTitle.text.toString(), binding.editCardContent.text.toString(), + ProgressType.TO_DO) + viewModel.addTodoItem(newToDoItem) + } + + ProgressType.IN_PROGRESS -> { + val newInprogressItem= TodoItem("test", binding.editCardTitle.text.toString(), binding.editCardContent.text.toString(), + ProgressType.IN_PROGRESS) + + viewModel.addInprogressItem(newInprogressItem) + } + else -> { + val newDoneItem= TodoItem("test", binding.editCardTitle.text.toString(), binding.editCardContent.text.toString(), + ProgressType.DONE) + + viewModel.addDoneItem(newDoneItem) + } + } + + dismiss() + } + + binding.btnCancle.setOnClickListener { dismiss() } + binding.editCardTitle.addTextChangedListener(titleChangeListener) + binding.editCardContent.addTextChangedListener(contentChangeListener) + } + + private val titleChangeListener = object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + + override fun afterTextChanged(titleInput: Editable?) { + if (titleInput != null) { + titleValidationFlag = when { + (titleInput.isEmpty()) -> false + else -> true + } + } + validationFlagCheck() + } + } + + private val contentChangeListener = object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + + override fun afterTextChanged(contentInput: Editable?) { + if (contentInput != null) { + contentValidationFlag = when { + (contentInput.isEmpty()) -> false + else -> true + } + } + validationFlagCheck() + } + } + + private fun validationFlagCheck() { + binding.btnRegister.isEnabled = titleValidationFlag && contentValidationFlag + + } + +} + diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoViewModel.kt b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoViewModel.kt index ab397476d..ba870f172 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoViewModel.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoViewModel.kt @@ -8,18 +8,19 @@ import androidx.lifecycle.viewModelScope import com.example.todo.model.ActionLog import com.example.todo.model.TodoItem import com.example.todo.respository.ActionLogRepository +import com.example.todo.respository.ToDoRepository import kotlinx.coroutines.launch -class ToDoViewModel(private val actionLogRepository: ActionLogRepository) : ViewModel() { +class ToDoViewModel(private val actionLogRepository: ActionLogRepository, private val toDoRepository: ToDoRepository) : ViewModel() { private val _todoList = MutableLiveData>() private val _inProgressList = MutableLiveData>() private val _doneList = MutableLiveData>() private val _actionList = MutableLiveData>() - val todoList: LiveData> = _todoList - val inProgressList: LiveData> = _inProgressList - val doneList: LiveData> = _doneList + var todoList: LiveData> = _todoList + var inProgressList: LiveData> = _inProgressList + var doneList: LiveData> = _doneList val actionList: LiveData> = _actionList init { @@ -33,4 +34,18 @@ class ToDoViewModel(private val actionLogRepository: ActionLogRepository) : View Log.d("ssss", actionLogs.toString()) } } + + fun addTodoItem(item:TodoItem){ + _todoList.value= todoList.value?.let { toDoRepository.addToDoItem(it, item) } + todoList= _todoList + } + + fun addInprogressItem(item:TodoItem){ + _inProgressList.value= inProgressList.value?.let { toDoRepository.addInProgressItem(it, item) } + inProgressList = _inProgressList + } + fun addDoneItem(item:TodoItem){ + _doneList.value= doneList.value?.let { toDoRepository.addDoneItem(it, item) } + doneList= _doneList + } } \ No newline at end of file diff --git a/android/app/src/main/res/drawable/ic_baseline_close_24.xml b/android/app/src/main/res/drawable/ic_baseline_close_24.xml new file mode 100644 index 000000000..16d6d37dd --- /dev/null +++ b/android/app/src/main/res/drawable/ic_baseline_close_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml b/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml index 7ed4c4e16..f6e97e607 100644 --- a/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml +++ b/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml @@ -71,6 +71,16 @@ android:layout_height="match_parent" android:layout_gravity="end"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/activity_todo.xml b/android/app/src/main/res/layout/activity_todo.xml index 4981980aa..cf91e65c0 100644 --- a/android/app/src/main/res/layout/activity_todo.xml +++ b/android/app/src/main/res/layout/activity_todo.xml @@ -72,6 +72,15 @@ android:layout_height="match_parent" android:layout_gravity="end"> + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 398c866b6..8c5523722 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -13,4 +13,11 @@ 삭제 이동 수정 + + + 새로운 카드 추가 + 제목을 입력해주세요 + 내용을 입력해주세요 + 등록 + 취소 \ No newline at end of file From b1a47baca8275510fbd8d11faf525821667a64f8 Mon Sep 17 00:00:00 2001 From: shim506 Date: Tue, 12 Apr 2022 11:14:38 +0900 Subject: [PATCH 03/18] =?UTF-8?q?Feat:=20toddTittle=20=EC=BB=A4=EC=8A=A4?= =?UTF-8?q?=ED=85=80=20=EB=B7=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - item_count_background 리소스 정의 - activity_todo 레이아웃 크기에 맞게 수정 - 커스텀 뷰 클래스 및 레이아웃 정의 --- .../example/todo/ui/common/TodoTitleView.kt | 29 ++++++++ .../com/example/todo/ui/toDo/ToDoActivity.kt | 21 +++--- .../com/example/todo/ui/toDo/TodoAdapter.kt | 5 +- .../main/res/drawable/ic_baseline_add_24.xml | 10 +++ .../res/drawable/item_count_background.xml | 14 ++++ .../res/layout-sw720dp-land/activity_todo.xml | 69 +++++++++++++++---- .../app/src/main/res/layout/activity_todo.xml | 69 +++++++++++++++---- .../src/main/res/layout/todo_title_view.xml | 47 +++++++++++++ 8 files changed, 222 insertions(+), 42 deletions(-) create mode 100644 android/app/src/main/java/com/example/todo/ui/common/TodoTitleView.kt create mode 100644 android/app/src/main/res/drawable/ic_baseline_add_24.xml create mode 100644 android/app/src/main/res/drawable/item_count_background.xml create mode 100644 android/app/src/main/res/layout/todo_title_view.xml diff --git a/android/app/src/main/java/com/example/todo/ui/common/TodoTitleView.kt b/android/app/src/main/java/com/example/todo/ui/common/TodoTitleView.kt new file mode 100644 index 000000000..8e048655c --- /dev/null +++ b/android/app/src/main/java/com/example/todo/ui/common/TodoTitleView.kt @@ -0,0 +1,29 @@ +package com.example.todo.ui.common + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.Button + +import android.widget.LinearLayout +import android.widget.TextView +import com.example.todo.R +import com.example.todo.databinding.TodoTitleViewBinding + + +class TodoTitleView(context: Context, attrs: AttributeSet) : + LinearLayout(context, attrs) { + lateinit var title: TextView + lateinit var count: TextView + lateinit var addButton: Button + + init { + LayoutInflater.from(context).inflate(R.layout.todo_title_view, this, true) + title = findViewById(R.id.tv_todo_title) + count = findViewById(R.id.tv_content_count) + addButton = findViewById(R.id.btn_add) + val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater + } + + +} \ No newline at end of file diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt index d078499b6..2ae903d34 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt @@ -12,11 +12,8 @@ import com.example.todo.R import com.example.todo.ui.action.ActionDiffCallback import com.example.todo.databinding.ActivityTodoBinding -import com.example.todo.model.ActionLog -import com.example.todo.model.ActionType -import com.example.todo.model.ProgressType +import com.example.todo.model.* -import com.example.todo.model.TodoItem import com.example.todo.ui.action.ActionAdapter import com.example.todo.ui.common.ViewModelFactory @@ -34,15 +31,9 @@ class ToDoActivity : AppCompatActivity() { setContentView(R.layout.activity_todo) binding = DataBindingUtil.setContentView(this, R.layout.activity_todo) setToolBar() - setCloseDrawerBtn() initializeRecyclerViews() addDummyDataInRecyclerView() - } - private fun setCloseDrawerBtn(){ - binding.ibtnCloseDrawer.setOnClickListener { - binding.draw.closeDrawer(GravityCompat.END) - } } private fun setToolBar() { @@ -128,21 +119,31 @@ class ToDoActivity : AppCompatActivity() { binding.rvActionLog.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) + binding.todoTitleViewTodo.title.text = "해야할 일" + binding.todoTitleViewInProgress.title.text = "하고있는 일" + binding.todoTitleViewTodoDone.title.text = "완료한 일" + toDoViewModel.todoList.observe(this) { todoAdapter.submitList(it) + binding.todoTitleViewTodo.count.text = it.size.toString() } toDoViewModel.inProgressList.observe(this) { inProgressAdapter.submitList(it) + binding.todoTitleViewInProgress.count.text = (it.size).toString() } toDoViewModel.doneList.observe(this) { doneAdapter.submitList(it) + binding.todoTitleViewTodoDone.count.text = (it.size).toString() } toDoViewModel.actionList.observe(this) { actionAdapter.submitList(it) + // 테스트용 + binding.todoTitleViewTodo.count.text = it.size.toString() } + } companion object { diff --git a/android/app/src/main/java/com/example/todo/ui/toDo/TodoAdapter.kt b/android/app/src/main/java/com/example/todo/ui/toDo/TodoAdapter.kt index 0d15777d5..e31c76992 100644 --- a/android/app/src/main/java/com/example/todo/ui/toDo/TodoAdapter.kt +++ b/android/app/src/main/java/com/example/todo/ui/toDo/TodoAdapter.kt @@ -12,14 +12,15 @@ class TodoAdapter( todoDiffCallback: DiffUtil.ItemCallback ) : ListAdapter(todoDiffCallback) { - class ViewHolder(private val itemViewBinding: TodoItemBinding) : RecyclerView.ViewHolder(itemViewBinding.root) { + class ViewHolder(private val itemViewBinding: TodoItemBinding) : + RecyclerView.ViewHolder(itemViewBinding.root) { fun bind(cardItem: TodoItem) { itemViewBinding.toDoItem = cardItem } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val binding= TodoItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + val binding = TodoItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) return ViewHolder(binding) } diff --git a/android/app/src/main/res/drawable/ic_baseline_add_24.xml b/android/app/src/main/res/drawable/ic_baseline_add_24.xml new file mode 100644 index 000000000..eb232541d --- /dev/null +++ b/android/app/src/main/res/drawable/ic_baseline_add_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/android/app/src/main/res/drawable/item_count_background.xml b/android/app/src/main/res/drawable/item_count_background.xml new file mode 100644 index 000000000..38aa16944 --- /dev/null +++ b/android/app/src/main/res/drawable/item_count_background.xml @@ -0,0 +1,14 @@ + + + + + + + /> + \ No newline at end of file diff --git a/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml b/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml index f6e97e607..aa86e4f8e 100644 --- a/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml +++ b/android/app/src/main/res/layout-sw720dp-land/activity_todo.xml @@ -16,7 +16,9 @@ + android:layout_height="match_parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintVertical_weight="7"> + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_todo" /> + + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_in_progress" /> + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_todo_done" /> + + @@ -71,16 +120,6 @@ android:layout_height="match_parent" android:layout_gravity="end"> - - + android:layout_height="match_parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintVertical_weight="7"> + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_todo" /> + + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_in_progress" /> + app:layout_constraintTop_toBottomOf="@+id/todo_title_view_todo_done" /> + + @@ -72,15 +120,6 @@ android:layout_height="match_parent" android:layout_gravity="end"> - - + + + + + + + + + + +