chore: Improve file structure
This commit is contained in:
parent
c68515a42c
commit
e481bb70fc
|
@ -1,9 +1,6 @@
|
|||
package com.p_vacho.neat_calendar.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
@ -13,6 +10,8 @@ import androidx.core.view.WindowInsetsCompat
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.p_vacho.neat_calendar.R
|
||||
import com.p_vacho.neat_calendar.adapters.CalendarAdapter
|
||||
import com.p_vacho.neat_calendar.models.CalendarDay
|
||||
import org.threeten.bp.YearMonth
|
||||
import org.threeten.bp.format.TextStyle
|
||||
import java.util.Locale
|
||||
|
@ -69,16 +68,16 @@ class CalendarActivity : AppCompatActivity() {
|
|||
val startOffset = (dayOfWeek - 1 + 7) % 7
|
||||
|
||||
// Generate calendar days
|
||||
val days = mutableListOf<Day>()
|
||||
val days = mutableListOf<CalendarDay>()
|
||||
|
||||
// Add padding for days of the previous month
|
||||
for (i in 1..startOffset) {
|
||||
days.add(Day(dayNumber = ""))
|
||||
days.add(CalendarDay(dayNumber = ""))
|
||||
}
|
||||
|
||||
// Add the actual days of the current month
|
||||
for (i in 1..daysInMonth) {
|
||||
days.add(Day(dayNumber = i.toString(), hasEvents = eventDays.contains(i)))
|
||||
days.add(CalendarDay(dayNumber = i.toString(), hasEvents = eventDays.contains(i)))
|
||||
}
|
||||
|
||||
// Set up RecyclerView
|
||||
|
@ -86,38 +85,3 @@ class CalendarActivity : AppCompatActivity() {
|
|||
rvCalendar.adapter = CalendarAdapter(days)
|
||||
}
|
||||
}
|
||||
|
||||
data class Day(
|
||||
val dayNumber: String, // Day of the month (e.g., "1", "2", ...)
|
||||
val hasEvents: Boolean = false
|
||||
)
|
||||
|
||||
class CalendarAdapter(private val days: List<Day>) :
|
||||
RecyclerView.Adapter<CalendarAdapter.DayViewHolder>() {
|
||||
|
||||
class DayViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val tvDay: TextView = itemView.findViewById(R.id.tvDay)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DayViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_calendar_day, parent, false)
|
||||
return DayViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: DayViewHolder, position: Int) {
|
||||
val day = days[position]
|
||||
|
||||
// Set the day number
|
||||
holder.tvDay.text = day.dayNumber
|
||||
|
||||
// Visually indicate days with events
|
||||
if (day.hasEvents) {
|
||||
holder.tvDay.setBackgroundResource(R.drawable.event_indicator_background)
|
||||
} else {
|
||||
holder.tvDay.setBackgroundResource(android.R.color.transparent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = days.size
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.p_vacho.neat_calendar.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.p_vacho.neat_calendar.R
|
||||
import com.p_vacho.neat_calendar.models.CalendarDay
|
||||
|
||||
class CalendarAdapter(private val days: List<CalendarDay>) :
|
||||
RecyclerView.Adapter<CalendarAdapter.DayViewHolder>() {
|
||||
|
||||
class DayViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val tvDay: TextView = itemView.findViewById(R.id.tvDay)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DayViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_calendar_day, parent, false)
|
||||
return DayViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: DayViewHolder, position: Int) {
|
||||
val day = days[position]
|
||||
|
||||
// Set the day number
|
||||
holder.tvDay.text = day.dayNumber
|
||||
|
||||
// Visually indicate days with events
|
||||
if (day.hasEvents) {
|
||||
holder.tvDay.setBackgroundResource(R.drawable.event_indicator_background)
|
||||
} else {
|
||||
holder.tvDay.setBackgroundResource(android.R.color.transparent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = days.size
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.p_vacho.neat_calendar.models
|
||||
|
||||
data class CalendarDay(
|
||||
val dayNumber: String, // Day of the month (e.g., "1", "2", ...)
|
||||
val hasEvents: Boolean = false
|
||||
)
|
Loading…
Reference in a new issue