Compare commits
3 Commits
v2.0.5-bet
...
v2.0.5-bet
Author | SHA1 | Date | |
---|---|---|---|
37cb43dc80 | |||
ea372dd76d | |||
7076311e94 |
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -18,7 +18,7 @@ android {
|
|||||||
applicationId "com.tommasoberlose.anotherwidget"
|
applicationId "com.tommasoberlose.anotherwidget"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 70
|
versionCode 71
|
||||||
versionName "2.0.5"
|
versionName "2.0.5"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
BIN
app/release/app-release.aab
Normal file
BIN
app/release/app-release.aab
Normal file
Binary file not shown.
@ -90,6 +90,33 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".receivers.PlayerReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="com.android.music.metachanged" />
|
||||||
|
<action android:name="com.android.music.playstatechanged" />
|
||||||
|
<action android:name="com.android.music.playbackcomplete" />
|
||||||
|
<action android:name="com.android.music.queuechanged" />
|
||||||
|
|
||||||
|
<action android:name="com.htc.music.metachanged" />
|
||||||
|
<action android:name="fm.last.android.metachanged" />
|
||||||
|
<action android:name="com.sec.android.app.music.metachanged" />
|
||||||
|
<action android:name="com.nullsoft.winamp.metachanged" />
|
||||||
|
<action android:name="com.amazon.mp3.metachanged" />
|
||||||
|
<action android:name="com.miui.player.metachanged" />
|
||||||
|
<action android:name="com.real.IMP.metachanged" />
|
||||||
|
<action android:name="com.sonyericsson.music.metachanged" />
|
||||||
|
<action android:name="com.rdio.android.metachanged" />
|
||||||
|
<action android:name="com.samsung.sec.android.MusicPlayer.metachanged" />
|
||||||
|
<action android:name="com.andrew.apollo.metachanged" />
|
||||||
|
<action android:name="com.spotify.music.playbackstatechanged"/>
|
||||||
|
<action android:name="com.spotify.music.metadatachanged"/>
|
||||||
|
<action android:name="com.spotify.music.queuechanged"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".receivers.WidgetClickListenerReceiver"
|
android:name=".receivers.WidgetClickListenerReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -5,7 +5,6 @@ import com.chibatching.kotpref.bulk
|
|||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
import com.tommasoberlose.anotherwidget.models.Event
|
||||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||||
import com.tommasoberlose.anotherwidget.services.UpdatesWorker
|
|
||||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
@ -57,7 +56,7 @@ class EventRepository(val context: Context) {
|
|||||||
} else {
|
} else {
|
||||||
resetNextEventData()
|
resetNextEventData()
|
||||||
}
|
}
|
||||||
UpdatesWorker.setUpdates(context)
|
UpdatesReceiver.setUpdates(context)
|
||||||
MainWidget.updateWidget(context)
|
MainWidget.updateWidget(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +73,7 @@ class EventRepository(val context: Context) {
|
|||||||
} else {
|
} else {
|
||||||
resetNextEventData()
|
resetNextEventData()
|
||||||
}
|
}
|
||||||
UpdatesWorker.setUpdates(context)
|
UpdatesReceiver.setUpdates(context)
|
||||||
MainWidget.updateWidget(context)
|
MainWidget.updateWidget(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import com.chibatching.kotpref.KotprefModel
|
|||||||
object Preferences : KotprefModel() {
|
object Preferences : KotprefModel() {
|
||||||
override val commitAllPropertiesByDefault: Boolean = true
|
override val commitAllPropertiesByDefault: Boolean = true
|
||||||
|
|
||||||
var darkThemePreference by intPref(default = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) MODE_NIGHT_FOLLOW_SYSTEM else MODE_NIGHT_AUTO_BATTERY)
|
var darkThemePreference by intPref(default = MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
|
|
||||||
var showEvents by booleanPref(key = "PREF_SHOW_EVENTS", default = false)
|
var showEvents by booleanPref(key = "PREF_SHOW_EVENTS", default = false)
|
||||||
var showWeather by booleanPref(key = "PREF_SHOW_WEATHER", default = false)
|
var showWeather by booleanPref(key = "PREF_SHOW_WEATHER", default = false)
|
||||||
|
@ -20,15 +20,12 @@ object BitmapHelper {
|
|||||||
view.measure(measuredWidth, measuredHeight)
|
view.measure(measuredWidth, measuredHeight)
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
if (draw) {
|
|
||||||
Log.d("ciao", "bitmap ${view.measuredWidth}, ${view.measuredHeight}")
|
|
||||||
}
|
|
||||||
val btm = Bitmap.createBitmap(
|
val btm = Bitmap.createBitmap(
|
||||||
view.measuredWidth,
|
view.measuredWidth,
|
||||||
view.measuredHeight,
|
view.measuredHeight,
|
||||||
if (true || draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
if (draw) Bitmap.Config.ARGB_8888 else Bitmap.Config.ALPHA_8
|
||||||
)
|
)
|
||||||
if (true || draw) {
|
if (draw) {
|
||||||
//Bind a canvas to it
|
//Bind a canvas to it
|
||||||
val canvas = Canvas(btm)
|
val canvas = Canvas(btm)
|
||||||
// draw the view on the canvas
|
// draw the view on the canvas
|
||||||
|
@ -4,13 +4,11 @@ import android.Manifest
|
|||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import android.util.Log
|
|
||||||
import com.tommasoberlose.anotherwidget.services.EventListenerJob
|
import com.tommasoberlose.anotherwidget.services.EventListenerJob
|
||||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
import com.tommasoberlose.anotherwidget.models.Event
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||||
import com.tommasoberlose.anotherwidget.services.UpdatesWorker
|
|
||||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||||
@ -125,8 +123,7 @@ object CalendarHelper {
|
|||||||
eventRepository.resetNextEventData()
|
eventRepository.resetNextEventData()
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdatesWorker.setUpdates(context)
|
UpdatesReceiver.setUpdates(context)
|
||||||
Log.d("ciao", "force update? 7")
|
|
||||||
MainWidget.updateWidget(context)
|
MainWidget.updateWidget(context)
|
||||||
|
|
||||||
EventBus.getDefault().post(MainActivity.UpdateUiMessageEvent())
|
EventBus.getDefault().post(MainActivity.UpdateUiMessageEvent())
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.tommasoberlose.anotherwidget.helpers
|
package com.tommasoberlose.anotherwidget.helpers
|
||||||
|
|
||||||
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.ContentUris
|
import android.content.ContentUris
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -11,12 +12,23 @@ import android.provider.CalendarContract
|
|||||||
import android.provider.CalendarContract.Events
|
import android.provider.CalendarContract.Events
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
import com.tommasoberlose.anotherwidget.models.Event
|
||||||
|
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
object IntentHelper {
|
object IntentHelper {
|
||||||
|
|
||||||
fun getGoogleMapsIntentFromAddress(context: Context, address:String): Intent {
|
fun getWidgetUpdateIntent(context: Context): Intent {
|
||||||
|
val widgetManager = AppWidgetManager.getInstance(context)
|
||||||
|
val widgetComponent = ComponentName(context, MainWidget::class.java)
|
||||||
|
val widgetIds = widgetManager.getAppWidgetIds(widgetComponent)
|
||||||
|
return Intent(context, MainWidget::class.java).apply {
|
||||||
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
|
||||||
|
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGoogleMapsIntentFromAddress(context: Context, address: String): Intent {
|
||||||
val gmmIntentUri: Uri = Uri.parse("geo:0,0?q=$address")
|
val gmmIntentUri: Uri = Uri.parse("geo:0,0?q=$address")
|
||||||
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
|
val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
|
||||||
mapIntent.`package` = "com.google.android.apps.maps"
|
mapIntent.`package` = "com.google.android.apps.maps"
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.tommasoberlose.anotherwidget.receivers
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
Log.d("ciao", "player ok")
|
||||||
|
|
||||||
|
// val cmd = intent.getStringExtra("command")
|
||||||
|
// Log.v("tag ", "$action / $cmd")
|
||||||
|
// val artist = intent.getStringExtra("artist")
|
||||||
|
// val album = intent.getStringExtra("album")
|
||||||
|
// val track = intent.getStringExtra("track")
|
||||||
|
// Log.v("tag", "$artist:$album:$track")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -19,7 +19,6 @@ import java.util.*
|
|||||||
class UpdatesReceiver : BroadcastReceiver() {
|
class UpdatesReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
Log.d("ciao", "che palle - ${intent.action}")
|
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intent.ACTION_BOOT_COMPLETED,
|
Intent.ACTION_BOOT_COMPLETED,
|
||||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||||
@ -32,7 +31,6 @@ class UpdatesReceiver : BroadcastReceiver() {
|
|||||||
Intent.ACTION_DATE_CHANGED,
|
Intent.ACTION_DATE_CHANGED,
|
||||||
AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED,
|
AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED,
|
||||||
Actions.ACTION_TIME_UPDATE -> {
|
Actions.ACTION_TIME_UPDATE -> {
|
||||||
Log.d("ciao", "force update? 4 - ${intent.action}")
|
|
||||||
MainWidget.updateWidget(context)
|
MainWidget.updateWidget(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,13 +53,12 @@ class UpdatesReceiver : BroadcastReceiver() {
|
|||||||
if (event.startDate > now.timeInMillis) {
|
if (event.startDate > now.timeInMillis) {
|
||||||
// Update the widget every hour till the event
|
// Update the widget every hour till the event
|
||||||
(0..diff.hours).forEach {
|
(0..diff.hours).forEach {
|
||||||
AlarmManagerCompat.setExactAndAllowWhileIdle(
|
setExactAndAllowWhileIdle(
|
||||||
this,
|
AlarmManager.RTC,
|
||||||
AlarmManager.RTC_WAKEUP,
|
if (event.startDate - it * 1000 * 60 * 60 > 60 * 1000) event.startDate - it * 1000 * 60 * 60 else now.timeInMillis + 120000,
|
||||||
if (event.startDate - it * 1000 * 60 * 60 > 60 * 1000) event.startDate - it * 1000 * 60 * 60 else 120000,
|
|
||||||
PendingIntent.getBroadcast(
|
PendingIntent.getBroadcast(
|
||||||
context,
|
context,
|
||||||
0,
|
event.eventID.toInt() + it,
|
||||||
Intent(context, UpdatesReceiver::class.java).apply {
|
Intent(context, UpdatesReceiver::class.java).apply {
|
||||||
action = Actions.ACTION_TIME_UPDATE
|
action = Actions.ACTION_TIME_UPDATE
|
||||||
},
|
},
|
||||||
@ -72,10 +69,10 @@ class UpdatesReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the widget one second after the event is finished
|
// Update the widget one second after the event is finished
|
||||||
AlarmManagerCompat.setExactAndAllowWhileIdle(this,
|
setExactAndAllowWhileIdle(
|
||||||
AlarmManager.RTC_WAKEUP,
|
AlarmManager.RTC,
|
||||||
if (event.endDate > 60 *1000) event.endDate else 120000,
|
if (event.endDate > 60 *1000) event.endDate else now.timeInMillis + 120000,
|
||||||
PendingIntent.getBroadcast(context, 0, Intent(context, UpdatesReceiver::class.java).apply { action = Actions.ACTION_TIME_UPDATE }, 0)
|
PendingIntent.getBroadcast(context, 1, Intent(context, UpdatesReceiver::class.java).apply { action = Actions.ACTION_TIME_UPDATE }, 0)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +80,12 @@ class UpdatesReceiver : BroadcastReceiver() {
|
|||||||
|
|
||||||
fun removeUpdates(context: Context) {
|
fun removeUpdates(context: Context) {
|
||||||
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||||
cancel(PendingIntent.getBroadcast(context, 0, Intent(context, UpdatesReceiver::class.java), 0))
|
cancel(PendingIntent.getBroadcast(context, 1, Intent(context, UpdatesReceiver::class.java), 0))
|
||||||
|
EventRepository(context).getEvents().forEach {
|
||||||
|
(0..24).forEach { hour ->
|
||||||
|
cancel(PendingIntent.getBroadcast(context, it.eventID.toInt() * hour, Intent(context, UpdatesReceiver::class.java), 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,10 @@ import android.app.PendingIntent
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
import com.tommasoberlose.anotherwidget.global.Actions
|
import com.tommasoberlose.anotherwidget.global.Actions
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||||
import com.tommasoberlose.anotherwidget.services.WeatherWorker
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
@ -20,7 +20,63 @@ class WeatherReceiver : BroadcastReceiver() {
|
|||||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||||
Intent.ACTION_TIMEZONE_CHANGED,
|
Intent.ACTION_TIMEZONE_CHANGED,
|
||||||
Intent.ACTION_LOCALE_CHANGED,
|
Intent.ACTION_LOCALE_CHANGED,
|
||||||
Intent.ACTION_TIME_CHANGED -> WeatherWorker.setUpdates(context)
|
Intent.ACTION_TIME_CHANGED -> setUpdates(context)
|
||||||
|
|
||||||
|
Actions.ACTION_WEATHER_UPDATE -> {
|
||||||
|
WeatherHelper.updateWeather(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val MINUTE = 60 * 1000L
|
||||||
|
fun setUpdates(context: Context) {
|
||||||
|
removeUpdates(context)
|
||||||
|
|
||||||
|
if (Preferences.showWeather && Preferences.weatherProviderApi != "") {
|
||||||
|
WeatherHelper.updateWeather(context)
|
||||||
|
|
||||||
|
val interval = MINUTE * when (Preferences.weatherRefreshPeriod) {
|
||||||
|
0 -> 30
|
||||||
|
1 -> 60
|
||||||
|
2 -> 60L * 3
|
||||||
|
3 -> 60L * 6
|
||||||
|
4 -> 60L * 12
|
||||||
|
5 -> 60L * 24
|
||||||
|
else -> 60
|
||||||
|
}
|
||||||
|
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||||
|
setRepeating(
|
||||||
|
AlarmManager.RTC,
|
||||||
|
Calendar.getInstance().timeInMillis + interval,
|
||||||
|
interval,
|
||||||
|
PendingIntent.getBroadcast(context, 0, Intent(context, WeatherReceiver::class.java).apply { action = Actions.ACTION_WEATHER_UPDATE }, 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setOneTimeUpdate(context: Context) {
|
||||||
|
if (Preferences.showWeather && Preferences.weatherProviderApi != "") {
|
||||||
|
listOf(10, 20, 30).forEach {
|
||||||
|
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||||
|
setExactAndAllowWhileIdle(
|
||||||
|
AlarmManager.RTC,
|
||||||
|
it * MINUTE,
|
||||||
|
PendingIntent.getBroadcast(context, it, Intent(context, WeatherReceiver::class.java).apply { action = Actions.ACTION_WEATHER_UPDATE }, 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeUpdates(context: Context) {
|
||||||
|
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||||
|
cancel(PendingIntent.getBroadcast(context, 0, Intent(context, WeatherReceiver::class.java).apply { action = Actions.ACTION_WEATHER_UPDATE }, 0))
|
||||||
|
listOf(10, 20, 30).forEach {
|
||||||
|
cancel(PendingIntent.getBroadcast(context, it, Intent(context, WeatherReceiver::class.java).apply { action = Actions.ACTION_WEATHER_UPDATE }, 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package com.tommasoberlose.anotherwidget.services
|
|
||||||
|
|
||||||
import android.app.AlarmManager
|
|
||||||
import android.content.Context
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.work.*
|
|
||||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
|
||||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
|
||||||
import org.joda.time.Period
|
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class UpdatesWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
|
|
||||||
override fun doWork(): Result {
|
|
||||||
Log.d("ciao1", "update ok: $inputData")
|
|
||||||
val repo = EventRepository(applicationContext)
|
|
||||||
val event = repo.getEventByEventId(inputData.getLong(EVENT_ID, -1))
|
|
||||||
event?.let {
|
|
||||||
scheduleEventUpdate(applicationContext, it)
|
|
||||||
}
|
|
||||||
MainWidget.updateWidget(applicationContext)
|
|
||||||
return Result.success()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val JOB_TAG = "UPDATES_WORKER"
|
|
||||||
private const val EVENT_ID = "event_id"
|
|
||||||
|
|
||||||
fun setUpdates(context: Context) {
|
|
||||||
removeUpdates(context)
|
|
||||||
|
|
||||||
EventRepository(context).getEvents().forEach { event ->
|
|
||||||
scheduleEventUpdate(context, event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun scheduleEventUpdate(context: Context, event: Event) {
|
|
||||||
val workManager = WorkManager.getInstance(context)
|
|
||||||
val now = Calendar.getInstance().apply {
|
|
||||||
set(Calendar.SECOND, 0)
|
|
||||||
set(Calendar.MILLISECOND, 0)
|
|
||||||
}
|
|
||||||
if (event.startDate > now.timeInMillis) {
|
|
||||||
val diff = Period(now.timeInMillis, event.startDate)
|
|
||||||
workManager.enqueueUniqueWork("UPDATES_JOB_ONE_TIME_${event.eventID}", ExistingWorkPolicy.REPLACE, OneTimeWorkRequestBuilder<WeatherWorker>()
|
|
||||||
.setInputData(Data.Builder().putLong(EVENT_ID, event.eventID).build())
|
|
||||||
.setInitialDelay(if (diff.minutes > 0) diff.minutes.toLong() else 60L, TimeUnit.MINUTES)
|
|
||||||
.addTag(JOB_TAG)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
Log.d("ciao1", "next update ${Date(now.timeInMillis + (if (diff.minutes > 0) diff.minutes.toLong() else 60L) * 60 * 1000)}")
|
|
||||||
} else if (event.endDate > now.timeInMillis) {
|
|
||||||
// Update the widget one second after the event is finished
|
|
||||||
workManager.enqueueUniqueWork("UPDATES_JOB_ONE_TIME_END_${event.eventID}", ExistingWorkPolicy.REPLACE, OneTimeWorkRequestBuilder<WeatherWorker>()
|
|
||||||
.setInitialDelay(event.endDate - now.timeInMillis, TimeUnit.MILLISECONDS)
|
|
||||||
.addTag(JOB_TAG)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeUpdates(context: Context) {
|
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag(JOB_TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package com.tommasoberlose.anotherwidget.services
|
|
||||||
|
|
||||||
import android.app.AlarmManager
|
|
||||||
import android.app.PendingIntent
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.work.*
|
|
||||||
import com.tommasoberlose.anotherwidget.global.Actions
|
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
|
||||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
|
||||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
|
|
||||||
class WeatherWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
|
|
||||||
override fun doWork(): Result {
|
|
||||||
Log.d("ciao1", "weather ok")
|
|
||||||
WeatherHelper.updateWeather(applicationContext)
|
|
||||||
return Result.success()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val JOB_TAG = "WEATHER_WORKER"
|
|
||||||
|
|
||||||
fun setUpdates(context: Context) {
|
|
||||||
removeUpdates(context)
|
|
||||||
|
|
||||||
if (Preferences.showWeather && Preferences.weatherProviderApi != "") {
|
|
||||||
WeatherHelper.updateWeather(context)
|
|
||||||
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
|
|
||||||
"WEATHER_JOB_PERIODIC",
|
|
||||||
ExistingPeriodicWorkPolicy.KEEP,
|
|
||||||
PeriodicWorkRequestBuilder<WeatherWorker>(
|
|
||||||
when (Preferences.weatherRefreshPeriod) {
|
|
||||||
0 -> 30
|
|
||||||
1 -> 60
|
|
||||||
2 -> 60L * 3
|
|
||||||
3 -> 60L * 6
|
|
||||||
4 -> 60L * 12
|
|
||||||
5 -> 60L * 24
|
|
||||||
else -> 60
|
|
||||||
}
|
|
||||||
, TimeUnit.MINUTES
|
|
||||||
)
|
|
||||||
.addTag(JOB_TAG)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setOneTimeUpdate(context: Context) {
|
|
||||||
val workManager = WorkManager.getInstance(context)
|
|
||||||
listOf(10L, 20L, 30L).forEach {
|
|
||||||
workManager.enqueueUniqueWork("WEATHER_JOB_ONE_TIME_$it", ExistingWorkPolicy.KEEP, OneTimeWorkRequestBuilder<WeatherWorker>().setInitialDelay(it, TimeUnit.MINUTES).addTag(JOB_TAG).build())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeUpdates(context: Context) {
|
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag(JOB_TAG)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,7 +11,6 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.Gravity
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.RelativeLayout
|
import android.widget.RelativeLayout
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -263,6 +262,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||||||
backgroundColor = ContextCompat.getColor(this@MainActivity, R.color.errorColorText)
|
backgroundColor = ContextCompat.getColor(this@MainActivity, R.color.errorColorText)
|
||||||
badgeGravity = BadgeDrawable.TOP_END
|
badgeGravity = BadgeDrawable.TOP_END
|
||||||
}?.isVisible = Preferences.showWeather && (Preferences.weatherProviderApi == "" || (Preferences.customLocationAdd == "" && !checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION)))
|
}?.isVisible = Preferences.showWeather && (Preferences.weatherProviderApi == "" || (Preferences.customLocationAdd == "" && !checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribeUi(viewModel: MainViewModel) {
|
private fun subscribeUi(viewModel: MainViewModel) {
|
||||||
|
@ -29,7 +29,6 @@ import com.tommasoberlose.anotherwidget.global.Preferences
|
|||||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||||
import com.tommasoberlose.anotherwidget.services.WeatherWorker
|
|
||||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.activities.CustomLocationActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.CustomLocationActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||||
@ -143,7 +142,7 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
|
|
||||||
if (activity?.checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
if (activity?.checkGrantedPermission(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACCESS_BACKGROUND_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
||||||
location_permission_alert?.isVisible = false
|
location_permission_alert?.isVisible = false
|
||||||
WeatherWorker.setUpdates(requireContext())
|
WeatherReceiver.setUpdates(requireContext())
|
||||||
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
||||||
location_permission_alert?.isVisible = true
|
location_permission_alert?.isVisible = true
|
||||||
location_permission_alert?.setOnClickListener {
|
location_permission_alert?.setOnClickListener {
|
||||||
@ -218,7 +217,7 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
Constants.RESULT_CODE_CUSTOM_LOCATION -> {
|
Constants.RESULT_CODE_CUSTOM_LOCATION -> {
|
||||||
WeatherWorker.setUpdates(requireContext())
|
WeatherReceiver.setUpdates(requireContext())
|
||||||
checkLocationPermission()
|
checkLocationPermission()
|
||||||
}
|
}
|
||||||
RequestCode.WEATHER_APP_REQUEST_CODE.code -> {
|
RequestCode.WEATHER_APP_REQUEST_CODE.code -> {
|
||||||
@ -229,7 +228,7 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
MainWidget.updateWidget(requireContext())
|
MainWidget.updateWidget(requireContext())
|
||||||
}
|
}
|
||||||
RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code -> {
|
RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code -> {
|
||||||
WeatherWorker.setOneTimeUpdate(requireContext())
|
WeatherReceiver.setOneTimeUpdate(requireContext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import android.graphics.Color
|
|||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import android.util.Log
|
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
@ -27,17 +26,14 @@ import com.tommasoberlose.anotherwidget.global.Actions
|
|||||||
import com.tommasoberlose.anotherwidget.global.Constants
|
import com.tommasoberlose.anotherwidget.global.Constants
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.helpers.*
|
import com.tommasoberlose.anotherwidget.helpers.*
|
||||||
import com.tommasoberlose.anotherwidget.helpers.WidgetHelper.reduceDimensionWithMaxWidth
|
|
||||||
import com.tommasoberlose.anotherwidget.receivers.NewCalendarEventReceiver
|
import com.tommasoberlose.anotherwidget.receivers.NewCalendarEventReceiver
|
||||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||||
|
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||||
import com.tommasoberlose.anotherwidget.receivers.WidgetClickListenerReceiver
|
import com.tommasoberlose.anotherwidget.receivers.WidgetClickListenerReceiver
|
||||||
import com.tommasoberlose.anotherwidget.services.UpdatesWorker
|
|
||||||
import com.tommasoberlose.anotherwidget.services.WeatherWorker
|
|
||||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||||
import com.tommasoberlose.anotherwidget.utils.getCapWordString
|
import com.tommasoberlose.anotherwidget.utils.getCapWordString
|
||||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||||
import kotlinx.android.synthetic.main.the_widget.view.*
|
import kotlinx.android.synthetic.main.the_widget.view.*
|
||||||
import kotlinx.android.synthetic.main.the_widget_sans.*
|
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -59,7 +55,7 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
|
|
||||||
override fun onEnabled(context: Context) {
|
override fun onEnabled(context: Context) {
|
||||||
CalendarHelper.updateEventList(context)
|
CalendarHelper.updateEventList(context)
|
||||||
WeatherWorker.setUpdates(context)
|
WeatherReceiver.setUpdates(context)
|
||||||
|
|
||||||
if (Preferences.showEvents) {
|
if (Preferences.showEvents) {
|
||||||
CalendarHelper.setEventUpdatesAndroidN(context)
|
CalendarHelper.setEventUpdatesAndroidN(context)
|
||||||
@ -70,21 +66,15 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
|
|
||||||
override fun onDisabled(context: Context) {
|
override fun onDisabled(context: Context) {
|
||||||
if (getWidgetCount(context) == 0) {
|
if (getWidgetCount(context) == 0) {
|
||||||
UpdatesWorker.removeUpdates(context)
|
UpdatesReceiver.removeUpdates(context)
|
||||||
WeatherWorker.removeUpdates(context)
|
WeatherReceiver.removeUpdates(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun updateWidget(context: Context) {
|
fun updateWidget(context: Context) {
|
||||||
val widgetManager = AppWidgetManager.getInstance(context)
|
context.sendBroadcast(IntentHelper.getWidgetUpdateIntent(context))
|
||||||
val widgetComponent = ComponentName(context, MainWidget::class.java)
|
|
||||||
val widgetIds = widgetManager.getAppWidgetIds(widgetComponent)
|
|
||||||
val update = Intent(context, MainWidget::class.java)
|
|
||||||
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds)
|
|
||||||
update.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
|
||||||
context.sendBroadcast(update)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getWidgetCount(context: Context): Int {
|
fun getWidgetCount(context: Context): Int {
|
||||||
@ -111,6 +101,13 @@ class MainWidget : AppWidgetProvider() {
|
|||||||
// Background
|
// Background
|
||||||
views.setInt(R.id.widget_shape_background, "setColorFilter", ColorHelper.getBackgroundColorRgb())
|
views.setInt(R.id.widget_shape_background, "setColorFilter", ColorHelper.getBackgroundColorRgb())
|
||||||
views.setInt(R.id.widget_shape_background, "setImageAlpha", ColorHelper.getBackgroundAlpha())
|
views.setInt(R.id.widget_shape_background, "setImageAlpha", ColorHelper.getBackgroundAlpha())
|
||||||
|
val refreshIntent = PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
appWidgetId,
|
||||||
|
IntentHelper.getWidgetUpdateIntent(context),
|
||||||
|
0
|
||||||
|
)
|
||||||
|
views.setOnClickPendingIntent(R.id.widget_shape_background, refreshIntent)
|
||||||
|
|
||||||
// Clock
|
// Clock
|
||||||
views = updateClockView(context, views, appWidgetId)
|
views = updateClockView(context, views, appWidgetId)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="70"
|
android:versionCode="71"
|
||||||
android:versionName="2.0.5" >
|
android:versionName="2.0.5" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#Wed May 06 15:59:56 CEST 2020
|
#Wed May 06 21:31:44 CEST 2020
|
||||||
base.0=/Users/tommaso/Documents/MyCode/another-widget/tasksintegration/build/intermediates/dex/debug/mergeProjectDexDebug/out/classes.dex
|
base.0=/Users/tommaso/Documents/MyCode/another-widget/tasksintegration/build/intermediates/dex/debug/mergeProjectDexDebug/out/classes.dex
|
||||||
path.0=classes.dex
|
path.0=classes.dex
|
||||||
renamed.0=classes.dex
|
renamed.0=classes.dex
|
||||||
|
Binary file not shown.
@ -4,7 +4,7 @@
|
|||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:targetSandboxVersion="2"
|
android:targetSandboxVersion="2"
|
||||||
android:versionCode="70"
|
android:versionCode="71"
|
||||||
android:versionName="2.0.5" >
|
android:versionName="2.0.5" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
3 xmlns:dist="http://schemas.android.com/apk/distribution"
|
3 xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
4 featureSplit="tasksintegration"
|
4 featureSplit="tasksintegration"
|
||||||
5 package="com.tommasoberlose.anotherwidget"
|
5 package="com.tommasoberlose.anotherwidget"
|
||||||
6 android:versionCode="70"
|
6 android:versionCode="71"
|
||||||
7 android:versionName="2.0.5" >
|
7 android:versionName="2.0.5" >
|
||||||
8
|
8
|
||||||
9 <uses-sdk
|
9 <uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="70"
|
android:versionCode="71"
|
||||||
android:versionName="2.0.5" >
|
android:versionName="2.0.5" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||||
featureSplit="tasksintegration"
|
featureSplit="tasksintegration"
|
||||||
package="com.tommasoberlose.anotherwidget"
|
package="com.tommasoberlose.anotherwidget"
|
||||||
android:versionCode="70"
|
android:versionCode="71"
|
||||||
android:versionName="2.0.5" >
|
android:versionName="2.0.5" >
|
||||||
|
|
||||||
<uses-sdk android:targetSdkVersion="29" />
|
<uses-sdk android:targetSdkVersion="29" />
|
||||||
|
Reference in New Issue
Block a user