properly update the weekly screen if some color changes

This commit is contained in:
tibbi 2017-01-22 16:48:25 +01:00
parent 03a11ff99b
commit c1a2051f8c
2 changed files with 19 additions and 8 deletions

View File

@ -41,6 +41,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
private var mSnackbar: Snackbar? = null private var mSnackbar: Snackbar? = null
private var mEventListFragment: EventListFragment? = null private var mEventListFragment: EventListFragment? = null
private var mStoredTextColor = 0 private var mStoredTextColor = 0
private var mStoredBackgroundColor = 0
private var mStoredPrimaryColor = 0
private var mStoredIsSundayFirst = false private var mStoredIsSundayFirst = false
companion object { companion object {
@ -52,16 +54,18 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
calendar_fab.setOnClickListener { addNewEvent() } calendar_fab.setOnClickListener { addNewEvent() }
updateViewPager() updateViewPager()
mStoredTextColor = config.textColor
mStoredIsSundayFirst = config.isSundayFirst
checkWhatsNewDialog() checkWhatsNewDialog()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (mStoredTextColor != config.textColor) if (mStoredTextColor != config.textColor || mStoredBackgroundColor != config.backgroundColor || mStoredPrimaryColor != config.primaryColor)
updateViewPager() updateViewPager()
mStoredTextColor = config.textColor
mStoredPrimaryColor = config.primaryColor
mStoredBackgroundColor = config.backgroundColor
if (mStoredIsSundayFirst != config.isSundayFirst && config.storedView == WEEKLY_VIEW) if (mStoredIsSundayFirst != config.isSundayFirst && config.storedView == WEEKLY_VIEW)
fillWeeklyViewPager() fillWeeklyViewPager()
@ -74,6 +78,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
checkDeleteEvents() checkDeleteEvents()
mStoredTextColor = config.textColor mStoredTextColor = config.textColor
mStoredIsSundayFirst = config.isSundayFirst mStoredIsSundayFirst = config.isSundayFirst
mStoredBackgroundColor = config.backgroundColor
mStoredPrimaryColor = config.primaryColor
} }
override fun onDestroy() { override fun onDestroy() {
@ -195,10 +201,12 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener {
week_view_hours_holder.removeAllViews() week_view_hours_holder.removeAllViews()
for (i in 1..23) { for (i in 1..23) {
val view = layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView
val value = i.toString() val value = i.toString()
view.text = if (value.length == 2) value else "0$value" (layoutInflater.inflate(R.layout.weekly_view_hour_textview, null, false) as TextView).apply {
week_view_hours_holder.addView(view) text = if (value.length == 2) value else "0$value"
setTextColor(mStoredTextColor)
week_view_hours_holder.addView(this)
}
} }
week_view_view_pager.apply { week_view_view_pager.apply {

View File

@ -94,10 +94,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
private fun setupDayLabels() { private fun setupDayLabels() {
var curDay = Formatter.getDateTimeFromTS(mWeekTimestamp) var curDay = Formatter.getDateTimeFromTS(mWeekTimestamp)
val textColor = context.config.textColor
for (i in 0..6) { for (i in 0..6) {
val view = mView.findViewById(mRes.getIdentifier("week_day_label_$i", "id", context.packageName)) as TextView
val dayLetter = getDayLetter(curDay.dayOfWeek) val dayLetter = getDayLetter(curDay.dayOfWeek)
view.text = "$dayLetter\n${curDay.dayOfMonth}" (mView.findViewById(mRes.getIdentifier("week_day_label_$i", "id", context.packageName)) as TextView).apply {
text = "$dayLetter\n${curDay.dayOfMonth}"
setTextColor(textColor)
}
curDay = curDay.plusDays(1) curDay = curDay.plusDays(1)
} }
} }