allow clicking on list items

This commit is contained in:
tibbi 2016-11-29 21:48:55 +01:00
parent f96c7a875c
commit 029ebfc983
2 changed files with 17 additions and 3 deletions

View file

@ -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

View file

@ -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)
}