use the proper default event color at google events

This commit is contained in:
tibbi 2017-07-28 21:51:23 +02:00
parent dc5846f268
commit 890a7f34a6
4 changed files with 17 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Color
import android.media.RingtoneManager
import android.net.Uri
import android.os.Bundle
@ -25,6 +26,7 @@ import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.helpers.FONT_SIZE_LARGE
import com.simplemobiletools.calendar.helpers.FONT_SIZE_MEDIUM
import com.simplemobiletools.calendar.helpers.FONT_SIZE_SMALL
import com.simplemobiletools.calendar.helpers.PRIMARY
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.toast
@ -354,6 +356,7 @@ class SettingsActivity : SimpleActivity() {
private fun fetchEventsIfHasPermissions() {
try {
getGoogleSyncService().colors().get().execute() // just checking if we have the permission for fetching user data
storeCalendarData()
config.googleSync = true
runOnUiThread {
settings_google_sync.isChecked = true
@ -372,6 +375,14 @@ class SettingsActivity : SimpleActivity() {
settings_google_sync.isChecked = false
config.googleSync = false
config.syncAccountName = ""
config.googleDefaultEventColor = config.primaryColor
}
private fun storeCalendarData() {
Thread({
val calendar = getGoogleSyncService().calendarList().get(PRIMARY).execute()
config.googleDefaultEventColor = Color.parseColor(calendar.backgroundColor)
}).start()
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {

View file

@ -186,7 +186,7 @@ class FetchGoogleEventsTask(val context: Context, val googleSyncListener: Google
}
if (eventTypeId == -1) {
val newColor = if (eventColors[colorId] != 0) eventColors[colorId] else context.config.primaryColor
val newColor = if (eventColors[colorId] != 0) eventColors[colorId] else context.config.googleDefaultEventColor
val newEventType = EventType(0, eventType, newColor)
eventTypeId = dbHelper.insertEventType(newEventType)
eventTypes.add(newEventType)

View file

@ -86,6 +86,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getString(SYNC_ACCOUNT_NAME, "")
set(syncAccountName) = prefs.edit().putString(SYNC_ACCOUNT_NAME, syncAccountName).apply()
var googleDefaultEventColor: Int
get() = prefs.getInt(GOOGLE_DEFAULT_EVENT_COLOR, primaryColor)
set(color) = prefs.edit().putInt(GOOGLE_DEFAULT_EVENT_COLOR, color).apply()
fun addDisplayEventType(type: String) {
addDisplayEventTypes(HashSet<String>(Arrays.asList(type)))
}

View file

@ -45,6 +45,7 @@ val GOOGLE_SYNC = "google_sync"
val SYNC_ACCOUNT_NAME = "sync_account_name"
val SNOOZE_DELAY = "snooze_delay"
val DISPLAY_PAST_EVENTS = "display_past_events"
val GOOGLE_DEFAULT_EVENT_COLOR = "google_default_event_color"
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)