diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 4ef1306..e543d34 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/app/build.gradle b/app/build.gradle
index 49e26a7..cead686 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -22,7 +22,7 @@ android {
applicationId "com.tommasoberlose.anotherwidget"
minSdkVersion 23
targetSdkVersion 30
- versionCode 119
+ versionCode 120
versionName "2.2.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 93d20a3..f25cecf 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -152,7 +152,8 @@
+ android:exported="false"
+ android:foregroundServiceType="dataSync" />
= 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
override fun onBind(intent: Intent?): IBinder? {
@@ -171,4 +187,32 @@ class UpdateCalendarService : Service() {
job?.cancel()
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()
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/MainActivity.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/MainActivity.kt
index e8c689f..6435d89 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/MainActivity.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/activities/MainActivity.kt
@@ -4,6 +4,7 @@ import android.Manifest
import android.app.Activity
import android.appwidget.AppWidgetManager
import android.content.Intent
+import android.content.SharedPreferences
import android.os.Bundle
import android.view.View
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.ui.activities.tabs.WeatherProviderActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
+import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
-class MainActivity : AppCompatActivity() {
+class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
private var mAppWidgetId: Int = -1
private lateinit var viewModel: MainViewModel
@@ -140,4 +142,18 @@ class MainActivity : AppCompatActivity() {
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)
+ }
}
diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt
index 6a4865f..3e63482 100644
--- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt
+++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt
@@ -102,9 +102,7 @@ class MainFragment : Fragment() {
}
binding.actionSettings.setOnClickListener {
- Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment, null, null, FragmentNavigatorExtras(
-// binding.fragmentTitle to "fragment_title"
- ))
+ Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment,)
}
binding.preview.layoutParams = binding.preview.layoutParams.apply {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 856db05..7db7ae1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -103,6 +103,11 @@
Events invitations
Declined events
+ calendar-sync
+ Events sync service
+ Service used to synchronize the calendar events.
+ Syncing calendar events…
+
Weather
Show the weather
@@ -172,7 +177,7 @@
Select a weather provider from the list.\nA few providers need a free personal account,\nbut they are usually more accurate.
location-access
- Background service
+ Weather update service
Service used to update the weather based on the current location of the user.
Updating the weather…
We\'re updating the weather based on your current location.