add a Go To Today button at the monthly widget

This commit is contained in:
tibbi 2018-08-05 23:20:22 +02:00
parent cd5a3433b6
commit 00443afab7
6 changed files with 35 additions and 7 deletions

View File

@ -199,7 +199,7 @@ class WidgetMonthlyConfigureActivity : SimpleActivity(), MonthlyCalendar {
}
}
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean) {
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
runOnUiThread {
mDays = days
top_value.text = month

View File

@ -89,7 +89,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
mCalendar?.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
}
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean) {
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
val newHash = month.hashCode() + days.hashCode().toLong()
if ((mLastHash != 0L && !checkedEvents) || mLastHash == newHash) {
return

View File

@ -79,7 +79,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
if (markDaysWithEvents) {
markDaysWithEvents(days)
} else {
mCallback.updateMonthlyCalendar(mContext, monthName, days, false)
mCallback.updateMonthlyCalendar(mContext, monthName, days, false, mTargetDate)
}
}
@ -110,7 +110,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
days.filter { dayEvents.keys.contains(it.code) }.forEach {
it.dayEvents = dayEvents[it.code]!!
}
mCallback.updateMonthlyCalendar(mContext, monthName, days, true)
mCallback.updateMonthlyCalendar(mContext, monthName, days, true, mTargetDate)
}
}

View File

@ -21,6 +21,7 @@ import org.joda.time.DateTime
class MyWidgetMonthlyProvider : AppWidgetProvider() {
private val PREV = "prev"
private val NEXT = "next"
private val GO_TO_TODAY = "go_to_today"
private val NEW_EVENT = "new_event"
companion object {
@ -66,6 +67,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
when (intent.action) {
PREV -> getPrevMonth(context)
NEXT -> getNextMonth(context)
GO_TO_TODAY -> goToToday(context)
NEW_EVENT -> context.launchNewEventIntent()
else -> super.onReceive(context, intent)
}
@ -81,6 +83,11 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate!!)
}
private fun goToToday(context: Context) {
targetDate = DateTime.now().withDayOfMonth(1)
MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate!!)
}
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
val displayWeekNumbers = context.config.showWeekNumbers
val textColor = context.config.widgetTextColor
@ -150,7 +157,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
}
private val monthlyCalendar = object : MonthlyCalendar {
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean) {
override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime) {
val largerFontSize = context.config.getFontSize() + 3f
val textColor = context.config.widgetTextColor
val resources = context.resources
@ -171,13 +178,21 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor)
views.setImageViewBitmap(R.id.top_right_arrow, bmp)
bmp = resources.getColoredBitmap(R.drawable.ic_today, textColor)
views.setImageViewBitmap(R.id.top_go_to_today, bmp)
bmp = resources.getColoredBitmap(R.drawable.ic_plus, textColor)
views.setImageViewBitmap(R.id.top_new_event, bmp)
val shouldGoToTodayBeVisible = currTargetDate.withTime(0, 0, 0, 0) != DateTime.now().withDayOfMonth(1).withTime(0, 0, 0, 0)
views.setVisibleIf(R.id.top_go_to_today, shouldGoToTodayBeVisible)
updateDayLabels(context, views, resources, textColor)
updateDays(context, views, days)
setupIntent(context, views, PREV, R.id.top_left_arrow)
setupIntent(context, views, NEXT, R.id.top_right_arrow)
setupIntent(context, views, GO_TO_TODAY, R.id.top_go_to_today)
setupIntent(context, views, NEW_EVENT, R.id.top_new_event)
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode(context)

View File

@ -2,7 +2,8 @@ package com.simplemobiletools.calendar.interfaces
import android.content.Context
import com.simplemobiletools.calendar.models.DayMonthly
import org.joda.time.DateTime
interface MonthlyCalendar {
fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean)
fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList<DayMonthly>, checkedEvents: Boolean, currTargetDate: DateTime)
}

View File

@ -38,11 +38,23 @@
android:layout_height="match_parent"
android:layout_alignBottom="@+id/top_value"
android:layout_alignTop="@+id/top_value"
android:layout_toLeftOf="@+id/top_new_event"
android:layout_toLeftOf="@+id/top_go_to_today"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:src="@drawable/ic_pointer_right"/>
<ImageView
android:id="@+id/top_go_to_today"
style="@style/ArrowStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/top_value"
android:layout_alignTop="@+id/top_value"
android:layout_toLeftOf="@+id/top_new_event"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:src="@drawable/ic_today"/>
<ImageView
android:id="@+id/top_new_event"
style="@style/ArrowStyle"