allow clicking on list items
This commit is contained in:
parent
f96c7a875c
commit
029ebfc983
2 changed files with 17 additions and 3 deletions
|
@ -8,17 +8,17 @@ import android.graphics.Color
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import android.widget.RemoteViewsService
|
import android.widget.RemoteViewsService
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
|
import com.simplemobiletools.calendar.R.id.event_item_holder
|
||||||
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
||||||
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
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.ListEvent
|
||||||
import com.simplemobiletools.calendar.models.ListItem
|
import com.simplemobiletools.calendar.models.ListItem
|
||||||
import com.simplemobiletools.calendar.models.ListSection
|
import com.simplemobiletools.calendar.models.ListSection
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
|
||||||
val ITEM_EVENT = 0
|
val ITEM_EVENT = 0
|
||||||
val ITEM_HEADER = 1
|
val ITEM_HEADER = 1
|
||||||
|
@ -38,6 +38,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
||||||
override fun getViewAt(position: Int): RemoteViews {
|
override fun getViewAt(position: Int): RemoteViews {
|
||||||
val type = getItemViewType(position)
|
val type = getItemViewType(position)
|
||||||
val remoteView: RemoteViews
|
val remoteView: RemoteViews
|
||||||
|
|
||||||
if (type == ITEM_EVENT) {
|
if (type == ITEM_EVENT) {
|
||||||
val item = events[position] as ListEvent
|
val item = events[position] as ListEvent
|
||||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_item_widget)
|
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_description, "setTextColor", textColor)
|
||||||
setInt(R.id.event_item_start, "setTextColor", textColor)
|
setInt(R.id.event_item_start, "setTextColor", textColor)
|
||||||
setInt(R.id.event_item_end, "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 {
|
} else {
|
||||||
val item = events[position] as ListSection
|
val item = events[position] as ListSection
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.calendar.helpers
|
package com.simplemobiletools.calendar.helpers
|
||||||
|
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.appwidget.AppWidgetProvider
|
import android.appwidget.AppWidgetProvider
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
|
@ -7,8 +8,10 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.net.Uri
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.calendar.R
|
import com.simplemobiletools.calendar.R
|
||||||
|
import com.simplemobiletools.calendar.activities.EventActivity
|
||||||
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
import com.simplemobiletools.calendar.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.calendar.services.WidgetService
|
import com.simplemobiletools.calendar.services.WidgetService
|
||||||
|
|
||||||
|
@ -46,8 +49,14 @@ class MyWidgetListProvider : AppWidgetProvider() {
|
||||||
mRemoteViews.setInt(R.id.widget_event_list, "setBackgroundColor", bgColor)
|
mRemoteViews.setInt(R.id.widget_event_list, "setBackgroundColor", bgColor)
|
||||||
|
|
||||||
val intent = Intent(context, WidgetService::class.java)
|
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)
|
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)
|
val thisWidget = ComponentName(mContext, MyWidgetListProvider::class.java)
|
||||||
AppWidgetManager.getInstance(mContext).updateAppWidget(thisWidget, mRemoteViews)
|
AppWidgetManager.getInstance(mContext).updateAppWidget(thisWidget, mRemoteViews)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue