feat: Add support for moving between months
This commit is contained in:
parent
a1d96a4d01
commit
19e097e88f
|
@ -4,6 +4,7 @@ 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
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -19,6 +20,10 @@ import java.util.Locale
|
|||
class CalendarActivity : AppCompatActivity() {
|
||||
private lateinit var tvMonthYear: TextView
|
||||
private lateinit var rvCalendar: RecyclerView
|
||||
private lateinit var btnPreviousMonth: ImageButton
|
||||
private lateinit var btnNextMonth: ImageButton
|
||||
|
||||
private var currentYearMonth: YearMonth = YearMonth.now()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -32,9 +37,20 @@ class CalendarActivity : AppCompatActivity() {
|
|||
|
||||
tvMonthYear = findViewById(R.id.tvMonthYear)
|
||||
rvCalendar = findViewById(R.id.rvCalendar)
|
||||
btnPreviousMonth = findViewById(R.id.btnPreviousMonth)
|
||||
btnNextMonth = findViewById(R.id.btnNextMonth)
|
||||
|
||||
val currentMonth = YearMonth.now()
|
||||
setCalendarForMonth(currentMonth)
|
||||
setCalendarForMonth(currentYearMonth)
|
||||
|
||||
btnPreviousMonth.setOnClickListener {
|
||||
currentYearMonth = currentYearMonth.minusMonths(1)
|
||||
setCalendarForMonth(currentYearMonth)
|
||||
}
|
||||
|
||||
btnNextMonth.setOnClickListener {
|
||||
currentYearMonth = currentYearMonth.plusMonths(1)
|
||||
setCalendarForMonth(currentYearMonth)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setCalendarForMonth(yearMonth: YearMonth) {
|
||||
|
|
9
app/src/main/res/drawable/ic_arrow_left.xml
Normal file
9
app/src/main/res/drawable/ic_arrow_left.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:pathData="M560,680 L360,480l200,-200v400Z"
|
||||
android:fillColor="#e8eaed"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_arrow_right.xml
Normal file
9
app/src/main/res/drawable/ic_arrow_right.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:pathData="M400,680v-400l200,200 -200,200Z"
|
||||
android:fillColor="#e8eaed"/>
|
||||
</vector>
|
|
@ -7,6 +7,20 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context=".activities.CalendarActivity">
|
||||
|
||||
<!-- Previous Month Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnPreviousMonth"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:padding="8dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_left"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvMonthYear"
|
||||
android:contentDescription="@string/previous_month" />
|
||||
|
||||
<!-- Month-Year Text -->
|
||||
<TextView
|
||||
android:id="@+id/tvMonthYear"
|
||||
android:layout_width="0dp"
|
||||
|
@ -17,6 +31,21 @@
|
|||
tools:text="January 2024"
|
||||
android:textAppearance="?attr/textAppearanceHeadline6"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/btnPreviousMonth"
|
||||
app:layout_constraintEnd_toStartOf="@id/btnNextMonth" />
|
||||
|
||||
<!-- Next Month Button -->
|
||||
<ImageButton
|
||||
android:id="@+id/btnNextMonth"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:padding="8dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_right"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/tvMonthYear"
|
||||
android:contentDescription="@string/next_month" />
|
||||
|
||||
<!-- Day Names Row -->
|
||||
<LinearLayout
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
<string name="base_url_hint">https://myapiurl.com</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="previous_month">Previous Month</string>
|
||||
<string name="next_month">Next Month</string>
|
||||
<string name="monday_short">Mo</string>
|
||||
<string name="tuesday_short">Tu</string>
|
||||
<string name="wednesday_short">We</string>
|
||||
|
|
Loading…
Reference in a new issue