some code cleanup at the day fragment

This commit is contained in:
tibbi 2018-01-19 23:48:07 +01:00
parent f3ca86e809
commit ba602c6495
3 changed files with 32 additions and 26 deletions

View File

@ -35,8 +35,9 @@ class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChange
val intent = intent ?: return val intent = intent ?: return
mDayCode = intent.getStringExtra(DAY_CODE) mDayCode = intent.getStringExtra(DAY_CODE)
if (mDayCode.isEmpty()) if (mDayCode.isEmpty()) {
return return
}
fillViewPager(mDayCode) fillViewPager(mDayCode)

View File

@ -48,13 +48,6 @@ class DayFragment : Fragment(), DeleteEventsListener {
mHolder = view.day_holder mHolder = view.day_holder
mDayCode = arguments!!.getString(DAY_CODE) mDayCode = arguments!!.getString(DAY_CODE)
val day = Formatter.getDayTitle(context!!, mDayCode)
mHolder.top_value.apply {
text = day
setOnClickListener { pickDay() }
setTextColor(context.config.textColor)
}
setupButtons() setupButtons()
return view return view
} }
@ -67,20 +60,28 @@ class DayFragment : Fragment(), DeleteEventsListener {
private fun setupButtons() { private fun setupButtons() {
mTextColor = context!!.config.textColor mTextColor = context!!.config.textColor
mHolder.apply { mHolder.top_left_arrow.apply {
top_left_arrow.applyColorFilter(mTextColor) applyColorFilter(mTextColor)
top_right_arrow.applyColorFilter(mTextColor) background = null
top_left_arrow.background = null setOnClickListener {
top_right_arrow.background = null
top_left_arrow.setOnClickListener {
mListener?.goLeft() mListener?.goLeft()
} }
}
top_right_arrow.setOnClickListener { mHolder.top_right_arrow.apply {
applyColorFilter(mTextColor)
background = null
setOnClickListener {
mListener?.goRight() mListener?.goRight()
} }
} }
val day = Formatter.getDayTitle(context!!, mDayCode)
mHolder.top_value.apply {
text = day
setOnClickListener { pickDay() }
setTextColor(context.config.textColor)
}
} }
fun getDayEventsAdapter() = mHolder.day_events?.adapter as? DayEventsAdapter fun getDayEventsAdapter() = mHolder.day_events?.adapter as? DayEventsAdapter

View File

@ -33,8 +33,8 @@ class MonthFragment : Fragment(), MonthlyCalendar {
private var mSundayFirst = false private var mSundayFirst = false
private var mDayCode = "" private var mDayCode = ""
private var mPackageName = "" private var mPackageName = ""
private var dayLabelHeight = 0 private var mDayLabelHeight = 0
private var lastHash = 0L private var mLastHash = 0L
private var mCalendar: MonthlyCalendarImpl? = null private var mCalendar: MonthlyCalendarImpl? = null
var listener: NavigationListener? = null var listener: NavigationListener? = null
@ -47,14 +47,12 @@ class MonthFragment : Fragment(), MonthlyCalendar {
val view = inflater.inflate(R.layout.fragment_month, container, false) val view = inflater.inflate(R.layout.fragment_month, container, false)
mRes = resources mRes = resources
mPackageName = activity!!.packageName mPackageName = activity!!.packageName
mHolder = view.calendar_holder mHolder = view.calendar_holder
mDayCode = arguments!!.getString(DAY_CODE) mDayCode = arguments!!.getString(DAY_CODE)
mConfig = context!!.config mConfig = context!!.config
mSundayFirst = mConfig.isSundayFirst mSundayFirst = mConfig.isSundayFirst
setupButtons() setupButtons()
setupLabels() setupLabels()
mCalendar = MonthlyCalendarImpl(this, context!!) mCalendar = MonthlyCalendarImpl(this, context!!)
@ -72,6 +70,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
mTargetDate = Formatter.getDateTimeFromCode(mDayCode) mTargetDate = Formatter.getDateTimeFromCode(mDayCode)
getDays(false) // prefill the screen asap, even if without events getDays(false) // prefill the screen asap, even if without events
} }
updateCalendar() updateCalendar()
} }
@ -81,10 +80,11 @@ class MonthFragment : Fragment(), MonthlyCalendar {
override fun updateMonthlyCalendar(context: Context, month: String, days: List<DayMonthly>, checkedEvents: Boolean) { override fun updateMonthlyCalendar(context: Context, month: String, days: List<DayMonthly>, checkedEvents: Boolean) {
val newHash = month.hashCode() + days.hashCode().toLong() val newHash = month.hashCode() + days.hashCode().toLong()
if ((lastHash != 0L && !checkedEvents) || lastHash == newHash) { if ((mLastHash != 0L && !checkedEvents) || mLastHash == newHash) {
return return
} }
lastHash = newHash
mLastHash = newHash
activity?.runOnUiThread { activity?.runOnUiThread {
mHolder.top_value.apply { mHolder.top_value.apply {
@ -96,8 +96,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
} }
private fun setupButtons() { private fun setupButtons() {
val baseColor = mConfig.textColor mTextColor = mConfig.textColor
mTextColor = baseColor
mHolder.top_left_arrow.apply { mHolder.top_left_arrow.apply {
applyColorFilter(mTextColor) applyColorFilter(mTextColor)
@ -115,7 +114,12 @@ class MonthFragment : Fragment(), MonthlyCalendar {
} }
} }
mHolder.top_value.setOnClickListener { showMonthDialog() } mHolder.top_value.apply {
setTextColor(mConfig.textColor)
setOnClickListener {
showMonthDialog()
}
}
} }
private fun showMonthDialog() { private fun showMonthDialog() {
@ -182,7 +186,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
setOnClickListener { openDay(day.code) } setOnClickListener { openDay(day.code) }
removeAllViews() removeAllViews()
context.addDayNumber(mTextColor, day, this, dayLabelHeight) { dayLabelHeight = it } context.addDayNumber(mTextColor, day, this, mDayLabelHeight) { mDayLabelHeight = it }
context.addDayEvents(day, this, mRes, dividerMargin) context.addDayEvents(day, this, mRes, dividerMargin)
} }
} }