Compare commits

...

35 Commits

Author SHA1 Message Date
2762f12151 Add the background location disclaimer 2020-10-02 19:46:52 +02:00
a873c71918 Update the ui 2020-10-02 18:02:22 +02:00
e8f3c110a8 Add the dark theme colors 2020-10-02 17:36:39 +02:00
72bf3b04a7 Fix #156 2020-10-02 16:16:32 +02:00
ca6fb75dfd Fix #191 2020-10-02 15:45:59 +02:00
59dc5de21a Fix #169 2020-10-02 15:00:37 +02:00
ec40a277d7 Fix #186, fix #187 2020-10-02 11:30:59 +02:00
507b7f2318 Fix #174, fix #185 2020-10-02 11:23:23 +02:00
1a709a9406 Merge pull request #172 from Matromag/patch-2
Update translation
2020-10-02 11:19:14 +02:00
770ba0cd13 Merge pull request #173 from Steve-Mr/master
Simplified Chinese translations
2020-10-02 11:18:51 +02:00
6a92225edf Merge pull request #178 from shtraus12/master
fixed Russian localisation
2020-10-02 11:17:46 +02:00
ce801d4a7d Merge pull request #192 from d-l-n/master
i have translated language app to Spanish
2020-10-02 11:16:59 +02:00
25da807bd5 Translated strings to Spanish (master branch) 2020-09-13 20:14:05 -03:00
63212d13b1 translated a few strings to Spanish (master branch) 2020-09-12 21:19:11 -03:00
79ad9b2500 updated file name lol 2020-09-11 22:26:25 -03:00
9c0aa0a9ef added model 2020-09-11 22:25:28 -03:00
b9197ddf2e fix Russian localisation 2020-06-30 15:17:50 +03:00
d1362f7d81 modify chinese translation 2020-06-16 13:17:11 +08:00
a8c7d115ae change one sentence 2020-06-13 16:16:40 +08:00
a5a753e198 Add Chinese translation 2020-06-13 16:14:42 +08:00
39ede20518 Update translation 2020-06-12 15:17:28 +02:00
5527e6e405 Merge pull request #161 from Drumber/translation
Update German translation
2020-05-25 10:59:41 +02:00
565ed11f53 Merge pull request #160 from Moutony/patch-11
Update French (v2.0.12)
2020-05-25 10:30:44 +02:00
4bd8653d32 Merge pull request #154 from zmni/translation
Update Indonesian translation
2020-05-25 10:30:32 +02:00
d121119ca9 Accept and close #162 2020-05-25 10:30:04 +02:00
e82a34bcc7 Fix #157, fix #163 2020-05-25 10:16:21 +02:00
8867a1fbbd Update strings.xml
fixed just another too long string
2020-05-23 13:57:21 +02:00
7265883d6c Update strings.xml
- fixed too long words
- small cosmetic changes
2020-05-23 13:39:28 +02:00
7a4fc6ff58 Update German translation
- removed untranslatable strings
- added new string (line 203: nothing)
- fixed typos
2020-05-23 12:14:17 +02:00
9f61215caa Update French
I shortened the word 'événement' because it was oddly long.
It made the text overstep to a second line because of the new on/off button.
2020-05-23 12:01:39 +02:00
7ccf7eb8f6 Update Indonesian translation
Ref: 0d2287dbdf (diff-01dafb3fd0217441330103cfc8300094)
2020-05-23 04:32:15 +07:00
704448a848 Double-tap on the capitalize icon to set the date to uppercase 2020-05-22 19:25:34 +02:00
fa366b3d45 Merge pull request #151 from shtraus12/master
Fixed Russian translation
2020-05-22 19:22:16 +02:00
e58fef66aa Close #148 2020-05-22 19:18:29 +02:00
c120bad9c6 Update strings.xml 2020-05-22 19:48:39 +03:00
248 changed files with 1785 additions and 521 deletions

Binary file not shown.

View File

@ -1,6 +1,22 @@
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings> </JetCodeStyleSettings>
<codeStyleSettings language="XML"> <codeStyleSettings language="XML">

2
.idea/modules.xml generated
View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/Another Widget.iml" filepath="$PROJECT_DIR$/Another Widget.iml" group="Another Widget" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/Another_Widget.iml" filepath="$PROJECT_DIR$/.idea/modules/Another_Widget.iml" group="Another_Widget" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" group="Another Widget/app" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" group="Another Widget/app" />
</modules> </modules>
</component> </component>

View File

@ -18,8 +18,8 @@ android {
applicationId "com.tommasoberlose.anotherwidget" applicationId "com.tommasoberlose.anotherwidget"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 29 targetSdkVersion 29
versionCode 101 versionCode 105
versionName "2.0.12" versionName "2.0.13"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -59,13 +59,13 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13' testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// UI // UI
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.2.0-alpha06' implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'androidx.browser:browser:1.2.0' implementation 'androidx.browser:browser:1.2.0'
implementation 'net.idik:slimadapter:2.1.2' implementation 'net.idik:slimadapter:2.1.2'
implementation 'com.google.android:flexbox:2.0.1' implementation 'com.google.android:flexbox:2.0.1'
@ -75,18 +75,18 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.work:work-runtime-ktx:2.3.4" implementation "androidx.work:work-runtime-ktx:2.4.0"
// EventBus // EventBus
implementation 'org.greenrobot:eventbus:3.1.1' implementation 'org.greenrobot:eventbus:3.1.1'
// Navigation // Navigation
implementation 'androidx.navigation:navigation-fragment:2.3.0-alpha05' implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2' implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
// Other // Other
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'joda-time:joda-time:2.9.9' implementation 'joda-time:joda-time:2.10.3'
implementation 'me.everything:providers-android:1.0.1' implementation 'me.everything:providers-android:1.0.1'
implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2' implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2'
@ -96,34 +96,30 @@ dependencies {
// Fitness // Fitness
implementation 'com.google.android.gms:play-services-fitness:18.0.0' implementation 'com.google.android.gms:play-services-fitness:18.0.0'
implementation 'com.google.android.gms:play-services-auth:18.0.0' implementation 'com.google.android.gms:play-services-auth:18.1.0'
//Weather //Weather
implementation 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:2.0.2' implementation 'com.github.KwabenBerko:OpenWeatherMap-Android-Library:2.0.2'
implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-location:17.1.0'
// Billing // Billing
implementation 'com.android.billingclient:billing:2.2.0' implementation 'com.android.billingclient:billing:3.0.1'
implementation 'com.android.billingclient:billing-ktx:2.2.0' implementation 'com.android.billingclient:billing-ktx:3.0.1'
// KTX // KTX
implementation "androidx.core:core-ktx:1.2.0" implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
implementation "androidx.palette:palette-ktx:1.0.0" implementation "androidx.palette:palette-ktx:1.0.0"
implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.core:core-ktx:1.3.2'
// Add the Firebase SDK for Crashlytics. // Add the Firebase SDK for Crashlytics.
implementation 'com.google.firebase:firebase-crashlytics:17.0.0' implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
// Preferences // Preferences
implementation 'com.chibatching.kotpref:kotpref:2.10.0' implementation 'com.chibatching.kotpref:kotpref:2.11.0'
implementation 'com.chibatching.kotpref:livedata-support:2.10.0' implementation 'com.chibatching.kotpref:livedata-support:2.10.0'
implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.preference:preference-ktx:1.1.1'
// Permissions // Permissions
implementation 'com.karumi:dexter:6.1.0' implementation 'com.karumi:dexter:6.1.0'
// Billing
implementation 'com.android.billingclient:billing:2.2.0'
implementation 'com.android.billingclient:billing-ktx:2.2.0'
} }

Binary file not shown.

View File

@ -11,8 +11,8 @@ typealias DialogCallback = () -> Unit
class MaterialBottomSheetDialog( class MaterialBottomSheetDialog(
context: Context, context: Context,
private val title: String? = "", private val title: String? = null,
private val message: String? = "" private val message: String? = null
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { ) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
private var positiveButtonLabel: String? = null private var positiveButtonLabel: String? = null
@ -36,7 +36,7 @@ class MaterialBottomSheetDialog(
val view = View.inflate(context, R.layout.bottom_sheet_dialog, null) val view = View.inflate(context, R.layout.bottom_sheet_dialog, null)
// Header // Header
view.message.isVisible = title != null view.title.isVisible = title != null
view.title.text = title ?: "" view.title.text = title ?: ""
view.message.isVisible = message != null view.message.isVisible = message != null

View File

@ -5,12 +5,14 @@ import android.provider.CalendarContract
import android.util.Log import android.util.Log
import com.chibatching.kotpref.bulk import com.chibatching.kotpref.bulk
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
import com.tommasoberlose.anotherwidget.models.Event import com.tommasoberlose.anotherwidget.models.Event
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import io.realm.Realm import io.realm.Realm
import io.realm.RealmResults import io.realm.RealmResults
import java.util.* import java.util.*
import kotlin.Comparator
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
class EventRepository(val context: Context) { class EventRepository(val context: Context) {
@ -68,7 +70,7 @@ class EventRepository(val context: Context) {
val events = getEvents() val events = getEvents()
if (events.isNotEmpty()) { if (events.isNotEmpty()) {
val newNextEvent = events.first() val newNextEvent = events.first()
Preferences.nextEventId = newNextEvent!!.eventID Preferences.nextEventId = newNextEvent.eventID
newNextEvent newNextEvent
} else { } else {
resetNextEventData() resetNextEventData()
@ -96,9 +98,9 @@ class EventRepository(val context: Context) {
if (eventList.isNotEmpty()) { if (eventList.isNotEmpty()) {
val index = eventList.indexOfFirst { it.eventID == Preferences.nextEventId } val index = eventList.indexOfFirst { it.eventID == Preferences.nextEventId }
if (index > -1 && index < eventList.size - 1) { if (index > -1 && index < eventList.size - 1) {
Preferences.nextEventId = eventList[index + 1]!!.eventID Preferences.nextEventId = eventList[index + 1].eventID
} else { } else {
Preferences.nextEventId = eventList.first()!!.eventID Preferences.nextEventId = eventList.first().eventID
} }
} else { } else {
resetNextEventData() resetNextEventData()
@ -112,9 +114,9 @@ class EventRepository(val context: Context) {
if (eventList.isNotEmpty()) { if (eventList.isNotEmpty()) {
val index = eventList.indexOfFirst { it.eventID == Preferences.nextEventId } val index = eventList.indexOfFirst { it.eventID == Preferences.nextEventId }
if (index > 0) { if (index > 0) {
Preferences.nextEventId = eventList[index - 1]!!.eventID Preferences.nextEventId = eventList[index - 1].eventID
} else { } else {
Preferences.nextEventId = eventList.last()!!.eventID Preferences.nextEventId = eventList.last().eventID
} }
} else { } else {
resetNextEventData() resetNextEventData()
@ -130,8 +132,7 @@ class EventRepository(val context: Context) {
.where(Event::class.java) .where(Event::class.java)
.greaterThan("endDate", now) .greaterThan("endDate", now)
.findAll() .findAll()
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) } .applyFilters()
.filter { (Preferences.calendarAllDay || !it.allDay) }
} }
private fun getEvents(): List<Event> { private fun getEvents(): List<Event> {
@ -156,8 +157,7 @@ class EventRepository(val context: Context) {
.greaterThan("endDate", now) .greaterThan("endDate", now)
.lessThanOrEqualTo("startDate", limit.timeInMillis) .lessThanOrEqualTo("startDate", limit.timeInMillis)
.findAll() .findAll()
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) } .applyFilters()
.filter { (Preferences.calendarAllDay || !it.allDay) }
} }
fun getEventsCount(): Int = getEvents().size fun getEventsCount(): Int = getEvents().size

View File

@ -15,6 +15,13 @@ object Constants {
LARGE(3) LARGE(3)
} }
enum class SecondRowTopMargin(val value: Int) {
NONE(0),
SMALL(1),
MEDIUM(2),
LARGE(3)
}
enum class GlanceProviderId(val id: String) { enum class GlanceProviderId(val id: String) {
PLAYING_SONG("PLAYING_SONG"), PLAYING_SONG("PLAYING_SONG"),
NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"), NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"),

View File

@ -31,6 +31,7 @@ object Preferences : KotprefModel() {
var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "") var customLocationAdd by stringPref(key = "PREF_CUSTOM_LOCATION_ADD", default = "")
var dateFormat by stringPref(default = "") var dateFormat by stringPref(default = "")
var isDateCapitalize by booleanPref(default = true) var isDateCapitalize by booleanPref(default = true)
var isDateUppercase by booleanPref(default = false)
var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1) var weatherRefreshPeriod by intPref(key = "PREF_WEATHER_REFRESH_PERIOD", default = 1)
var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1) var showUntil by intPref(key = "PREF_SHOW_UNTIL", default = 1)
var calendarAppName by stringPref(key = "PREF_CALENDAR_APP_NAME", default = "") var calendarAppName by stringPref(key = "PREF_CALENDAR_APP_NAME", default = "")
@ -55,6 +56,20 @@ object Preferences : KotprefModel() {
var clockTextColor by stringPref(default = "#FFFFFF") var clockTextColor by stringPref(default = "#FFFFFF")
var clockTextAlpha by stringPref(default = "FF") var clockTextAlpha by stringPref(default = "FF")
var textGlobalColorDark by stringPref(default = "#FFFFFF")
var textGlobalAlphaDark by stringPref(default = "FF")
var textSecondaryColorDark by stringPref(default = "#FFFFFF")
var textSecondaryAlphaDark by stringPref(default = "FF")
var backgroundCardColorDark by stringPref(default = "#000000")
var backgroundCardAlphaDark by stringPref(default = "00")
var clockTextColorDark by stringPref(default = "#FFFFFF")
var clockTextAlphaDark by stringPref(default = "FF")
var showAMPMIndicator by booleanPref(default = true) var showAMPMIndicator by booleanPref(default = true)
var weatherIconPack by intPref(default = Constants.WeatherIconPack.DEFAULT.value) var weatherIconPack by intPref(default = Constants.WeatherIconPack.DEFAULT.value)
@ -64,12 +79,17 @@ object Preferences : KotprefModel() {
var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f) var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f)
var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f) var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f)
var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.value) var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.value)
var secondRowTopMargin by intPref(default = Constants.SecondRowTopMargin.NONE.value)
var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false) var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false)
var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "") var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "")
var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "") var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "")
var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1) var textShadow by intPref(key = "PREF_TEXT_SHADOW", default = 1)
var textShadowDark by intPref(default = 1)
var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME", default = true) var showDiffTime by booleanPref(key = "PREF_SHOW_DIFF_TIME", default = true)
var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false) var showDeclinedEvents by booleanPref(key = "PREF_SHOW_DECLINED_EVENTS", default = false)
var showInvitedEvents by booleanPref(default = false)
var showAcceptedEvents by booleanPref(default = true)
var showOnlyBusyEvents by booleanPref(default = false)
var secondRowInformation by intPref(key = "PREF_SECOND_ROW_INFORMATION", default = 0) var secondRowInformation by intPref(key = "PREF_SECOND_ROW_INFORMATION", default = 0)
var customFont by intPref(key = "PREF_CUSTOM_FONT", default = Constants.CUSTOM_FONT_PRODUCT_SANS) var customFont by intPref(key = "PREF_CUSTOM_FONT", default = Constants.CUSTOM_FONT_PRODUCT_SANS)
var customFontFile by stringPref(key = "PREF_CUSTOM_FONT_FILE") var customFontFile by stringPref(key = "PREF_CUSTOM_FONT_FILE")

View File

@ -12,8 +12,7 @@ object AlarmHelper {
val alarm = nextAlarmClock val alarm = nextAlarmClock
return if ( return if (
alarm != null alarm != null
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 10 * 60 * 1000 && alarm.triggerTime - Calendar.getInstance().timeInMillis > 5 * 60 * 1000
&& alarm.triggerTime - Calendar.getInstance().timeInMillis < 12 * 60 * 60 * 1000
) { ) {
"%s %s".format( "%s %s".format(
SimpleDateFormat("EEE", Locale.getDefault()).format(alarm.triggerTime), SimpleDateFormat("EEE", Locale.getDefault()).format(alarm.triggerTime),

View File

@ -104,13 +104,12 @@ object BitmapHelper {
} }
fun drawableToBitmap(drawable: Drawable): Bitmap? { fun drawableToBitmap(drawable: Drawable): Bitmap? {
var bitmap: Bitmap? = null
if (drawable is BitmapDrawable) { if (drawable is BitmapDrawable) {
if (drawable.bitmap != null) { if (drawable.bitmap != null) {
return drawable.bitmap return drawable.bitmap
} }
} }
bitmap = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) { val bitmap: Bitmap = if (drawable.intrinsicWidth <= 0 || drawable.intrinsicHeight <= 0) {
Bitmap.createBitmap( Bitmap.createBitmap(
1, 1,
1, 1,

View File

@ -69,4 +69,15 @@ object CalendarHelper {
fun removeEventUpdatesAndroidN(context: Context) { fun removeEventUpdatesAndroidN(context: Context) {
EventListenerJob.remove(context) EventListenerJob.remove(context)
} }
fun List<Event>.applyFilters() : List<Event> {
return this
.asSequence()
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) }
.filter { (Preferences.showAcceptedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED) }
.filter { (Preferences.showInvitedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_INVITED) }
.filter { (Preferences.calendarAllDay || !it.allDay) }
.filter { (!Preferences.showOnlyBusyEvents || it.availability != CalendarContract.EventsEntity.AVAILABILITY_FREE) }
.toList()
}
} }

View File

@ -7,97 +7,97 @@ import com.tommasoberlose.anotherwidget.global.Preferences
import kotlin.math.roundToInt import kotlin.math.roundToInt
object ColorHelper { object ColorHelper {
fun getFontColor(): Int { fun getFontColor(isDark: Boolean): Int {
return try { return try {
Color.parseColor("#%s%s".format(Preferences.textGlobalAlpha, Preferences.textGlobalColor.replace("#", ""))) Color.parseColor("#%s%s".format(if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark, (if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark).replace("#", "")))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getFontColorAlpha(): Int { fun getFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.textGlobalAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getFontColorRgb(): Int { fun getFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.textGlobalColor) Color.parseColor((if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getSecondaryFontColor(): Int { fun getSecondaryFontColor(isDark: Boolean): Int {
return try { return try {
Color.parseColor("#%s%s".format(Preferences.textSecondaryAlpha, Preferences.textSecondaryColor.replace("#", ""))) Color.parseColor("#%s%s".format((if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark), (if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark).replace("#", "")))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getSecondaryFontColorAlpha(): Int { fun getSecondaryFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.textSecondaryAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getSecondaryFontColorRgb(): Int { fun getSecondaryFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.textSecondaryColor) Color.parseColor((if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getClockFontColor(): Int { fun getClockFontColor(isDark: Boolean): Int {
return try { return try {
Color.parseColor("#%s%s".format(Preferences.clockTextAlpha, Preferences.clockTextColor.replace("#", ""))) Color.parseColor("#%s%s".format((if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark), (if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark).replace("#", "")))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#FFFFFFFF") Color.parseColor("#FFFFFFFF")
} }
} }
fun getClockFontColorAlpha(): Int { fun getClockFontColorAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.clockTextAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"FF".toIntValue().toDouble() * 255 / 100 "FF".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getClockFontColorRgb(): Int { fun getClockFontColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.clockTextColor) Color.parseColor((if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }
} }
fun getBackgroundColor(): Int { fun getBackgroundColor(isDark: Boolean): Int {
return try { return try {
Color.parseColor("#%s%s".format(Preferences.backgroundCardAlpha, Preferences.backgroundCardColor.replace("#", ""))) Color.parseColor("#%s%s".format((if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark), (if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark).replace("#", "")))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#00000000") Color.parseColor("#00000000")
} }
} }
fun getBackgroundAlpha(): Int { fun getBackgroundAlpha(isDark: Boolean): Int {
return try { return try {
Preferences.backgroundCardAlpha.toIntValue().toDouble() * 255 / 100 (if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark).toIntValue().toDouble() * 255 / 100
} catch (e: Exception) { } catch (e: Exception) {
"00".toIntValue().toDouble() * 255 / 100 "00".toIntValue().toDouble() * 255 / 100
}.roundToInt() }.roundToInt()
} }
fun getBackgroundColorRgb(): Int { fun getBackgroundColorRgb(isDark: Boolean): Int {
return try { return try {
Color.parseColor(Preferences.backgroundCardColor) Color.parseColor((if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark))
} catch (e: Exception) { } catch (e: Exception) {
Color.parseColor("#000000") Color.parseColor("#000000")
} }

View File

@ -2,7 +2,6 @@ package com.tommasoberlose.anotherwidget.helpers
import android.content.Context import android.content.Context
import android.text.format.DateUtils import android.text.format.DateUtils
import android.util.Log
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.utils.getCapWordString import com.tommasoberlose.anotherwidget.utils.getCapWordString
import java.lang.Exception import java.lang.Exception
@ -17,7 +16,11 @@ object DateHelper {
} catch (e: Exception) { } catch (e: Exception) {
getDefaultDateText(context, date) getDefaultDateText(context, date)
} }
if (Preferences.isDateCapitalize) text.getCapWordString() else text when {
Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault())
Preferences.isDateCapitalize -> text.getCapWordString()
else -> text
}
} else { } else {
val flags: Int = val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
@ -25,17 +28,20 @@ object DateHelper {
SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time), SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time),
DateUtils.formatDateTime(context, date.timeInMillis, flags) DateUtils.formatDateTime(context, date.timeInMillis, flags)
) )
if (Preferences.isDateCapitalize) text.getCapWordString() else text when {
Preferences.isDateUppercase -> text.toUpperCase(Locale.getDefault())
Preferences.isDateCapitalize -> text.getCapWordString()
else -> text
}
} }
} }
fun getDefaultDateText(context: Context, date: Calendar): String { fun getDefaultDateText(context: Context, date: Calendar): String {
val flags: Int = val flags: Int =
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
val text = "%s, %s".format( return "%s, %s".format(
SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time), SimpleDateFormat("EEEE", Locale.getDefault()).format(date.time),
DateUtils.formatDateTime(context, date.timeInMillis, flags) DateUtils.formatDateTime(context, date.timeInMillis, flags)
) )
return if (Preferences.isDateCapitalize) text.getCapWordString() else text
} }
} }

View File

@ -10,6 +10,8 @@ import android.media.session.MediaSessionManager
import android.media.session.PlaybackState import android.media.session.PlaybackState
import android.util.Log import android.util.Log
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import com.chibatching.kotpref.Kotpref
import com.chibatching.kotpref.blockingBulk
import com.chibatching.kotpref.bulk import com.chibatching.kotpref.bulk
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.receivers.MusicNotificationListener import com.tommasoberlose.anotherwidget.receivers.MusicNotificationListener
@ -28,6 +30,7 @@ object MediaPlayerHelper {
} }
fun updatePlayingMediaInfo(context: Context) { fun updatePlayingMediaInfo(context: Context) {
Kotpref.init(context)
if (NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.packageName)) { if (NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.packageName)) {
val list = try { val list = try {
(context.getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager).getActiveSessions( (context.getSystemService(Context.MEDIA_SESSION_SERVICE) as MediaSessionManager).getActiveSessions(
@ -65,20 +68,21 @@ object MediaPlayerHelper {
} }
if (!isSomeonePlaying) { if (!isSomeonePlaying) {
removeMediaInfo() removeMediaInfo(context)
} }
} else { } else {
removeMediaInfo() removeMediaInfo(context)
} }
} else { } else {
removeMediaInfo() removeMediaInfo(context)
} }
MainWidget.updateWidget(context) MainWidget.updateWidget(context)
} }
private fun removeMediaInfo() { private fun removeMediaInfo(context: Context) {
Preferences.bulk { Kotpref.init(context)
Preferences.blockingBulk {
remove(Preferences::mediaPlayerTitle) remove(Preferences::mediaPlayerTitle)
remove(Preferences::mediaPlayerArtist) remove(Preferences::mediaPlayerArtist)
remove(Preferences::mediaPlayerAlbum) remove(Preferences::mediaPlayerAlbum)

View File

@ -17,7 +17,8 @@ open class Event(
var calendarID: Int = 0, var calendarID: Int = 0,
var allDay: Boolean = false, var allDay: Boolean = false,
var address: String = "", var address: String = "",
var selfAttendeeStatus: Int = CalendarContract.Attendees.ATTENDEE_STATUS_NONE var selfAttendeeStatus: Int = CalendarContract.Attendees.ATTENDEE_STATUS_NONE,
var availability: Int = CalendarContract.EventsEntity.AVAILABILITY_BUSY
) : RealmObject() { ) : RealmObject() {
override fun toString(): String { override fun toString(): String {
return "Event:\nEVENT ID: " + eventID + "\nTITLE: " + title + "\nSTART DATE: " + Date(startDate) + "\nEND DATE: " + Date(endDate) + "\nCAL ID: " + calendarID + "\nADDRESS: " + address return "Event:\nEVENT ID: " + eventID + "\nTITLE: " + title + "\nSTART DATE: " + Date(startDate) + "\nEND DATE: " + Date(endDate) + "\nCAL ID: " + calendarID + "\nADDRESS: " + address

View File

@ -8,6 +8,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
import android.util.Log import android.util.Log
import com.chibatching.kotpref.Kotpref
import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.fitness.Fitness import com.google.android.gms.fitness.Fitness
@ -35,15 +36,16 @@ class ActivityDetectionReceiver : BroadcastReceiver() {
} }
} else { } else {
if (intent.action == Intent.ACTION_BOOT_COMPLETED || intent.action == Intent.ACTION_MY_PACKAGE_REPLACED && Preferences.showDailySteps && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission(Manifest.permission.ACTIVITY_RECOGNITION)) { if (intent.action == Intent.ACTION_BOOT_COMPLETED || intent.action == Intent.ACTION_MY_PACKAGE_REPLACED && Preferences.showDailySteps && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission(Manifest.permission.ACTIVITY_RECOGNITION)) {
resetDailySteps() resetDailySteps(context)
registerFence(context) registerFence(context)
} else { } else {
resetDailySteps() resetDailySteps(context)
} }
} }
} }
private fun resetDailySteps() { private fun resetDailySteps(context: Context) {
Kotpref.init(context)
Preferences.googleFitSteps = -1 Preferences.googleFitSteps = -1
} }
@ -54,6 +56,7 @@ class ActivityDetectionReceiver : BroadcastReceiver() {
.build() .build()
fun registerFence(context: Context) { fun registerFence(context: Context) {
Kotpref.init(context)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission( if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission(
Manifest.permission.ACTIVITY_RECOGNITION)) { Manifest.permission.ACTIVITY_RECOGNITION)) {
val transitions = mutableListOf<ActivityTransition>() val transitions = mutableListOf<ActivityTransition>()
@ -116,6 +119,7 @@ class ActivityDetectionReceiver : BroadcastReceiver() {
} }
fun requestDailySteps(context: Context) { fun requestDailySteps(context: Context) {
Kotpref.init(context)
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context) val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
if (account != null && GoogleSignIn.hasPermissions(account, FITNESS_OPTIONS)) { if (account != null && GoogleSignIn.hasPermissions(account, FITNESS_OPTIONS)) {

View File

@ -52,7 +52,7 @@ class BatteryListenerJob : JobService() {
} }
} }
fun remove(context: Context) { private fun remove(context: Context) {
val js = context.getSystemService(JobScheduler::class.java) val js = context.getSystemService(JobScheduler::class.java)
js?.cancel(chargingJobId) js?.cancel(chargingJobId)
js?.cancel(notChargingJobId) js?.cancel(notChargingJobId)

View File

@ -3,11 +3,13 @@ package com.tommasoberlose.anotherwidget.services
import android.Manifest import android.Manifest
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.provider.CalendarContract
import android.util.Log import android.util.Log
import androidx.core.app.JobIntentService import androidx.core.app.JobIntentService
import com.tommasoberlose.anotherwidget.db.EventRepository import com.tommasoberlose.anotherwidget.db.EventRepository
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
import com.tommasoberlose.anotherwidget.models.Event import com.tommasoberlose.anotherwidget.models.Event
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
@ -22,7 +24,7 @@ import kotlin.collections.ArrayList
class UpdateCalendarJob : JobIntentService() { class UpdateCalendarJob : JobIntentService() {
companion object { companion object {
val jobId = 1200 private const val jobId = 1200
fun enqueueWork(context: Context, work: Intent) { fun enqueueWork(context: Context, work: Intent) {
enqueueWork(context, UpdateCalendarJob::class.java, jobId, work) enqueueWork(context, UpdateCalendarJob::class.java, jobId, work)
@ -83,7 +85,8 @@ class UpdateCalendarJob : JobIntentService() {
calendarID = e.calendarId.toInt(), calendarID = e.calendarId.toInt(),
allDay = e.allDay, allDay = e.allDay,
address = e.eventLocation ?: "", address = e.eventLocation ?: "",
selfAttendeeStatus = e.selfAttendeeStatus.toInt() selfAttendeeStatus = e.selfAttendeeStatus.toInt(),
availability = e.availability
) )
) )
} }
@ -92,17 +95,27 @@ class UpdateCalendarJob : JobIntentService() {
} }
} }
if (eventList.isEmpty()) { val filteredEventList = eventList
.applyFilters()
if (filteredEventList.isEmpty()) {
eventRepository.resetNextEventData() eventRepository.resetNextEventData()
eventRepository.clearEvents() eventRepository.clearEvents()
} else { } else {
eventList.sortWith(Comparator { event: Event, event1: Event -> eventList.sortWith(Comparator { event: Event, event1: Event ->
if (event.allDay && event1.allDay) { val date = Calendar.getInstance().apply { timeInMillis = event.startDate }
event.startDate.compareTo(event1.startDate) val date1 = Calendar.getInstance().apply { timeInMillis = event1.startDate }
} else if (event.allDay) {
1 if (date.get(Calendar.DAY_OF_YEAR) == date1.get(Calendar.DAY_OF_YEAR) && date.get(Calendar.YEAR) == date1.get(Calendar.YEAR)) {
} else if (event1.allDay) { if (event.allDay && event1.allDay) {
-1 event1.startDate.compareTo(event.startDate)
} else if (event.allDay) {
-1
} else if (event1.allDay) {
1
} else {
event1.startDate.compareTo(event.startDate)
}
} else { } else {
event1.startDate.compareTo(event.startDate) event1.startDate.compareTo(event.startDate)
} }
@ -111,9 +124,7 @@ class UpdateCalendarJob : JobIntentService() {
eventRepository.saveEvents( eventRepository.saveEvents(
eventList eventList
) )
eventRepository.saveNextEventData( eventRepository.saveNextEventData(filteredEventList.first())
eventList[0]
)
} }
} catch (ignored: java.lang.Exception) { } catch (ignored: java.lang.Exception) {

View File

@ -6,12 +6,14 @@ import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.chibatching.kotpref.blockingBulk
import com.chibatching.kotpref.bulk import com.chibatching.kotpref.bulk
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomDateBinding import com.tommasoberlose.anotherwidget.databinding.ActivityCustomDateBinding
@ -90,10 +92,14 @@ class CustomDateActivity : AppCompatActivity() {
"__" "__"
} }
if (Preferences.isDateCapitalize) { if (viewModel.isDateCapitalize.value == true) {
text = text.getCapWordString() text = text.getCapWordString()
} }
if (viewModel.isDateUppercase.value == true) {
text = text.toUpperCase(Locale.getDefault())
}
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
action_save.isVisible = text != ERROR_STRING action_save.isVisible = text != ERROR_STRING
loader.visibility = View.INVISIBLE loader.visibility = View.INVISIBLE
@ -105,8 +111,30 @@ class CustomDateActivity : AppCompatActivity() {
viewModel.isDateCapitalize.observe(this, Observer { viewModel.isDateCapitalize.observe(this, Observer {
viewModel.dateInput.value = viewModel.dateInput.value viewModel.dateInput.value = viewModel.dateInput.value
binding.isdCapitalizeEnabled = it updateCapitalizeUi()
}) })
viewModel.isDateUppercase.observe(this, Observer {
viewModel.dateInput.value = viewModel.dateInput.value
updateCapitalizeUi()
})
}
private fun updateCapitalizeUi() {
when {
viewModel.isDateUppercase.value == true -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish))
action_capitalize.alpha = 1f
}
viewModel.isDateCapitalize.value == true -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.ic_capitalize))
action_capitalize.alpha = 1f
}
else -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish))
action_capitalize.alpha = 0.3f
}
}
} }
private fun setupListener() { private fun setupListener() {
@ -115,12 +143,29 @@ class CustomDateActivity : AppCompatActivity() {
} }
action_save.setOnClickListener { action_save.setOnClickListener {
Preferences.dateFormat = viewModel.dateInput.value ?: "" Preferences.blockingBulk {
dateFormat = viewModel.dateInput.value ?: ""
isDateCapitalize = viewModel.isDateCapitalize.value ?: true
isDateUppercase = viewModel.isDateUppercase.value ?: false
}
finish() finish()
} }
action_capitalize.setOnClickListener { action_capitalize.setOnClickListener {
Preferences.isDateCapitalize = !Preferences.isDateCapitalize when {
viewModel.isDateUppercase.value == true -> {
viewModel.isDateCapitalize.value = false
viewModel.isDateUppercase.value = false
}
viewModel.isDateCapitalize.value == true -> {
viewModel.isDateCapitalize.value = false
viewModel.isDateUppercase.value = true
}
else -> {
viewModel.isDateCapitalize.value = true
viewModel.isDateUppercase.value = false
}
}
} }
action_capitalize.setOnLongClickListener { action_capitalize.setOnLongClickListener {

View File

@ -28,6 +28,7 @@ import com.karumi.dexter.MultiplePermissionsReport
import com.karumi.dexter.PermissionToken import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionRequest import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomLocationBinding import com.tommasoberlose.anotherwidget.databinding.ActivityCustomLocationBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
@ -62,7 +63,11 @@ class CustomLocationActivity : AppCompatActivity() {
injector injector
.text(R.id.text, getString(R.string.custom_location_gps)) .text(R.id.text, getString(R.string.custom_location_gps))
.clicked(R.id.text) { .clicked(R.id.text) {
requirePermission() MaterialBottomSheetDialog(this, message = getString(R.string.background_location_warning))
.setPositiveButton(getString(android.R.string.ok)) {
requirePermission()
}
.show()
} }
} }
.register<Address>(R.layout.custom_location_item) { item, injector -> .register<Address>(R.layout.custom_location_item) { item, injector ->

View File

@ -4,7 +4,7 @@ import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.provider.CalendarContract
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -31,10 +31,8 @@ import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
import com.tommasoberlose.anotherwidget.helpers.DateHelper
import com.tommasoberlose.anotherwidget.helpers.IntentHelper import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.isDefaultSet import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import com.tommasoberlose.anotherwidget.utils.toast import com.tommasoberlose.anotherwidget.utils.toast
@ -42,7 +40,6 @@ import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.util.*
import kotlin.Comparator import kotlin.Comparator
class CalendarTabFragment : Fragment() { class CalendarTabFragment : Fragment() {
@ -77,7 +74,7 @@ class CalendarTabFragment : Fragment() {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
show_all_day_toggle.isChecked = Preferences.calendarAllDay show_all_day_toggle.isChecked = Preferences.calendarAllDay
show_declined_events_toggle.isChecked = Preferences.showDeclinedEvents show_only_busy_events_toggle.isChecked = Preferences.showOnlyBusyEvents
show_diff_time_toggle.isChecked = Preferences.showDiffTime show_diff_time_toggle.isChecked = Preferences.showDiffTime
show_multiple_events_toggle.isChecked = Preferences.showNextEvent show_multiple_events_toggle.isChecked = Preferences.showNextEvent
@ -113,12 +110,6 @@ class CalendarTabFragment : Fragment() {
} }
}) })
viewModel.showDeclinedEvents.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
show_declined_events_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
}
})
viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer { viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
second_row_info_label?.text = getString(SettingsStringHelper.getSecondRowInfoString(it)) second_row_info_label?.text = getString(SettingsStringHelper.getSecondRowInfoString(it))
@ -258,18 +249,58 @@ class CalendarTabFragment : Fragment() {
show_all_day_toggle.setOnCheckedChangeListener { _, isChecked -> show_all_day_toggle.setOnCheckedChangeListener { _, isChecked ->
if (Preferences.showEvents) { if (Preferences.showEvents) {
Preferences.calendarAllDay = isChecked Preferences.calendarAllDay = isChecked
updateCalendar()
} }
} }
action_show_declined_events.setOnClickListener { action_change_attendee_filter.setOnClickListener {
if (Preferences.showEvents) { if (Preferences.showEvents) {
show_declined_events_toggle.isChecked = !show_declined_events_toggle.isChecked val selectedValues = emptyList<Int>().toMutableList()
if (Preferences.showDeclinedEvents) {
selectedValues.add(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
}
if (Preferences.showInvitedEvents) {
selectedValues.add(CalendarContract.Attendees.ATTENDEE_STATUS_INVITED)
}
if (Preferences.showAcceptedEvents) {
selectedValues.add(CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED)
}
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_attendee_status_title), isMultiSelection = true)
.setSelectedValues(selectedValues)
dialog.addItem(
getString(R.string.attendee_status_invited),
CalendarContract.Attendees.ATTENDEE_STATUS_INVITED
)
dialog.addItem(
getString(R.string.attendee_status_accepted),
CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED
)
dialog.addItem(
getString(R.string.attendee_status_declined),
CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED
)
dialog.addOnMultipleSelectItemListener { values ->
Preferences.showDeclinedEvents = values.contains(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
Preferences.showAcceptedEvents = values.contains(CalendarContract.Attendees.ATTENDEE_STATUS_ACCEPTED)
Preferences.showInvitedEvents = values.contains(CalendarContract.Attendees.ATTENDEE_STATUS_INVITED)
updateCalendar()
}.show()
} }
} }
show_declined_events_toggle.setOnCheckedChangeListener { _, isChecked -> action_show_only_busy_events.setOnClickListener {
if (Preferences.showEvents) { if (Preferences.showEvents) {
Preferences.showDeclinedEvents = isChecked show_only_busy_events_toggle.isChecked = !show_only_busy_events_toggle.isChecked
}
}
show_only_busy_events_toggle.setOnCheckedChangeListener { _, isChecked ->
if (Preferences.showEvents) {
Preferences.showOnlyBusyEvents = isChecked
updateCalendar()
} }
} }

View File

@ -36,6 +36,7 @@ import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.isDefaultSet import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -95,6 +96,7 @@ class ClockTabFragment : Fragment() {
) { ) {
binding.isClockVisible = Preferences.showClock binding.isClockVisible = Preferences.showClock
binding.is24Format = DateFormat.is24HourFormat(requireContext()) binding.is24Format = DateFormat.is24HourFormat(requireContext())
binding.isDarkModeEnabled = activity?.isDarkTheme() == true
viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer { viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer {
large_clock_warning?.isVisible = it large_clock_warning?.isVisible = it
@ -127,7 +129,18 @@ class ClockTabFragment : Fragment() {
clock_text_color_label?.text = getString(R.string.transparent) clock_text_color_label?.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = clock_text_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.clockTextColorDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.clockTextAlphaDark == "00") {
clock_text_color_label?.text = getString(R.string.transparent)
} else {
clock_text_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -138,7 +151,18 @@ class ClockTabFragment : Fragment() {
clock_text_color_label?.text = getString(R.string.transparent) clock_text_color_label?.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = clock_text_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.clockTextAlphaDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.clockTextAlphaDark == "00") {
clock_text_color_label?.text = getString(R.string.transparent)
} else {
clock_text_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -217,16 +241,25 @@ class ClockTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
getSelected = ColorHelper::getClockFontColorRgb, getSelected = { ColorHelper.getClockFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) val colorString = Integer.toHexString(color)
Preferences.clockTextColor = if (activity?.isDarkTheme() == true) {
"#" + if (colorString.length > 6) colorString.substring(2) else colorString Preferences.clockTextColorDark =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
} else {
Preferences.clockTextColor =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
}
}, },
showAlphaSelector = true, showAlphaSelector = true,
alpha = Preferences.clockTextAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.clockTextAlphaDark.toIntValue() else Preferences.clockTextAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.clockTextAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.clockTextAlphaDark = alpha.toHexValue()
} else {
Preferences.clockTextAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }

View File

@ -12,10 +12,12 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.chibatching.kotpref.blockingBulk
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.databinding.FragmentGeneralSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentGeneralSettingsBinding
import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
import com.tommasoberlose.anotherwidget.helpers.ColorHelper import com.tommasoberlose.anotherwidget.helpers.ColorHelper
@ -26,7 +28,10 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.android.synthetic.main.fragment_general_settings.* import kotlinx.android.synthetic.main.fragment_general_settings.*
import kotlinx.android.synthetic.main.fragment_general_settings.scrollView
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -60,6 +65,7 @@ class GeneralTabFragment : Fragment() {
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
binding.isDarkModeEnabled = activity?.isDarkTheme() == true
return binding.root return binding.root
} }
@ -102,7 +108,18 @@ class GeneralTabFragment : Fragment() {
font_color_label?.text = getString(R.string.transparent) font_color_label?.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.textGlobalColorDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.textGlobalAlphaDark == "00") {
font_color_label?.text = getString(R.string.transparent)
} else {
font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -113,7 +130,18 @@ class GeneralTabFragment : Fragment() {
font_color_label?.text = getString(R.string.transparent) font_color_label?.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.textGlobalAlphaDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.textGlobalAlphaDark == "00") {
font_color_label?.text = getString(R.string.transparent)
} else {
font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -124,7 +152,18 @@ class GeneralTabFragment : Fragment() {
secondary_font_color_label?.text = getString(R.string.transparent) secondary_font_color_label?.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = secondary_font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.textSecondaryColorDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.textSecondaryAlphaDark == "00") {
secondary_font_color_label?.text = getString(R.string.transparent)
} else {
secondary_font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -135,7 +174,29 @@ class GeneralTabFragment : Fragment() {
secondary_font_color_label?.text = getString(R.string.transparent) secondary_font_color_label?.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = secondary_font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.textSecondaryAlphaDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.textSecondaryAlphaDark == "00") {
secondary_font_color_label?.text = getString(R.string.transparent)
} else {
secondary_font_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.secondRowTopMargin.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
second_row_top_margin_label?.text = when (it) {
Constants.SecondRowTopMargin.NONE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_none)
Constants.SecondRowTopMargin.SMALL.value -> getString(R.string.settings_clock_bottom_margin_subtitle_small)
Constants.SecondRowTopMargin.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large)
else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium)
} }
} }
}) })
@ -146,7 +207,18 @@ class GeneralTabFragment : Fragment() {
background_color_label?.text = getString(R.string.transparent) background_color_label?.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = background_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.backgroundCardColorDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.backgroundCardAlphaDark == "00") {
background_color_label?.text = getString(R.string.transparent)
} else {
background_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
@ -157,14 +229,37 @@ class GeneralTabFragment : Fragment() {
background_color_label?.text = getString(R.string.transparent) background_color_label?.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = background_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor())).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
}
}
})
viewModel.backgroundCardAlphaDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (Preferences.backgroundCardAlphaDark == "00") {
background_color_label?.text = getString(R.string.transparent)
} else {
background_color_label?.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) })
viewModel.textShadow.observe(viewLifecycleOwner, Observer { viewModel.textShadow.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
text_shadow_label?.text = getString(SettingsStringHelper.getTextShadowString(it)) if (activity?.isDarkTheme() != true) {
text_shadow_label?.text =
getString(SettingsStringHelper.getTextShadowString(it))
}
}
})
viewModel.textShadowDark.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
if (activity?.isDarkTheme() == true) {
text_shadow_label?.text =
getString(SettingsStringHelper.getTextShadowString(it))
}
} }
}) })
@ -213,15 +308,23 @@ class GeneralTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
getSelected = ColorHelper::getFontColorRgb, getSelected = { ColorHelper.getFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) val colorString = Integer.toHexString(color)
Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString if (activity?.isDarkTheme() == true) {
Preferences.textGlobalColorDark = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
} else {
Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
}
}, },
showAlphaSelector = true, showAlphaSelector = true,
alpha = Preferences.textGlobalAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.textGlobalAlphaDark.toIntValue() else Preferences.textGlobalAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.textGlobalAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.textGlobalAlphaDark = alpha.toHexValue()
} else {
Preferences.textGlobalAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
@ -230,19 +333,55 @@ class GeneralTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_secondary_font_color_title), header = getString(R.string.settings_secondary_font_color_title),
getSelected = ColorHelper::getSecondaryFontColorRgb, getSelected = { ColorHelper.getSecondaryFontColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) val colorString = Integer.toHexString(color)
Preferences.textSecondaryColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString if (activity?.isDarkTheme() == true) {
Preferences.textSecondaryColorDark =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
} else {
Preferences.textSecondaryColor =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
}
}, },
showAlphaSelector = true, showAlphaSelector = true,
alpha = Preferences.textSecondaryAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.textSecondaryAlphaDark.toIntValue() else Preferences.textSecondaryAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.textSecondaryAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.textSecondaryAlphaDark = alpha.toHexValue()
} else {
Preferences.textSecondaryAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
action_second_row_top_margin_size.setOnClickListener {
BottomSheetMenu<Int>(
requireContext(),
header = getString(R.string.settings_secondary_row_top_margin_title)
).setSelectedValue(Preferences.secondRowTopMargin)
.addItem(
getString(R.string.settings_clock_bottom_margin_subtitle_none),
Constants.SecondRowTopMargin.NONE.value
)
.addItem(
getString(R.string.settings_clock_bottom_margin_subtitle_small),
Constants.SecondRowTopMargin.SMALL.value
)
.addItem(
getString(R.string.settings_clock_bottom_margin_subtitle_medium),
Constants.SecondRowTopMargin.MEDIUM.value
)
.addItem(
getString(R.string.settings_clock_bottom_margin_subtitle_large),
Constants.SecondRowTopMargin.LARGE.value
)
.addOnSelectItemListener { value ->
Preferences.secondRowTopMargin = value
}.show()
}
action_date_format.setOnClickListener { action_date_format.setOnClickListener {
val now = Calendar.getInstance() val now = Calendar.getInstance()
val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat) val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat)
@ -254,10 +393,20 @@ class GeneralTabFragment : Fragment() {
dialog.addItem(getString(R.string.custom_date_format), "-") dialog.addItem(getString(R.string.custom_date_format), "-")
dialog.addOnSelectItemListener { value -> dialog.addOnSelectItemListener { value ->
if (value == "-") { when (value) {
startActivity(Intent(requireContext(), CustomDateActivity::class.java)) "-" -> {
} else { startActivity(Intent(requireContext(), CustomDateActivity::class.java))
Preferences.dateFormat = value }
"" -> {
Preferences.blockingBulk {
isDateCapitalize = false
isDateUppercase = false
}
Preferences.dateFormat = value
}
else -> {
Preferences.dateFormat = value
}
} }
}.show() }.show()
} }
@ -266,26 +415,40 @@ class GeneralTabFragment : Fragment() {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_background_color_title), header = getString(R.string.settings_background_color_title),
getSelected = { ColorHelper.getBackgroundColorRgb() }, getSelected = { ColorHelper.getBackgroundColorRgb(activity?.isDarkTheme() == true) },
onColorSelected = { color: Int -> onColorSelected = { color: Int ->
val colorString = Integer.toHexString(color) val colorString = Integer.toHexString(color)
Preferences.backgroundCardColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString if (activity?.isDarkTheme() == true) {
Preferences.backgroundCardColorDark =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
} else {
Preferences.backgroundCardColor =
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
}
}, },
showAlphaSelector = true, showAlphaSelector = true,
alpha = Preferences.backgroundCardAlpha.toIntValue(), alpha = if (activity?.isDarkTheme() == true) Preferences.backgroundCardAlphaDark.toIntValue() else Preferences.backgroundCardAlpha.toIntValue(),
onAlphaChangeListener = { alpha -> onAlphaChangeListener = { alpha ->
Preferences.backgroundCardAlpha = alpha.toHexValue() if (activity?.isDarkTheme() == true) {
Preferences.backgroundCardAlphaDark = alpha.toHexValue()
} else {
Preferences.backgroundCardAlpha = alpha.toHexValue()
}
} }
).show() ).show()
} }
action_text_shadow.setOnClickListener { action_text_shadow.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(Preferences.textShadow) val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow)
(2 downTo 0).forEach { (2 downTo 0).forEach {
dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it) dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it)
} }
dialog.addOnSelectItemListener { value -> dialog.addOnSelectItemListener { value ->
Preferences.textShadow = value if (activity?.isDarkTheme() == true) {
Preferences.textShadowDark = value
} else {
Preferences.textShadow = value
}
}.show() }.show()
} }

View File

@ -8,8 +8,10 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.provider.Settings
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
@ -34,6 +36,7 @@ import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.components.CustomNotesDialog import com.tommasoberlose.anotherwidget.components.CustomNotesDialog
import com.tommasoberlose.anotherwidget.components.GlanceProviderSortMenu import com.tommasoberlose.anotherwidget.components.GlanceProviderSortMenu
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentGlanceSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentGlanceSettingsBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.AlarmHelper import com.tommasoberlose.anotherwidget.helpers.AlarmHelper
@ -188,7 +191,9 @@ class GlanceTabFragment : Fragment() {
} catch (e: Exception) { } catch (e: Exception) {
alarm.showIntent?.creatorPackage ?: "" alarm.showIntent?.creatorPackage ?: ""
} }
activity?.toast(getString(R.string.next_alarm_warning).format(appNameOrPackage), long = true) MaterialBottomSheetDialog(requireContext(), message = getString(R.string.next_alarm_warning).format(appNameOrPackage))
.setPositiveButton(getString(android.R.string.ok))
.show()
} }
} }
true true
@ -274,19 +279,23 @@ class GlanceTabFragment : Fragment() {
} }
private fun checkNotificationPermission() { private fun checkNotificationPermission() {
if (NotificationManagerCompat.getEnabledListenerPackages(requireContext()).contains(requireContext().packageName)) { when {
notification_permission_alert?.isVisible = false NotificationManagerCompat.getEnabledListenerPackages(requireContext()).contains(requireContext().packageName) -> {
MediaPlayerHelper.updatePlayingMediaInfo(requireContext()) notification_permission_alert?.isVisible = false
show_music_label?.text = if (Preferences.showMusic) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) MediaPlayerHelper.updatePlayingMediaInfo(requireContext())
} else if (Preferences.showMusic) { show_music_label?.text = if (Preferences.showMusic) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
notification_permission_alert?.isVisible = true }
show_music_label?.text = getString(R.string.settings_request_notification_access) Preferences.showMusic -> {
notification_permission_alert?.setOnClickListener { notification_permission_alert?.isVisible = true
activity?.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")) show_music_label?.text = getString(R.string.settings_request_notification_access)
notification_permission_alert?.setOnClickListener {
activity?.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"))
}
}
else -> {
show_music_label?.text = getString(R.string.settings_not_visible)
notification_permission_alert?.isVisible = false
} }
} else {
show_music_label?.text = getString(R.string.settings_not_visible)
notification_permission_alert?.isVisible = false
} }
} }

View File

@ -42,6 +42,7 @@ import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper import com.tommasoberlose.anotherwidget.utils.getCurrentWallpaper
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.toPixel import com.tommasoberlose.anotherwidget.utils.toPixel
import kotlinx.android.synthetic.main.fragment_app_main.* import kotlinx.android.synthetic.main.fragment_app_main.*
import kotlinx.android.synthetic.main.the_widget_sans.* import kotlinx.android.synthetic.main.the_widget_sans.*
@ -62,8 +63,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis.create(MaterialSharedAxis.X, true) enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
reenterTransition = MaterialSharedAxis.create(MaterialSharedAxis.X, false) reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
} }
override fun onCreateView( override fun onCreateView(
@ -93,9 +94,9 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
}.attach() }.attach()
// Init clock // Init clock
time.setTextColor(ColorHelper.getClockFontColor()) time.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext())) time.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()))
time_am_pm.setTextColor(ColorHelper.getClockFontColor()) time_am_pm.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2) time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2)
time_container.isVisible = Preferences.showClock time_container.isVisible = Preferences.showClock
@ -134,7 +135,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
preview?.setCardBackgroundColor( preview?.setCardBackgroundColor(
ContextCompat.getColor( ContextCompat.getColor(
requireContext(), requireContext(),
if (ColorHelper.getFontColor() if (ColorHelper.getFontColor(activity?.isDarkTheme() == true)
.isColorDark() .isColorDark()
) android.R.color.white else R.color.colorAccent ) android.R.color.white else R.color.colorAccent
) )
@ -143,7 +144,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
BitmapHelper.getTintedDrawable( BitmapHelper.getTintedDrawable(
requireContext(), requireContext(),
R.drawable.card_background, R.drawable.card_background,
ColorHelper.getBackgroundColor() ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true)
) )
) )
uiJob = lifecycleScope.launch(Dispatchers.IO) { uiJob = lifecycleScope.launch(Dispatchers.IO) {
@ -165,8 +166,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
// Clock // Clock
time?.setTextColor(ColorHelper.getClockFontColor()) time?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time_am_pm?.setTextColor(ColorHelper.getClockFontColor()) time_am_pm?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))
time?.setTextSize( time?.setTextSize(
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) Preferences.clockTextSize.toPixel(requireContext())
@ -372,7 +373,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
super.onPause() super.onPause()
} }
var delayJob: Job? = null private var delayJob: Job? = null
override fun onSharedPreferenceChanged(preferences: SharedPreferences, p1: String) { override fun onSharedPreferenceChanged(preferences: SharedPreferences, p1: String) {
delayJob?.cancel() delayJob?.cancel()

View File

@ -50,8 +50,8 @@ class SettingsFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis.create(MaterialSharedAxis.X, true) enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
returnTransition = MaterialSharedAxis.create(MaterialSharedAxis.X, false) returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
} }
override fun onCreateView( override fun onCreateView(

View File

@ -26,6 +26,7 @@ import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.components.IconPackSelector import com.tommasoberlose.anotherwidget.components.IconPackSelector
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
@ -110,6 +111,7 @@ class WeatherTabFragment : Fragment() {
viewModel.customLocationAdd.observe(viewLifecycleOwner, Observer { viewModel.customLocationAdd.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
background_location_warning.isVisible = it == ""
label_custom_location?.text = label_custom_location?.text =
if (it == "") getString(R.string.custom_location_gps) else it if (it == "") getString(R.string.custom_location_gps) else it
} }
@ -164,7 +166,11 @@ class WeatherTabFragment : Fragment() {
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") { } else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
location_permission_alert?.isVisible = true location_permission_alert?.isVisible = true
location_permission_alert?.setOnClickListener { location_permission_alert?.setOnClickListener {
requirePermission() MaterialBottomSheetDialog(requireContext(), message = getString(R.string.background_location_warning))
.setPositiveButton(getString(android.R.string.ok)) {
requirePermission()
}
.show()
} }
} else { } else {
location_permission_alert?.isVisible = false location_permission_alert?.isVisible = false
@ -216,6 +222,9 @@ class WeatherTabFragment : Fragment() {
.addItem(getString(R.string.fahrenheit), "F") .addItem(getString(R.string.fahrenheit), "F")
.addItem(getString(R.string.celsius), "C") .addItem(getString(R.string.celsius), "C")
.addOnSelectItemListener { value -> .addOnSelectItemListener { value ->
if (value != Preferences.weatherTempUnit) {
WeatherHelper.updateWeather(requireContext())
}
Preferences.weatherTempUnit = value Preferences.weatherTempUnit = value
}.show() }.show()
} }

View File

@ -8,5 +8,6 @@ import com.tommasoberlose.anotherwidget.global.Preferences
class CustomDateViewModel(application: Application) : AndroidViewModel(application) { class CustomDateViewModel(application: Application) : AndroidViewModel(application) {
val dateInput: MutableLiveData<String> = MutableLiveData(if (Preferences.dateFormat == "") "EEEE, MMM dd" else Preferences.dateFormat) val dateInput: MutableLiveData<String> = MutableLiveData(if (Preferences.dateFormat == "") "EEEE, MMM dd" else Preferences.dateFormat)
val isDateCapitalize = Preferences.asLiveData(Preferences::isDateCapitalize) val isDateCapitalize = MutableLiveData<Boolean>(Preferences.isDateCapitalize)
val isDateUppercase = MutableLiveData<Boolean>(Preferences.isDateUppercase)
} }

View File

@ -13,12 +13,20 @@ class MainViewModel : ViewModel() {
val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha) val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha)
val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor) val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor)
val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha) val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha)
val textGlobalColorDark = Preferences.asLiveData(Preferences::textGlobalColorDark)
val textGlobalAlphaDark = Preferences.asLiveData(Preferences::textGlobalAlphaDark)
val textSecondaryColorDark = Preferences.asLiveData(Preferences::textSecondaryColorDark)
val textSecondaryAlphaDark = Preferences.asLiveData(Preferences::textSecondaryAlphaDark)
val backgroundCardColorDark = Preferences.asLiveData(Preferences::backgroundCardColorDark)
val backgroundCardAlphaDark = Preferences.asLiveData(Preferences::backgroundCardAlphaDark)
val textMainSize = Preferences.asLiveData(Preferences::textMainSize) val textMainSize = Preferences.asLiveData(Preferences::textMainSize)
val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize) val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize)
val textShadow = Preferences.asLiveData(Preferences::textShadow) val textShadow = Preferences.asLiveData(Preferences::textShadow)
val textShadowDark = Preferences.asLiveData(Preferences::textShadowDark)
val customFont = Preferences.asLiveData(Preferences::customFont) val customFont = Preferences.asLiveData(Preferences::customFont)
val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation)
val showDividers = Preferences.asLiveData(Preferences::showDividers) val showDividers = Preferences.asLiveData(Preferences::showDividers)
val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin)
// Calendar Settings // Calendar Settings
val showEvents = Preferences.asLiveData(Preferences::showEvents) val showEvents = Preferences.asLiveData(Preferences::showEvents)
@ -30,12 +38,15 @@ class MainViewModel : ViewModel() {
val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails) val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails)
val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName) val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName)
val widgetUpdateFrequency = Preferences.asLiveData(Preferences::widgetUpdateFrequency) val widgetUpdateFrequency = Preferences.asLiveData(Preferences::widgetUpdateFrequency)
val showOnlyBusyEvents = Preferences.asLiveData(Preferences::showOnlyBusyEvents)
// Clock Settings // Clock Settings
val showClock = Preferences.asLiveData(Preferences::showClock) val showClock = Preferences.asLiveData(Preferences::showClock)
val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize) val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize)
val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor) val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor)
val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha) val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha)
val clockTextColorDark = Preferences.asLiveData(Preferences::clockTextColorDark)
val clockTextAlphaDark = Preferences.asLiveData(Preferences::clockTextAlphaDark)
val showAMPMIndicator = Preferences.asLiveData(Preferences::showAMPMIndicator) val showAMPMIndicator = Preferences.asLiveData(Preferences::showAMPMIndicator)
val clockAppName = Preferences.asLiveData(Preferences::clockAppName) val clockAppName = Preferences.asLiveData(Preferences::clockAppName)

View File

@ -15,10 +15,7 @@ import android.text.format.DateUtils
import android.util.Log import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.*
import android.widget.RemoteViews
import android.widget.TextClock
import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
@ -27,9 +24,11 @@ import com.tommasoberlose.anotherwidget.global.Actions
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.* import com.tommasoberlose.anotherwidget.helpers.*
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
import com.tommasoberlose.anotherwidget.receivers.* import com.tommasoberlose.anotherwidget.receivers.*
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.getCapWordString import com.tommasoberlose.anotherwidget.utils.getCapWordString
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.toPixel import com.tommasoberlose.anotherwidget.utils.toPixel
import kotlinx.android.synthetic.main.the_widget.view.* import kotlinx.android.synthetic.main.the_widget.view.*
import java.lang.Exception import java.lang.Exception
@ -102,12 +101,12 @@ class MainWidget : AppWidgetProvider() {
views.setInt( views.setInt(
R.id.widget_shape_background, R.id.widget_shape_background,
"setColorFilter", "setColorFilter",
ColorHelper.getBackgroundColorRgb() ColorHelper.getBackgroundColorRgb(context.isDarkTheme())
) )
views.setInt( views.setInt(
R.id.widget_shape_background, R.id.widget_shape_background,
"setImageAlpha", "setImageAlpha",
ColorHelper.getBackgroundAlpha() ColorHelper.getBackgroundAlpha(context.isDarkTheme())
) )
val refreshIntent = PendingIntent.getActivity( val refreshIntent = PendingIntent.getActivity(
context, context,
@ -264,7 +263,21 @@ class MainWidget : AppWidgetProvider() {
views.setViewVisibility(R.id.empty_layout_rect, View.GONE) views.setViewVisibility(R.id.empty_layout_rect, View.GONE)
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
views.setViewVisibility(
R.id.second_row_top_margin_small_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
)
views.setViewVisibility(
R.id.second_row_top_margin_medium_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
)
views.setViewVisibility(
R.id.second_row_top_margin_large_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
)
} else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) { } else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) {
var showSomething = false
loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) { loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
when (provider) { when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
@ -276,6 +289,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent) views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -288,6 +302,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent) views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -302,6 +317,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent) views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -320,26 +336,44 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent) views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent)
showSomething = true
break@loop break@loop
} }
} }
} }
} }
views.setImageViewBitmap(
R.id.next_event_rect,
BitmapHelper.getBitmapFromView(v.next_event, draw = false)
)
views.setImageViewBitmap( if (showSomething) {
R.id.second_row_rect, views.setImageViewBitmap(
BitmapHelper.getBitmapFromView(v.second_row, draw = false) R.id.next_event_rect,
) BitmapHelper.getBitmapFromView(v.next_event, draw = false)
)
views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) views.setImageViewBitmap(
views.setViewVisibility(R.id.empty_layout_rect, View.GONE) R.id.second_row_rect,
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) BitmapHelper.getBitmapFromView(v.second_row, draw = false)
views.setOnClickPendingIntent(R.id.next_event_rect, calPIntent) )
views.setViewVisibility(R.id.second_row_rect, View.VISIBLE)
views.setViewVisibility(R.id.empty_layout_rect, View.GONE)
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
views.setOnClickPendingIntent(R.id.next_event_rect, calPIntent)
views.setViewVisibility(
R.id.second_row_top_margin_small_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
)
views.setViewVisibility(
R.id.second_row_top_margin_medium_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
)
views.setViewVisibility(
R.id.second_row_top_margin_large_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
)
}
} }
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
@ -408,8 +442,8 @@ class MainWidget : AppWidgetProvider() {
views.setViewVisibility(R.id.clock_bottom_margin_medium, View.GONE) views.setViewVisibility(R.id.clock_bottom_margin_medium, View.GONE)
views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE) views.setViewVisibility(R.id.clock_bottom_margin_large, View.GONE)
} else { } else {
views.setTextColor(R.id.time, ColorHelper.getClockFontColor()) views.setTextColor(R.id.time, ColorHelper.getClockFontColor(context.isDarkTheme()))
views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor()) views.setTextColor(R.id.time_am_pm, ColorHelper.getClockFontColor(context.isDarkTheme()))
views.setTextViewTextSize( views.setTextViewTextSize(
R.id.time, R.id.time,
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
@ -537,6 +571,10 @@ class MainWidget : AppWidgetProvider() {
v.empty_layout.visibility = View.GONE v.empty_layout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE v.calendar_layout.visibility = View.VISIBLE
v.second_row_top_margin_small.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
v.second_row_top_margin_medium.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
v.second_row_top_margin_large.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
} else if (GlanceProviderHelper.showGlanceProviders(context)) { } else if (GlanceProviderHelper.showGlanceProviders(context)) {
v.second_row_icon.isVisible = true v.second_row_icon.isVisible = true
var showSomething = false var showSomething = false
@ -615,6 +653,10 @@ class MainWidget : AppWidgetProvider() {
v.next_event.text = DateHelper.getDateText(context, now) v.next_event.text = DateHelper.getDateText(context, now)
v.empty_layout.visibility = View.GONE v.empty_layout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE v.calendar_layout.visibility = View.VISIBLE
v.second_row_top_margin_small.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
v.second_row_top_margin_medium.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
v.second_row_top_margin_large.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
} else { } else {
v.second_row_icon.isVisible = false v.second_row_icon.isVisible = false
} }
@ -623,7 +665,7 @@ class MainWidget : AppWidgetProvider() {
// Color // Color
listOf<TextView>(v.empty_date, v.divider1, v.temp, v.next_event, v.next_event_difference_time, v.divider3, v.special_temp).forEach { listOf<TextView>(v.empty_date, v.divider1, v.temp, v.next_event, v.next_event_difference_time, v.divider3, v.special_temp).forEach {
it.setTextColor(ColorHelper.getFontColor()) it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme()))
} }
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
@ -631,11 +673,12 @@ class MainWidget : AppWidgetProvider() {
} else { } else {
listOf<ImageView>(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon) listOf<ImageView>(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon)
}.forEach { }.forEach {
it.setColorFilter(ColorHelper.getFontColor()) it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme()))
it.alpha = (if (context.isDarkTheme()) Preferences.textGlobalAlphaDark.toIntValue().toFloat() else Preferences.textGlobalAlpha.toIntValue().toFloat()) / 100
} }
listOf<TextView>(v.next_event_date, v.divider2, v.calendar_temp).forEach { listOf<TextView>(v.next_event_date, v.divider2, v.calendar_temp).forEach {
it.setTextColor(ColorHelper.getSecondaryFontColor()) it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme()))
} }
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
@ -643,7 +686,8 @@ class MainWidget : AppWidgetProvider() {
} else { } else {
listOf<ImageView>(v.second_row_icon, v.weather_icon) listOf<ImageView>(v.second_row_icon, v.weather_icon)
}.forEach { }.forEach {
it.setColorFilter(ColorHelper.getSecondaryFontColor()) it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme()))
it.alpha = (if (context.isDarkTheme()) Preferences.textSecondaryAlphaDark.toIntValue().toFloat() else Preferences.textSecondaryAlpha.toIntValue().toFloat()) / 100
} }
// Text Size // Text Size
@ -683,19 +727,19 @@ class MainWidget : AppWidgetProvider() {
// Shadows // Shadows
val shadowRadius = when (Preferences.textShadow) { val shadowRadius = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> 0f 0 -> 0f
1 -> 5f 1 -> 5f
2 -> 5f 2 -> 5f
else -> 5f else -> 5f
} }
val shadowColor = when (Preferences.textShadow) { val shadowColor = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> Color.TRANSPARENT 0 -> Color.TRANSPARENT
1 -> R.color.black_50 1 -> R.color.black_50
2 -> Color.BLACK 2 -> Color.BLACK
else -> R.color.black_50 else -> R.color.black_50
} }
val shadowDy = when (Preferences.textShadow) { val shadowDy = when (if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) {
0 -> 0f 0 -> 0f
1 -> 0f 1 -> 0f
2 -> 1f 2 -> 1f

View File

@ -143,11 +143,11 @@ fun Context.isTablet(): Boolean {
} }
fun String.md5(): String { fun String.md5(): String {
val MD5 = "MD5" val mD5 = "MD5"
try { try {
// Create MD5 Hash // Create MD5 Hash
val digest = java.security.MessageDigest val digest = java.security.MessageDigest
.getInstance(MD5) .getInstance(mD5)
digest.update(toByteArray()) digest.update(toByteArray())
val messageDigest = digest.digest() val messageDigest = digest.digest()
@ -172,7 +172,7 @@ fun String.isValidEmail(): Boolean
= this.isNotEmpty() && = this.isNotEmpty() &&
Patterns.EMAIL_ADDRESS.matcher(this).matches() Patterns.EMAIL_ADDRESS.matcher(this).matches()
fun Activity.isDarkTheme(): Boolean { fun Context.isDarkTheme(): Boolean {
return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES return resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 732 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 601 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Some files were not shown because too many files have changed in this diff Show More