Fix update calendar service
This commit is contained in:
parent
d2087d094f
commit
24bb811f93
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -22,7 +22,7 @@ android {
|
|||||||
applicationId "com.tommasoberlose.anotherwidget"
|
applicationId "com.tommasoberlose.anotherwidget"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 119
|
versionCode 120
|
||||||
versionName "2.2.2"
|
versionName "2.2.2"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
@ -152,7 +152,8 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".services.UpdateCalendarService"
|
android:name=".services.UpdateCalendarService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"/>
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="dataSync" />
|
||||||
<service
|
<service
|
||||||
android:name=".services.LocationService"
|
android:name=".services.LocationService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -115,7 +115,6 @@ class LocationService : Service() {
|
|||||||
val builder = NotificationCompat.Builder(this@LocationService, getString(R.string.location_access_notification_channel_id))
|
val builder = NotificationCompat.Builder(this@LocationService, getString(R.string.location_access_notification_channel_id))
|
||||||
.setSmallIcon(R.drawable.ic_stat_notification)
|
.setSmallIcon(R.drawable.ic_stat_notification)
|
||||||
.setContentTitle(getString(R.string.location_access_notification_title))
|
.setContentTitle(getString(R.string.location_access_notification_title))
|
||||||
.setStyle(NotificationCompat.BigTextStyle().bigText(getString(R.string.location_access_notification_subtitle)))
|
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setColor(ContextCompat.getColor(this@LocationService, R.color.colorAccent))
|
.setColor(ContextCompat.getColor(this@LocationService, R.color.colorAccent))
|
||||||
|
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package com.tommasoberlose.anotherwidget.services
|
package com.tommasoberlose.anotherwidget.services
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.Service
|
import android.app.*
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.tommasoberlose.anotherwidget.R
|
||||||
import com.tommasoberlose.anotherwidget.db.EventRepository
|
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||||
@ -13,6 +17,7 @@ import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
|
|||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.sortEvents
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.sortEvents
|
||||||
import com.tommasoberlose.anotherwidget.models.Event
|
import com.tommasoberlose.anotherwidget.models.Event
|
||||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||||
|
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
|
||||||
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
|
||||||
@ -28,10 +33,21 @@ import kotlin.collections.ArrayList
|
|||||||
class UpdateCalendarService : Service() {
|
class UpdateCalendarService : Service() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val CALENDAR_SYNC_NOTIFICATION_ID = 28466
|
||||||
fun enqueueWork(context: Context) {
|
fun enqueueWork(context: Context) {
|
||||||
context.startService(Intent(context, UpdateCalendarService::class.java))
|
context.startService(Intent(context, UpdateCalendarService::class.java))
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(Intent(context, UpdateCalendarService::class.java))
|
||||||
|
} else {
|
||||||
|
context.startService(Intent(context, UpdateCalendarService::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
startForeground(CALENDAR_SYNC_NOTIFICATION_ID, getCalendarSyncNotification())
|
||||||
|
}
|
||||||
|
|
||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
|
|
||||||
@ -171,4 +187,32 @@ class UpdateCalendarService : Service() {
|
|||||||
job?.cancel()
|
job?.cancel()
|
||||||
job = null
|
job = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCalendarSyncNotification(): Notification {
|
||||||
|
with(NotificationManagerCompat.from(this)) {
|
||||||
|
// Create channel
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
createNotificationChannel(
|
||||||
|
NotificationChannel(
|
||||||
|
getString(R.string.calendar_sync_notification_channel_id),
|
||||||
|
getString(R.string.calendar_sync_notification_channel_name),
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
).apply {
|
||||||
|
description = getString(R.string.calendar_sync_notification_channel_description)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val builder = NotificationCompat.Builder(this@UpdateCalendarService, getString(R.string.calendar_sync_notification_channel_id))
|
||||||
|
.setSmallIcon(R.drawable.ic_stat_notification)
|
||||||
|
.setContentTitle(getString(R.string.calendar_sync_notification_title))
|
||||||
|
.setOngoing(true)
|
||||||
|
.setColor(ContextCompat.getColor(this@UpdateCalendarService, R.color.colorAccent))
|
||||||
|
|
||||||
|
// Main intent that open the activity
|
||||||
|
builder.setContentIntent(PendingIntent.getActivity(this@UpdateCalendarService, 0, Intent(this@UpdateCalendarService, MainActivity::class.java), PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
|
||||||
|
return builder.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import android.Manifest
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -22,9 +23,10 @@ import com.tommasoberlose.anotherwidget.global.Preferences
|
|||||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||||
import com.tommasoberlose.anotherwidget.ui.activities.tabs.WeatherProviderActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.tabs.WeatherProviderActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||||
|
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private var mAppWidgetId: Int = -1
|
private var mAppWidgetId: Int = -1
|
||||||
private lateinit var viewModel: MainViewModel
|
private lateinit var viewModel: MainViewModel
|
||||||
@ -140,4 +142,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Preferences.showEvents = false
|
Preferences.showEvents = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
Preferences.preferences.registerOnSharedPreferenceChangeListener(this)
|
||||||
|
super.onStart()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
Preferences.preferences.unregisterOnSharedPreferenceChangeListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onSharedPreferenceChanged(p0: SharedPreferences?, p1: String?) {
|
||||||
|
MainWidget.updateWidget(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,7 @@ class MainFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.actionSettings.setOnClickListener {
|
binding.actionSettings.setOnClickListener {
|
||||||
Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment, null, null, FragmentNavigatorExtras(
|
Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment,)
|
||||||
// binding.fragmentTitle to "fragment_title"
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.preview.layoutParams = binding.preview.layoutParams.apply {
|
binding.preview.layoutParams = binding.preview.layoutParams.apply {
|
||||||
|
@ -103,6 +103,11 @@
|
|||||||
<string name="attendee_status_invited">Events invitations</string>
|
<string name="attendee_status_invited">Events invitations</string>
|
||||||
<string name="attendee_status_declined">Declined events</string>
|
<string name="attendee_status_declined">Declined events</string>
|
||||||
|
|
||||||
|
<string name="calendar_sync_notification_channel_id" translatable="false">calendar-sync</string>
|
||||||
|
<string name="calendar_sync_notification_channel_name">Events sync service</string>
|
||||||
|
<string name="calendar_sync_notification_channel_description">Service used to synchronize the calendar events.</string>
|
||||||
|
<string name="calendar_sync_notification_title">Syncing calendar events…</string>
|
||||||
|
|
||||||
<!-- Weather -->
|
<!-- Weather -->
|
||||||
<string name="settings_weather_title">Weather</string>
|
<string name="settings_weather_title">Weather</string>
|
||||||
<string name="title_permission_location">Show the weather</string>
|
<string name="title_permission_location">Show the weather</string>
|
||||||
@ -172,7 +177,7 @@
|
|||||||
<string name="weather_provider_activity_subtitle">Select a weather provider from the list.\nA few providers need a free personal account,\nbut they are usually more accurate.</string>
|
<string name="weather_provider_activity_subtitle">Select a weather provider from the list.\nA few providers need a free personal account,\nbut they are usually more accurate.</string>
|
||||||
|
|
||||||
<string name="location_access_notification_channel_id" translatable="false">location-access</string>
|
<string name="location_access_notification_channel_id" translatable="false">location-access</string>
|
||||||
<string name="location_access_notification_channel_name">Background service</string>
|
<string name="location_access_notification_channel_name">Weather update service</string>
|
||||||
<string name="location_access_notification_channel_description">Service used to update the weather based on the current location of the user.</string>
|
<string name="location_access_notification_channel_description">Service used to update the weather based on the current location of the user.</string>
|
||||||
<string name="location_access_notification_title">Updating the weather…</string>
|
<string name="location_access_notification_title">Updating the weather…</string>
|
||||||
<string name="location_access_notification_subtitle">We\'re updating the weather based on your current location.</string>
|
<string name="location_access_notification_subtitle">We\'re updating the weather based on your current location.</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user