From 53c88f1ab2e488fcaf8d58d63226a44ff72f8f5c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 6 Feb 2020 20:41:36 +0100 Subject: [PATCH] updating commons to 5.22.5 --- app/build.gradle | 2 +- .../calendar/pro/activities/SettingsActivity.kt | 6 ------ .../pro/adapters/EventListWidgetAdapter.kt | 5 +++-- .../calendar/pro/extensions/Context.kt | 11 +++++++++++ .../calendar/pro/helpers/Config.kt | 15 --------------- .../calendar/pro/helpers/Constants.kt | 6 ------ .../calendar/pro/helpers/MyWidgetListProvider.kt | 3 ++- .../pro/helpers/MyWidgetMonthlyProvider.kt | 9 +++++---- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b8597957c..cb7fee3ac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -64,7 +64,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.21.9' + implementation 'com.simplemobiletools:commons:5.22.5' implementation 'joda-time:joda-time:2.10.1' implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt index 13c0bc2ef..0c5a24ce1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt @@ -515,12 +515,6 @@ class SettingsActivity : SimpleActivity() { } } - private fun getFontSizeText() = getString(when (config.fontSize) { - FONT_SIZE_SMALL -> R.string.small - FONT_SIZE_MEDIUM -> R.string.medium - else -> R.string.large - }) - private fun setupCustomizeWidgetColors() { settings_customize_widget_colors_holder.setOnClickListener { Intent(this, WidgetListConfigureActivity::class.java).apply { 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 848c00a45..cf779ea55 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 @@ -10,6 +10,7 @@ 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.helpers.* import com.simplemobiletools.calendar.pro.helpers.Formatter @@ -34,7 +35,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi private var weakTextColor = textColor.adjustAlpha(LOW_ALPHA) private val replaceDescription = context.config.replaceDescription private val dimPastEvents = context.config.dimPastEvents - private var mediumFontSize = context.config.getFontSize() + private var mediumFontSize = context.getWidgetFontSize() override fun getViewAt(position: Int): RemoteViews? { val type = getItemViewType(position) @@ -154,7 +155,7 @@ class EventListWidgetAdapter(val context: Context) : RemoteViewsService.RemoteVi override fun onDataSetChanged() { textColor = context.config.widgetTextColor weakTextColor = textColor.adjustAlpha(LOW_ALPHA) - mediumFontSize = context.config.getFontSize() + mediumFontSize = context.getWidgetFontSize() 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/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index 862c7bea0..0b0fd0321 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -512,3 +512,14 @@ fun Context.refreshCalDAVCalendars(ids: String, showToasts: Boolean) { } } } + + +fun Context.getWidgetFontSize() = when (config.fontSize) { + FONT_SIZE_SMALL -> getWidgetSmallFontSize() + FONT_SIZE_MEDIUM -> getWidgetMediumFontSize() + else -> getWidgetLargeFontSize() +} + +fun Context.getWidgetSmallFontSize() = getWidgetMediumFontSize() - 3f +fun Context.getWidgetMediumFontSize() = resources.getDimension(R.dimen.day_text_size) / resources.displayMetrics.density +fun Context.getWidgetLargeFontSize() = getWidgetMediumFontSize() + 3f diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt index 59afb9a72..a4039255d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.calendar.pro.helpers import android.content.Context import android.media.AudioManager -import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.scheduleCalDAVSync import com.simplemobiletools.commons.extensions.getDefaultAlarmTitle @@ -73,10 +72,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getStringSet(DISPLAY_EVENT_TYPES, HashSet()) set(displayEventTypes) = prefs.edit().remove(DISPLAY_EVENT_TYPES).putStringSet(DISPLAY_EVENT_TYPES, displayEventTypes).apply() - var fontSize: Int - get() = prefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM) - set(size) = prefs.edit().putInt(FONT_SIZE, size).apply() - var listWidgetViewToOpen: Int get() = prefs.getInt(LIST_WIDGET_VIEW_TO_OPEN, DAILY_VIEW) set(viewToOpenFromListWidget) = prefs.edit().putInt(LIST_WIDGET_VIEW_TO_OPEN, viewToOpenFromListWidget).apply() @@ -140,16 +135,6 @@ class Config(context: Context) : BaseConfig(context) { displayEventTypes = currDisplayEventTypes } - fun getFontSize() = when (fontSize) { - FONT_SIZE_SMALL -> getSmallFontSize() - FONT_SIZE_MEDIUM -> getMediumFontSize() - else -> getLargeFontSize() - } - - private fun getSmallFontSize() = getMediumFontSize() - 3f - private fun getMediumFontSize() = context.resources.getDimension(R.dimen.day_text_size) / context.resources.displayMetrics.density - private fun getLargeFontSize() = getMediumFontSize() + 3f - var usePreviousEventReminders: Boolean get() = prefs.getBoolean(USE_PREVIOUS_EVENT_REMINDERS, true) set(usePreviousEventReminders) = prefs.edit().putBoolean(USE_PREVIOUS_EVENT_REMINDERS, usePreviousEventReminders).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt index e42d8e3d1..eedbdb6cc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt @@ -50,7 +50,6 @@ const val LAST_EVENT_REMINDER_MINUTES = "reminder_minutes" const val LAST_EVENT_REMINDER_MINUTES_2 = "reminder_minutes_2" const val LAST_EVENT_REMINDER_MINUTES_3 = "reminder_minutes_3" const val DISPLAY_EVENT_TYPES = "display_event_types" -const val FONT_SIZE = "font_size" const val LIST_WIDGET_VIEW_TO_OPEN = "list_widget_view_to_open" const val CALDAV_SYNC = "caldav_sync" const val CALDAV_SYNCED_CALENDAR_IDS = "caldav_synced_calendar_ids" @@ -142,11 +141,6 @@ const val FR = "FR" const val SA = "SA" const val SU = "SU" -// font sizes -const val FONT_SIZE_SMALL = 0 -const val FONT_SIZE_MEDIUM = 1 -const val FONT_SIZE_LARGE = 2 - const val SOURCE_SIMPLE_CALENDAR = "simple-calendar" const val SOURCE_IMPORTED_ICS = "imported-ics" const val SOURCE_CONTACT_BIRTHDAY = "contact-birthday" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt index ae5e4b6c2..5d288eec2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetListProvider.kt @@ -11,6 +11,7 @@ import android.widget.RemoteViews import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config +import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize import com.simplemobiletools.calendar.pro.extensions.launchNewEventIntent import com.simplemobiletools.calendar.pro.services.WidgetService import com.simplemobiletools.calendar.pro.services.WidgetServiceEmpty @@ -27,7 +28,7 @@ class MyWidgetListProvider : AppWidgetProvider() { } private fun performUpdate(context: Context) { - val fontSize = context.config.getFontSize() + val fontSize = context.getWidgetFontSize() val textColor = context.config.widgetTextColor val appWidgetManager = AppWidgetManager.getInstance(context) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt index 9bf4c04a2..7dd7300ca 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/MyWidgetMonthlyProvider.kt @@ -12,6 +12,7 @@ import android.widget.RemoteViews import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SplashActivity import com.simplemobiletools.calendar.pro.extensions.config +import com.simplemobiletools.calendar.pro.extensions.getWidgetFontSize import com.simplemobiletools.calendar.pro.extensions.launchNewEventIntent import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.pro.models.DayMonthly @@ -93,7 +94,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { val displayWeekNumbers = context.config.showWeekNumbers val textColor = context.config.widgetTextColor val dimPastEvents = context.config.dimPastEvents - val smallerFontSize = context.config.getFontSize() - 3f + val smallerFontSize = context.getWidgetFontSize() - 3f val res = context.resources val len = days.size val packageName = context.packageName @@ -148,7 +149,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private fun addDayNumber(context: Context, views: RemoteViews, day: DayMonthly, textColor: Int, id: Int) { val newRemoteView = RemoteViews(context.packageName, R.layout.day_monthly_number_view).apply { setText(R.id.day_monthly_number_id, day.value.toString()) - setTextSize(R.id.day_monthly_number_id, context.config.getFontSize() - 3f) + setTextSize(R.id.day_monthly_number_id, context.getWidgetFontSize() - 3f) if (day.isToday) { setBackgroundColor(R.id.day_monthly_number_id, textColor) @@ -162,7 +163,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private val monthlyCalendar = object : MonthlyCalendar { override fun updateMonthlyCalendar(context: Context, month: String, days: ArrayList, checkedEvents: Boolean, currTargetDate: DateTime) { - val largerFontSize = context.config.getFontSize() + 3f + val largerFontSize = context.getWidgetFontSize() + 3f val textColor = context.config.widgetTextColor val resources = context.resources @@ -212,7 +213,7 @@ class MyWidgetMonthlyProvider : AppWidgetProvider() { private fun updateDayLabels(context: Context, views: RemoteViews, resources: Resources, textColor: Int) { val sundayFirst = context.config.isSundayFirst - val smallerFontSize = context.config.getFontSize() + val smallerFontSize = context.getWidgetFontSize() val packageName = context.packageName val letters = context.resources.getStringArray(R.array.week_day_letters) for (i in 0..6) {