Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ android {
enabled = true
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.todolist.model

enum class Status(val status: String) {
TODO("todo"),
IN_PROGRESS("inProgress"),
DONE("done")
}
8 changes: 8 additions & 0 deletions android/app/src/main/java/com/example/todolist/model/Task.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.todolist.model

data class Task(
val title: String?,
val content: String?,
val status: Status,
val author: String = "Android"
)
90 changes: 90 additions & 0 deletions android/app/src/main/java/com/example/todolist/ui/Dialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.example.todolist.ui

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
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 android.view.Window
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.activityViewModels
import com.example.todolist.databinding.DialogNewCardBinding
import com.example.todolist.model.Status
import com.example.todolist.model.Task

class Dialog : DialogFragment() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jminie-o8o
다이얼로그를 DialogFragment 로 구현하셨던 이유가 무엇인가요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renovatio0424
DialogFragment 는 말 그대로 Fragment 이기 때문에 Fragment 의 생명주기를 활용할 수 있습니다.
Dialog를 활용할 때 Activity가 파괴되더라도 dialog가 존재하여 생기는 메모리 leak 등을 방지할 수 있는 장점이 있기 때문에 DialogFragment 로 구현했습니다.

private var _binding: DialogNewCardBinding? = null
private val binding get() = _binding
private val viewModel: ViewModel by activityViewModels()
private var titleFlag = false
private var contentsFlag = false

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = DialogNewCardBinding.inflate(inflater, container, false)
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) // 다이얼로그의 곡선 주변에 배경색을 맞춰주는 코드
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
dialog?.setCanceledOnTouchOutside(false) // 다이얼로그 외부의 영역 터치 시 취소 불가능

return binding?.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding?.btnCancel?.setOnClickListener { dismiss() }

binding?.etTitle?.addTextChangedListener(titleListener)
binding?.etContents?.addTextChangedListener(contentsListener)

binding?.btnRegister?.setOnClickListener {
val task = Task(
binding?.etTitle?.text?.toString(),
binding?.etContents?.text?.toString(),
Status.TODO
)
viewModel.addTask(task)
dismiss()
}
}

private val titleListener = 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(s: Editable?) {
if (s != null) {
titleFlag = when {
s.isEmpty() -> false
else -> true
}
}
flagCheck()
}
}

private val contentsListener = 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(s: Editable?) {
if (s != null) {
contentsFlag = when {
s.isEmpty() -> false
else -> true
}
}
flagCheck()
}
}

fun flagCheck() {
binding?.btnRegister?.isEnabled = titleFlag && contentsFlag
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class MainActivity : AppCompatActivity() {
viewModel.history.observe(this) { histories ->
historyAdapter.submitList(histories)
}

binding.includeTodo?.btnTodoAdd?.setOnClickListener {
val dialog = Dialog()
dialog.show(supportFragmentManager, "Dialog")
}
}

private fun onDrawerEvent() {
Expand Down
11 changes: 11 additions & 0 deletions android/app/src/main/java/com/example/todolist/ui/ViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.todolist.model.ActionType.*
import com.example.todolist.model.History
import com.example.todolist.model.Task

class ViewModel : ViewModel() {

private val _history = MutableLiveData<List<History>>()
val history: LiveData<List<History>>
get() = _history

private val todoItems: MutableList<Task> = mutableListOf()
private var _todoTask = MutableLiveData<MutableList<Task>>()
val todoTask: LiveData<MutableList<Task>>
get() = _todoTask

fun loadDummyData() {
_history.value = getDummyData()
}

fun addTask(task: Task) {
todoItems.add(task)
_todoTask.value = todoItems
}

private fun getDummyData(): List<History> {
return listOf(
History(1, MOVE, "HTML/CSS공부하기", "해야할 일", "하고 있는 일", "2022-04-05 21:19:00"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/todo_light_blue" />
<corners android:radius="10dp" />
</shape>
6 changes: 6 additions & 0 deletions android/app/src/main/res/drawable/able_dialog_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/todo_blue" />
<corners android:radius="10dp" />
</shape>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/badge_background_gray.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/todo_gray02"/>
</shape>
7 changes: 7 additions & 0 deletions android/app/src/main/res/drawable/dialog_background_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/todo_white"/>
<stroke android:width="2dp" android:color="@color/todo_blue" />
<corners android:radius="10dp"/>
</shape>
6 changes: 6 additions & 0 deletions android/app/src/main/res/drawable/dialog_button_cancel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/todo_grey04" />
<corners android:radius="10dp" />
</shape>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/edittext_cursor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="1.5dp"/>
<solid android:color="@color/todo_grey03"/>
</shape>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/ic_baseline_add_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#BDBDBD"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>
5 changes: 5 additions & 0 deletions android/app/src/main/res/drawable/selector_dialog_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/able_dialog_button" android:state_enabled="true" />
<item android:drawable="@drawable/disable_dialog_button" android:state_enabled="false" />
</selector>
9 changes: 9 additions & 0 deletions android/app/src/main/res/drawable/selector_dialog_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:color="@color/todo_white"
android:state_enabled="true" />
<item
android:color="@color/todo_grey05"
android:state_enabled="false" />
</selector>
10 changes: 10 additions & 0 deletions android/app/src/main/res/layout-sw720dp-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
android:src="@drawable/ic_baseline_menu_32" />

</androidx.appcompat.widget.Toolbar>

<include
android:id="@+id/include_todo"
layout="@layout/view_todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="51dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tb_main" />
</androidx.constraintlayout.widget.ConstraintLayout>

<LinearLayout
Expand Down
94 changes: 94 additions & 0 deletions android/app/src/main/res/layout/dialog_new_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_dialog"
android:layout_width="540dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="@drawable/dialog_background_white"
android:gravity="center">

<TextView
android:id="@+id/tv_add_dialog_title"
style="@style/TextHeadline5.bold.20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:text="@string/label_add_new_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/et_title"
style="@style/Subtitle1.bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="20dp"
android:background="@android:color/transparent"
android:hint="@string/label_dialog_add_title"
android:importantForAutofill="no"
android:inputType="text"
android:textCursorDrawable="@drawable/edittext_cursor"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_add_dialog_title" />

<EditText
android:id="@+id/et_contents"
style="@style/Subtitle1.14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="14dp"
android:background="@android:color/transparent"
android:hint="@string/label_dialog_add_contents"
android:importantForAutofill="no"
android:inputType="text"
android:textCursorDrawable="@drawable/edittext_cursor"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/et_title" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_register"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp"
android:background="@drawable/selector_dialog_button"
android:enabled="false"
android:text="@string/label_dialog_register"
android:textColor="@drawable/selector_dialog_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="15dp"
android:background="@drawable/dialog_button_cancel"
android:text="@string/label_dialog_cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_register" />


</androidx.constraintlayout.widget.ConstraintLayout>


</FrameLayout>
</layout>
49 changes: 49 additions & 0 deletions android/app/src/main/res/layout/view_todo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/tv_todo_title"
style="@style/Subtitle1.bold.18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_todo_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_todo_badge"
style="@style/Subtitle2.bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="@drawable/badge_background_gray"
android:padding="2dp"
app:layout_constraintStart_toEndOf="@+id/tv_todo_title"
app:layout_constraintTop_toTopOf="parent"
tools:text="113" />


<ImageButton
android:id="@+id/btn_todo_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="136dp"
android:background="@android:color/transparent"
android:contentDescription="@string/description_add_button"
android:src="@drawable/ic_baseline_add_24"
app:layout_constraintStart_toEndOf="@+id/tv_todo_badge"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading