moving the Go To Date handling of month fragment to the fragment holder
This commit is contained in:
parent
bbd34a9870
commit
494b9efacd
8 changed files with 36 additions and 39 deletions
|
@ -173,7 +173,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
when (item.itemId) {
|
||||
R.id.change_view -> showViewDialog()
|
||||
R.id.go_to_today -> goToToday()
|
||||
R.id.go_to_date -> goToDate()
|
||||
R.id.go_to_date -> showGoToDateDialog()
|
||||
R.id.filter -> showFilterDialog()
|
||||
R.id.refresh_caldav_calendars -> refreshCalDAVCalendars(true)
|
||||
R.id.add_holidays -> addHolidays()
|
||||
|
@ -341,8 +341,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
currentFragments.last().goToToday()
|
||||
}
|
||||
|
||||
private fun goToDate() {
|
||||
currentFragments.last().goToDate()
|
||||
fun showGoToDateDialog() {
|
||||
currentFragments.last().showGoToDateDialog()
|
||||
}
|
||||
|
||||
private fun resetActionBarTitle() {
|
||||
|
|
|
@ -99,7 +99,7 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
|||
setupFragment()
|
||||
}
|
||||
|
||||
override fun goToDate() {
|
||||
override fun showGoToDateDialog() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
|
|||
|
||||
override fun goToToday() {}
|
||||
|
||||
override fun goToDate() {}
|
||||
override fun showGoToDateDialog() {}
|
||||
|
||||
override fun refreshEvents() {
|
||||
checkEvents()
|
||||
|
|
|
@ -6,9 +6,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.DatePicker
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.MainActivity
|
||||
|
@ -21,9 +19,6 @@ import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar
|
|||
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener
|
||||
import com.simplemobiletools.calendar.pro.models.DayMonthly
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.getDialogTheme
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import kotlinx.android.synthetic.main.fragment_month.view.*
|
||||
import kotlinx.android.synthetic.main.top_navigation.view.*
|
||||
import org.joda.time.DateTime
|
||||
|
@ -137,35 +132,11 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
|||
mHolder.top_value.apply {
|
||||
setTextColor(mConfig.textColor)
|
||||
setOnClickListener {
|
||||
showMonthDialog()
|
||||
(activity as MainActivity).showGoToDateDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMonthDialog() {
|
||||
activity!!.setTheme(context!!.getDialogTheme())
|
||||
val view = layoutInflater.inflate(R.layout.date_picker, null)
|
||||
val datePicker = view.findViewById<DatePicker>(R.id.date_picker)
|
||||
datePicker.findViewById<View>(Resources.getSystem().getIdentifier("day", "id", "android")).beGone()
|
||||
|
||||
val dateTime = DateTime(mCalendar!!.mTargetDate.toString())
|
||||
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)
|
||||
|
||||
AlertDialog.Builder(context!!)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> positivePressed(dateTime, datePicker) }
|
||||
.create().apply {
|
||||
activity?.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun positivePressed(dateTime: DateTime, datePicker: DatePicker) {
|
||||
val month = datePicker.month + 1
|
||||
val year = datePicker.year
|
||||
val newDateTime = dateTime.withDate(year, month, 1)
|
||||
listener?.goToDateTime(newDateTime)
|
||||
}
|
||||
|
||||
private fun updateDays(days: ArrayList<DayMonthly>) {
|
||||
mHolder.month_view_wrapper.updateDays(days) {
|
||||
(activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(it.code))
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package com.simplemobiletools.calendar.pro.fragments
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.DatePicker
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.MainActivity
|
||||
|
@ -14,6 +17,9 @@ import com.simplemobiletools.calendar.pro.extensions.getMonthCode
|
|||
import com.simplemobiletools.calendar.pro.helpers.DAY_CODE
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.getDialogTheme
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.updateActionBarTitle
|
||||
import com.simplemobiletools.commons.views.MyViewPager
|
||||
import kotlinx.android.synthetic.main.fragment_months_holder.view.*
|
||||
|
@ -99,8 +105,28 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
|
|||
setupFragment()
|
||||
}
|
||||
|
||||
override fun goToDate() {
|
||||
override fun showGoToDateDialog() {
|
||||
activity!!.setTheme(context!!.getDialogTheme())
|
||||
val view = layoutInflater.inflate(R.layout.date_picker, null)
|
||||
val datePicker = view.findViewById<DatePicker>(R.id.date_picker)
|
||||
datePicker.findViewById<View>(Resources.getSystem().getIdentifier("day", "id", "android")).beGone()
|
||||
|
||||
val dateTime = DateTime(Formatter.getDateTimeFromCode(currentDayCode).toString())
|
||||
datePicker.init(dateTime.year, dateTime.monthOfYear - 1, 1, null)
|
||||
|
||||
AlertDialog.Builder(context!!)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.ok) { dialog, which -> datePicked(dateTime, datePicker) }
|
||||
.create().apply {
|
||||
activity?.setupDialogStuff(view, this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun datePicked(dateTime: DateTime, datePicker: DatePicker) {
|
||||
val month = datePicker.month + 1
|
||||
val year = datePicker.year
|
||||
val newDateTime = dateTime.withDate(year, month, 1)
|
||||
goToDateTime(newDateTime)
|
||||
}
|
||||
|
||||
override fun refreshEvents() {
|
||||
|
|
|
@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
|
|||
abstract class MyFragmentHolder : Fragment() {
|
||||
abstract fun goToToday()
|
||||
|
||||
abstract fun goToDate()
|
||||
abstract fun showGoToDateDialog()
|
||||
|
||||
abstract fun refreshEvents()
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
|
|||
setupFragment()
|
||||
}
|
||||
|
||||
override fun goToDate() {
|
||||
override fun showGoToDateDialog() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class YearFragmentsHolder : MyFragmentHolder() {
|
|||
setupFragment()
|
||||
}
|
||||
|
||||
override fun goToDate() {
|
||||
override fun showGoToDateDialog() {
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue