require write_calendar permission before activating caldav sync
This commit is contained in:
parent
cde8deb059
commit
3eef430226
4 changed files with 31 additions and 2 deletions
|
@ -11,6 +11,9 @@
|
|||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
|
||||
|
||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -90,6 +90,10 @@ class MainActivity : SimpleActivity(), NavigationListener {
|
|||
config.googleSync = false
|
||||
}
|
||||
|
||||
if (!hasCalendarPermission()) {
|
||||
config.caldavSync = false
|
||||
}
|
||||
|
||||
if (isGoogleSyncActive()) {
|
||||
FetchGoogleEventsTask(applicationContext, googleSyncListener).execute()
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ class SettingsActivity : SimpleActivity() {
|
|||
private val ACCOUNTS_PERMISSION = 2
|
||||
private val REQUEST_ACCOUNT_NAME = 3
|
||||
private val REQUEST_GOOGLE_PLAY_SERVICES = 4
|
||||
private val CALENDAR_PERMISSION = 5
|
||||
|
||||
lateinit var res: Resources
|
||||
private var mStoredPrimaryColor = 0
|
||||
|
@ -135,11 +136,23 @@ class SettingsActivity : SimpleActivity() {
|
|||
private fun setupCaldavSync() {
|
||||
settings_caldav_sync.isChecked = config.caldavSync
|
||||
settings_caldav_sync_holder.setOnClickListener {
|
||||
settings_caldav_sync.toggle()
|
||||
config.caldavSync = settings_caldav_sync.isChecked
|
||||
if (config.caldavSync) {
|
||||
toggleCaldavSync()
|
||||
} else {
|
||||
if (hasCalendarPermission()) {
|
||||
toggleCaldavSync()
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALENDAR), CALENDAR_PERMISSION)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleCaldavSync() {
|
||||
settings_caldav_sync.toggle()
|
||||
config.caldavSync = settings_caldav_sync.isChecked
|
||||
}
|
||||
|
||||
private fun toggleGoogleSync() {
|
||||
settings_google_sync.toggle()
|
||||
|
||||
|
@ -438,6 +451,10 @@ class SettingsActivity : SimpleActivity() {
|
|||
} else {
|
||||
disableGoogleSync()
|
||||
}
|
||||
} else if (requestCode == CALENDAR_PERMISSION) {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
toggleCaldavSync()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.calendar.extensions
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.TargetApi
|
||||
import android.app.AlarmManager
|
||||
import android.app.Notification
|
||||
|
@ -9,10 +10,12 @@ import android.appwidget.AppWidgetManager
|
|||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v7.app.NotificationCompat
|
||||
import com.google.api.client.extensions.android.http.AndroidHttp
|
||||
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
|
||||
|
@ -35,6 +38,8 @@ import org.joda.time.DateTimeZone
|
|||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
fun Context.hasCalendarPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
val widgetsCnt = AppWidgetManager.getInstance(this).getAppWidgetIds(ComponentName(this, MyWidgetMonthlyProvider::class.java))
|
||||
if (widgetsCnt.isNotEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue