adding some widget related improvements
This commit is contained in:
parent
b1324e93bb
commit
67dae16d11
9 changed files with 149 additions and 114 deletions
|
@ -138,25 +138,90 @@ class WidgetListConfigureActivity : SimpleActivity() {
|
|||
val listItems = ArrayList<ListItem>(10)
|
||||
var dateTime = DateTime.now().withTime(0, 0, 0, 0).plusDays(1)
|
||||
var code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
||||
var day = Formatter.getDayTitle(this, code)
|
||||
var day = Formatter.getDateDayTitle(code)
|
||||
listItems.add(ListSectionDay(day, code, false, false))
|
||||
|
||||
var time = dateTime.withHourOfDay(7)
|
||||
listItems.add(ListEvent(1, time.seconds(), time.plusMinutes(30).seconds(), getString(R.string.sample_title_1), getString(R.string.sample_description_1), false, config.primaryColor, "", false, false))
|
||||
listItems.add(
|
||||
ListEvent(
|
||||
1,
|
||||
time.seconds(),
|
||||
time.plusMinutes(30).seconds(),
|
||||
getString(R.string.sample_title_1),
|
||||
getString(R.string.sample_description_1),
|
||||
false,
|
||||
config.primaryColor,
|
||||
"",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
time = dateTime.withHourOfDay(8)
|
||||
listItems.add(ListEvent(2, time.seconds(), time.plusHours(1).seconds(), getString(R.string.sample_title_2), getString(R.string.sample_description_2), false, config.primaryColor, "", false, false))
|
||||
listItems.add(
|
||||
ListEvent(
|
||||
2,
|
||||
time.seconds(),
|
||||
time.plusHours(1).seconds(),
|
||||
getString(R.string.sample_title_2),
|
||||
getString(R.string.sample_description_2),
|
||||
false,
|
||||
config.primaryColor,
|
||||
"",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
dateTime = dateTime.plusDays(1)
|
||||
code = Formatter.getDayCodeFromTS(dateTime.seconds())
|
||||
day = Formatter.getDayTitle(this, code)
|
||||
day = Formatter.getDateDayTitle(code)
|
||||
listItems.add(ListSectionDay(day, code, false, false))
|
||||
|
||||
time = dateTime.withHourOfDay(8)
|
||||
listItems.add(ListEvent(3, time.seconds(), time.plusHours(1).seconds(), getString(R.string.sample_title_3), "", false, config.primaryColor, "", false, false))
|
||||
listItems.add(
|
||||
ListEvent(
|
||||
3,
|
||||
time.seconds(),
|
||||
time.plusHours(1).seconds(),
|
||||
getString(R.string.sample_title_3),
|
||||
"",
|
||||
false,
|
||||
config.primaryColor,
|
||||
"",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
time = dateTime.withHourOfDay(13)
|
||||
listItems.add(ListEvent(4, time.seconds(), time.plusHours(1).seconds(), getString(R.string.sample_title_4), getString(R.string.sample_description_4), false, config.primaryColor, "", false, false))
|
||||
listItems.add(
|
||||
ListEvent(
|
||||
4,
|
||||
time.seconds(),
|
||||
time.plusHours(1).seconds(),
|
||||
getString(R.string.sample_title_4),
|
||||
getString(R.string.sample_description_4),
|
||||
false,
|
||||
config.primaryColor,
|
||||
"",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
time = dateTime.withHourOfDay(18)
|
||||
listItems.add(ListEvent(5, time.seconds(), time.plusMinutes(10).seconds(), getString(R.string.sample_title_5), "", false, config.primaryColor, "", false, false))
|
||||
listItems.add(
|
||||
ListEvent(
|
||||
5,
|
||||
time.seconds(),
|
||||
time.plusMinutes(10).seconds(),
|
||||
getString(R.string.sample_title_5),
|
||||
"",
|
||||
false,
|
||||
config.primaryColor,
|
||||
"",
|
||||
false,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
return listItems
|
||||
}
|
||||
|
|
|
@ -2,26 +2,16 @@ package com.simplemobiletools.calendar.pro.adapters
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.RemoteViewsService
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.R.id.event_item_holder
|
||||
import com.simplemobiletools.calendar.pro.R.id.event_section_title
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.ListEvent
|
||||
import com.simplemobiletools.calendar.pro.models.ListItem
|
||||
import com.simplemobiletools.calendar.pro.models.ListSectionDay
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
import com.simplemobiletools.commons.extensions.setBackgroundColor
|
||||
import com.simplemobiletools.commons.extensions.setText
|
||||
import com.simplemobiletools.commons.extensions.setTextSize
|
||||
import com.simplemobiletools.calendar.pro.models.*
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
|
||||
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA
|
||||
import org.joda.time.DateTime
|
||||
|
@ -29,7 +19,8 @@ import java.util.*
|
|||
|
||||
class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteViewsFactory {
|
||||
private val ITEM_EVENT = 0
|
||||
private val ITEM_HEADER = 1
|
||||
private val ITEM_SECTION_DAY = 1
|
||||
private val ITEM_SECTION_MONTH = 2
|
||||
|
||||
private val allDayString = context.resources.getString(R.string.all_day)
|
||||
private var events = ArrayList<ListItem>()
|
||||
|
@ -45,65 +36,39 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
|
||||
if (type == ITEM_EVENT) {
|
||||
val event = events[position] as ListEvent
|
||||
val layout = getItemViewLayout(event)
|
||||
val layout = R.layout.event_list_item_widget
|
||||
remoteView = RemoteViews(context.packageName, layout)
|
||||
setupListEvent(remoteView, event)
|
||||
} else {
|
||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_widget)
|
||||
} else if (type == ITEM_SECTION_DAY) {
|
||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_day_widget)
|
||||
val section = events.getOrNull(position) as? ListSectionDay
|
||||
if (section != null) {
|
||||
setupListSection(remoteView, section)
|
||||
setupListSectionDay(remoteView, section)
|
||||
}
|
||||
} else {
|
||||
remoteView = RemoteViews(context.packageName, R.layout.event_list_section_month_widget)
|
||||
val section = events.getOrNull(position) as? ListSectionMonth
|
||||
if (section != null) {
|
||||
setupListSectionMonth(remoteView, section)
|
||||
}
|
||||
}
|
||||
|
||||
return remoteView
|
||||
}
|
||||
|
||||
private fun getItemViewLayout(event: ListEvent): Int {
|
||||
val detailField = if (replaceDescription) event.location else event.description
|
||||
return if (detailField.isNotEmpty()) {
|
||||
R.layout.event_list_item_widget
|
||||
} else if (event.startTS == event.endTS) {
|
||||
R.layout.event_list_item_widget
|
||||
} else if (event.isAllDay) {
|
||||
val startCode = Formatter.getDayCodeFromTS(event.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(event.endTS)
|
||||
if (startCode == endCode) {
|
||||
R.layout.event_list_item_widget
|
||||
} else {
|
||||
R.layout.event_list_item_widget
|
||||
}
|
||||
} else {
|
||||
R.layout.event_list_item_widget
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListEvent(remoteView: RemoteViews, item: ListEvent) {
|
||||
var curTextColor = textColor
|
||||
remoteView.apply {
|
||||
setText(R.id.event_item_title, item.title)
|
||||
setText(R.id.event_item_description, if (replaceDescription) item.location else item.description)
|
||||
setText(R.id.event_item_time, if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS))
|
||||
setBackgroundColor(R.id.event_item_color_bar, item.color)
|
||||
setText(R.id.event_item_title, item.title)
|
||||
|
||||
if (item.startTS == item.endTS) {
|
||||
setViewVisibility(R.id.event_item_end, View.INVISIBLE)
|
||||
} else {
|
||||
setViewVisibility(R.id.event_item_end, View.VISIBLE)
|
||||
var endString = Formatter.getTimeFromTS(context, item.endTS)
|
||||
val startCode = Formatter.getDayCodeFromTS(item.startTS)
|
||||
val endCode = Formatter.getDayCodeFromTS(item.endTS)
|
||||
val timeText = if (item.isAllDay) allDayString else Formatter.getTimeFromTS(context, item.startTS)
|
||||
setText(R.id.event_item_time, timeText)
|
||||
|
||||
if (startCode != endCode) {
|
||||
if (item.isAllDay) {
|
||||
endString = Formatter.getDateFromCode(context, endCode, true)
|
||||
} else {
|
||||
endString += " (${Formatter.getDateFromCode(context, endCode, true)})"
|
||||
}
|
||||
} else if (item.isAllDay) {
|
||||
setViewVisibility(R.id.event_item_end, View.INVISIBLE)
|
||||
}
|
||||
setText(R.id.event_item_end, endString)
|
||||
// we cannot change the event_item_color_bar rules dynamically, so do it like this
|
||||
val descriptionText = if (replaceDescription) item.location else item.description
|
||||
if (descriptionText.isNotEmpty()) {
|
||||
setText(R.id.event_item_time, "$timeText\n$descriptionText")
|
||||
}
|
||||
|
||||
if (dimPastEvents && item.isPastEvent) {
|
||||
|
@ -111,14 +76,10 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
}
|
||||
|
||||
setTextColor(R.id.event_item_title, curTextColor)
|
||||
setTextColor(R.id.event_item_description, curTextColor)
|
||||
setTextColor(R.id.event_item_time, curTextColor)
|
||||
setTextColor(R.id.event_item_end, curTextColor)
|
||||
|
||||
setTextSize(R.id.event_item_title, mediumFontSize)
|
||||
setTextSize(R.id.event_item_description, mediumFontSize)
|
||||
setTextSize(R.id.event_item_time, mediumFontSize)
|
||||
setTextSize(R.id.event_item_end, mediumFontSize)
|
||||
|
||||
Intent().apply {
|
||||
putExtra(EVENT_ID, item.id)
|
||||
|
@ -128,7 +89,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupListSection(remoteView: RemoteViews, item: ListSectionDay) {
|
||||
private fun setupListSectionDay(remoteView: RemoteViews, item: ListSectionDay) {
|
||||
var curTextColor = textColor
|
||||
if (dimPastEvents && item.isPastSection) {
|
||||
curTextColor = weakTextColor
|
||||
|
@ -147,7 +108,19 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
}
|
||||
}
|
||||
|
||||
private fun getItemViewType(position: Int) = if (events.getOrNull(position) is ListEvent) ITEM_EVENT else ITEM_HEADER
|
||||
private fun setupListSectionMonth(remoteView: RemoteViews, item: ListSectionMonth) {
|
||||
val curTextColor = textColor
|
||||
remoteView.apply {
|
||||
setTextColor(event_section_title, curTextColor)
|
||||
setText(event_section_title, item.title)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getItemViewType(position: Int) = when {
|
||||
events.getOrNull(position) is ListEvent -> ITEM_EVENT
|
||||
events.getOrNull(position) is ListSectionDay -> ITEM_SECTION_DAY
|
||||
else -> ITEM_SECTION_MONTH
|
||||
}
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
|
@ -181,13 +154,21 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi
|
|||
}.thenBy { it.title }.thenBy { if (replaceDescription) it.location else it.description })
|
||||
|
||||
var prevCode = ""
|
||||
var prevMonthLabel = ""
|
||||
val now = getNowSeconds()
|
||||
val today = Formatter.getDayTitle(context, Formatter.getDayCodeFromTS(now))
|
||||
|
||||
sorted.forEach {
|
||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||
val monthLabel = Formatter.getLongMonthYear(context, code)
|
||||
if (monthLabel != prevMonthLabel) {
|
||||
val listSectionMonth = ListSectionMonth(monthLabel)
|
||||
listItems.add(listSectionMonth)
|
||||
prevMonthLabel = monthLabel
|
||||
}
|
||||
|
||||
if (code != prevCode) {
|
||||
val day = Formatter.getDayTitle(context, code)
|
||||
val day = Formatter.getDateDayTitle(code)
|
||||
val isToday = day == today
|
||||
val listSection = ListSectionDay(day, code, isToday, !isToday && it.startTS < now)
|
||||
listItems.add(listSection)
|
||||
|
|
|
@ -6,7 +6,7 @@ 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 getViewAt(position: Int) = RemoteViews(context.packageName, R.layout.event_list_section_day_widget)
|
||||
|
||||
override fun getLoadingView() = null
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package com.simplemobiletools.calendar.pro.extensions
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.widget.TextView
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
|
||||
fun TextView.addResizedBackgroundDrawable(res: Resources, drawableHeight: Int, primaryColor: Int, drawableId: Int) {
|
||||
val baseDrawable = res.getDrawable(drawableId)
|
||||
val bitmap = (baseDrawable as BitmapDrawable).bitmap
|
||||
val scaledDrawable = BitmapDrawable(res, Bitmap.createScaledBitmap(bitmap, drawableHeight, drawableHeight, true))
|
||||
val baseDrawable = res.getDrawable(drawableId).toBitmap(drawableHeight, drawableHeight)
|
||||
val scaledDrawable = BitmapDrawable(res, baseDrawable)
|
||||
scaledDrawable.applyColorFilter(primaryColor)
|
||||
background = scaledDrawable
|
||||
}
|
||||
|
|
|
@ -4,43 +4,30 @@
|
|||
android:id="@+id/event_item_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/medium_margin"
|
||||
android:layout_marginTop="@dimen/small_margin"
|
||||
android:layout_marginEnd="@dimen/medium_margin"
|
||||
android:layout_marginBottom="@dimen/medium_margin"
|
||||
android:background="@drawable/section_holder_stroke"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/medium_margin">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/event_item_color_bar"
|
||||
android:layout_width="4dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/event_item_time"
|
||||
android:layout_alignBottom="@+id/event_item_end"
|
||||
android:layout_alignTop="@+id/event_item_title"
|
||||
android:layout_alignBottom="@+id/event_item_time"
|
||||
android:layout_marginEnd="@dimen/small_margin"
|
||||
android:background="@drawable/event_list_color_bar"
|
||||
android:paddingTop="@dimen/tiny_margin"
|
||||
android:paddingBottom="@dimen/tiny_margin" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@+id/event_item_color_bar"
|
||||
android:textSize="@dimen/day_text_size"
|
||||
tools:text="13:00" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_time"
|
||||
android:layout_toEndOf="@+id/event_item_color_bar"
|
||||
android:includeFontPadding="false"
|
||||
android:text="15:00"
|
||||
android:textSize="@dimen/day_text_size" />
|
||||
android:scaleType="fitXY" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/normal_margin"
|
||||
android:layout_toEndOf="@+id/event_item_time"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
|
@ -48,17 +35,14 @@
|
|||
tools:text="Event title" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/event_item_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/event_item_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/event_item_title"
|
||||
android:layout_marginStart="@dimen/normal_margin"
|
||||
android:layout_toEndOf="@+id/event_item_end"
|
||||
android:ellipsize="end"
|
||||
android:includeFontPadding="false"
|
||||
android:maxLines="1"
|
||||
android:paddingEnd="@dimen/small_margin"
|
||||
android:textSize="@dimen/day_text_size"
|
||||
tools:text="Event description" />
|
||||
android:layout_alignStart="@+id/event_item_title"
|
||||
android:alpha="0.8"
|
||||
android:lineSpacingExtra="2dp"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="13:00" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
android:id="@+id/event_section_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableTop="@drawable/divider_width"
|
||||
android:drawablePadding="1dp"
|
||||
android:paddingTop="@dimen/small_margin"
|
||||
android:paddingStart="@dimen/bigger_margin"
|
||||
android:paddingBottom="@dimen/small_margin"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
android:textStyle="bold" />
|
10
app/src/main/res/layout/event_list_section_month_widget.xml
Normal file
10
app/src/main/res/layout/event_list_section_month_widget.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/event_section_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/small_margin"
|
||||
android:textAllCaps="true"
|
||||
android:textFontWeight="300"
|
||||
android:textSize="20sp" />
|
|
@ -16,7 +16,6 @@
|
|||
android:background="@drawable/widget_round_background"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:paddingStart="@dimen/activity_margin"
|
||||
android:paddingTop="@dimen/medium_margin"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_below="@+id/widget_event_new_event"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:paddingStart="@dimen/medium_margin"
|
||||
android:paddingBottom="@dimen/small_margin" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue