mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-16 20:00:39 +01:00
show the day picking dialog on day label click
This commit is contained in:
parent
7520656d2c
commit
ff9e691c68
@ -5,9 +5,11 @@ import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.*
|
||||
import android.widget.AbsListView
|
||||
import android.widget.AdapterView
|
||||
import android.widget.DatePicker
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.calendar.*
|
||||
import com.simplemobiletools.calendar.Formatter
|
||||
@ -41,6 +43,7 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
|
||||
val day = Formatter.getEventDate(activity.applicationContext, mDayCode)
|
||||
mHolder.month_value.text = day
|
||||
mHolder.month_value.setOnClickListener { pickDay() }
|
||||
|
||||
setupButtons()
|
||||
return view
|
||||
@ -78,6 +81,30 @@ class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnIte
|
||||
mListener = listener
|
||||
}
|
||||
|
||||
fun pickDay() {
|
||||
val theme = if (mConfig.isDarkTheme) R.style.MyAlertDialog_Dark else R.style.MyAlertDialog
|
||||
val alertDialog = AlertDialog.Builder(context, theme)
|
||||
val view = getLayoutInflater(arguments).inflate(R.layout.date_picker, null)
|
||||
val datePicker = view.findViewById(R.id.date_picker) as DatePicker
|
||||
|
||||
val dateTime = Formatter.getDateTimeFromCode(mDayCode)
|
||||
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, dateTime.dayOfMonth, null)
|
||||
|
||||
alertDialog.apply {
|
||||
setView(view)
|
||||
setNegativeButton(R.string.cancel, null)
|
||||
setPositiveButton(R.string.ok) { dialog, id ->
|
||||
val month = datePicker.month + 1
|
||||
val year = datePicker.year
|
||||
val day = datePicker.dayOfMonth
|
||||
val newDateTime = dateTime.withDayOfMonth(day).withMonthOfYear(month).withYear(year)
|
||||
mListener?.goToDateTime(newDateTime)
|
||||
}
|
||||
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkEvents() {
|
||||
val startTS = Formatter.getDayStartTS(mDayCode)
|
||||
val endTS = Formatter.getDayEndTS(mDayCode)
|
||||
|
@ -113,15 +113,18 @@ class MonthFragment : Fragment(), Calendar {
|
||||
val dateTime = DateTime(mCalendar!!.targetDate.toString())
|
||||
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)
|
||||
|
||||
alertDialog.setView(view)
|
||||
alertDialog.setNegativeButton(R.string.cancel, null)
|
||||
alertDialog.setPositiveButton(R.string.ok) { dialog, id ->
|
||||
val month = datePicker.month + 1
|
||||
val year = datePicker.year
|
||||
mListener?.goToDateTime(DateTime().withMonthOfYear(month).withYear(year))
|
||||
}
|
||||
alertDialog.apply {
|
||||
setView(view)
|
||||
setNegativeButton(R.string.cancel, null)
|
||||
setPositiveButton(R.string.ok) { dialog, id ->
|
||||
val month = datePicker.month + 1
|
||||
val year = datePicker.year
|
||||
val newDateTime = dateTime.withMonthOfYear(month).withYear(year)
|
||||
mListener?.goToDateTime(newDateTime)
|
||||
}
|
||||
|
||||
alertDialog.show()
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun hideDayPicker(datePicker: DatePicker) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user