mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add a Go To Today button at the monthly widget
This commit is contained in:
@@ -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 {
|
runOnUiThread {
|
||||||
mDays = days
|
mDays = days
|
||||||
top_value.text = month
|
top_value.text = month
|
||||||
|
@@ -89,7 +89,7 @@ class MonthFragment : Fragment(), MonthlyCalendar {
|
|||||||
mCalendar?.updateMonthlyCalendar(Formatter.getDateTimeFromCode(mDayCode))
|
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()
|
val newHash = month.hashCode() + days.hashCode().toLong()
|
||||||
if ((mLastHash != 0L && !checkedEvents) || mLastHash == newHash) {
|
if ((mLastHash != 0L && !checkedEvents) || mLastHash == newHash) {
|
||||||
return
|
return
|
||||||
|
@@ -79,7 +79,7 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
|||||||
if (markDaysWithEvents) {
|
if (markDaysWithEvents) {
|
||||||
markDaysWithEvents(days)
|
markDaysWithEvents(days)
|
||||||
} else {
|
} 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 {
|
days.filter { dayEvents.keys.contains(it.code) }.forEach {
|
||||||
it.dayEvents = dayEvents[it.code]!!
|
it.dayEvents = dayEvents[it.code]!!
|
||||||
}
|
}
|
||||||
mCallback.updateMonthlyCalendar(mContext, monthName, days, true)
|
mCallback.updateMonthlyCalendar(mContext, monthName, days, true, mTargetDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@ import org.joda.time.DateTime
|
|||||||
class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
||||||
private val PREV = "prev"
|
private val PREV = "prev"
|
||||||
private val NEXT = "next"
|
private val NEXT = "next"
|
||||||
|
private val GO_TO_TODAY = "go_to_today"
|
||||||
private val NEW_EVENT = "new_event"
|
private val NEW_EVENT = "new_event"
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -66,6 +67,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
PREV -> getPrevMonth(context)
|
PREV -> getPrevMonth(context)
|
||||||
NEXT -> getNextMonth(context)
|
NEXT -> getNextMonth(context)
|
||||||
|
GO_TO_TODAY -> goToToday(context)
|
||||||
NEW_EVENT -> context.launchNewEventIntent()
|
NEW_EVENT -> context.launchNewEventIntent()
|
||||||
else -> super.onReceive(context, intent)
|
else -> super.onReceive(context, intent)
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,11 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
MonthlyCalendarImpl(monthlyCalendar, context).getMonth(targetDate!!)
|
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>) {
|
private fun updateDays(context: Context, views: RemoteViews, days: List<DayMonthly>) {
|
||||||
val displayWeekNumbers = context.config.showWeekNumbers
|
val displayWeekNumbers = context.config.showWeekNumbers
|
||||||
val textColor = context.config.widgetTextColor
|
val textColor = context.config.widgetTextColor
|
||||||
@@ -150,7 +157,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val monthlyCalendar = object : MonthlyCalendar {
|
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 largerFontSize = context.config.getFontSize() + 3f
|
||||||
val textColor = context.config.widgetTextColor
|
val textColor = context.config.widgetTextColor
|
||||||
val resources = context.resources
|
val resources = context.resources
|
||||||
@@ -171,13 +178,21 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() {
|
|||||||
bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor)
|
bmp = resources.getColoredBitmap(R.drawable.ic_pointer_right, textColor)
|
||||||
views.setImageViewBitmap(R.id.top_right_arrow, bmp)
|
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)
|
bmp = resources.getColoredBitmap(R.drawable.ic_plus, textColor)
|
||||||
views.setImageViewBitmap(R.id.top_new_event, bmp)
|
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)
|
updateDayLabels(context, views, resources, textColor)
|
||||||
updateDays(context, views, days)
|
updateDays(context, views, days)
|
||||||
|
|
||||||
setupIntent(context, views, PREV, R.id.top_left_arrow)
|
setupIntent(context, views, PREV, R.id.top_left_arrow)
|
||||||
setupIntent(context, views, NEXT, R.id.top_right_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)
|
setupIntent(context, views, NEW_EVENT, R.id.top_new_event)
|
||||||
|
|
||||||
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode(context)
|
val monthCode = days.firstOrNull { it.code.substring(6) == "01" }?.code ?: Formatter.getTodayCode(context)
|
||||||
|
@@ -2,7 +2,8 @@ package com.simplemobiletools.calendar.interfaces
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.calendar.models.DayMonthly
|
import com.simplemobiletools.calendar.models.DayMonthly
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
interface MonthlyCalendar {
|
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)
|
||||||
}
|
}
|
||||||
|
@@ -38,11 +38,23 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignBottom="@+id/top_value"
|
android:layout_alignBottom="@+id/top_value"
|
||||||
android:layout_alignTop="@+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:paddingLeft="@dimen/medium_margin"
|
||||||
android:paddingRight="@dimen/medium_margin"
|
android:paddingRight="@dimen/medium_margin"
|
||||||
android:src="@drawable/ic_pointer_right"/>
|
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
|
<ImageView
|
||||||
android:id="@+id/top_new_event"
|
android:id="@+id/top_new_event"
|
||||||
style="@style/ArrowStyle"
|
style="@style/ArrowStyle"
|
||||||
|
Reference in New Issue
Block a user