-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
236 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/main/java/com/ssjm/sw_hackathon/goal/recycler/DayOfWeekAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.ssjm.sw_hackathon.goal.recycler | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.ssjm.sw_hackathon.R | ||
import com.ssjm.sw_hackathon.databinding.ItemDayOfTodoBinding | ||
|
||
class DayOfWeekAdapter (private val context: Context, | ||
) : RecyclerView.Adapter<DayOfWeekAdapter.DayOfWeekViewHolder>() { | ||
|
||
var items = mutableListOf<DayOfWeekItem>() | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : | ||
DayOfWeekViewHolder { | ||
|
||
val view = LayoutInflater.from(context).inflate(R.layout.item_day_of_todo, parent, false) | ||
|
||
return DayOfWeekViewHolder(ItemDayOfTodoBinding.bind(view)) | ||
} | ||
|
||
override fun getItemCount(): Int = items.size | ||
|
||
override fun onBindViewHolder(holder: DayOfWeekViewHolder, position: Int) { | ||
holder.bind(items[position]) | ||
|
||
// 날짜 아이템 클릭 시 | ||
holder.itemView.setOnClickListener { | ||
for(i: Int in 0..(items.size - 1)) { | ||
if(i == position) | ||
items[i].selected = true | ||
else | ||
items[i].selected = false | ||
} | ||
notifyDataSetChanged() | ||
} | ||
} | ||
|
||
inner class DayOfWeekViewHolder(private val binding: ItemDayOfTodoBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun bind(item: DayOfWeekItem) { | ||
// 요일 | ||
binding.textTodoListDay.text = item.dayOfWeek | ||
|
||
// 일 | ||
binding.textTodoListDate.text = item.day.toString() | ||
|
||
// 달성도 | ||
if(item.progress == "done") { | ||
binding.textTodoListDate.setTextColor(context.resources.getColor(R.color.white)) | ||
binding.textTodoListDate.setBackgroundResource(R.drawable.shape_todo_round_done) | ||
} | ||
else if(item.progress == "fail") { | ||
binding.textTodoListDate.setTextColor(context.resources.getColor(R.color.white)) | ||
binding.textTodoListDate.setBackgroundResource(R.drawable.shape_todo_round_fail) | ||
} | ||
else if(item.progress == "some") { | ||
binding.textTodoListDate.setTextColor(context.resources.getColor(R.color.white)) | ||
binding.textTodoListDate.setBackgroundResource(R.drawable.shape_todo_round_some) | ||
} | ||
else if(item.progress == "none") { | ||
binding.textTodoListDate.setTextColor(context.resources.getColor(R.color.gray04)) | ||
binding.textTodoListDate.setBackgroundResource(R.drawable.shape_todo_round_none) | ||
} | ||
|
||
// 선택 유무 | ||
if(item.selected) { | ||
binding.linearTodoBox.setBackgroundResource(R.drawable.shape_todo_today) | ||
binding.textTodoListDay.setTextColor(context.resources.getColor(R.color.white)) | ||
} | ||
else { | ||
binding.linearTodoBox.setBackgroundResource(R.drawable.shape_todo_today_not) | ||
binding.textTodoListDay.setTextColor(context.resources.getColor(R.color.black03)) | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/ssjm/sw_hackathon/goal/recycler/DayOfWeekItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ssjm.sw_hackathon.goal.recycler | ||
|
||
import java.time.LocalDate | ||
|
||
data class DayOfWeekItem( | ||
var date: LocalDate, // 날짜 | ||
var day: Int, // 일 | ||
var dayOfWeek: String, // 요일 | ||
var progress: String, // 진행도: done, some, fail, none | ||
var selected: Boolean = false, // 선택 유무 | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/res/layouts/goal/drawable/shape_todo_round_none.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:padding="10dp" | ||
android:shape="rectangle"> | ||
|
||
<solid android:color="@color/gray06"/> | ||
<corners | ||
android:radius="20dp" /> | ||
|
||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters