diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt index ad7b681f9..b4e46013a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/WidgetListConfigureActivity.kt @@ -138,25 +138,90 @@ class WidgetListConfigureActivity : SimpleActivity() { val listItems = ArrayList(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 } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt index 389bef780..d93ef2766 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapter.kt @@ -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() @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapterEmpty.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapterEmpty.kt index 09564fdba..c18c87f94 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapterEmpty.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/EventListWidgetAdapterEmpty.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt index a0adf4c8e..cb765cf4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/TextView.kt @@ -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 } diff --git a/app/src/main/res/layout/event_list_item_widget.xml b/app/src/main/res/layout/event_list_item_widget.xml index eb1ddce4d..59b5419da 100644 --- a/app/src/main/res/layout/event_list_item_widget.xml +++ b/app/src/main/res/layout/event_list_item_widget.xml @@ -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"> - - - - + android:scaleType="fitXY" /> + android:layout_alignStart="@+id/event_item_title" + android:alpha="0.8" + android:lineSpacingExtra="2dp" + android:textSize="@dimen/normal_text_size" + tools:text="13:00" /> diff --git a/app/src/main/res/layout/event_list_section_widget.xml b/app/src/main/res/layout/event_list_section_day_widget.xml similarity index 73% rename from app/src/main/res/layout/event_list_section_widget.xml rename to app/src/main/res/layout/event_list_section_day_widget.xml index d73e30977..7973c5887 100644 --- a/app/src/main/res/layout/event_list_section_widget.xml +++ b/app/src/main/res/layout/event_list_section_day_widget.xml @@ -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" /> diff --git a/app/src/main/res/layout/event_list_section_month_widget.xml b/app/src/main/res/layout/event_list_section_month_widget.xml new file mode 100644 index 000000000..f678ba54f --- /dev/null +++ b/app/src/main/res/layout/event_list_section_month_widget.xml @@ -0,0 +1,10 @@ + + diff --git a/app/src/main/res/layout/widget_config_list.xml b/app/src/main/res/layout/widget_config_list.xml index 2946f3f09..5a4cc3d7a 100644 --- a/app/src/main/res/layout/widget_config_list.xml +++ b/app/src/main/res/layout/widget_config_list.xml @@ -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" /> diff --git a/app/src/main/res/layout/widget_event_list.xml b/app/src/main/res/layout/widget_event_list.xml index ee31313c4..15a5db8a1 100644 --- a/app/src/main/res/layout/widget_event_list.xml +++ b/app/src/main/res/layout/widget_event_list.xml @@ -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" />