From 029ebfc98316662d7995f2d479d0a4a49a2f0c18 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 29 Nov 2016 21:48:55 +0100 Subject: [PATCH] allow clicking on list items --- .../calendar/adapters/EventListWidgetAdapter.kt | 11 ++++++++--- .../calendar/helpers/MyWidgetListProvider.kt | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt index 86cbd1e14..1aa91a27a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt @@ -8,17 +8,17 @@ import android.graphics.Color import android.widget.RemoteViews import android.widget.RemoteViewsService import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.R.id.event_item_holder import com.simplemobiletools.calendar.extensions.adjustAlpha +import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.Formatter -import com.simplemobiletools.calendar.helpers.HIGH_ALPHA -import com.simplemobiletools.calendar.helpers.PREFS_KEY -import com.simplemobiletools.calendar.helpers.WIDGET_TEXT_COLOR import com.simplemobiletools.calendar.models.ListEvent import com.simplemobiletools.calendar.models.ListItem import com.simplemobiletools.calendar.models.ListSection import org.joda.time.DateTime import java.util.* + class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory { val ITEM_EVENT = 0 val ITEM_HEADER = 1 @@ -38,6 +38,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV override fun getViewAt(position: Int): RemoteViews { val type = getItemViewType(position) val remoteView: RemoteViews + if (type == ITEM_EVENT) { val item = events[position] as ListEvent remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget) @@ -51,6 +52,10 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV setInt(R.id.event_item_description, "setTextColor", textColor) setInt(R.id.event_item_start, "setTextColor", textColor) setInt(R.id.event_item_end, "setTextColor", textColor) + + val intent = Intent() + intent.putExtra(EVENT_ID, item.id) + setOnClickFillInIntent(event_item_holder, intent) } } else { val item = events[position] as ListSection diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt index f892f7b89..b93a9cbd8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MyWidgetListProvider.kt @@ -1,5 +1,6 @@ package com.simplemobiletools.calendar.helpers +import android.app.PendingIntent import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.ComponentName @@ -7,8 +8,10 @@ import android.content.Context import android.content.Intent import android.content.res.Resources import android.graphics.Color +import android.net.Uri import android.widget.RemoteViews import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.activities.EventActivity import com.simplemobiletools.calendar.extensions.adjustAlpha import com.simplemobiletools.calendar.services.WidgetService @@ -46,8 +49,14 @@ class MyWidgetListProvider : AppWidgetProvider() { mRemoteViews.setInt(R.id.widget_event_list, "setBackgroundColor", bgColor) val intent = Intent(context, WidgetService::class.java) + intent.data = Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)) mRemoteViews.setRemoteAdapter(R.id.widget_event_list, intent) + val startActivityIntent = Intent(context, EventActivity::class.java) + val startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT) + mRemoteViews.setPendingIntentTemplate(R.id.widget_event_list, startActivityPendingIntent) + + val thisWidget = ComponentName(mContext, MyWidgetListProvider::class.java) AppWidgetManager.getInstance(mContext).updateAppWidget(thisWidget, mRemoteViews) }