From 7520656d2c29b0ea5d488a16b24e1ff63e84d520 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 17 Sep 2016 23:31:07 +0200 Subject: [PATCH] implement the arrows at Day screen --- .../calendar/activities/DayActivity.kt | 4 +- .../calendar/fragments/DayFragment.kt | 45 +++++++++++++++++-- .../calendar/fragments/MonthFragment.kt | 13 +++--- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt index 36eb18c01..fc2b36d6f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt @@ -252,11 +252,11 @@ class DayActivity : SimpleActivity(), NavigationListener, DBHelper.DBOperationsL } override fun goLeft() { - + view_pager.currentItem = view_pager.currentItem - 1 } override fun goRight() { - + view_pager.currentItem = view_pager.currentItem + 1 } override fun goToDateTime(dateTime: DateTime) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt index 4b98fcff9..236db4695 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt @@ -1,5 +1,8 @@ package com.simplemobiletools.calendar.fragments +import android.content.res.Resources +import android.graphics.Color +import android.graphics.PorterDuff import android.os.Bundle import android.support.v4.app.Fragment import android.view.* @@ -16,25 +19,61 @@ import java.util.* class DayFragment : Fragment(), DBHelper.DBOperationsListener, AdapterView.OnItemClickListener, AbsListView.MultiChoiceModeListener { + private var mTextColor: Int = 0 + private var mWeakTextColor: Int = 0 + private var mTextColorWithEvent: Int = 0 + private var mWeakTextColorWithEvent: Int = 0 private var mDayCode: String = "" private var mEvents: MutableList? = null private var mListener: NavigationListener? = null + lateinit var mRes: Resources lateinit var mHolder: RelativeLayout + lateinit var mConfig: Config override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater!!.inflate(R.layout.day_fragment, container, false) + mRes = resources mHolder = view.day_holder + + mConfig = Config.newInstance(context) mDayCode = arguments.getString(Constants.DAY_CODE) val day = Formatter.getEventDate(activity.applicationContext, mDayCode) - view.month_value.text = day - - checkEvents() + mHolder.month_value.text = day + setupButtons() return view } + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + checkEvents() + } + + private fun setupButtons() { + val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK + mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA) + mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA) + mWeakTextColor = Utils.adjustAlpha(baseColor, Constants.LOW_ALPHA) + mWeakTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.LOW_ALPHA) + + mHolder.apply { + top_left_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP) + top_right_arrow.drawable.mutate().setColorFilter(mTextColor, PorterDuff.Mode.SRC_ATOP) + top_left_arrow.background = null + top_right_arrow.background = null + + top_left_arrow.setOnClickListener { + mListener?.goLeft() + } + + top_right_arrow.setOnClickListener { + mListener?.goRight() + } + } + } + fun setListener(listener: NavigationListener) { mListener = listener } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt index 8fc615907..2749dda63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/MonthFragment.kt @@ -45,7 +45,7 @@ class MonthFragment : Fragment(), Calendar { mConfig = Config.newInstance(context) mSundayFirst = mConfig.isSundayFirst - setupColors() + setupButtons() mPackageName = activity.packageName mDayTextSize = mRes.getDimension(R.dimen.day_text_size) / mRes.displayMetrics.density @@ -78,7 +78,7 @@ class MonthFragment : Fragment(), Calendar { mListener = listener } - private fun setupColors() { + private fun setupButtons() { val baseColor = if (mConfig.isDarkTheme) Color.WHITE else Color.BLACK mTextColor = Utils.adjustAlpha(baseColor, Constants.HIGH_ALPHA) mTextColorWithEvent = Utils.adjustAlpha(mRes.getColor(R.color.colorPrimary), Constants.HIGH_ALPHA) @@ -92,13 +92,11 @@ class MonthFragment : Fragment(), Calendar { top_right_arrow.background = null top_left_arrow.setOnClickListener { - if (mListener != null) - mListener!!.goLeft() + mListener?.goLeft() } top_right_arrow.setOnClickListener { - if (mListener != null) - mListener!!.goRight() + mListener?.goRight() } month_value.setOnClickListener { showMonthDialog() } @@ -120,8 +118,7 @@ class MonthFragment : Fragment(), Calendar { alertDialog.setPositiveButton(R.string.ok) { dialog, id -> val month = datePicker.month + 1 val year = datePicker.year - if (mListener != null) - mListener!!.goToDateTime(DateTime().withMonthOfYear(month).withYear(year)) + mListener?.goToDateTime(DateTime().withMonthOfYear(month).withYear(year)) } alertDialog.show()