Fix #262
This commit is contained in:
parent
108ecdece0
commit
34fb35f2ab
@ -150,9 +150,9 @@
|
|||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.UpdateCalendarJob"
|
android:name=".services.UpdateCalendarService"
|
||||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
android:enabled="true"
|
||||||
android:exported="true"/>
|
android:exported="false"/>
|
||||||
<service
|
<service
|
||||||
android:name=".services.LocationService"
|
android:name=".services.LocationService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -1,29 +1,16 @@
|
|||||||
package com.tommasoberlose.anotherwidget.helpers
|
package com.tommasoberlose.anotherwidget.helpers
|
||||||
|
|
||||||
import android.Manifest
|
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.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
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.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.services.UpdateCalendarService
|
||||||
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
|
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||||
import me.everything.providers.android.calendar.CalendarProvider
|
import me.everything.providers.android.calendar.CalendarProvider
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.Comparator
|
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +19,7 @@ import kotlin.collections.ArrayList
|
|||||||
|
|
||||||
object CalendarHelper {
|
object CalendarHelper {
|
||||||
fun updateEventList(context: Context) {
|
fun updateEventList(context: Context) {
|
||||||
UpdateCalendarJob.enqueueWork(context, Intent())
|
UpdateCalendarService.enqueueWork(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
fun getCalendarList(context: Context): List<me.everything.providers.android.calendar.Calendar> {
|
||||||
|
@ -63,10 +63,20 @@ object SettingsStringHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getVariantLabel(context: Context, variant: String): String = when {
|
fun getVariantLabel(context: Context, variant: String): String = when {
|
||||||
|
variant == "italic" -> context.getString(R.string.font_italic)
|
||||||
|
variant.contains("100") && variant.contains("italic") -> context.getString(R.string.font_100_italic)
|
||||||
|
variant.contains("200") && variant.contains("italic") -> context.getString(R.string.font_200_italic)
|
||||||
|
variant.contains("300") && variant.contains("italic") -> context.getString(R.string.font_300_italic)
|
||||||
|
variant.contains("400") && variant.contains("italic") -> context.getString(R.string.font_400_italic)
|
||||||
|
variant.contains("500") && variant.contains("italic") -> context.getString(R.string.font_500_italic)
|
||||||
|
variant.contains("600") && variant.contains("italic") -> context.getString(R.string.font_600_italic)
|
||||||
|
variant.contains("700") && variant.contains("italic") -> context.getString(R.string.font_700_italic)
|
||||||
|
variant.contains("800") && variant.contains("italic") -> context.getString(R.string.font_800_italic)
|
||||||
|
variant.contains("900") && variant.contains("italic") -> context.getString(R.string.font_900_italic)
|
||||||
|
variant == "regular" || variant.contains("400") -> context.getString(R.string.font_400)
|
||||||
variant.contains("100") -> context.getString(R.string.font_100)
|
variant.contains("100") -> context.getString(R.string.font_100)
|
||||||
variant.contains("200") -> context.getString(R.string.font_200)
|
variant.contains("200") -> context.getString(R.string.font_200)
|
||||||
variant.contains("300") -> context.getString(R.string.font_300)
|
variant.contains("300") -> context.getString(R.string.font_300)
|
||||||
variant.contains("regular") || variant.contains("400") -> context.getString(R.string.font_400)
|
|
||||||
variant.contains("500") -> context.getString(R.string.font_500)
|
variant.contains("500") -> context.getString(R.string.font_500)
|
||||||
variant.contains("600") -> context.getString(R.string.font_600)
|
variant.contains("600") -> context.getString(R.string.font_600)
|
||||||
variant.contains("700") -> context.getString(R.string.font_700)
|
variant.contains("700") -> context.getString(R.string.font_700)
|
||||||
|
@ -2,6 +2,7 @@ package com.tommasoberlose.anotherwidget.network
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.chibatching.kotpref.Kotpref
|
||||||
import com.google.gson.internal.LinkedTreeMap
|
import com.google.gson.internal.LinkedTreeMap
|
||||||
import com.haroldadmin.cnradapter.NetworkResponse
|
import com.haroldadmin.cnradapter.NetworkResponse
|
||||||
import com.haroldadmin.cnradapter.executeWithRetry
|
import com.haroldadmin.cnradapter.executeWithRetry
|
||||||
@ -26,6 +27,7 @@ import java.util.*
|
|||||||
|
|
||||||
class WeatherNetworkApi(val context: Context) {
|
class WeatherNetworkApi(val context: Context) {
|
||||||
suspend fun updateWeather() {
|
suspend fun updateWeather() {
|
||||||
|
Kotpref.init(context)
|
||||||
Preferences.weatherProviderError = "-"
|
Preferences.weatherProviderError = "-"
|
||||||
Preferences.weatherProviderLocationError = ""
|
Preferences.weatherProviderLocationError = ""
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import kotlin.collections.ArrayList
|
|||||||
|
|
||||||
class LocationService : Service() {
|
class LocationService : Service() {
|
||||||
|
|
||||||
private val jobs: ArrayList<Job> = ArrayList()
|
private var job: Job? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
@ -34,13 +34,13 @@ class LocationService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
if (ActivityCompat.checkSelfPermission(
|
job?.cancel()
|
||||||
this,
|
job = GlobalScope.launch(Dispatchers.IO) {
|
||||||
Manifest.permission.ACCESS_FINE_LOCATION
|
if (ActivityCompat.checkSelfPermission(
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
this@LocationService,
|
||||||
) {
|
Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
jobs += GlobalScope.launch(Dispatchers.IO) {
|
) {
|
||||||
LocationServices.getFusedLocationProviderClient(this@LocationService).lastLocation.addOnCompleteListener { task ->
|
LocationServices.getFusedLocationProviderClient(this@LocationService).lastLocation.addOnCompleteListener { task ->
|
||||||
val networkApi = WeatherNetworkApi(this@LocationService)
|
val networkApi = WeatherNetworkApi(this@LocationService)
|
||||||
if (task.isSuccessful) {
|
if (task.isSuccessful) {
|
||||||
@ -67,18 +67,17 @@ class LocationService : Service() {
|
|||||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
stopSelf()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
stopSelf()
|
|
||||||
}
|
}
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
jobs.forEach {
|
job?.cancel()
|
||||||
it.cancel()
|
job = null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -1,153 +0,0 @@
|
|||||||
package com.tommasoberlose.anotherwidget.services
|
|
||||||
|
|
||||||
import android.Manifest
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.provider.CalendarContract
|
|
||||||
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.helpers.CalendarHelper.applyFilters
|
|
||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.sortEvents
|
|
||||||
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 {
|
|
||||||
private const 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 {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check all day events
|
|
||||||
val startDate = Calendar.getInstance()
|
|
||||||
startDate.timeInMillis = instance.begin
|
|
||||||
val endDate = Calendar.getInstance()
|
|
||||||
endDate.timeInMillis = instance.end
|
|
||||||
|
|
||||||
val isAllDay = e.allDay || (
|
|
||||||
startDate.get(Calendar.MILLISECOND) == 0
|
|
||||||
&& startDate.get(Calendar.SECOND) == 0
|
|
||||||
&& startDate.get(Calendar.MINUTE) == 0
|
|
||||||
&& startDate.get(Calendar.HOUR_OF_DAY) == 0
|
|
||||||
&& endDate.get(Calendar.MILLISECOND) == 0
|
|
||||||
&& endDate.get(Calendar.SECOND) == 0
|
|
||||||
&& endDate.get(Calendar.MINUTE) == 0
|
|
||||||
&& endDate.get(Calendar.HOUR_OF_DAY) == 0
|
|
||||||
)
|
|
||||||
|
|
||||||
eventList.add(
|
|
||||||
Event(
|
|
||||||
id = instance.id,
|
|
||||||
eventID = e.id,
|
|
||||||
title = e.title ?: "",
|
|
||||||
startDate = instance.begin,
|
|
||||||
endDate = instance.end,
|
|
||||||
calendarID = e.calendarId.toInt(),
|
|
||||||
allDay = isAllDay,
|
|
||||||
address = e.eventLocation ?: "",
|
|
||||||
selfAttendeeStatus = e.selfAttendeeStatus.toInt(),
|
|
||||||
availability = e.availability
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (ignored: Exception) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val sortedEvents = eventList.sortEvents()
|
|
||||||
val filteredEventList = sortedEvents
|
|
||||||
.applyFilters()
|
|
||||||
|
|
||||||
if (filteredEventList.isEmpty()) {
|
|
||||||
eventRepository.resetNextEventData()
|
|
||||||
eventRepository.clearEvents()
|
|
||||||
} else {
|
|
||||||
eventRepository.saveEvents(
|
|
||||||
sortedEvents
|
|
||||||
)
|
|
||||||
eventRepository.saveNextEventData(filteredEventList.first())
|
|
||||||
}
|
|
||||||
} catch (ignored: java.lang.Exception) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eventRepository.resetNextEventData()
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdatesReceiver.setUpdates(this)
|
|
||||||
MainWidget.updateWidget(this)
|
|
||||||
|
|
||||||
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
|
||||||
eventRepository.close()
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,174 @@
|
|||||||
|
package com.tommasoberlose.anotherwidget.services
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.IBinder
|
||||||
|
import android.util.Log
|
||||||
|
import com.tommasoberlose.anotherwidget.db.EventRepository
|
||||||
|
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||||
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||||
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.applyFilters
|
||||||
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper.sortEvents
|
||||||
|
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 kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import me.everything.providers.android.calendar.CalendarProvider
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
|
class UpdateCalendarService : Service() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun enqueueWork(context: Context) {
|
||||||
|
context.startService(Intent(context, UpdateCalendarService::class.java))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var job: Job? = null
|
||||||
|
|
||||||
|
override fun onBind(intent: Intent?): IBinder? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
job?.cancel()
|
||||||
|
job = GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
|
||||||
|
val eventRepository = EventRepository(this@UpdateCalendarService)
|
||||||
|
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 {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkGrantedPermission(
|
||||||
|
Manifest.permission.READ_CALENDAR
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
eventRepository.resetNextEventData()
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
val provider = CalendarProvider(this@UpdateCalendarService)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check all day events
|
||||||
|
val startDate = Calendar.getInstance()
|
||||||
|
startDate.timeInMillis = instance.begin
|
||||||
|
val endDate = Calendar.getInstance()
|
||||||
|
endDate.timeInMillis = instance.end
|
||||||
|
|
||||||
|
val isAllDay = e.allDay || (
|
||||||
|
startDate.get(Calendar.MILLISECOND) == 0
|
||||||
|
&& startDate.get(Calendar.SECOND) == 0
|
||||||
|
&& startDate.get(Calendar.MINUTE) == 0
|
||||||
|
&& startDate.get(Calendar.HOUR_OF_DAY) == 0
|
||||||
|
&& endDate.get(Calendar.MILLISECOND) == 0
|
||||||
|
&& endDate.get(Calendar.SECOND) == 0
|
||||||
|
&& endDate.get(Calendar.MINUTE) == 0
|
||||||
|
&& endDate.get(Calendar.HOUR_OF_DAY) == 0
|
||||||
|
)
|
||||||
|
|
||||||
|
eventList.add(
|
||||||
|
Event(
|
||||||
|
id = instance.id,
|
||||||
|
eventID = e.id,
|
||||||
|
title = e.title ?: "",
|
||||||
|
startDate = instance.begin,
|
||||||
|
endDate = instance.end,
|
||||||
|
calendarID = e.calendarId.toInt(),
|
||||||
|
allDay = isAllDay,
|
||||||
|
address = e.eventLocation ?: "",
|
||||||
|
selfAttendeeStatus = e.selfAttendeeStatus.toInt(),
|
||||||
|
availability = e.availability
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val sortedEvents = eventList.sortEvents()
|
||||||
|
val filteredEventList = sortedEvents
|
||||||
|
.applyFilters()
|
||||||
|
|
||||||
|
if (filteredEventList.isEmpty()) {
|
||||||
|
eventRepository.resetNextEventData()
|
||||||
|
eventRepository.clearEvents()
|
||||||
|
} else {
|
||||||
|
eventRepository.saveEvents(
|
||||||
|
sortedEvents
|
||||||
|
)
|
||||||
|
eventRepository.saveNextEventData(filteredEventList.first())
|
||||||
|
}
|
||||||
|
} catch (ignored: java.lang.Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eventRepository.resetNextEventData()
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatesReceiver.setUpdates(this@UpdateCalendarService)
|
||||||
|
MainWidget.updateWidget(this@UpdateCalendarService)
|
||||||
|
|
||||||
|
EventBus.getDefault().post(MainFragment.UpdateUiMessageEvent())
|
||||||
|
eventRepository.close()
|
||||||
|
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
|
||||||
|
return START_STICKY
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
job?.cancel()
|
||||||
|
job = null
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import android.graphics.Typeface
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.HandlerThread
|
import android.os.HandlerThread
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@ -18,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.chibatching.kotpref.blockingBulk
|
import com.chibatching.kotpref.blockingBulk
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.koolio.library.Font
|
import com.koolio.library.Font
|
||||||
import com.tommasoberlose.anotherwidget.R
|
import com.tommasoberlose.anotherwidget.R
|
||||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||||
@ -125,7 +127,7 @@ class CustomFontActivity : AppCompatActivity() {
|
|||||||
if (item.fontVariants.isEmpty()) {
|
if (item.fontVariants.isEmpty()) {
|
||||||
dialog.addItem(SettingsStringHelper.getVariantLabel(this, "regular"), -1)
|
dialog.addItem(SettingsStringHelper.getVariantLabel(this, "regular"), -1)
|
||||||
} else {
|
} else {
|
||||||
item.fontVariants.filter { !it.contains("italic") }
|
item.fontVariants
|
||||||
.forEachIndexed { index, s ->
|
.forEachIndexed { index, s ->
|
||||||
dialog.addItem(SettingsStringHelper.getVariantLabel(this, s), index)
|
dialog.addItem(SettingsStringHelper.getVariantLabel(this, s), index)
|
||||||
}
|
}
|
||||||
|
@ -274,22 +274,23 @@ class GlanceTabFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
Constants.GlanceProviderId.EVENTS -> {
|
Constants.GlanceProviderId.EVENTS -> {
|
||||||
isVisible =
|
isVisible =
|
||||||
Preferences.showEventsAsGlanceProvider && Preferences.showEvents && requireContext().checkGrantedPermission(
|
Preferences.showEventsAsGlanceProvider
|
||||||
Manifest.permission.READ_CALENDAR
|
val hasError = !Preferences.showEvents || !requireContext().checkGrantedPermission(
|
||||||
)
|
Manifest.permission.READ_CALENDAR
|
||||||
|
)
|
||||||
injector.text(
|
injector.text(
|
||||||
R.id.label,
|
R.id.label,
|
||||||
if (isVisible) getString(R.string.settings_visible) else getString(
|
if (isVisible && !hasError) getString(R.string.settings_visible) else getString(
|
||||||
R.string.settings_not_visible
|
R.string.settings_not_visible
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
injector.visibility(
|
injector.visibility(
|
||||||
R.id.error_icon,
|
R.id.error_icon,
|
||||||
if (isVisible) View.GONE else View.VISIBLE
|
if (isVisible && hasError) View.VISIBLE else View.GONE
|
||||||
)
|
)
|
||||||
injector.visibility(
|
injector.visibility(
|
||||||
R.id.info_icon,
|
R.id.info_icon,
|
||||||
if (isVisible) View.VISIBLE else View.GONE
|
if (!(isVisible && hasError)) View.VISIBLE else View.GONE
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,16 @@
|
|||||||
<string name="font_700" translatable="false">Bold</string>
|
<string name="font_700" translatable="false">Bold</string>
|
||||||
<string name="font_800" translatable="false">Black</string>
|
<string name="font_800" translatable="false">Black</string>
|
||||||
<string name="font_900" translatable="false">Heavy</string>
|
<string name="font_900" translatable="false">Heavy</string>
|
||||||
|
<string name="font_italic" translatable="false">Italic</string>
|
||||||
|
<string name="font_100_italic" translatable="false">Thin Italic</string>
|
||||||
|
<string name="font_200_italic" translatable="false">Light Italic</string>
|
||||||
|
<string name="font_300_italic" translatable="false">Book Italic</string>
|
||||||
|
<string name="font_400_italic" translatable="false">Regular Italic</string>
|
||||||
|
<string name="font_500_italic" translatable="false">Medium Italic</string>
|
||||||
|
<string name="font_600_italic" translatable="false">Semi-bold Italic</string>
|
||||||
|
<string name="font_700_italic" translatable="false">Bold Italic</string>
|
||||||
|
<string name="font_800_italic" translatable="false">Black Italic</string>
|
||||||
|
<string name="font_900_italic" translatable="false">Heavy Italic</string>
|
||||||
|
|
||||||
<!-- Calendar -->
|
<!-- Calendar -->
|
||||||
<string name="settings_calendar_title">Calendar</string>
|
<string name="settings_calendar_title">Calendar</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user