moving the Go To Date handling of month fragment to the fragment holder

This commit is contained in:
tibbi 2019-03-06 20:13:49 +01:00
parent bbd34a9870
commit 494b9efacd
8 changed files with 36 additions and 39 deletions

View file

@ -173,7 +173,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
when (item.itemId) { when (item.itemId) {
R.id.change_view -> showViewDialog() R.id.change_view -> showViewDialog()
R.id.go_to_today -> goToToday() R.id.go_to_today -> goToToday()
R.id.go_to_date -> goToDate() R.id.go_to_date -> showGoToDateDialog()
R.id.filter -> showFilterDialog() R.id.filter -> showFilterDialog()
R.id.refresh_caldav_calendars -> refreshCalDAVCalendars(true) R.id.refresh_caldav_calendars -> refreshCalDAVCalendars(true)
R.id.add_holidays -> addHolidays() R.id.add_holidays -> addHolidays()
@ -341,8 +341,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
currentFragments.last().goToToday() currentFragments.last().goToToday()
} }
private fun goToDate() { fun showGoToDateDialog() {
currentFragments.last().goToDate() currentFragments.last().showGoToDateDialog()
} }
private fun resetActionBarTitle() { private fun resetActionBarTitle() {

View file

@ -99,7 +99,7 @@ class DayFragmentsHolder : MyFragmentHolder(), NavigationListener {
setupFragment() setupFragment()
} }
override fun goToDate() { override fun showGoToDateDialog() {
} }

View file

@ -175,7 +175,7 @@ class EventListFragment : MyFragmentHolder(), RefreshRecyclerViewListener {
override fun goToToday() {} override fun goToToday() {}
override fun goToDate() {} override fun showGoToDateDialog() {}
override fun refreshEvents() { override fun refreshEvents() {
checkEvents() checkEvents()

View file

@ -6,9 +6,7 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.DatePicker
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity 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.interfaces.NavigationListener
import com.simplemobiletools.calendar.pro.models.DayMonthly import com.simplemobiletools.calendar.pro.models.DayMonthly
import com.simplemobiletools.commons.extensions.applyColorFilter 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.fragment_month.view.*
import kotlinx.android.synthetic.main.top_navigation.view.* import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime import org.joda.time.DateTime
@ -137,35 +132,11 @@ class MonthFragment : Fragment(), MonthlyCalendar {
mHolder.top_value.apply { mHolder.top_value.apply {
setTextColor(mConfig.textColor) setTextColor(mConfig.textColor)
setOnClickListener { 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>) { private fun updateDays(days: ArrayList<DayMonthly>) {
mHolder.month_view_wrapper.updateDays(days) { mHolder.month_view_wrapper.updateDays(days) {
(activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(it.code)) (activity as MainActivity).openDayFromMonthly(Formatter.getDateTimeFromCode(it.code))

View file

@ -1,10 +1,13 @@
package com.simplemobiletools.calendar.pro.fragments package com.simplemobiletools.calendar.pro.fragments
import android.content.res.Resources
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.DatePicker
import androidx.appcompat.app.AlertDialog
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.MainActivity 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.DAY_CODE
import com.simplemobiletools.calendar.pro.helpers.Formatter import com.simplemobiletools.calendar.pro.helpers.Formatter
import com.simplemobiletools.calendar.pro.interfaces.NavigationListener 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.extensions.updateActionBarTitle
import com.simplemobiletools.commons.views.MyViewPager import com.simplemobiletools.commons.views.MyViewPager
import kotlinx.android.synthetic.main.fragment_months_holder.view.* import kotlinx.android.synthetic.main.fragment_months_holder.view.*
@ -99,8 +105,28 @@ class MonthFragmentsHolder : MyFragmentHolder(), NavigationListener {
setupFragment() 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() { override fun refreshEvents() {

View file

@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
abstract class MyFragmentHolder : Fragment() { abstract class MyFragmentHolder : Fragment() {
abstract fun goToToday() abstract fun goToToday()
abstract fun goToDate() abstract fun showGoToDateDialog()
abstract fun refreshEvents() abstract fun refreshEvents()

View file

@ -130,7 +130,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener {
setupFragment() setupFragment()
} }
override fun goToDate() { override fun showGoToDateDialog() {
} }

View file

@ -83,7 +83,7 @@ class YearFragmentsHolder : MyFragmentHolder() {
setupFragment() setupFragment()
} }
override fun goToDate() { override fun showGoToDateDialog() {
} }