Compare commits
54 Commits
v2.0.9-bet
...
v2.0.12
Author | SHA1 | Date | |
---|---|---|---|
94825808f4 | |||
0d2287dbdf | |||
9e40586456 | |||
4d75f4ca0c | |||
0859632803 | |||
47562b35ca | |||
0f4f02ea28 | |||
31cf950eee | |||
f230d300ee | |||
c610857056 | |||
770040ad93 | |||
f784817296 | |||
ec1c25cb4c | |||
e1d2f5a782 | |||
6e8c6cf055 | |||
68b5997e8d | |||
56b21be946 | |||
fdc02b2cef | |||
863b8f79d8 | |||
857a8009b6 | |||
9199f28ad9 | |||
ddb1b7494a | |||
fd2b1ba976 | |||
90f0d7de00 | |||
66ad5e0839 | |||
2ac7e072e5 | |||
a3392dabcf | |||
c2c54a04d2 | |||
2c237058b3 | |||
aa2b4b0510 | |||
4c27d1dd9b | |||
eba5575ee2 | |||
aff7e407ca | |||
f7fc31d968 | |||
90b588603d | |||
5d9bd11abb | |||
01005ec443 | |||
eaf6400e8b | |||
30339c7375 | |||
87da284be4 | |||
573c6d03e5 | |||
79e87b0648 | |||
9e9a91690e | |||
5f699af509 | |||
aae40b9dd3 | |||
cebd679856 | |||
06443ddddb | |||
233761a169 | |||
b81461f725 | |||
26b1948b70 | |||
af64818dff | |||
f28596c194 | |||
7f41a92a91 | |||
40c9253159 |
4
.gitignore
vendored
@ -1,12 +1,10 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
/.idea/*
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
/tasksintegration/build
|
||||
apikey.properties
|
||||
/app/google-services.json
|
||||
|
BIN
.idea/caches/build_file_checksums.ser
generated
@ -13,6 +13,13 @@ Also, as much as possible, there are always updates and new features in the shor
|
||||
Help me developing with feedback and support me on how you can.
|
||||
<div style="text-align:center"><a href="https://play.google.com/store/apps/details?id=com.tommasoberlose.anotherwidget" target="_blank"><img src="google-play-badge.png" height="100" /></a></div>
|
||||
|
||||
|
||||
Help with translations
|
||||
-------
|
||||
|
||||
Hey! You could view the file strings.xml ([here](https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml)) that contains the English version of the app strings.
|
||||
You have to copy the file, create a copy of it inside the folder values-[LANGUAGE-SUFFIX] with the translated strings and create a pull request to submit your changes.
|
||||
|
||||
License
|
||||
-------
|
||||
Copyright (C) 2017-2020 Tommaso Berlose (http://tommasoberlose.com)
|
||||
|
@ -10,10 +10,6 @@ apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
apply plugin: 'realm-android'
|
||||
|
||||
def apiKeyPropertiesFile = rootProject.file("apikey.properties")
|
||||
def apiKeyProperties = new Properties()
|
||||
apiKeyProperties.load(new FileInputStream(apiKeyPropertiesFile))
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.3"
|
||||
@ -22,12 +18,10 @@ android {
|
||||
applicationId "com.tommasoberlose.anotherwidget"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 29
|
||||
versionCode 90
|
||||
versionName "2.0.9"
|
||||
versionCode 101
|
||||
versionName "2.0.12"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
manifestPlaceholders = [ "AWARENESS_API_KEY": apiKeyProperties['AWARENESS_API_KEY']]
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/my_backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:name=".AWApplication"
|
||||
@ -25,7 +24,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="LockedOrientationActivity">
|
||||
<activity android:name=".ui.activities.MainActivity" android:launchMode="singleInstance" android:theme="@style/AppTheme.Main">
|
||||
<activity android:name=".ui.activities.MainActivity" android:launchMode="singleInstance" android:theme="@style/AppTheme.Main" android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@ -116,6 +115,8 @@
|
||||
|
||||
<service android:name=".services.EventListenerJob" android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
<service android:name=".services.BatteryListenerJob" android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
<service android:name=".receivers.MusicNotificationListener"
|
||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
||||
<intent-filter>
|
||||
@ -131,6 +132,7 @@
|
||||
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
|
||||
<action android:name="android.intent.action.BATTERY_LOW"/>
|
||||
<action android:name="android.intent.action.BATTERY_OKAY"/>
|
||||
<action android:name="android.intent.action.BATTERY_CHANGED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
@ -143,6 +145,11 @@
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".services.UpdateCalendarJob"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
android:exported="true"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,24 @@
|
||||
package com.tommasoberlose.anotherwidget.components
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ScrollView
|
||||
|
||||
|
||||
class FixedFocusScrollView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0
|
||||
) : ScrollView(context, attrs, defStyle) {
|
||||
|
||||
var isScrollable = true
|
||||
|
||||
override fun scrollTo(x: Int, y: Int) {
|
||||
if (isScrollable) {
|
||||
super.scrollTo(x, y)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.tommasoberlose.anotherwidget.components
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.header
|
||||
import kotlinx.android.synthetic.main.fragment_weather_settings.*
|
||||
import kotlinx.android.synthetic.main.icon_pack_menu_item.view.*
|
||||
|
||||
class IconPackSelector(context: Context, private val header: String? = null) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
override fun show() {
|
||||
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
|
||||
|
||||
// Header
|
||||
view.header.isVisible = header != null
|
||||
view.header_text.text = header ?: ""
|
||||
|
||||
view.warning_text.isVisible = false
|
||||
|
||||
// Menu
|
||||
for (item in Constants.WeatherIconPack.values()) {
|
||||
val itemView = View.inflate(context, R.layout.icon_pack_menu_item, null)
|
||||
itemView.label.text = context.getString(R.string.settings_weather_icon_pack_default).format(item.value + 1)
|
||||
itemView.isSelected = item.value == Preferences.weatherIconPack
|
||||
|
||||
itemView.icon_1.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("01d", item.value)))
|
||||
itemView.icon_2.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("01n", item.value)))
|
||||
itemView.icon_3.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("10d", item.value)))
|
||||
itemView.icon_4.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource("09n", item.value)))
|
||||
|
||||
listOf<ImageView>(itemView.icon_1, itemView.icon_2, itemView.icon_3, itemView.icon_4).forEach {
|
||||
if (item == Constants.WeatherIconPack.MINIMAL) {
|
||||
it.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryText))
|
||||
} else {
|
||||
it.setColorFilter(ContextCompat.getColor(context, android.R.color.transparent))
|
||||
}
|
||||
}
|
||||
|
||||
itemView.setOnClickListener {
|
||||
Preferences.weatherIconPack = item.value
|
||||
this.dismiss()
|
||||
}
|
||||
view.menu.addView(itemView)
|
||||
}
|
||||
setContentView(view)
|
||||
super.show()
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.tommasoberlose.anotherwidget.components
|
||||
|
||||
import android.view.View
|
||||
import android.widget.CompoundButton
|
||||
|
||||
class MenuItem (
|
||||
val icon: Int,
|
||||
val getIcon: (() -> Int)? = null,
|
||||
val title: String,
|
||||
val label: String = "",
|
||||
val getLabel: (() -> String)? = null,
|
||||
val isEnabled: (() -> Boolean) = fun (): Boolean { return true },
|
||||
val onClick: View.OnClickListener? = null,
|
||||
val onLongClick: View.OnLongClickListener? = null,
|
||||
val showToggle: Boolean = false,
|
||||
val toggleValue: (() -> Boolean) = fun (): Boolean { return false },
|
||||
val onToggle: CompoundButton.OnCheckedChangeListener? = null,
|
||||
val showPermission: (() -> Boolean) = fun (): Boolean { return false },
|
||||
val onPermissionClickListener: View.OnClickListener? = null,
|
||||
val render: ((view: View) -> Unit)? = null
|
||||
)
|
@ -1,6 +1,7 @@
|
||||
package com.tommasoberlose.anotherwidget.db
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -22,6 +23,12 @@ class EventRepository(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun clearEvents() {
|
||||
realm.executeTransaction { realm ->
|
||||
realm.where(Event::class.java).findAll().deleteAllFromRealm()
|
||||
}
|
||||
}
|
||||
|
||||
fun resetNextEventData() {
|
||||
Preferences.bulk {
|
||||
remove(Preferences::nextEventId)
|
||||
@ -40,7 +47,22 @@ class EventRepository(val context: Context) {
|
||||
|
||||
fun getNextEvent(): Event? {
|
||||
val nextEvent = getEventByEventId(Preferences.nextEventId)
|
||||
val event = if (nextEvent != null && nextEvent.endDate > Calendar.getInstance().timeInMillis) {
|
||||
val now = Calendar.getInstance().timeInMillis
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = now
|
||||
when (Preferences.showUntil) {
|
||||
0 -> add(Calendar.HOUR, 3)
|
||||
1 -> add(Calendar.HOUR, 6)
|
||||
2 -> add(Calendar.HOUR, 12)
|
||||
3 -> add(Calendar.DAY_OF_MONTH, 1)
|
||||
4 -> add(Calendar.DAY_OF_MONTH, 3)
|
||||
5 -> add(Calendar.DAY_OF_MONTH, 7)
|
||||
6 -> add(Calendar.MINUTE, 30)
|
||||
7 -> add(Calendar.HOUR, 1)
|
||||
else -> add(Calendar.HOUR, 6)
|
||||
}
|
||||
}
|
||||
val event = if (nextEvent != null && nextEvent.endDate > now && nextEvent.startDate < limit.timeInMillis) {
|
||||
nextEvent
|
||||
} else {
|
||||
val events = getEvents()
|
||||
@ -101,10 +123,41 @@ class EventRepository(val context: Context) {
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
fun getEvents(): RealmResults<Event> {
|
||||
fun getFutureEvents(): List<Event> {
|
||||
val now = Calendar.getInstance().timeInMillis
|
||||
realm.refresh()
|
||||
return realm.where(Event::class.java).greaterThan("endDate", now).findAll()
|
||||
return realm
|
||||
.where(Event::class.java)
|
||||
.greaterThan("endDate", now)
|
||||
.findAll()
|
||||
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) }
|
||||
.filter { (Preferences.calendarAllDay || !it.allDay) }
|
||||
}
|
||||
|
||||
private fun getEvents(): List<Event> {
|
||||
val now = Calendar.getInstance().timeInMillis
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = now
|
||||
when (Preferences.showUntil) {
|
||||
0 -> add(Calendar.HOUR, 3)
|
||||
1 -> add(Calendar.HOUR, 6)
|
||||
2 -> add(Calendar.HOUR, 12)
|
||||
3 -> add(Calendar.DAY_OF_MONTH, 1)
|
||||
4 -> add(Calendar.DAY_OF_MONTH, 3)
|
||||
5 -> add(Calendar.DAY_OF_MONTH, 7)
|
||||
6 -> add(Calendar.MINUTE, 30)
|
||||
7 -> add(Calendar.HOUR, 1)
|
||||
else -> add(Calendar.HOUR, 6)
|
||||
}
|
||||
}
|
||||
realm.refresh()
|
||||
return realm
|
||||
.where(Event::class.java)
|
||||
.greaterThan("endDate", now)
|
||||
.lessThanOrEqualTo("startDate", limit.timeInMillis)
|
||||
.findAll()
|
||||
.filter { (Preferences.showDeclinedEvents || it.selfAttendeeStatus != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) }
|
||||
.filter { (Preferences.calendarAllDay || !it.allDay) }
|
||||
}
|
||||
|
||||
fun getEventsCount(): Int = getEvents().size
|
||||
|
@ -31,6 +31,8 @@ object Constants {
|
||||
|
||||
enum class WeatherIconPack(val value: Int) {
|
||||
DEFAULT(0),
|
||||
MINIMAL(1)
|
||||
MINIMAL(1),
|
||||
COOL(2),
|
||||
GOOGLE_NEWS(3)
|
||||
}
|
||||
}
|
@ -91,6 +91,7 @@ object Preferences : KotprefModel() {
|
||||
var showNextAlarm by booleanPref(default = true)
|
||||
var showBatteryCharging by booleanPref(default = false)
|
||||
var isBatteryLevelLow by booleanPref(default = false)
|
||||
var isCharging by booleanPref(default = false)
|
||||
var googleFitSteps by longPref(default = -1)
|
||||
var showDailySteps by booleanPref(default = false)
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Context.BATTERY_SERVICE
|
||||
import android.os.BatteryManager
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
|
||||
|
||||
object BatteryHelper {
|
||||
fun updateBatteryInfo(context: Context) {
|
||||
with(context.getSystemService(BATTERY_SERVICE) as BatteryManager) {
|
||||
Preferences.isBatteryLevelLow = getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) <= 15
|
||||
Preferences.isCharging = isCharging
|
||||
}
|
||||
}
|
||||
|
||||
fun getBatteryLevel(context: Context): Int {
|
||||
with(context.getSystemService(BATTERY_SERVICE) as BatteryManager) {
|
||||
return getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,14 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.Manifest
|
||||
import android.app.job.JobInfo
|
||||
import android.app.job.JobParameters
|
||||
import android.app.job.JobScheduler
|
||||
import android.app.job.JobService
|
||||
import android.content.ComponentName
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.provider.CalendarContract
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.services.EventListenerJob
|
||||
@ -10,6 +16,7 @@ import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.services.UpdateCalendarJob
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
@ -24,116 +31,8 @@ import kotlin.collections.ArrayList
|
||||
*/
|
||||
|
||||
object CalendarHelper {
|
||||
|
||||
fun updateEventList(context: Context) {
|
||||
val eventRepository = EventRepository(context)
|
||||
if (Preferences.showEvents) {
|
||||
val eventList = ArrayList<Event>()
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
val begin = Calendar.getInstance().apply {
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
}
|
||||
val limit = Calendar.getInstance()
|
||||
when (Preferences.showUntil) {
|
||||
0 -> limit.add(Calendar.HOUR, 3)
|
||||
1 -> limit.add(Calendar.HOUR, 6)
|
||||
2 -> limit.add(Calendar.HOUR, 12)
|
||||
3 -> limit.add(Calendar.DAY_OF_MONTH, 1)
|
||||
4 -> limit.add(Calendar.DAY_OF_MONTH, 3)
|
||||
5 -> limit.add(Calendar.DAY_OF_MONTH, 7)
|
||||
6 -> limit.add(Calendar.MINUTE, 30)
|
||||
7 -> limit.add(Calendar.HOUR, 1)
|
||||
else -> limit.add(Calendar.HOUR, 6)
|
||||
}
|
||||
|
||||
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
|
||||
ContentUris.appendId(builder, begin.timeInMillis)
|
||||
ContentUris.appendId(builder, limit.timeInMillis)
|
||||
|
||||
if (!context.checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR
|
||||
)
|
||||
) {
|
||||
eventRepository.resetNextEventData()
|
||||
} else {
|
||||
try {
|
||||
val provider = CalendarProvider(context)
|
||||
val data = provider.getInstances(begin.timeInMillis, limit.timeInMillis)
|
||||
if (data != null) {
|
||||
val instances = data.list
|
||||
for (instance in instances) {
|
||||
try {
|
||||
val e = provider.getEvent(instance.eventId)
|
||||
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && now.timeInMillis < instance.end && (Preferences.calendarAllDay || !e.allDay) && !getFilteredCalendarIdList().contains(
|
||||
e.calendarId
|
||||
) && (Preferences.showDeclinedEvents || e.selfAttendeeStatus.toInt() != CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
|
||||
) {
|
||||
if (e.allDay) {
|
||||
val start = Calendar.getInstance()
|
||||
start.timeInMillis = instance.begin
|
||||
val end = Calendar.getInstance()
|
||||
end.timeInMillis = instance.end
|
||||
instance.begin =
|
||||
start.timeInMillis - start.timeZone.getOffset(start.timeInMillis)
|
||||
instance.end =
|
||||
end.timeInMillis - end.timeZone.getOffset(end.timeInMillis)
|
||||
}
|
||||
eventList.add(
|
||||
Event(
|
||||
instance.id,
|
||||
e.id,
|
||||
e.title ?: "",
|
||||
instance.begin,
|
||||
instance.end,
|
||||
e.calendarId.toInt(),
|
||||
e.allDay,
|
||||
e.eventLocation ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventList.isEmpty()) {
|
||||
eventRepository.resetNextEventData()
|
||||
} else {
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
eventRepository.saveEvents(
|
||||
eventList
|
||||
)
|
||||
eventRepository.saveNextEventData(
|
||||
eventList[0]
|
||||
)
|
||||
}
|
||||
} catch (ignored: java.lang.Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventRepository.resetNextEventData()
|
||||
}
|
||||
|
||||
UpdatesReceiver.setUpdates(context)
|
||||
MainWidget.updateWidget(context)
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
UpdateCalendarJob.enqueueWork(context, Intent())
|
||||
}
|
||||
|
||||
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
||||
@ -155,7 +54,8 @@ object CalendarHelper {
|
||||
}
|
||||
|
||||
fun getFilteredCalendarIdList(): List<Long> {
|
||||
return Preferences.calendarFilter.split(",").map { it.replace(" ", "") }.filter { it != "" }.map { it.toLong() }
|
||||
return Preferences.calendarFilter.split(",").map { it.replace(" ", "") }
|
||||
.filter { it != "" }.map { it.toLong() }
|
||||
}
|
||||
|
||||
fun filterCalendar(list: List<Long>) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
@ -14,7 +15,6 @@ object GlanceProviderHelper {
|
||||
val enabledProviders = Preferences.enabledGlanceProviderOrder.split(",").filter { it != "" }
|
||||
|
||||
val providers = Constants.GlanceProviderId.values()
|
||||
.filter { it != Constants.GlanceProviderId.BATTERY_LEVEL_LOW }
|
||||
.filter {
|
||||
context.checkIfFitInstalled() || it != Constants.GlanceProviderId.GOOGLE_FIT_STEPS
|
||||
}.toTypedArray()
|
||||
@ -68,7 +68,7 @@ object GlanceProviderHelper {
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_daily_steps_title),
|
||||
R.drawable.round_steps
|
||||
R.drawable.round_directions_walk
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -79,12 +79,17 @@ object GlanceProviderHelper {
|
||||
}
|
||||
|
||||
fun showGlanceProviders(context: Context): Boolean {
|
||||
return Preferences.showGlance && EventRepository(context).getEventsCount() == 0 && (
|
||||
val eventRepository = EventRepository(context)
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
|
||||
val showGlance = Preferences.showGlance && (eventRepository.getEventsCount() == 0 || !Preferences.showEvents) && (
|
||||
(Preferences.showNextAlarm && AlarmHelper.getNextAlarm(context) != "") ||
|
||||
(MediaPlayerHelper.isSomeonePlaying(context)) ||
|
||||
(Preferences.isBatteryLevelLow) ||
|
||||
(Preferences.customNotes.isNotEmpty()) ||
|
||||
(Preferences.showDailySteps && Preferences.googleFitSteps > 0)
|
||||
)
|
||||
(MediaPlayerHelper.isSomeonePlaying(context)) ||
|
||||
(Preferences.showBatteryCharging && Preferences.isCharging || Preferences.isBatteryLevelLow) ||
|
||||
(Preferences.customNotes.isNotEmpty()) ||
|
||||
(Preferences.showDailySteps && Preferences.googleFitSteps > 0)
|
||||
)
|
||||
eventRepository.close()
|
||||
return showGlance
|
||||
}
|
||||
}
|
@ -11,9 +11,11 @@ import android.provider.AlarmClock
|
||||
import android.provider.CalendarContract
|
||||
import android.provider.CalendarContract.Events
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import java.util.*
|
||||
|
||||
|
||||
@ -64,12 +66,8 @@ object IntentHelper {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
addCategory(Intent.CATEGORY_DEFAULT)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
data = Uri.parse("dynact://velour/weather/ProxyActivity")
|
||||
component = ComponentName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.velour.DynamicActivityTrampoline")
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -98,10 +96,8 @@ object IntentHelper {
|
||||
data = calendarUri
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
data = calendarUri
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,6 +110,7 @@ object IntentHelper {
|
||||
if (Preferences.calendarAppPackage == "") {
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
data = uri
|
||||
flags = (Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
if (!e.allDay) {
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||
@ -131,23 +128,33 @@ object IntentHelper {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getCalendarIntent(context).apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
data = uri
|
||||
if (!e.allDay) {
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||
} else {
|
||||
val start = Calendar.getInstance().apply {
|
||||
timeInMillis = e.startDate
|
||||
val calendarIntent = getCalendarIntent(context)
|
||||
if (calendarIntent.action == Intent.ACTION_VIEW) {
|
||||
calendarIntent.apply {
|
||||
data = uri
|
||||
if (!e.allDay) {
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||
} else {
|
||||
val start = Calendar.getInstance().apply {
|
||||
timeInMillis = e.startDate
|
||||
}
|
||||
val end = Calendar.getInstance().apply {
|
||||
timeInMillis = e.endDate
|
||||
}
|
||||
putExtra(
|
||||
CalendarContract.EXTRA_EVENT_BEGIN_TIME,
|
||||
start.timeInMillis + start.timeZone.getOffset(start.timeInMillis)
|
||||
)
|
||||
putExtra(
|
||||
CalendarContract.EXTRA_EVENT_END_TIME,
|
||||
end.timeInMillis + end.timeZone.getOffset(end.timeInMillis)
|
||||
)
|
||||
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, 1)
|
||||
}
|
||||
val end = Calendar.getInstance().apply {
|
||||
timeInMillis = e.endDate
|
||||
}
|
||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.timeInMillis + start.timeZone.getOffset(start.timeInMillis))
|
||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.timeInMillis + end.timeZone.getOffset(end.timeInMillis))
|
||||
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, 1)
|
||||
}
|
||||
} else {
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,14 +181,17 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Intent(AlarmClock.ACTION_SHOW_ALARMS).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
}
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBatteryIntent(): Intent {
|
||||
return Intent(Intent.ACTION_POWER_USAGE_SUMMARY)
|
||||
}
|
||||
|
||||
fun getMusicIntent(context: Context): Intent {
|
||||
return when (Preferences.mediaPlayerPackage) {
|
||||
"" -> {
|
||||
@ -194,6 +204,7 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
@ -207,6 +218,7 @@ object IntentHelper {
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
context.toast(context.getString(R.string.error_opening_app))
|
||||
Intent()
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,22 @@ object SettingsStringHelper {
|
||||
return context.getString(R.string.now)
|
||||
}
|
||||
TimeUnit.MILLISECONDS.toHours(difference) < 12 -> {
|
||||
return DateUtils.getRelativeTimeSpanString(start, now, DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString()
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(difference) - 60 * TimeUnit.MILLISECONDS.toHours(difference)
|
||||
return if (minutes < 1 || minutes > 30) {
|
||||
DateUtils.getRelativeTimeSpanString(
|
||||
start,
|
||||
now - 1000 * 60 * 40,
|
||||
DateUtils.HOUR_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
).toString()
|
||||
} else {
|
||||
DateUtils.getRelativeTimeSpanString(
|
||||
start,
|
||||
now,
|
||||
DateUtils.HOUR_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE
|
||||
).toString()
|
||||
}
|
||||
}
|
||||
eventDate.dayOfYear == nowDate.plusDays(1).dayOfYear -> {
|
||||
return String.format("%s", context.getString(R.string.tomorrow))
|
||||
|
@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.os.Build
|
||||
import com.google.android.gms.location.LocationServices
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.network.WeatherNetworkApi
|
||||
@ -47,82 +46,202 @@ object WeatherHelper {
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
||||
fun getWeatherIconResource(icon: String): Int {
|
||||
when (icon) {
|
||||
fun getWeatherIconResource(icon: String, style: Int = Preferences.weatherIconPack): Int {
|
||||
return when (icon) {
|
||||
"01d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.clear_day else R.drawable.clear_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.clear_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.clear_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.clear_day_4
|
||||
else -> R.drawable.clear_day
|
||||
}
|
||||
}
|
||||
"02d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.partly_cloudy else R.drawable.partly_cloudy_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.partly_cloudy_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.partly_cloudy_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.partly_cloudy_4
|
||||
else -> R.drawable.partly_cloudy
|
||||
}
|
||||
}
|
||||
"03d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.mostly_cloudy else R.drawable.mostly_cloudy_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.mostly_cloudy_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.mostly_cloudy_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.mostly_cloudy_4
|
||||
else -> R.drawable.mostly_cloudy
|
||||
}
|
||||
}
|
||||
"04d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.cloudy_weather else R.drawable.cloudy_weather_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.cloudy_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.cloudy_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.cloudy_weather_4
|
||||
else -> R.drawable.cloudy_weather
|
||||
}
|
||||
}
|
||||
"09d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.storm_weather_day else R.drawable.storm_weather_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.storm_weather_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.storm_weather_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.storm_weather_day_4
|
||||
else -> R.drawable.storm_weather_day
|
||||
}
|
||||
}
|
||||
"10d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.rainy_day else R.drawable.rainy_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rainy_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rainy_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rainy_day_4
|
||||
else -> R.drawable.rainy_day
|
||||
}
|
||||
}
|
||||
"11d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.thunder_day else R.drawable.thunder_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.thunder_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.thunder_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.thunder_day_4
|
||||
else -> R.drawable.thunder_day
|
||||
}
|
||||
}
|
||||
"13d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.snow_day else R.drawable.snow_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.snow_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.snow_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.snow_day_4
|
||||
else -> R.drawable.snow_day
|
||||
}
|
||||
}
|
||||
"50d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.haze_day else R.drawable.haze_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_day_4
|
||||
else -> R.drawable.haze_day
|
||||
}
|
||||
}
|
||||
"80d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.windy_day else R.drawable.windy_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.windy_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.windy_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.windy_day_4
|
||||
else -> R.drawable.windy_day
|
||||
}
|
||||
}
|
||||
"81d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.rain_snow_day else R.drawable.rain_snow_day_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rain_snow_day_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rain_snow_day_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rain_snow_day_4
|
||||
else -> R.drawable.rain_snow_day
|
||||
}
|
||||
}
|
||||
"82d" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.haze_weather else R.drawable.haze_weather_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_weather_4
|
||||
else -> R.drawable.haze_weather
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
"01n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.clear_night else R.drawable.clear_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.clear_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.clear_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.clear_night_4
|
||||
else -> R.drawable.clear_night
|
||||
}
|
||||
}
|
||||
"02n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.partly_cloudy_night else R.drawable.partly_cloudy_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.partly_cloudy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.partly_cloudy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.partly_cloudy_night_4
|
||||
else -> R.drawable.partly_cloudy_night
|
||||
}
|
||||
}
|
||||
"03n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.mostly_cloudy_night else R.drawable.mostly_cloudy_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.mostly_cloudy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.mostly_cloudy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.mostly_cloudy_night_4
|
||||
else -> R.drawable.mostly_cloudy_night
|
||||
}
|
||||
}
|
||||
"04n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.cloudy_weather else R.drawable.cloudy_weather_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.cloudy_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.cloudy_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.cloudy_weather_4
|
||||
else -> R.drawable.cloudy_weather
|
||||
}
|
||||
}
|
||||
"09n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.storm_weather_night else R.drawable.storm_weather_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.storm_weather_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.storm_weather_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.storm_weather_night_4
|
||||
else -> R.drawable.storm_weather_night
|
||||
}
|
||||
}
|
||||
"10n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.rainy_night else R.drawable.rainy_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rainy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rainy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rainy_night_4
|
||||
else -> R.drawable.rainy_night
|
||||
}
|
||||
}
|
||||
"11n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.thunder_night else R.drawable.thunder_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.thunder_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.thunder_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.thunder_night_4
|
||||
else -> R.drawable.thunder_night
|
||||
}
|
||||
}
|
||||
"13n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.snow_night else R.drawable.snow_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.snow_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.snow_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.snow_night_4
|
||||
else -> R.drawable.snow_night
|
||||
}
|
||||
}
|
||||
"50n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.haze_night else R.drawable.haze_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_night_4
|
||||
else -> R.drawable.haze_night
|
||||
}
|
||||
}
|
||||
"80n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.windy_night else R.drawable.windy_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.windy_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.windy_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.windy_night_4
|
||||
else -> R.drawable.windy_night
|
||||
}
|
||||
}
|
||||
"81n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.rain_snow_night else R.drawable.rain_snow_night_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.rain_snow_night_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.rain_snow_night_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.rain_snow_night_4
|
||||
else -> R.drawable.rain_snow_night
|
||||
}
|
||||
}
|
||||
"82n" -> {
|
||||
return if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) R.drawable.haze_weather else R.drawable.haze_weather_2
|
||||
when (style) {
|
||||
Constants.WeatherIconPack.COOL.value -> R.drawable.haze_weather_3
|
||||
Constants.WeatherIconPack.MINIMAL.value -> R.drawable.haze_weather_2
|
||||
Constants.WeatherIconPack.GOOGLE_NEWS.value -> R.drawable.haze_weather_4
|
||||
else -> R.drawable.haze_weather
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
return R.drawable.unknown
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.tommasoberlose.anotherwidget.models
|
||||
|
||||
import android.provider.CalendarContract
|
||||
import io.realm.RealmObject
|
||||
import java.util.Date
|
||||
|
||||
@ -7,14 +8,17 @@ import java.util.Date
|
||||
* Created by tommaso on 05/10/17.
|
||||
*/
|
||||
|
||||
open class Event(var id: Long = 0,
|
||||
var eventID: Long = 0,
|
||||
var title: String = "",
|
||||
var startDate: Long = 0,
|
||||
var endDate: Long = 0,
|
||||
var calendarID: Int = 0,
|
||||
var allDay: Boolean = false,
|
||||
var address: String = "") : RealmObject() {
|
||||
open class Event(
|
||||
var id: Long = 0,
|
||||
var eventID: Long = 0,
|
||||
var title: String = "",
|
||||
var startDate: Long = 0,
|
||||
var endDate: Long = 0,
|
||||
var calendarID: Int = 0,
|
||||
var allDay: Boolean = false,
|
||||
var address: String = "",
|
||||
var selfAttendeeStatus: Int = CalendarContract.Attendees.ATTENDEE_STATUS_NONE
|
||||
) : RealmObject() {
|
||||
override fun toString(): String {
|
||||
return "Event:\nEVENT ID: " + eventID + "\nTITLE: " + title + "\nSTART DATE: " + Date(startDate) + "\nEND DATE: " + Date(endDate) + "\nCAL ID: " + calendarID + "\nADDRESS: " + address
|
||||
}
|
||||
|
@ -7,12 +7,15 @@ import android.os.BatteryManager
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
|
||||
class BatteryLevelReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
when(intent.action) {
|
||||
Intent.ACTION_BATTERY_LOW -> Preferences.isBatteryLevelLow = true
|
||||
Intent.ACTION_BATTERY_OKAY -> Preferences.isBatteryLevelLow = false
|
||||
Intent.ACTION_POWER_CONNECTED -> Preferences.isCharging = true
|
||||
Intent.ACTION_POWER_DISCONNECTED -> Preferences.isCharging = false
|
||||
}
|
||||
MainWidget.updateWidget(context)
|
||||
}
|
||||
|
@ -24,5 +24,6 @@ class NewCalendarEventReceiver : BroadcastReceiver() {
|
||||
eventRepository.goToPreviousEvent()
|
||||
}
|
||||
}
|
||||
eventRepository.close()
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.BatteryHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
@ -28,10 +29,12 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
Intent.ACTION_TIME_CHANGED,
|
||||
Intent.ACTION_TIMEZONE_CHANGED,
|
||||
Intent.ACTION_LOCALE_CHANGED,
|
||||
Actions.ACTION_CALENDAR_UPDATE -> CalendarHelper.updateEventList(context)
|
||||
Intent.ACTION_DATE_CHANGED,
|
||||
Actions.ACTION_CALENDAR_UPDATE -> {
|
||||
CalendarHelper.updateEventList(context)
|
||||
}
|
||||
|
||||
"com.sec.android.widgetapp.APPWIDGET_RESIZE",
|
||||
Intent.ACTION_DATE_CHANGED,
|
||||
AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED,
|
||||
Actions.ACTION_TIME_UPDATE -> {
|
||||
MainWidget.updateWidget(context)
|
||||
@ -50,7 +53,7 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
if (eventId == null) {
|
||||
removeUpdates(context)
|
||||
|
||||
eventRepository.getEvents().forEach { event ->
|
||||
eventRepository.getFutureEvents().forEach { event ->
|
||||
setEventUpdate(context, event)
|
||||
}
|
||||
} else {
|
||||
@ -59,6 +62,7 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
setEventUpdate(context, event)
|
||||
}
|
||||
}
|
||||
eventRepository.close()
|
||||
}
|
||||
|
||||
private fun setEventUpdate(context: Context, event: Event) {
|
||||
@ -68,65 +72,92 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
}
|
||||
val diff = Period(now.timeInMillis, event.startDate)
|
||||
if (event.startDate > now.timeInMillis) {
|
||||
// Update the widget every hour till the event
|
||||
if (diff.hours == 0) {
|
||||
var minutes = 0
|
||||
when (Preferences.widgetUpdateFrequency) {
|
||||
Constants.WidgetUpdateFrequency.DEFAULT.value -> {
|
||||
minutes = when {
|
||||
diff.minutes > 50 -> 50
|
||||
diff.minutes > 30 -> 30
|
||||
diff.minutes > 15 -> 15
|
||||
else -> 0
|
||||
val limit = when (Preferences.showUntil) {
|
||||
0 -> 1000 * 60 * 60 * 3
|
||||
1 -> 1000 * 60 * 60 * 6
|
||||
2 -> 1000 * 60 * 60 * 12
|
||||
3 -> 1000 * 60 * 60 * 24
|
||||
4 -> 1000 * 60 * 60 * 24 * 3
|
||||
5 -> 1000 * 60 * 60 * 24 * 7
|
||||
6 -> 1000 * 60 * 30
|
||||
7 -> 1000 * 60 * 60
|
||||
else -> 1000 * 60 * 60 * 6
|
||||
}
|
||||
if (event.startDate <= limit) {
|
||||
if (event.startDate > now.timeInMillis) {
|
||||
// Update the widget every hour till the event
|
||||
if (diff.hours == 0) {
|
||||
var minutes = 0
|
||||
when (Preferences.widgetUpdateFrequency) {
|
||||
Constants.WidgetUpdateFrequency.DEFAULT.value -> {
|
||||
minutes = when {
|
||||
diff.minutes > 50 -> 50
|
||||
diff.minutes > 30 -> 30
|
||||
diff.minutes > 15 -> 15
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
Constants.WidgetUpdateFrequency.HIGH.value -> {
|
||||
minutes = diff.minutes - (diff.minutes % 5)
|
||||
}
|
||||
}
|
||||
Constants.WidgetUpdateFrequency.HIGH.value -> {
|
||||
minutes = diff.minutes - (diff.minutes % 5)
|
||||
}
|
||||
}
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
if (event.startDate - minutes * 1000 * 60 > (now.timeInMillis + 120 * 1000)) event.startDate - 60 * 1000 * minutes else now.timeInMillis + 120000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
event.eventID.toInt(),
|
||||
Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_TIME_UPDATE
|
||||
putExtra(EVENT_ID, event.eventID)
|
||||
},
|
||||
0
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
if (event.startDate - minutes * 1000 * 60 > (now.timeInMillis + 120 * 1000)) event.startDate - 60 * 1000 * minutes else now.timeInMillis + 120000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
event.eventID.toInt(),
|
||||
Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_TIME_UPDATE
|
||||
putExtra(EVENT_ID, event.eventID)
|
||||
},
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
event.startDate - diff.hours * 1000 * 60 * 60 + if (diff.minutes > 30) (-30) else (+30),
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
event.eventID.toInt(),
|
||||
Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_TIME_UPDATE
|
||||
putExtra(EVENT_ID, event.eventID)
|
||||
},
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Update the widget one second after the event is finished
|
||||
val fireTime =
|
||||
if (event.endDate > now.timeInMillis + 120 * 1000) event.endDate else now.timeInMillis + 120000
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
event.startDate - diff.hours * 1000 * 60 * 60,
|
||||
fireTime,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
event.eventID.toInt(),
|
||||
Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_TIME_UPDATE
|
||||
putExtra(EVENT_ID, event.eventID)
|
||||
},
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// Update the widget one second after the event is finished
|
||||
val fireTime =
|
||||
if (event.endDate > now.timeInMillis + 120 * 1000) event.endDate else now.timeInMillis + 120000
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
fireTime,
|
||||
if (event.startDate - limit > now.timeInMillis + 120 * 1000) event.startDate - limit else now.timeInMillis + 120000,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
event.eventID.toInt(),
|
||||
Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_TIME_UPDATE
|
||||
putExtra(EVENT_ID, event.eventID)
|
||||
},
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -135,9 +166,11 @@ class UpdatesReceiver : BroadcastReceiver() {
|
||||
|
||||
fun removeUpdates(context: Context) {
|
||||
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||
EventRepository(context).getEvents().forEach {
|
||||
val eventRepository = EventRepository(context)
|
||||
eventRepository.getFutureEvents().forEach {
|
||||
cancel(PendingIntent.getBroadcast(context, it.eventID.toInt(), Intent(context, UpdatesReceiver::class.java), 0))
|
||||
}
|
||||
eventRepository.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.tommasoberlose.anotherwidget.services
|
||||
|
||||
import android.app.job.JobInfo
|
||||
import android.app.job.JobParameters
|
||||
import android.app.job.JobScheduler
|
||||
import android.app.job.JobService
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.provider.CalendarContract
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
|
||||
class BatteryListenerJob : JobService() {
|
||||
override fun onStartJob(params: JobParameters): Boolean {
|
||||
MainWidget.updateWidget(this)
|
||||
schedule(
|
||||
this
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onStopJob(params: JobParameters): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val chargingJobId = 1006
|
||||
private const val notChargingJobId = 1007
|
||||
fun schedule(context: Context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
remove(context)
|
||||
val componentName = ComponentName(
|
||||
context,
|
||||
EventListenerJob::class.java
|
||||
)
|
||||
with(context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler) {
|
||||
schedule(
|
||||
JobInfo.Builder(chargingJobId, componentName)
|
||||
.setRequiresCharging(true)
|
||||
.setPersisted(true)
|
||||
.build()
|
||||
)
|
||||
schedule(
|
||||
JobInfo.Builder(notChargingJobId, componentName)
|
||||
.setRequiresCharging(false)
|
||||
.setPersisted(true)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun remove(context: Context) {
|
||||
val js = context.getSystemService(JobScheduler::class.java)
|
||||
js?.cancel(chargingJobId)
|
||||
js?.cancel(notChargingJobId)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package com.tommasoberlose.anotherwidget.services
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import androidx.core.app.JobIntentService
|
||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.models.Event
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import me.everything.providers.android.calendar.CalendarProvider
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class UpdateCalendarJob : JobIntentService() {
|
||||
|
||||
companion object {
|
||||
val jobId = 1200
|
||||
|
||||
fun enqueueWork(context: Context, work: Intent) {
|
||||
enqueueWork(context, UpdateCalendarJob::class.java, jobId, work)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onHandleWork(intent: Intent) {
|
||||
val eventRepository = EventRepository(this)
|
||||
if (Preferences.showEvents) {
|
||||
val eventList = ArrayList<Event>()
|
||||
|
||||
val now = Calendar.getInstance()
|
||||
val begin = Calendar.getInstance().apply {
|
||||
set(Calendar.MILLISECOND, 0)
|
||||
set(Calendar.SECOND, 0)
|
||||
set(Calendar.MINUTE, 0)
|
||||
set(Calendar.HOUR_OF_DAY, 0)
|
||||
}
|
||||
val limit = Calendar.getInstance().apply {
|
||||
timeInMillis = begin.timeInMillis
|
||||
add(Calendar.DAY_OF_YEAR, 2)
|
||||
}
|
||||
|
||||
if (!checkGrantedPermission(
|
||||
Manifest.permission.READ_CALENDAR
|
||||
)
|
||||
) {
|
||||
eventRepository.resetNextEventData()
|
||||
} else {
|
||||
try {
|
||||
val provider = CalendarProvider(this)
|
||||
val data = provider.getInstances(begin.timeInMillis, limit.timeInMillis)
|
||||
if (data != null) {
|
||||
val instances = data.list
|
||||
for (instance in instances) {
|
||||
try {
|
||||
val e = provider.getEvent(instance.eventId)
|
||||
if (e != null && !e.deleted && instance.begin <= limit.timeInMillis && now.timeInMillis < instance.end && !CalendarHelper.getFilteredCalendarIdList()
|
||||
.contains(e.calendarId)
|
||||
) {
|
||||
if (e.allDay) {
|
||||
val start = Calendar.getInstance()
|
||||
start.timeInMillis = instance.begin
|
||||
val end = Calendar.getInstance()
|
||||
end.timeInMillis = instance.end
|
||||
instance.begin =
|
||||
start.timeInMillis - start.timeZone.getOffset(start.timeInMillis)
|
||||
instance.end =
|
||||
end.timeInMillis - end.timeZone.getOffset(end.timeInMillis)
|
||||
}
|
||||
eventList.add(
|
||||
Event(
|
||||
id = instance.id,
|
||||
eventID = e.id,
|
||||
title = e.title ?: "",
|
||||
startDate = instance.begin,
|
||||
endDate = instance.end,
|
||||
calendarID = e.calendarId.toInt(),
|
||||
allDay = e.allDay,
|
||||
address = e.eventLocation ?: "",
|
||||
selfAttendeeStatus = e.selfAttendeeStatus.toInt()
|
||||
)
|
||||
)
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventList.isEmpty()) {
|
||||
eventRepository.resetNextEventData()
|
||||
eventRepository.clearEvents()
|
||||
} else {
|
||||
eventList.sortWith(Comparator { event: Event, event1: Event ->
|
||||
if (event.allDay && event1.allDay) {
|
||||
event.startDate.compareTo(event1.startDate)
|
||||
} else if (event.allDay) {
|
||||
1
|
||||
} else if (event1.allDay) {
|
||||
-1
|
||||
} else {
|
||||
event1.startDate.compareTo(event.startDate)
|
||||
}
|
||||
})
|
||||
eventList.reverse()
|
||||
eventRepository.saveEvents(
|
||||
eventList
|
||||
)
|
||||
eventRepository.saveNextEventData(
|
||||
eventList[0]
|
||||
)
|
||||
}
|
||||
} catch (ignored: java.lang.Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventRepository.resetNextEventData()
|
||||
}
|
||||
|
||||
UpdatesReceiver.setUpdates(this)
|
||||
MainWidget.updateWidget(this)
|
||||
|
||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||
eventRepository.close()
|
||||
}
|
||||
}
|
@ -76,7 +76,9 @@ class MainActivity : AppCompatActivity() {
|
||||
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
|
||||
|
||||
controlExtras(intent)
|
||||
requirePermission()
|
||||
if (Preferences.showWallpaper) {
|
||||
requirePermission()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
@ -6,6 +6,7 @@ import android.location.Address
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.isVisible
|
||||
@ -45,8 +46,17 @@ class SupportDevActivity : AppCompatActivity(), PurchasesUpdatedListener {
|
||||
adapter = SlimAdapter.create()
|
||||
adapter
|
||||
.register<SkuDetails>(R.layout.inapp_product_layout) { item, injector ->
|
||||
item.sku
|
||||
injector
|
||||
.text(R.id.product_title, item.title.replace("(Another Widget)", ""))
|
||||
.with<TextView>(R.id.product_title) {
|
||||
it.text = when (item.sku) {
|
||||
"donation_coffee" -> getString(R.string.donation_coffee)
|
||||
"donation_donuts" -> getString(R.string.donation_donuts)
|
||||
"donation_breakfast" -> getString(R.string.donation_breakfast)
|
||||
"donation_lunch" -> getString(R.string.donation_lunch)
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
.text(R.id.product_price, item.price)
|
||||
.clicked(R.id.item) {
|
||||
viewModel.purchase(this, item)
|
||||
|
@ -32,11 +32,6 @@ class WeatherProviderActivity : AppCompatActivity() {
|
||||
openURI("https://home.openweathermap.org/users/sign_up")
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set), Html.FROM_HTML_MODE_LEGACY)
|
||||
} else {
|
||||
last_info.text = Html.fromHtml(getString(R.string.api_key_info_all_set))
|
||||
}
|
||||
api_key.editText?.setText(Preferences.weatherProviderApi)
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,11 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.DateHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.IntentHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
|
||||
@ -74,6 +76,11 @@ class CalendarTabFragment : Fragment() {
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
show_all_day_toggle.isChecked = Preferences.calendarAllDay
|
||||
show_declined_events_toggle.isChecked = Preferences.showDeclinedEvents
|
||||
show_diff_time_toggle.isChecked = Preferences.showDiffTime
|
||||
show_multiple_events_toggle.isChecked = Preferences.showNextEvent
|
||||
|
||||
setupListener()
|
||||
}
|
||||
|
||||
@ -82,6 +89,7 @@ class CalendarTabFragment : Fragment() {
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
binding.isCalendarEnabled = Preferences.showEvents
|
||||
binding.isDiffEnabled = Preferences.showDiffTime || !Preferences.showEvents
|
||||
|
||||
viewModel.showEvents.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
@ -92,23 +100,23 @@ class CalendarTabFragment : Fragment() {
|
||||
} else {
|
||||
CalendarHelper.removeEventUpdatesAndroidN(requireContext())
|
||||
}
|
||||
binding.isDiffEnabled = Preferences.showDiffTime || !it
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
viewModel.calendarAllDay.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
all_day_label?.text =
|
||||
if (it) getString(R.string.settings_all_day_subtitle_visible) else getString(R.string.settings_all_day_subtitle_gone)
|
||||
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
})
|
||||
|
||||
viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer {
|
||||
@ -120,6 +128,7 @@ class CalendarTabFragment : Fragment() {
|
||||
viewModel.showDiffTime.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_diff_time_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
binding.isDiffEnabled = it || !Preferences.showEvents
|
||||
}
|
||||
})
|
||||
|
||||
@ -138,7 +147,7 @@ class CalendarTabFragment : Fragment() {
|
||||
maintainScrollPosition {
|
||||
show_until_label?.text = getString(SettingsStringHelper.getShowUntilString(it))
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
updateCalendar()
|
||||
})
|
||||
|
||||
viewModel.showNextEvent.observe(viewLifecycleOwner, Observer {
|
||||
@ -150,7 +159,18 @@ class CalendarTabFragment : Fragment() {
|
||||
|
||||
viewModel.calendarAppName.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
calendar_app_label?.text = if (it != "") it else getString(R.string.default_calendar_app)
|
||||
calendar_app_label?.text = when {
|
||||
Preferences.clockAppName != "" -> Preferences.clockAppName
|
||||
else -> {
|
||||
if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) {
|
||||
getString(
|
||||
R.string.default_calendar_app
|
||||
)
|
||||
} else {
|
||||
getString(R.string.nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -215,14 +235,14 @@ class CalendarTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
dialog.addItem(
|
||||
if (calendarSelectorList[index].name == calendarSelectorList[index].accountName) getString(R.string.account_events) else calendarSelectorList[index].name,
|
||||
if (calendarSelectorList[index].name == calendarSelectorList[index].accountName) getString(R.string.main_calendar) else calendarSelectorList[index].name,
|
||||
calendarSelectorList[index].id
|
||||
)
|
||||
}
|
||||
|
||||
dialog.addOnMultipleSelectItemListener { values ->
|
||||
CalendarHelper.filterCalendar(calendarSelectorList.map { it.id }.filter { !values.contains(it) })
|
||||
checkReadEventsPermission()
|
||||
updateCalendar()
|
||||
}.show()
|
||||
} else {
|
||||
activity?.toast(getString(R.string.calendar_settings_list_error))
|
||||
@ -231,50 +251,54 @@ class CalendarTabFragment : Fragment() {
|
||||
|
||||
action_show_all_day.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_all_day_title)).setSelectedValue(Preferences.calendarAllDay)
|
||||
.addItem(getString(R.string.settings_all_day_subtitle_visible), true)
|
||||
.addItem(getString(R.string.settings_all_day_subtitle_gone), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.calendarAllDay = value
|
||||
}.show()
|
||||
show_all_day_toggle.isChecked = !show_all_day_toggle.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
show_all_day_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (Preferences.showEvents) {
|
||||
Preferences.calendarAllDay = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
action_show_declined_events.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_declined_events_title)).setSelectedValue(Preferences.showDeclinedEvents)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showDeclinedEvents = value
|
||||
}.show()
|
||||
show_declined_events_toggle.isChecked = !show_declined_events_toggle.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
show_declined_events_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (Preferences.showEvents) {
|
||||
Preferences.showDeclinedEvents = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
action_show_multiple_events.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_multiple_events_title)).setSelectedValue(Preferences.showNextEvent)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showNextEvent = value
|
||||
}.show()
|
||||
show_multiple_events_toggle.isChecked = !show_multiple_events_toggle.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
show_multiple_events_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (Preferences.showEvents) {
|
||||
Preferences.showNextEvent = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
action_show_diff_time.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_diff_time_title)).setSelectedValue(Preferences.showDiffTime)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showDiffTime = value
|
||||
}.show()
|
||||
show_diff_time_toggle.isChecked = !show_diff_time_toggle.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
show_diff_time_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (Preferences.showEvents) {
|
||||
Preferences.showDiffTime = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
action_widget_update_frequency.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
if (Preferences.showEvents && Preferences.showDiffTime) {
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_widget_update_frequency_title), message = getString(R.string.settings_widget_update_frequency_subtitle)).setSelectedValue(Preferences.widgetUpdateFrequency)
|
||||
.addItem(getString(R.string.settings_widget_update_frequency_high), Constants.WidgetUpdateFrequency.HIGH.value)
|
||||
.addItem(getString(R.string.settings_widget_update_frequency_default), Constants.WidgetUpdateFrequency.DEFAULT.value)
|
||||
@ -300,7 +324,7 @@ class CalendarTabFragment : Fragment() {
|
||||
action_show_until.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_show_until_title)).setSelectedValue(Preferences.showUntil)
|
||||
intArrayOf(6,7,0,1,2,3).forEach {
|
||||
intArrayOf(6,7,0,1,2,3, 4, 5).forEach {
|
||||
dialog.addItem(getString(SettingsStringHelper.getShowUntilString(it)), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
@ -329,7 +353,6 @@ class CalendarTabFragment : Fragment() {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.READ_CALENDAR) == true) {
|
||||
show_events_label?.text = if (showEvents) getString(R.string.show_events_visible) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert?.isVisible = false
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
} else {
|
||||
show_events_label?.text = if (showEvents) getString(R.string.description_permission_calendar) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert?.isVisible = showEvents
|
||||
@ -339,6 +362,12 @@ class CalendarTabFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCalendar() {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.READ_CALENDAR) == true) {
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
private fun requirePermission() {
|
||||
Dexter.withContext(requireContext())
|
||||
.withPermissions(
|
||||
@ -386,11 +415,11 @@ class CalendarTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateFormat
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -21,6 +23,7 @@ import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.components.FixedFocusScrollView
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentClockSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -29,9 +32,11 @@ import com.tommasoberlose.anotherwidget.helpers.AlarmHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toHexValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.toIntValue
|
||||
import com.tommasoberlose.anotherwidget.helpers.IntentHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
|
||||
import kotlinx.android.synthetic.main.fragment_clock_settings.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
@ -48,6 +53,7 @@ class ClockTabFragment : Fragment() {
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var colors: IntArray
|
||||
private lateinit var binding: FragmentClockSettingsBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -59,7 +65,7 @@ class ClockTabFragment : Fragment() {
|
||||
): View {
|
||||
|
||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
||||
val binding = DataBindingUtil.inflate<FragmentClockSettingsBinding>(inflater, R.layout.fragment_clock_settings, container, false)
|
||||
binding = DataBindingUtil.inflate<FragmentClockSettingsBinding>(inflater, R.layout.fragment_clock_settings, container, false)
|
||||
|
||||
subscribeUi(binding, viewModel)
|
||||
|
||||
@ -72,6 +78,8 @@ class ClockTabFragment : Fragment() {
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
ampm_indicator_toggle.isChecked = Preferences.showAMPMIndicator
|
||||
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val lazyColors = requireContext().resources.getIntArray(R.array.material_colors)
|
||||
withContext(Dispatchers.Main) {
|
||||
@ -86,6 +94,7 @@ class ClockTabFragment : Fragment() {
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
binding.isClockVisible = Preferences.showClock
|
||||
binding.is24Format = DateFormat.is24HourFormat(requireContext())
|
||||
|
||||
viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer {
|
||||
large_clock_warning?.isVisible = it
|
||||
@ -147,8 +156,18 @@ class ClockTabFragment : Fragment() {
|
||||
|
||||
viewModel.clockAppName.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
clock_app_label?.text =
|
||||
if (Preferences.clockAppName != "") Preferences.clockAppName else getString(R.string.default_clock_app)
|
||||
clock_app_label?.text = when {
|
||||
Preferences.clockAppName != "" -> Preferences.clockAppName
|
||||
else -> {
|
||||
if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
|
||||
getString(
|
||||
R.string.default_clock_app
|
||||
)
|
||||
} else {
|
||||
getString(R.string.nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -167,57 +186,88 @@ class ClockTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_clock_text_size.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.settings_clock_text_size_title)).setSelectedValue(Preferences.clockTextSize)
|
||||
(46 downTo 12).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
if (Preferences.showClock) {
|
||||
val dialog = BottomSheetMenu<Float>(
|
||||
requireContext(),
|
||||
header = getString(R.string.settings_clock_text_size_title)
|
||||
).setSelectedValue(Preferences.clockTextSize)
|
||||
(46 downTo 12).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.clockTextSize = value
|
||||
}.show()
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.clockTextSize = value
|
||||
}.show()
|
||||
}
|
||||
|
||||
action_ampm_indicator_size.setOnClickListener {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_ampm_indicator_title)).setSelectedValue(Preferences.showAMPMIndicator)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showAMPMIndicator = value
|
||||
}.show()
|
||||
if (Preferences.showClock) {
|
||||
ampm_indicator_toggle.isChecked = !ampm_indicator_toggle.isChecked
|
||||
}
|
||||
}
|
||||
|
||||
ampm_indicator_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (Preferences.showClock) {
|
||||
Preferences.showAMPMIndicator = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
action_clock_text_color.setOnClickListener {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
getSelected = ColorHelper::getClockFontColorRgb,
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.clockTextColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
},
|
||||
showAlphaSelector = true,
|
||||
alpha = Preferences.clockTextAlpha.toIntValue(),
|
||||
onAlphaChangeListener = { alpha ->
|
||||
Preferences.clockTextAlpha = alpha.toHexValue()
|
||||
}
|
||||
).show()
|
||||
if (Preferences.showClock) {
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
getSelected = ColorHelper::getClockFontColorRgb,
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.clockTextColor =
|
||||
"#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
},
|
||||
showAlphaSelector = true,
|
||||
alpha = Preferences.clockTextAlpha.toIntValue(),
|
||||
onAlphaChangeListener = { alpha ->
|
||||
Preferences.clockTextAlpha = alpha.toHexValue()
|
||||
}
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
action_clock_bottom_margin_size.setOnClickListener {
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_clock_bottom_margin_title)).setSelectedValue(Preferences.clockBottomMargin)
|
||||
.addItem(getString(R.string.settings_clock_bottom_margin_subtitle_none), Constants.ClockBottomMargin.NONE.value)
|
||||
.addItem(getString(R.string.settings_clock_bottom_margin_subtitle_small), Constants.ClockBottomMargin.SMALL.value)
|
||||
.addItem(getString(R.string.settings_clock_bottom_margin_subtitle_medium), Constants.ClockBottomMargin.MEDIUM.value)
|
||||
.addItem(getString(R.string.settings_clock_bottom_margin_subtitle_large), Constants.ClockBottomMargin.LARGE.value)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.clockBottomMargin = value
|
||||
}.show()
|
||||
if (Preferences.showClock) {
|
||||
BottomSheetMenu<Int>(
|
||||
requireContext(),
|
||||
header = getString(R.string.settings_clock_bottom_margin_title)
|
||||
).setSelectedValue(Preferences.clockBottomMargin)
|
||||
.addItem(
|
||||
getString(R.string.settings_clock_bottom_margin_subtitle_none),
|
||||
Constants.ClockBottomMargin.NONE.value
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_clock_bottom_margin_subtitle_small),
|
||||
Constants.ClockBottomMargin.SMALL.value
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_clock_bottom_margin_subtitle_medium),
|
||||
Constants.ClockBottomMargin.MEDIUM.value
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_clock_bottom_margin_subtitle_large),
|
||||
Constants.ClockBottomMargin.LARGE.value
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.clockBottomMargin = value
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
action_clock_app.setOnClickListener {
|
||||
if (Preferences.showClock) {
|
||||
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java),
|
||||
RequestCode.CLOCK_APP_REQUEST_CODE.code
|
||||
)
|
||||
if (Preferences.showClock) {
|
||||
startActivityForResult(
|
||||
Intent(requireContext(), ChooseApplicationActivity::class.java),
|
||||
RequestCode.CLOCK_APP_REQUEST_CODE.code
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -232,12 +282,17 @@ class ClockTabFragment : Fragment() {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
binding.is24Format = DateFormat.is24HourFormat(requireContext())
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,8 @@ class GeneralTabFragment : Fragment() {
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
show_dividers_toggle.isChecked = Preferences.showDividers
|
||||
|
||||
setupListener()
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val lazyColors = requireContext().resources.getIntArray(R.array.material_colors)
|
||||
@ -186,15 +188,6 @@ class GeneralTabFragment : Fragment() {
|
||||
})
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
action_main_text_size.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_main_text_size)).setSelectedValue(Preferences.textMainSize)
|
||||
@ -251,24 +244,22 @@ class GeneralTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_date_format.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
val now = Calendar.getInstance()
|
||||
val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat)
|
||||
val now = Calendar.getInstance()
|
||||
val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat)
|
||||
|
||||
dialog.addItem(DateHelper.getDefaultDateText(requireContext(), now), "")
|
||||
if (Preferences.dateFormat != "") {
|
||||
dialog.addItem(DateHelper.getDateText(requireContext(), now), Preferences.dateFormat)
|
||||
}
|
||||
dialog.addItem(getString(R.string.custom_date_format), "-")
|
||||
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
if (value == "-") {
|
||||
startActivity(Intent(requireContext(), CustomDateActivity::class.java))
|
||||
} else {
|
||||
Preferences.dateFormat = value
|
||||
}
|
||||
}.show()
|
||||
dialog.addItem(DateHelper.getDefaultDateText(requireContext(), now), "")
|
||||
if (Preferences.dateFormat != "") {
|
||||
dialog.addItem(DateHelper.getDateText(requireContext(), now), Preferences.dateFormat)
|
||||
}
|
||||
dialog.addItem(getString(R.string.custom_date_format), "-")
|
||||
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
if (value == "-") {
|
||||
startActivity(Intent(requireContext(), CustomDateActivity::class.java))
|
||||
} else {
|
||||
Preferences.dateFormat = value
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
action_background_color.setOnClickListener {
|
||||
@ -321,12 +312,11 @@ class GeneralTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_show_dividers.setOnClickListener {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_multiple_events_title)).setSelectedValue(Preferences.showDividers)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showDividers = value
|
||||
}.show()
|
||||
show_dividers_toggle.isChecked = !show_dividers_toggle.isChecked
|
||||
}
|
||||
|
||||
show_dividers_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
Preferences.showDividers = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,4 +338,13 @@ class GeneralTabFragment : Fragment() {
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.checkIfFitInstalled
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_glance_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_glance_settings.scrollView
|
||||
@ -97,6 +98,7 @@ class GlanceTabFragment : Fragment() {
|
||||
viewModel.showGlance.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
binding.isGlanceVisible = it
|
||||
show_glance_label.text = if (it) getString(R.string.description_show_glance_visible) else getString(R.string.description_show_glance_not_visible)
|
||||
}
|
||||
})
|
||||
|
||||
@ -176,6 +178,22 @@ class GlanceTabFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
action_show_next_alarm.setOnLongClickListener {
|
||||
with(requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||
val alarm = nextAlarmClock
|
||||
if (alarm != null && alarm.showIntent != null) {
|
||||
val pm = requireContext().packageManager as PackageManager
|
||||
val appNameOrPackage = try {
|
||||
pm.getApplicationLabel(pm.getApplicationInfo(alarm.showIntent?.creatorPackage ?: "", 0))
|
||||
} catch (e: Exception) {
|
||||
alarm.showIntent?.creatorPackage ?: ""
|
||||
}
|
||||
activity?.toast(getString(R.string.next_alarm_warning).format(appNameOrPackage), long = true)
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
action_show_low_battery_level_warning.setOnClickListener {
|
||||
if (Preferences.showGlance) {
|
||||
BottomSheetMenu<Boolean>(
|
||||
@ -231,8 +249,7 @@ class GlanceTabFragment : Fragment() {
|
||||
} catch (e: Exception) {
|
||||
alarm.showIntent?.creatorPackage ?: ""
|
||||
}
|
||||
show_next_alarm_warning.text =
|
||||
getString(R.string.next_alarm_warning).format(appNameOrPackage)
|
||||
show_next_alarm_warning.text = getString(R.string.next_alarm_warning).format(appNameOrPackage)
|
||||
} else {
|
||||
show_next_alarm_label?.text = if (Preferences.showNextAlarm) getString(R.string.settings_visible) else getString(
|
||||
R.string.settings_not_visible)
|
||||
@ -356,11 +373,11 @@ class GlanceTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package com.tommasoberlose.anotherwidget.ui.fragments
|
||||
|
||||
import android.Manifest
|
||||
import android.animation.ValueAnimator
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
@ -14,7 +16,6 @@ import android.util.TypedValue
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.animation.addListener
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
@ -145,7 +146,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
ColorHelper.getBackgroundColor()
|
||||
)
|
||||
)
|
||||
uiJob = viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
|
||||
uiJob = lifecycleScope.launch(Dispatchers.IO) {
|
||||
val generatedView = MainWidget.generateWidgetView(requireContext())
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
@ -186,7 +187,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
clock_bottom_margin_large?.isVisible =
|
||||
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value
|
||||
|
||||
if ((Preferences.showClock && time_container?.isVisible == false) || (!Preferences.showClock && time_container?.isVisible == true)) {
|
||||
if ((Preferences.showClock && (time?.alpha ?: 1f < 1f)) || (!Preferences.showClock && (time?.alpha ?: 0f > 0f))) {
|
||||
if (Preferences.showClock) {
|
||||
time_container?.layoutParams = time_container.layoutParams.apply {
|
||||
height = RelativeLayout.LayoutParams.WRAP_CONTENT
|
||||
@ -230,10 +231,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
).apply {
|
||||
duration = 500L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview.layoutParams = layoutParams
|
||||
if (preview != null) {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
@ -253,10 +256,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
).apply {
|
||||
duration = 300L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview?.layoutParams = layoutParams
|
||||
if (preview != null) {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview?.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
@ -278,10 +283,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
).apply {
|
||||
duration = 300L
|
||||
addUpdateListener {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview.layoutParams = layoutParams
|
||||
if (preview != null) {
|
||||
val animatedValue = animatedValue as Int
|
||||
val layoutParams = preview.layoutParams
|
||||
layoutParams.height = animatedValue
|
||||
preview.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ class SettingsFragment : Fragment() {
|
||||
binding.lifecycleOwner = this
|
||||
binding.viewModel = viewModel
|
||||
|
||||
subscribeUi(viewModel)
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@ -75,7 +77,8 @@ class SettingsFragment : Fragment() {
|
||||
Navigation.findNavController(it).popBackStack()
|
||||
}
|
||||
|
||||
subscribeUi(viewModel)
|
||||
show_widget_preview_toggle.isChecked = Preferences.showPreview
|
||||
show_wallpaper_toggle.isChecked = Preferences.showWallpaper
|
||||
|
||||
setupListener()
|
||||
|
||||
@ -120,44 +123,26 @@ class SettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
|
||||
action_show_widget_preview.setOnClickListener {
|
||||
maintainScrollPosition {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.action_show_widget_preview))
|
||||
.setSelectedValue(Preferences.showPreview)
|
||||
.addItem(
|
||||
getString(R.string.settings_visible),
|
||||
true
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_not_visible),
|
||||
false
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.showPreview = value
|
||||
}.show()
|
||||
}
|
||||
show_widget_preview_toggle.isChecked = !show_widget_preview_toggle.isChecked
|
||||
}
|
||||
|
||||
show_widget_preview_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
Preferences.showPreview = isChecked
|
||||
}
|
||||
|
||||
action_show_wallpaper.setOnClickListener {
|
||||
maintainScrollPosition {
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_title_show_wallpaper))
|
||||
.setSelectedValue(Preferences.showWallpaper && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true)
|
||||
.addItem(
|
||||
getString(R.string.settings_visible),
|
||||
true
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_not_visible),
|
||||
false
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
if (value) {
|
||||
requirePermission()
|
||||
} else {
|
||||
Preferences.showWallpaper = value
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
action_show_wallpaper.setOnClickListener {
|
||||
show_wallpaper_toggle.isChecked = !show_wallpaper_toggle.isChecked
|
||||
}
|
||||
|
||||
show_wallpaper_toggle.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
requirePermission()
|
||||
} else {
|
||||
Preferences.showWallpaper = isChecked
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,11 +196,11 @@ class SettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -226,8 +211,11 @@ class SettingsFragment : Fragment() {
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
|
||||
report?.let {
|
||||
Preferences.showWallpaper = false
|
||||
Preferences.showWallpaper = report.areAllPermissionsGranted()
|
||||
if (report.areAllPermissionsGranted()) {
|
||||
Preferences.showWallpaper = true
|
||||
} else {
|
||||
show_wallpaper_toggle?.isChecked = false
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onPermissionRationaleShouldBeShown(
|
||||
|
@ -10,6 +10,7 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.BuildCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -24,11 +25,14 @@ import com.karumi.dexter.listener.PermissionRequest
|
||||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.components.IconPackSelector
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.CustomLocationActivity
|
||||
@ -129,10 +133,13 @@ class WeatherTabFragment : Fragment() {
|
||||
|
||||
viewModel.weatherIconPack.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
label_weather_icon_pack?.text = when (it) {
|
||||
Constants.WeatherIconPack.MINIMAL.value -> getString(R.string.settings_weather_icon_pack_minimal)
|
||||
else -> getString(R.string.settings_weather_icon_pack_default)
|
||||
}
|
||||
label_weather_icon_pack?.text = getString(R.string.settings_weather_icon_pack_default).format((it + 1))
|
||||
// weather_icon_pack.setImageDrawable(ContextCompat.getDrawable(requireContext(), WeatherHelper.getWeatherIconResource("02d")))
|
||||
// if (it == Constants.WeatherIconPack.MINIMAL.value) {
|
||||
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), R.color.colorPrimaryText))
|
||||
// } else {
|
||||
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), android.R.color.transparent))
|
||||
// }
|
||||
}
|
||||
checkLocationPermission()
|
||||
})
|
||||
@ -230,12 +237,7 @@ class WeatherTabFragment : Fragment() {
|
||||
|
||||
action_weather_icon_pack.setOnClickListener {
|
||||
if (Preferences.showWeather) {
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).setSelectedValue(Preferences.weatherIconPack)
|
||||
.addItem(getString(R.string.settings_weather_icon_pack_default), Constants.WeatherIconPack.DEFAULT.value)
|
||||
.addItem(getString(R.string.settings_weather_icon_pack_minimal), Constants.WeatherIconPack.MINIMAL.value)
|
||||
.addOnSelectItemListener { value ->
|
||||
Preferences.weatherIconPack = value
|
||||
}.show()
|
||||
IconPackSelector(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).show()
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,11 +298,11 @@ class WeatherTabFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
val scrollPosition = scrollView.scrollY
|
||||
scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
lifecycleScope.launch {
|
||||
delay(200)
|
||||
scrollView.smoothScrollTo(0, scrollPosition)
|
||||
scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.RemoteViews
|
||||
import android.widget.TextClock
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
@ -36,6 +37,7 @@ import java.text.DateFormat
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
class MainWidget : AppWidgetProvider() {
|
||||
@ -111,7 +113,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
appWidgetId,
|
||||
IntentHelper.getWidgetUpdateIntent(context),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||
} catch (ex: Exception) {
|
||||
@ -140,9 +142,8 @@ class MainWidget : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
private fun updateCalendarView(context: Context, v: View, views: RemoteViews, widgetID: Int): RemoteViews {
|
||||
val eventRepository = EventRepository(context)
|
||||
try {
|
||||
val eventRepository = EventRepository(context)
|
||||
|
||||
views.setImageViewBitmap(
|
||||
R.id.empty_date_rect,
|
||||
BitmapHelper.getBitmapFromView(v.empty_date, draw = false)
|
||||
@ -157,7 +158,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getCalendarIntent(context),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.empty_date_rect, calPIntent)
|
||||
|
||||
@ -180,7 +181,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
NewCalendarEventReceiver::class.java
|
||||
).apply { action = Actions.ACTION_GO_TO_NEXT_EVENT },
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
|
||||
@ -198,7 +199,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
NewCalendarEventReceiver::class.java
|
||||
).apply { action = Actions.ACTION_GO_TO_PREVIOUS_EVENT },
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
)
|
||||
} else {
|
||||
@ -210,7 +211,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getEventIntent(context, nextEvent),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.next_event_rect, pIntent)
|
||||
views.setOnClickPendingIntent(R.id.next_event_difference_time_rect, pIntent)
|
||||
@ -233,7 +234,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getGoogleMapsIntentFromAddress(context, nextEvent.address),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, mapIntent)
|
||||
} else {
|
||||
@ -245,7 +246,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
nextEvent,
|
||||
forceEventDetails = true
|
||||
),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, pIntentDetail)
|
||||
}
|
||||
@ -263,7 +264,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
|
||||
views.setViewVisibility(R.id.empty_layout_rect, View.GONE)
|
||||
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE)
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) {
|
||||
loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
@ -272,7 +273,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getMusicIntent(context),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent)
|
||||
break@loop
|
||||
@ -284,22 +285,25 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getClockIntent(context),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent)
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.isBatteryLevelLow) {
|
||||
val alarmIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getClockIntent(context),
|
||||
0
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent)
|
||||
break@loop
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging || Preferences.isBatteryLevelLow) {
|
||||
val batteryIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getBatteryIntent(),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent)
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
@ -313,7 +317,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
context,
|
||||
widgetID,
|
||||
IntentHelper.getFitIntent(context),
|
||||
0
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent)
|
||||
break@loop
|
||||
@ -340,6 +344,8 @@ class MainWidget : AppWidgetProvider() {
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
CrashlyticsReceiver.sendCrash(context, ex)
|
||||
} finally {
|
||||
eventRepository.close()
|
||||
}
|
||||
|
||||
return views
|
||||
@ -525,7 +531,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
|
||||
} else {
|
||||
val flags: Int = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
|
||||
v.next_event_date.text = DateUtils.formatDateTime(context, now.timeInMillis, flags)
|
||||
v.next_event_date.text = DateUtils.formatDateTime(context, nextEvent.startDate, flags)
|
||||
}
|
||||
}
|
||||
|
||||
@ -533,6 +539,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
v.calendar_layout.visibility = View.VISIBLE
|
||||
} else if (GlanceProviderHelper.showGlanceProviders(context)) {
|
||||
v.second_row_icon.isVisible = true
|
||||
var showSomething = false
|
||||
loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
@ -544,6 +551,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
)
|
||||
)
|
||||
v.next_event_date.text = MediaPlayerHelper.getMediaInfo()
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
@ -556,47 +564,60 @@ class MainWidget : AppWidgetProvider() {
|
||||
)
|
||||
)
|
||||
v.next_event_date.text = AlarmHelper.getNextAlarm(context)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
if (Preferences.isBatteryLevelLow) {
|
||||
v.second_row_icon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_battery_charging_full
|
||||
)
|
||||
)
|
||||
v.next_event_date.text = context.getString(R.string.battery_low_warning)
|
||||
break@loop
|
||||
if (Preferences.showBatteryCharging) {
|
||||
BatteryHelper.updateBatteryInfo(context)
|
||||
if (Preferences.isCharging) {
|
||||
v.second_row_icon.isVisible = false
|
||||
val batteryLevel = BatteryHelper.getBatteryLevel(context)
|
||||
if (batteryLevel == 100) {
|
||||
v.next_event_date.text = "%s - %d%%".format(context.getString(R.string.charging), batteryLevel)
|
||||
} else {
|
||||
v.next_event_date.text = context.getString(R.string.charging)
|
||||
}
|
||||
showSomething = true
|
||||
break@loop
|
||||
} else if (Preferences.isBatteryLevelLow) {
|
||||
v.second_row_icon.isVisible = false
|
||||
v.next_event_date.text =
|
||||
context.getString(R.string.battery_low_warning)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
if (Preferences.customNotes.isNotEmpty()) {
|
||||
v.second_row_icon.isVisible = false
|
||||
v.next_event_date.text = Preferences.customNotes
|
||||
v.next_event_date.gravity
|
||||
v.next_event_date.maxLines = 2
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
|
||||
v.second_row_icon.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
context,
|
||||
R.drawable.round_steps
|
||||
)
|
||||
)
|
||||
v.second_row_icon.isVisible = false
|
||||
v.next_event_date.text = context.getString(R.string.daily_steps_counter).format(Preferences.googleFitSteps)
|
||||
showSomething = true
|
||||
break@loop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v.next_event.text = DateHelper.getDateText(context, now)
|
||||
v.empty_layout.visibility = View.GONE
|
||||
v.calendar_layout.visibility = View.VISIBLE
|
||||
if (showSomething) {
|
||||
v.next_event.text = DateHelper.getDateText(context, now)
|
||||
v.empty_layout.visibility = View.GONE
|
||||
v.calendar_layout.visibility = View.VISIBLE
|
||||
} else {
|
||||
v.second_row_icon.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -605,7 +626,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
it.setTextColor(ColorHelper.getFontColor())
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) {
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
|
||||
listOf<ImageView>(v.action_next, v.action_previous)
|
||||
} else {
|
||||
listOf<ImageView>(v.action_next, v.action_previous, v.empty_weather_icon, v.special_weather_icon)
|
||||
@ -617,7 +638,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
it.setTextColor(ColorHelper.getSecondaryFontColor())
|
||||
}
|
||||
|
||||
if (Preferences.weatherIconPack == Constants.WeatherIconPack.DEFAULT.value) {
|
||||
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
|
||||
listOf<ImageView>(v.second_row_icon)
|
||||
} else {
|
||||
listOf<ImageView>(v.second_row_icon, v.weather_icon)
|
||||
@ -698,7 +719,7 @@ class MainWidget : AppWidgetProvider() {
|
||||
v.weather.visibility = View.VISIBLE
|
||||
v.calendar_weather.visibility = View.VISIBLE
|
||||
v.special_weather.visibility = View.VISIBLE
|
||||
val currentTemp = String.format(Locale.getDefault(), "%.0f °%s", Preferences.weatherTemp, Preferences.weatherRealTempUnit)
|
||||
val currentTemp = String.format(Locale.getDefault(), "%d °%s", Preferences.weatherTemp.roundToInt(), Preferences.weatherRealTempUnit)
|
||||
|
||||
val icon: String = Preferences.weatherIcon
|
||||
if (icon == "") {
|
||||
@ -734,6 +755,8 @@ class MainWidget : AppWidgetProvider() {
|
||||
it.isVisible = Preferences.showDividers
|
||||
}
|
||||
|
||||
eventRepository.close()
|
||||
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
@ -222,3 +222,12 @@ fun Context.checkIfFitInstalled(): Boolean {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fun Intent.isDefaultSet(context: Context): Boolean {
|
||||
val pm = context.packageManager
|
||||
return try {
|
||||
resolveActivity(pm) != null && resolveActivity(pm).packageName.isNotBlank()
|
||||
} catch (ex: java.lang.Exception) {
|
||||
false
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable-hdpi/round_cloud_circle_black_18.png
Normal file
After Width: | Height: | Size: 357 B |
BIN
app/src/main/res/drawable-hdpi/round_cloud_circle_black_24.png
Normal file
After Width: | Height: | Size: 421 B |
BIN
app/src/main/res/drawable-hdpi/round_cloud_circle_black_36.png
Normal file
After Width: | Height: | Size: 602 B |
BIN
app/src/main/res/drawable-hdpi/round_cloud_circle_black_48.png
Normal file
After Width: | Height: | Size: 765 B |
BIN
app/src/main/res/drawable-hdpi/round_publish_black_18.png
Normal file
After Width: | Height: | Size: 193 B |
BIN
app/src/main/res/drawable-hdpi/round_publish_black_24.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
app/src/main/res/drawable-hdpi/round_publish_black_36.png
Normal file
After Width: | Height: | Size: 296 B |
BIN
app/src/main/res/drawable-hdpi/round_publish_black_48.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
app/src/main/res/drawable-mdpi/round_cloud_circle_black_18.png
Normal file
After Width: | Height: | Size: 265 B |
BIN
app/src/main/res/drawable-mdpi/round_cloud_circle_black_24.png
Normal file
After Width: | Height: | Size: 310 B |
BIN
app/src/main/res/drawable-mdpi/round_cloud_circle_black_36.png
Normal file
After Width: | Height: | Size: 421 B |
BIN
app/src/main/res/drawable-mdpi/round_cloud_circle_black_48.png
Normal file
After Width: | Height: | Size: 540 B |
BIN
app/src/main/res/drawable-mdpi/round_publish_black_18.png
Normal file
After Width: | Height: | Size: 150 B |
BIN
app/src/main/res/drawable-mdpi/round_publish_black_24.png
Normal file
After Width: | Height: | Size: 139 B |
BIN
app/src/main/res/drawable-mdpi/round_publish_black_36.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
app/src/main/res/drawable-mdpi/round_publish_black_48.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
app/src/main/res/drawable-xhdpi/round_cloud_circle_black_18.png
Normal file
After Width: | Height: | Size: 421 B |
BIN
app/src/main/res/drawable-xhdpi/round_cloud_circle_black_24.png
Normal file
After Width: | Height: | Size: 540 B |
BIN
app/src/main/res/drawable-xhdpi/round_cloud_circle_black_36.png
Normal file
After Width: | Height: | Size: 765 B |
BIN
app/src/main/res/drawable-xhdpi/round_cloud_circle_black_48.png
Normal file
After Width: | Height: | Size: 996 B |
BIN
app/src/main/res/drawable-xhdpi/round_publish_black_18.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
app/src/main/res/drawable-xhdpi/round_publish_black_24.png
Normal file
After Width: | Height: | Size: 241 B |
BIN
app/src/main/res/drawable-xhdpi/round_publish_black_36.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
app/src/main/res/drawable-xhdpi/round_publish_black_48.png
Normal file
After Width: | Height: | Size: 393 B |
BIN
app/src/main/res/drawable-xxhdpi/round_cloud_circle_black_18.png
Normal file
After Width: | Height: | Size: 602 B |
BIN
app/src/main/res/drawable-xxhdpi/round_cloud_circle_black_24.png
Normal file
After Width: | Height: | Size: 765 B |
BIN
app/src/main/res/drawable-xxhdpi/round_cloud_circle_black_36.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_cloud_circle_black_48.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/drawable-xxhdpi/round_publish_black_18.png
Normal file
After Width: | Height: | Size: 296 B |
BIN
app/src/main/res/drawable-xxhdpi/round_publish_black_24.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
app/src/main/res/drawable-xxhdpi/round_publish_black_36.png
Normal file
After Width: | Height: | Size: 452 B |
BIN
app/src/main/res/drawable-xxhdpi/round_publish_black_48.png
Normal file
After Width: | Height: | Size: 587 B |
After Width: | Height: | Size: 765 B |
After Width: | Height: | Size: 996 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/round_publish_black_18.png
Normal file
After Width: | Height: | Size: 313 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_publish_black_24.png
Normal file
After Width: | Height: | Size: 393 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_publish_black_36.png
Normal file
After Width: | Height: | Size: 587 B |
BIN
app/src/main/res/drawable-xxxhdpi/round_publish_black_48.png
Normal file
After Width: | Height: | Size: 722 B |
BIN
app/src/main/res/drawable/alarm.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
app/src/main/res/drawable/calendar.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/drawable/clear_day_3.png
Normal file
After Width: | Height: | Size: 685 B |
BIN
app/src/main/res/drawable/clear_day_4.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
app/src/main/res/drawable/clear_night_3.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
app/src/main/res/drawable/clear_night_4.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/drawable/clock.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
app/src/main/res/drawable/cloudy_weather_3.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
app/src/main/res/drawable/cloudy_weather_4.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/drawable/haze_day_3.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
app/src/main/res/drawable/haze_day_4.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/drawable/haze_night_3.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
app/src/main/res/drawable/haze_night_4.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/drawable/haze_weather_3.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
app/src/main/res/drawable/haze_weather_4.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
app/src/main/res/drawable/menu.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/res/drawable/mostly_cloudy_3.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
app/src/main/res/drawable/mostly_cloudy_4.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/drawable/mostly_cloudy_night_3.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
app/src/main/res/drawable/mostly_cloudy_night_4.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
app/src/main/res/drawable/partly_cloudy_3.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/drawable/partly_cloudy_4.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
app/src/main/res/drawable/partly_cloudy_night_3.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
app/src/main/res/drawable/partly_cloudy_night_4.png
Normal file
After Width: | Height: | Size: 3.6 KiB |