-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from TeamCatchMe/feature/calendar_challenge
- Loading branch information
Showing
13 changed files
with
434 additions
and
3 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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/teamcatchme/calendar/CalendarActivity.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,51 @@ | ||
package com.teamcatchme.calendar | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.teamcatchme.catchmesample.databinding.ActivityCalendarBinding | ||
import java.time.LocalDate | ||
|
||
class CalendarActivity : AppCompatActivity() { | ||
companion object { | ||
const val RIGHT = 1 | ||
const val LEFT = -1 | ||
} | ||
|
||
private fun onArrowClicked(direction: Int) { | ||
binding.viewpagerCalendar.setCurrentItem( | ||
binding.viewpagerCalendar.currentItem + direction, | ||
true | ||
) | ||
} | ||
|
||
lateinit var binding: ActivityCalendarBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityCalendarBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
val monthAdapter = MonthAdapter() | ||
val dateTime = LocalDate.now() | ||
val currentYear = dateTime.year | ||
val currentMonth = dateTime.month.value | ||
Log.d("태그", "set current month ${36 + currentMonth}") | ||
binding.viewpagerCalendar.adapter = monthAdapter | ||
binding.viewpagerCalendar.currentItem = 35 + currentMonth | ||
updateTxtUI(currentYear, currentMonth) | ||
binding.viewpagerCalendar.registerOnPageChangeCallback(object : | ||
ViewPager2.OnPageChangeCallback() { | ||
override fun onPageSelected(position: Int) { | ||
updateTxtUI(currentYear - 3 + (position / 12), (position % 12) + 1) | ||
} | ||
}) | ||
binding.btnReportDialogMoveLeft.setOnClickListener { onArrowClicked(LEFT) } | ||
binding.btnReportDialogMoveRight.setOnClickListener { onArrowClicked(RIGHT) } | ||
} | ||
|
||
fun updateTxtUI(year: Int, month: Int) { | ||
val txtYearMonth = "$year - $month" | ||
binding.txtCalendarYearmonth.text = txtYearMonth | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/src/main/java/com/teamcatchme/calendar/CalendarAdapter.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,118 @@ | ||
package com.teamcatchme.calendar | ||
|
||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.teamcatchme.catchmesample.R | ||
import com.teamcatchme.catchmesample.databinding.ItemCalendarCachuFalseBinding | ||
import com.teamcatchme.catchmesample.databinding.ItemCalendarCachuTrueBinding | ||
import com.teamcatchme.catchmesample.databinding.ItemCalendarNoBinding | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
import kotlin.collections.HashMap | ||
|
||
class CalendarAdapter(val yearMonth: String) : | ||
RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
|
||
private val dateData = mutableListOf<HashMap<Int, Int>>() | ||
private val cachuData = HashMap<Int, Int>() | ||
|
||
fun setCachuData(newData: HashMap<Int, Int>) { | ||
cachuData.clear() | ||
cachuData.putAll(newData) | ||
setDateData() | ||
} | ||
|
||
private fun setDateData() { | ||
val firstDateFormat = "$yearMonth-01" | ||
val calendar = Calendar.getInstance() | ||
calendar.time = SimpleDateFormat("yyyy-MM-dd").parse(firstDateFormat) | ||
val firstDateOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1 | ||
val lastDate = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) | ||
|
||
for (i in 1..firstDateOfWeek) { | ||
dateData.add(hashMapOf(-1 to -1)) | ||
} | ||
for (i in 1..lastDate) { | ||
val idx = cachuData[i] ?: 0 | ||
dateData.add(hashMapOf(i to idx)) | ||
} | ||
for (i in firstDateOfWeek + lastDate + 1..42) { | ||
dateData.add(hashMapOf(-1 to -1)) | ||
} | ||
|
||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int { | ||
return dateData[position].values.first() | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
return when (viewType) { | ||
-1 -> { | ||
val binding = ItemCalendarNoBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
NoneTypeViewHolder(binding) | ||
} | ||
0 -> { | ||
val binding = ItemCalendarCachuFalseBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
DateTypeViewHolder(binding) | ||
} | ||
else -> { | ||
val binding = ItemCalendarCachuTrueBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
CachuTypeViewHolder(binding) | ||
} | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
val obj = dateData[position] | ||
when (obj.values.first()) { | ||
-1 -> (holder as NoneTypeViewHolder) | ||
0 -> (holder as DateTypeViewHolder).onBind(obj.keys.first()) | ||
else -> (holder as CachuTypeViewHolder).onBind( | ||
obj.keys.first(), | ||
obj.values.first(), | ||
yearMonth | ||
) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = dateData.size | ||
|
||
class NoneTypeViewHolder(binding: ItemCalendarNoBinding) : RecyclerView.ViewHolder(binding.root) | ||
|
||
class DateTypeViewHolder(private val binding: ItemCalendarCachuFalseBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(date: Int) { | ||
binding.txtCalendarDate.text = date.toString() | ||
} | ||
} | ||
|
||
class CachuTypeViewHolder(private val binding: ItemCalendarCachuTrueBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(date: Int, cachuIdx: Int, yearMonth: String) { | ||
binding.txtCalendarDate.text = date.toString() | ||
binding.imgCalendarCachu.setImageResource(R.drawable.ic_cachu1) | ||
binding.constraintCalendarCachuTrue.setOnClickListener { | ||
val txtCalendarToast = "$yearMonth-$date" | ||
Log.d("태그", "clicked : $txtCalendarToast") | ||
// 여기에 Dialog 띄우는 로직 | ||
} | ||
} | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/teamcatchme/calendar/CalendarYearMonthData.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,6 @@ | ||
package com.teamcatchme.calendar | ||
|
||
data class CalendarYearMonthData( | ||
val year: Int, | ||
val month: Int | ||
) |
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/teamcatchme/calendar/MonthAdapter.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,57 @@ | ||
package com.teamcatchme.calendar | ||
|
||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.teamcatchme.catchmesample.databinding.ItemCalendarMonthBinding | ||
import java.time.LocalDate | ||
|
||
class MonthAdapter : | ||
ListAdapter<String, MonthAdapter.ViewHolder>(CalendarAdapterUtilCallBack()) { | ||
private val yearList = mutableListOf<String>() | ||
|
||
init { | ||
val dateTime = LocalDate.now() | ||
val currentYear = dateTime.year | ||
for (year in currentYear - 3..currentYear) { | ||
for (month in 1..12) { | ||
val txtYearMonth = year.toString() + "-" + String.format("%02d", month) | ||
yearList.add(txtYearMonth) | ||
} | ||
} | ||
this.submitList(yearList) | ||
} | ||
|
||
class ViewHolder(private val dataBinding: ItemCalendarMonthBinding) : | ||
RecyclerView.ViewHolder(dataBinding.root) { | ||
fun onBind(yearMonth: String) { | ||
val calendarAdapter = CalendarAdapter(yearMonth) | ||
// 여기서 서버 통신으로 캐츄 데이터를 받아온다 | ||
val cachuData = hashMapOf(5 to 1) | ||
calendarAdapter.setCachuData(cachuData) | ||
dataBinding.rcvCalendar.adapter = calendarAdapter | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val binding = | ||
ItemCalendarMonthBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
Log.d("태그", "$position, ${yearList[position]}") | ||
holder.onBind(getItem(position)) | ||
} | ||
|
||
class CalendarAdapterUtilCallBack : DiffUtil.ItemCallback<String>() { | ||
override fun areItemsTheSame(oldItem: String, newItem: String): Boolean = | ||
oldItem.hashCode() == newItem.hashCode() | ||
|
||
override fun areContentsTheSame(oldItem: String, newItem: String): Boolean = | ||
oldItem == newItem | ||
} | ||
} |
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 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="48" | ||
android:viewportHeight="48"> | ||
<path | ||
android:fillAlpha="0.3" | ||
android:fillColor="@color/black" | ||
android:pathData="M23.9993,24.0004L28,20.0011L26.0004,18L20,24.0004L26.0004,30.0007L28,27.9996L23.9993,24.0004Z" | ||
android:strokeAlpha="0.3" /> | ||
</vector> |
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 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="48dp" | ||
android:height="48dp" | ||
android:viewportWidth="48" | ||
android:viewportHeight="48"> | ||
<path | ||
android:fillAlpha="0.3" | ||
android:fillColor="@color/black" | ||
android:pathData="M24,24l-4,-3.999L22,18l6,6 -6,6 -2,-2 4,-4z" | ||
android:strokeAlpha="0.3" /> | ||
</vector> |
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,12 @@ | ||
<vector android:height="40dp" android:viewportHeight="65" | ||
android:viewportWidth="65" android:width="40dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="#1C1D1D" android:pathData="M31.9824,55.0133C41.6586,55.0133 49.5027,53.6992 49.5027,52.0782C49.5027,50.4572 41.6586,49.1431 31.9824,49.1431C22.3062,49.1431 14.4622,50.4572 14.4622,52.0782C14.4622,53.6992 22.3062,55.0133 31.9824,55.0133Z"/> | ||
<path android:fillColor="#5B81A6" android:pathData="M39.11,46.9218C25.1876,46.9218 15.9305,43.4764 15.1631,31.3146C15.1386,30.9432 15.1484,30.5718 15.1852,30.2004C15.6167,25.7946 17.1342,21.5085 18.7669,17.2029C19.4632,15.3654 19.9069,13.9066 20.5247,12.609C20.0834,12.8338 19.6495,13.0684 19.2254,13.3152C19.1739,13.3445 19.1224,13.3787 19.0734,13.4154C15.4598,16.0789 15.146,18.3001 13.6162,22.3369C11.9859,26.6425 10.466,30.9286 10.0345,35.3344C9.9977,35.7033 9.9903,36.0772 10.0124,36.4486C10.7797,48.6128 20.0368,52.0558 33.9592,52.0558C46.2342,52.0558 51.3236,52.1316 55.6188,45.0769C51.9635,46.9536 47.0359,46.9218 39.11,46.9218Z"/> | ||
<path android:fillColor="#709CD2" android:pathData="M57.7297,39.9791C58.025,32.9693 56.4302,28.4756 54.1635,24.5693C51.9731,20.7952 52.7016,17.9708 49.6252,14.5051C49.5292,14.3974 49.416,14.3044 49.2929,14.2285C48.3528,13.6558 47.3683,13.1393 46.3494,12.6792C41.9932,11.1642 39.3672,11.4995 34.7501,11.4995C30.1355,11.4995 27.32,10.0848 21.7086,12.011C21.6545,12.0306 21.5979,12.0526 21.5462,12.0771C21.1893,12.2411 20.8399,12.4124 20.4928,12.5886C19.8726,13.8883 19.4272,15.3519 18.7282,17.19C17.0916,21.5026 15.5657,25.7956 15.1325,30.2085C15.0956,30.5781 15.0882,30.9525 15.1104,31.3246C15.8807,43.5084 25.1739,46.957 39.1506,46.957C47.1074,46.957 52.0568,46.9864 55.7238,45.1067C56.1742,44.37 56.6148,43.5574 57.0528,42.6567C57.4589,41.8196 57.6903,40.9067 57.7297,39.9791Z"/> | ||
<path android:fillColor="#222222" android:pathData="M31.8367,27.76C31.9651,26.9265 31.5138,26.1652 30.8288,26.0597C30.1437,25.9542 29.4843,26.5444 29.356,27.378C29.2276,28.2115 29.6789,28.9728 30.3639,29.0783C31.0489,29.1838 31.7083,28.5936 31.8367,27.76Z"/> | ||
<path android:fillColor="#222222" android:pathData="M47.2855,27.3246C47.4166,26.4737 46.9566,25.6967 46.2582,25.5891C45.5598,25.4816 44.8874,26.0842 44.7563,26.9351C44.6253,27.7861 45.0852,28.5631 45.7837,28.6706C46.4821,28.7782 47.1545,28.1756 47.2855,27.3246Z"/> | ||
<path android:fillColor="#2F4564" android:pathData="M36.0548,29.3393C36.6821,28.9154 37.3987,29.3468 38.4771,29.4017C39.5555,29.4565 41.5001,28.5812 42.3107,29.2146C43.1213,29.8481 43.1213,33.5862 39.1791,34.0326C35.2394,34.4789 34.5373,31.8007 35.1501,30.3069C35.4348,29.6161 35.6881,29.5887 36.0548,29.3393Z"/> | ||
<path android:fillColor="#D15F53" android:pathData="M38.5036,31.6672C37.0186,31.6963 36.3246,32.667 36.0286,33.2966C36.6958,33.8759 37.7586,34.2171 39.3456,34.0293C40.5394,33.8865 41.3717,33.4262 41.9322,32.8363C41.2503,32.2306 40.1196,31.6354 38.5036,31.6672Z"/> | ||
<path android:fillAlpha="0.2" android:fillColor="#ffffff" | ||
android:pathData="M48.2416,16.5985C48.6024,15.9736 47.9035,14.8947 46.6807,14.1887C45.4579,13.4827 44.1742,13.4169 43.8134,14.0418C43.4526,14.6667 44.1514,15.7456 45.3742,16.4516C46.597,17.1576 47.8808,17.2234 48.2416,16.5985Z" android:strokeAlpha="0.2"/> | ||
</vector> |
Oops, something went wrong.