Skip to content

Commit 5f8ab05

Browse files
authored
Merge pull request #4 from shim506/feature/android/navigation_drawer
[Android] ActionLogItem 클래스 정의, ActionLogAdapter 정의, Navigation Drawer+ toolBar에 menu버튼과 연동, 파일구조 수정
2 parents ba047a1 + 63eb9d6 commit 5f8ab05

File tree

16 files changed

+305
-135
lines changed

16 files changed

+305
-135
lines changed

android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ dependencies {
3737
implementation 'androidx.appcompat:appcompat:1.4.1'
3838
implementation 'com.google.android.material:material:1.5.0'
3939
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
40+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
4041
testImplementation 'junit:junit:4.13.2'
4142
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
4243
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
android:supportsRtl="true"
1111
android:theme="@style/Theme.Todo">
1212
<activity
13-
android:name=".ui.MainActivity"
13+
android:name=".ui.toDo.ToDoActivity"
1414
android:exported="true">
1515
<intent-filter>
1616
<action android:name="android.intent.action.MAIN" />

android/app/src/main/AndroidManifest.xml.rej

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example.todo.common
2+
3+
enum class ProgressType(val value:String){
4+
TO_DO("해야 할일"), IN_PROGRESS("하고 있는일"), DONE("한 일")
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.example.todo.model
2+
3+
import com.example.todo.common.ProgressType
4+
import java.time.LocalDateTime
5+
6+
enum class ActionType(val value:String){
7+
ADD("등록"),REMOVE("삭제"),MOVE("이동"),UPDATE("수정"),
8+
}
9+
10+
11+
data class ActionLog(val title:String, val actionType:ActionType, val time:LocalDateTime , val nowProgressType:ProgressType, val prevProgressType: ProgressType?=null ){
12+
13+
override fun toString(): String {
14+
return when(actionType){
15+
ActionType.ADD ->{
16+
"${nowProgressType.value}${title}${actionType.value}합니다"
17+
}
18+
ActionType.REMOVE->{
19+
"${nowProgressType.value}에서 ${title}${actionType.value}합니다"
20+
}
21+
22+
ActionType.MOVE->{
23+
"${title}${prevProgressType?.value}에서 ${nowProgressType.value}${actionType.value}합니다"
24+
}
25+
ActionType.UPDATE->{
26+
"${title}${actionType.value}합니다"
27+
}
28+
29+
30+
}
31+
}
32+
}

android/app/src/main/java/com/example/todo/model/TodoItem.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.example.todo.model
22

3-
data class TodoItem(var itemId: String, val title: String, val content: String)
3+
import com.example.todo.common.ProgressType
4+
5+
data class TodoItem(var itemId: String, val title: String, val content: String, val type: ProgressType)
46

57

68

android/app/src/main/java/com/example/todo/ui/MainActivity.kt

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.example.todo.ui.action
2+
3+
import android.os.Build
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.TextView
8+
import androidx.annotation.RequiresApi
9+
import androidx.recyclerview.widget.DiffUtil
10+
import androidx.recyclerview.widget.ListAdapter
11+
import androidx.recyclerview.widget.RecyclerView
12+
import com.example.todo.R
13+
import com.example.todo.model.ActionLog
14+
import java.time.Duration
15+
import java.time.LocalDate
16+
import java.time.LocalDateTime
17+
import java.time.ZoneId
18+
import java.util.*
19+
20+
class ActionAdapter(
21+
actionDiffCallback: DiffUtil.ItemCallback<ActionLog>
22+
) :
23+
ListAdapter<ActionLog, ActionAdapter.ViewHolder>(actionDiffCallback) {
24+
25+
class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
26+
27+
private val content: TextView = itemView.findViewById(R.id.tv_action_content)
28+
private val time: TextView = itemView.findViewById(R.id.tv_action_time)
29+
30+
@RequiresApi(Build.VERSION_CODES.O)
31+
fun bind(actionItem: ActionLog) {
32+
content.text = actionItem.toString()
33+
time.text = getTimeDiff(actionItem.time)
34+
}
35+
36+
37+
38+
@RequiresApi(Build.VERSION_CODES.O)
39+
fun getTimeDiff(actionDateTime: LocalDateTime):String {
40+
val nowDateTime = LocalDateTime.now(ZoneId.of("Asia/Seoul"))
41+
val duration= Duration.between(actionDateTime, nowDateTime)
42+
return when {
43+
duration.toDays() > 0 -> {
44+
"${duration.toDays()}일전"
45+
}
46+
duration.toHours()>0 -> {
47+
"${duration.toHours()}시간전"
48+
}
49+
else -> {
50+
"${duration.toMinutes()}분전"
51+
}
52+
}
53+
}
54+
}
55+
56+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
57+
val view = LayoutInflater.from(parent.context).inflate(R.layout.action_log_item, parent, false)
58+
return ViewHolder(view)
59+
}
60+
61+
@RequiresApi(Build.VERSION_CODES.O)
62+
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
63+
holder.bind(getItem(position))
64+
}
65+
66+
}

android/app/src/main/java/com/example/todo/ui/ToDoActivity.kt renamed to android/app/src/main/java/com/example/todo/ui/toDo/ToDoActivity.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
package com.example.todo.ui
1+
package com.example.todo.ui.toDo
22

3+
import android.os.Build
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
56
import android.view.Menu
7+
import android.view.MenuItem
8+
import androidx.annotation.RequiresApi
69
import androidx.appcompat.widget.Toolbar
10+
import androidx.core.view.GravityCompat
11+
import androidx.drawerlayout.widget.DrawerLayout
712
import androidx.recyclerview.widget.LinearLayoutManager
813
import androidx.recyclerview.widget.RecyclerView
914
import com.example.todo.R
1015
import com.example.todo.common.TodoDiffCallback
1116
import com.example.todo.model.TodoItem
17+
import java.time.Duration
18+
import java.time.LocalDateTime
19+
import java.time.ZoneId
1220

1321
class ToDoActivity : AppCompatActivity() {
1422
lateinit var rv: RecyclerView
23+
lateinit var rv2:RecyclerView
24+
lateinit var draw:DrawerLayout
25+
1526
override fun onCreate(savedInstanceState: Bundle?) {
1627
super.onCreate(savedInstanceState)
1728
setContentView(R.layout.activity_todo)
1829
val toolbar= findViewById<Toolbar>(R.id.tb_main)
1930
setSupportActionBar(toolbar)
2031
supportActionBar?.setDisplayShowTitleEnabled(false)
21-
32+
draw= findViewById(R.id.draw)
2233

2334
val adapter = TodoAdapter(TodoDiffCallback())
2435
rv = findViewById(R.id.rv)
36+
rv2= findViewById(R.id.rv2)
2537
rv.adapter = adapter
2638
rv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
39+
rv2.adapter=adapter
40+
rv2.layoutManager= LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
2741

2842
val list = mutableListOf<TodoItem>()
2943
list.add(
@@ -43,10 +57,24 @@ class ToDoActivity : AppCompatActivity() {
4357
)
4458

4559
adapter.submitList(list)
60+
61+
4662
}
4763

64+
4865
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
4966
menuInflater.inflate(R.menu.toolbar_action, menu)
5067
return true
5168
}
69+
70+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
71+
when(item.itemId){
72+
R.id.action_menu-> {
73+
draw.openDrawer(GravityCompat.END)
74+
}
75+
76+
}
77+
78+
return super.onOptionsItemSelected(item)
79+
}
5280
}

android/app/src/main/java/com/example/todo/ui/TodoAdapter.kt renamed to android/app/src/main/java/com/example/todo/ui/toDo/TodoAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.todo.ui
1+
package com.example.todo.ui.toDo
22

33
import android.view.LayoutInflater
44
import android.view.View

0 commit comments

Comments
 (0)