From f285bee7256e743bd697eec63937fa4280628cf2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 29 Jan 2017 21:26:42 +0100 Subject: [PATCH] add some initial things related to Google Sync, obtaining the account name --- app/build.gradle | 9 +++ app/src/main/AndroidManifest.xml | 3 + .../calendar/activities/SettingsActivity.kt | 62 ++++++++++++++++++- .../calendar/helpers/Config.kt | 8 +++ .../calendar/helpers/Constants.kt | 2 + app/src/main/res/layout/activity_settings.xml | 26 +++++++- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es-rES/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-hi-rIN/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-iw/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 18 files changed, 116 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08acf6a82..cae0f6c1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -36,6 +36,15 @@ dependencies { compile 'joda-time:joda-time:2.9.1' compile 'com.facebook.stetho:stetho:1.4.1' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' + + compile 'com.google.android.gms:play-services-auth:10.0.1' + compile('com.google.api-client:google-api-client-android:1.22.0') { + exclude group: 'org.apache.httpcomponents' + } + compile('com.google.apis:google-api-services-calendar:v3-rev230-1.22.0') { + exclude group: 'org.apache.httpcomponents' + } + compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 63dc54ab1..71230579c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + + + (RingtoneManager.EXTRA_RINGTONE_PICKED_URI) if (uri == null) { config.reminderSound = "" @@ -193,6 +221,34 @@ class SettingsActivity : SimpleActivity() { settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri).getTitle(this) config.reminderSound = uri.toString() } + } else if (resultCode == RESULT_OK && requestCode == REQUEST_ACCOUNT && resultData?.extras != null) { + val accountName = resultData!!.getStringExtra(AccountManager.KEY_ACCOUNT_NAME) + config.syncAccountName = accountName + credential.selectedAccountName = accountName + } + } + + private fun checkGetAccountsPermission() { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.GET_ACCOUNTS), ACCOUNTS_PERMISSION) + } else { + showAccountChooser() + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + + if (requestCode == ACCOUNTS_PERMISSION) { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + showAccountChooser() + } + } + } + + private fun showAccountChooser() { + if (config.syncAccountName.isEmpty()) { + startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt index b4eeb86fc..0596d3e91 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -59,6 +59,14 @@ class Config(context: Context) : BaseConfig(context) { prefs.edit().putInt(REMINDER_MINUTES, mins).apply() } + var googleSync: Boolean + get() = prefs.getBoolean(GOOGLE_SYNC, false) + set(googleSync) = prefs.edit().putBoolean(GOOGLE_SYNC, googleSync).apply() + + var syncAccountName: String + get() = prefs.getString(SYNC_ACCOUNT_NAME, "") + set(syncAccountName) = prefs.edit().putString(SYNC_ACCOUNT_NAME, syncAccountName).apply() + fun getDefaultNotificationSound(): String { try { return RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION)?.toString() ?: "" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index 2cdef502a..6ae0356e6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -39,6 +39,8 @@ val REMINDER_SOUND = "reminder_sound" val VIEW = "view" val REMINDER_TYPE = "reminder_type" val REMINDER_MINUTES = "reminder_minutes" +val GOOGLE_SYNC = "google_sync" +val SYNC_ACCOUNT_NAME = "sync_account_name" val letterIDs = intArrayOf(R.string.sunday_letter, R.string.monday_letter, R.string.tuesday_letter, R.string.wednesday_letter, R.string.thursday_letter, R.string.friday_letter, R.string.saturday_letter) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index bfed750fd..f58c33cd8 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -31,7 +31,7 @@ + android:text="@string/google_sync"/> @@ -105,6 +105,26 @@ + + + + + + No app capable of setting ringtone found Kein Klingelton gewählt The day cannot end earlier than it starts + Google sync 1 Termin gelöscht diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 2a807337a..9c863583d 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 evento borrado diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 37a352f30..fcc874adc 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -73,6 +73,7 @@ Aucune application capable de configurer la sonnerie trouvée None The day cannot end earlier than it starts + Google sync 1 événement supprimé diff --git a/app/src/main/res/values-hi-rIN/strings.xml b/app/src/main/res/values-hi-rIN/strings.xml index fa28b3fb7..76bdbaa47 100644 --- a/app/src/main/res/values-hi-rIN/strings.xml +++ b/app/src/main/res/values-hi-rIN/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 इवेंट डिलीट किया गया diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 64966997c..1a324927f 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 bejegyzés törölve diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 778dfedbb..c237e120b 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 evento eliminato diff --git a/app/src/main/res/values-iw/strings.xml b/app/src/main/res/values-iw/strings.xml index 5350d06f0..0441b8039 100644 --- a/app/src/main/res/values-iw/strings.xml +++ b/app/src/main/res/values-iw/strings.xml @@ -73,6 +73,7 @@ לא נמצאה אפליקציה להגדרת רינגטון ללא היום לא יכול להסתיים מוקדם משהוא מתחיל + Google sync אירוע אחד נמחק diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 553b0d4ca..ad0c438e5 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 イベントを削除しました diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 81025d775..9dbd69703 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -73,6 +73,7 @@ Não foi encontrada qualquer aplicação capaz de definir o som Nenhum O dia final não pode ser antes do inicial + Google sync 1 evento apagado diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index dee8ba5dc..347b3ca50 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -73,6 +73,7 @@ Не найдено приложение для выбора рингтона Нет The day cannot end earlier than it starts + Google sync 1 событие удалено diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index ce2579d36..2278db40a 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -73,6 +73,7 @@ Hittade ingen app som kan ställa in ljudet Ingen Dagen kan inte börja innan den tar slut + Google sync 1 händelse borttagen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be667290a..70d34175a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -73,6 +73,7 @@ No app capable of setting ringtone found None The day cannot end earlier than it starts + Google sync 1 event deleted