From 897fa21ec4c8866ac5ce4ff0890119d924d33fc6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 27 Nov 2021 11:02:54 +0100 Subject: [PATCH] fix #1553, make the List View widget more compact --- .../pro/adapters/EventListWidgetAdapter.kt | 27 ++++++++++++++----- .../res/layout/event_list_item_widget.xml | 10 +++---- .../layout/event_list_section_day_widget.xml | 2 +- .../event_list_section_month_widget.xml | 3 ++- 4 files changed, 27 insertions(+), 15 deletions(-) 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 a2cf9a757..cae4d6c77 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 @@ -14,6 +14,7 @@ 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 com.simplemobiletools.commons.helpers.mydebug import org.joda.time.DateTime import java.util.* @@ -26,11 +27,24 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi private var events = ArrayList() private var textColor = context.config.widgetTextColor private var weakTextColor = textColor.adjustAlpha(MEDIUM_ALPHA) - private val displayDescription = context.config.displayDescription - private val replaceDescription = context.config.replaceDescription - private val dimPastEvents = context.config.dimPastEvents + private var displayDescription = context.config.displayDescription + private var replaceDescription = context.config.replaceDescription + private var dimPastEvents = context.config.dimPastEvents private var mediumFontSize = context.getWidgetFontSize() + init { + initConfigValues() + } + + private fun initConfigValues() { + textColor = context.config.widgetTextColor + weakTextColor = textColor.adjustAlpha(MEDIUM_ALPHA) + displayDescription = context.config.displayDescription + replaceDescription = context.config.replaceDescription + dimPastEvents = context.config.dimPastEvents + mediumFontSize = context.getWidgetFontSize() + } + override fun getViewAt(position: Int): RemoteViews { val type = getItemViewType(position) val remoteView: RemoteViews @@ -108,7 +122,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi remoteView.apply { setTextColor(event_section_title, curTextColor) - setTextSize(event_section_title, mediumFontSize) + setTextSize(event_section_title, mediumFontSize - 3f) setText(event_section_title, item.title) Intent().apply { @@ -123,6 +137,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi val curTextColor = textColor remoteView.apply { setTextColor(event_section_title, curTextColor) + setTextSize(event_section_title, mediumFontSize) setText(event_section_title, item.title) } } @@ -142,9 +157,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi override fun getItemId(position: Int) = position.toLong() override fun onDataSetChanged() { - textColor = context.config.widgetTextColor - weakTextColor = textColor.adjustAlpha(LOWER_ALPHA) - mediumFontSize = context.getWidgetFontSize() + initConfigValues() val fromTS = DateTime().seconds() - context.config.displayPastEvents * 60 val toTS = DateTime().plusYears(1).seconds() context.eventsHelper.getEventsSync(fromTS, toTS, applyTypeFilter = true) { 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 3072ae81a..56e0537ba 100644 --- a/app/src/main/res/layout/event_list_item_widget.xml +++ b/app/src/main/res/layout/event_list_item_widget.xml @@ -5,12 +5,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/small_margin" - android:layout_marginTop="@dimen/small_margin" android:layout_marginEnd="@dimen/small_margin" - android:layout_marginBottom="@dimen/medium_margin" - android:background="@drawable/section_holder_stroke" - android:paddingTop="@dimen/medium_margin" - android:paddingBottom="@dimen/medium_margin"> + android:paddingTop="@dimen/small_margin" + android:paddingBottom="@dimen/small_margin"> 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 index f678ba54f..762298457 100644 --- a/app/src/main/res/layout/event_list_section_month_widget.xml +++ b/app/src/main/res/layout/event_list_section_month_widget.xml @@ -3,8 +3,9 @@ android:id="@+id/event_section_title" android:layout_width="match_parent" android:layout_height="wrap_content" + android:includeFontPadding="false" android:paddingStart="@dimen/medium_margin" android:paddingBottom="@dimen/small_margin" android:textAllCaps="true" android:textFontWeight="300" - android:textSize="20sp" /> + android:textSize="16sp" />