update Commons to 2.30.6 for easy runtime permissions handling

This commit is contained in:
tibbi 2017-10-21 17:38:07 +02:00
parent e5bc145b27
commit 125fcc3055
6 changed files with 27 additions and 71 deletions

View File

@ -44,7 +44,7 @@ ext {
}
dependencies {
compile 'com.simplemobiletools:commons:2.30.4'
compile 'com.simplemobiletools:commons:2.30.6'
compile 'joda-time:joda-time:2.9.1'
compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -1,10 +1,8 @@
package com.simplemobiletools.calendar.activities
import android.Manifest
import android.content.ContentResolver
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.database.ContentObserver
import android.database.Cursor
import android.net.Uri
@ -12,7 +10,6 @@ import android.os.Bundle
import android.os.Handler
import android.provider.CalendarContract
import android.provider.ContactsContract
import android.support.v4.app.ActivityCompat
import android.support.v4.view.ViewPager
import android.util.SparseIntArray
import android.view.Menu
@ -39,9 +36,7 @@ import com.simplemobiletools.calendar.views.MyScrollView
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.LICENSE_JODA
import com.simplemobiletools.commons.helpers.LICENSE_KOTLIN
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.models.Release
import kotlinx.android.synthetic.main.activity_main.*
@ -56,9 +51,6 @@ class MainActivity : SimpleActivity(), NavigationListener {
private val PREFILLED_MONTHS = 97
private val PREFILLED_YEARS = 31
private val PREFILLED_WEEKS = 61
private val PERMISSION_STORAGE_IMPORT = 1
private val PERMISSION_STORAGE_EXPORT = 2
private val PERMISSION_CONTACTS = 3
private var mIsMonthSelected = false
private var mStoredTextColor = 0
@ -108,7 +100,7 @@ class MainActivity : SimpleActivity(), NavigationListener {
storeStateVariables()
updateViewPager()
if (!hasCalendarPermission()) {
if (!hasPermission(PERMISSION_WRITE_CALENDAR)) {
config.caldavSync = false
}
@ -293,12 +285,14 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
private fun tryAddBirthdays() {
if (hasContactsPermission()) {
handlePermission(PERMISSION_READ_CONTACTS) {
if (it) {
Thread({
addBirthdays()
}).start()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_CONTACTS), PERMISSION_CONTACTS)
toast(R.string.no_contacts_permission)
}
}
}
@ -399,10 +393,10 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
private fun tryImportEvents() {
if (hasReadStoragePermission()) {
handlePermission(PERMISSION_READ_STORAGE) {
if (it) {
importEvents()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), PERMISSION_STORAGE_IMPORT)
}
}
}
@ -442,10 +436,10 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
private fun tryExportEvents() {
if (hasReadStoragePermission()) {
handlePermission(PERMISSION_WRITE_STORAGE) {
if (it) {
exportEvents()
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), PERMISSION_STORAGE_EXPORT)
}
}
}
@ -673,18 +667,6 @@ class MainActivity : SimpleActivity(), NavigationListener {
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
when (requestCode) {
PERMISSION_STORAGE_IMPORT -> importEvents()
PERMISSION_STORAGE_EXPORT -> exportEvents()
PERMISSION_CONTACTS -> Thread({ addBirthdays() }).start()
}
}
}
private fun getHolidayRadioItems(): ArrayList<RadioItem> {
val items = ArrayList<RadioItem>()

View File

@ -1,14 +1,11 @@
package com.simplemobiletools.calendar.activities
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Resources
import android.media.RingtoneManager
import android.net.Uri
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.ActivityCompat
import android.text.TextUtils
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog
@ -25,12 +22,12 @@ import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
private val GET_RINGTONE_URI = 1
private val CALENDAR_PERMISSION = 5
lateinit var res: Resources
private var mStoredPrimaryColor = 0
@ -106,10 +103,10 @@ class SettingsActivity : SimpleActivity() {
if (config.caldavSync) {
toggleCaldavSync(false)
} else {
if (hasCalendarPermission()) {
handlePermission(PERMISSION_WRITE_CALENDAR) {
if (it) {
toggleCaldavSync(true)
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_CALENDAR), CALENDAR_PERMISSION)
}
}
}
}
@ -352,14 +349,4 @@ class SettingsActivity : SimpleActivity() {
}
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == CALENDAR_PERMISSION) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
toggleCaldavSync(true)
}
}
}
}

View File

@ -1,10 +1,7 @@
package com.simplemobiletools.calendar.extensions
import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
@ -12,8 +9,6 @@ import com.simplemobiletools.calendar.helpers.IcsExporter
import com.simplemobiletools.commons.extensions.toast
import java.io.File
fun Activity.hasContactsPermission() = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
fun SimpleActivity.shareEvents(ids: List<Int>) {
val file = getTempFile()
if (file == null) {

View File

@ -1,6 +1,5 @@
package com.simplemobiletools.calendar.extensions
import android.Manifest
import android.annotation.TargetApi
import android.app.AlarmManager
import android.app.Notification
@ -10,13 +9,11 @@ import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Color
import android.graphics.PorterDuff
import android.net.Uri
import android.os.Build
import android.support.v4.content.ContextCompat
import android.support.v7.app.NotificationCompat
import android.view.Gravity
import android.view.View
@ -38,8 +35,6 @@ 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()) {

View File

@ -10,15 +10,12 @@ import android.util.SparseIntArray
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.hasCalendarPermission
import com.simplemobiletools.calendar.extensions.scheduleCalDAVSync
import com.simplemobiletools.calendar.models.CalDAVCalendar
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.getIntValue
import com.simplemobiletools.commons.extensions.getLongValue
import com.simplemobiletools.commons.extensions.getStringValue
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
import java.util.*
import kotlin.collections.ArrayList
@ -43,7 +40,7 @@ class CalDAVHandler(val context: Context) {
fun getCalDAVCalendars(activity: SimpleActivity? = null, ids: String = ""): List<CalDAVCalendar> {
val calendars = ArrayList<CalDAVCalendar>()
if (!context.hasCalendarPermission()) {
if (!context.hasPermission(PERMISSION_WRITE_CALENDAR)) {
return calendars
}