Merge pull request #1811 from Naveen3Singh/caldav_issues

CalDAV refresh improvement
This commit is contained in:
Tibor Kaputa 2022-08-28 19:54:05 +02:00 committed by GitHub
commit f845567698
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 3 deletions

View File

@ -197,6 +197,7 @@
<activity
android:name=".activities.EventTypePickerActivity"
android:excludeFromRecents="true"
android:exported="false"
android:theme="@style/Theme.Transparent" />

View File

@ -206,6 +206,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
main_toolbar.setNavigationOnClickListener {
onBackPressed()
}
if (config.caldavSync) {
updateCalDAVEvents()
}
}
override fun onPause() {
@ -561,14 +565,22 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
}
private fun updateCalDAVEvents() {
ensureBackgroundThread {
calDAVHelper.refreshCalendars(showToasts = false, scheduleNextSync = true) {
refreshViewPager()
}
}
}
private fun refreshCalDAVCalendars(showRefreshToast: Boolean) {
showCalDAVRefreshToast = showRefreshToast
if (showRefreshToast) {
toast(R.string.refreshing)
}
updateCalDAVEvents()
syncCalDAVCalendars {
calDAVHelper.refreshCalendars(true, true) {
calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) {
calDAVChanged()
}
}

View File

@ -328,7 +328,7 @@ class SettingsActivity : SimpleActivity() {
}
syncCalDAVCalendars {
calDAVHelper.refreshCalendars(true, true) {
calDAVHelper.refreshCalendars(showToasts = true, scheduleNextSync = true) {
if (settings_caldav_sync.isChecked) {
toast(R.string.synchronization_completed)
}

View File

@ -23,6 +23,7 @@ import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.AlarmManagerCompat
import androidx.core.app.NotificationCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.print.PrintHelper
import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.EventActivity
@ -57,6 +58,8 @@ val Context.completedTasksDB: TasksDao get() = EventsDatabase.getInstance(applic
val Context.eventsHelper: EventsHelper get() = EventsHelper(this)
val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this)
val Context.localBroadcastManager: LocalBroadcastManager get() = LocalBroadcastManager.getInstance(this)
fun Context.updateWidgets() {
val widgetIDs = AppWidgetManager.getInstance(applicationContext)?.getAppWidgetIds(ComponentName(applicationContext, MyWidgetMonthlyProvider::class.java))
?: return
@ -603,6 +606,7 @@ fun Context.refreshCalDAVCalendars(ids: String, showToasts: Boolean) {
Bundle().apply {
putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true)
putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true)
accounts.forEach {
ContentResolver.requestSync(it, uri.authority, this)
}

View File

@ -227,6 +227,7 @@ const val IS_NEW_EVENT = "IS_NEW_EVENT"
// actions
const val ACTION_MARK_COMPLETED = "ACTION_MARK_COMPLETED"
const val ACTION_REFRESH_EVENTS = "ACTION_REFRESH_EVENTS"
fun getNowSeconds() = System.currentTimeMillis() / 1000L