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
mDayCode = intent.getStringExtra(DAY_CODE)
if (mDayCode.isEmpty())
if (mDayCode.isEmpty()) {
return
}
fillViewPager(mDayCode)

View File

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

View File

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