mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
adding a Go To Today button at the list widget
This commit is contained in:
parent
31c73e1e1a
commit
e1986f3d58
@ -176,6 +176,10 @@
|
||||
android:name=".services.WidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS"/>
|
||||
|
||||
<service
|
||||
android:name=".services.WidgetServiceEmpty"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS"/>
|
||||
|
||||
<service android:name=".services.SnoozeService"/>
|
||||
|
||||
<service
|
||||
|
@ -129,9 +129,9 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||
}
|
||||
|
||||
remoteView.apply {
|
||||
setTextColor(R.id.event_section_title, curTextColor)
|
||||
setTextSize(R.id.event_section_title, mediumFontSize)
|
||||
setText(R.id.event_section_title, item.title)
|
||||
setTextColor(event_section_title, curTextColor)
|
||||
setTextSize(event_section_title, mediumFontSize)
|
||||
setText(event_section_title, item.title)
|
||||
|
||||
Intent().apply {
|
||||
putExtra(DAY_CODE, item.code)
|
||||
@ -145,7 +145,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
override fun getViewTypeCount() = 3
|
||||
override fun getViewTypeCount() = 2
|
||||
|
||||
override fun onCreate() {}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.simplemobiletools.calendar.pro.adapters
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.RemoteViewsService
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
|
||||
class EventListWidgetAdapterEmpty(val context: Context) : RemoteViewsService.RemoteViewsFactory {
|
||||
override fun getViewAt(position: Int) = RemoteViews(context.packageName, R.layout.event_list_section_widget)
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
override fun getViewTypeCount() = 1
|
||||
|
||||
override fun onCreate() {}
|
||||
|
||||
override fun getItemId(position: Int) = 0L
|
||||
|
||||
override fun onDataSetChanged() {}
|
||||
|
||||
override fun hasStableIds() = true
|
||||
|
||||
override fun getCount() = 0
|
||||
|
||||
override fun onDestroy() {}
|
||||
}
|
@ -13,12 +13,14 @@ import com.simplemobiletools.calendar.pro.activities.SplashActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.launchNewEventIntent
|
||||
import com.simplemobiletools.calendar.pro.services.WidgetService
|
||||
import com.simplemobiletools.calendar.pro.services.WidgetServiceEmpty
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import org.joda.time.DateTime
|
||||
|
||||
class MyWidgetListProvider : AppWidgetProvider() {
|
||||
private val NEW_EVENT = "new_event"
|
||||
private val LAUNCH_CAL = "launch_cal"
|
||||
private val GO_TO_TODAY = "go_to_today"
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
performUpdate(context)
|
||||
@ -46,6 +48,9 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
||||
setupIntent(context, views, NEW_EVENT, R.id.widget_event_new_event)
|
||||
setupIntent(context, views, LAUNCH_CAL, R.id.widget_event_list_today)
|
||||
|
||||
views.setImageViewBitmap(R.id.widget_event_go_to_today, context.resources.getColoredBitmap(R.drawable.ic_today, textColor))
|
||||
setupIntent(context, views, GO_TO_TODAY, R.id.widget_event_go_to_today)
|
||||
|
||||
Intent(context, WidgetService::class.java).apply {
|
||||
data = Uri.parse(this.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.widget_event_list, this)
|
||||
@ -75,6 +80,7 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
||||
when (intent.action) {
|
||||
NEW_EVENT -> context.launchNewEventIntent()
|
||||
LAUNCH_CAL -> launchCalenderInDefaultView(context)
|
||||
GO_TO_TODAY -> goToToday(context)
|
||||
else -> super.onReceive(context, intent)
|
||||
}
|
||||
}
|
||||
@ -87,4 +93,20 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
||||
context.startActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
// hacky solution for reseting the events list
|
||||
private fun goToToday(context: Context) {
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_event_list)
|
||||
Intent(context, WidgetServiceEmpty::class.java).apply {
|
||||
data = Uri.parse(this.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.widget_event_list, this)
|
||||
}
|
||||
|
||||
appWidgetManager.updateAppWidget(it, views)
|
||||
}
|
||||
|
||||
performUpdate(context)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.simplemobiletools.calendar.pro.services
|
||||
|
||||
import android.content.Intent
|
||||
import android.widget.RemoteViewsService
|
||||
import com.simplemobiletools.calendar.pro.adapters.EventListWidgetAdapterEmpty
|
||||
|
||||
class WidgetServiceEmpty : RemoteViewsService() {
|
||||
override fun onGetViewFactory(intent: Intent) = EventListWidgetAdapterEmpty(applicationContext)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/widget_event_list_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -9,15 +10,30 @@
|
||||
android:id="@+id/widget_event_list_today"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/widget_event_new_event"
|
||||
android:layout_alignBottom="@+id/widget_event_new_event"
|
||||
android:layout_toStartOf="@+id/widget_event_new_event"
|
||||
android:layout_alignTop="@+id/widget_event_go_to_today"
|
||||
android:layout_alignBottom="@+id/widget_event_go_to_today"
|
||||
android:layout_toStartOf="@+id/widget_event_go_to_today"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/medium_margin"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="July 18"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widget_event_go_to_today"
|
||||
style="@style/ArrowStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_toStartOf="@+id/widget_event_new_event"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingEnd="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/small_margin"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_today"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/widget_event_new_event"
|
||||
|
Loading…
x
Reference in New Issue
Block a user