diff --git a/app/src/gms/java/me/blog/korn123/easydiary/activities/DevActivity.kt b/app/src/gms/java/me/blog/korn123/easydiary/activities/DevActivity.kt index ae21093dc..9b459a798 100644 --- a/app/src/gms/java/me/blog/korn123/easydiary/activities/DevActivity.kt +++ b/app/src/gms/java/me/blog/korn123/easydiary/activities/DevActivity.kt @@ -1,43 +1,23 @@ package me.blog.korn123.easydiary.activities -import android.accounts.Account import android.app.Activity import android.content.Intent import android.os.Bundle -import android.util.Log import android.widget.Button import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts -import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.common.api.ApiException import com.google.android.gms.tasks.Task -import com.google.api.client.extensions.android.http.AndroidHttp -import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential -import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException -import com.google.api.client.json.gson.GsonFactory -import com.google.api.services.calendar.Calendar -import com.google.api.services.calendar.CalendarScopes -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import me.blog.korn123.easydiary.R -import me.blog.korn123.easydiary.adapters.OptionItemAdapter -import me.blog.korn123.easydiary.databinding.DialogFontsBinding +import io.github.aafactory.commons.extensions.showAlertDialog import me.blog.korn123.easydiary.enums.DialogMode import me.blog.korn123.easydiary.extensions.makeSnackBar -import me.blog.korn123.easydiary.extensions.makeToast import me.blog.korn123.easydiary.extensions.pauseLock -import me.blog.korn123.easydiary.extensions.updateAlertDialogWithIcon -import me.blog.korn123.easydiary.helper.AAF_TEST +import me.blog.korn123.easydiary.extensions.showAlertDialog import me.blog.korn123.easydiary.helper.DriveServiceHelper -import me.blog.korn123.easydiary.helper.EasyDiaryDbHelper import me.blog.korn123.easydiary.helper.GoogleOAuthHelper -import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.initGoogleSignAccount -import me.blog.korn123.easydiary.models.Diary import me.blog.korn123.easydiary.services.FullBackupService class DevActivity : BaseDevActivity() { @@ -47,7 +27,7 @@ class DevActivity : BaseDevActivity() { * ***************************************************************************************************/ private lateinit var mRequestGoogleSignInLauncher: ActivityResultLauncher - private lateinit var mRequestGoogleCalendarPermissions: ActivityResultLauncher + private lateinit var mPermissionCallback: () -> Unit override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -70,21 +50,22 @@ class DevActivity : BaseDevActivity() { } } - mRequestGoogleCalendarPermissions = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { - pauseLock() - when (it.resultCode == Activity.RESULT_OK && it.data != null) { - true -> { - mPermissionCallback.invoke() - } - false -> { - makeSnackBar("Google account verification failed.") + // GMSP + val gmsButtons = arrayOf( + Button(this).apply { + text = "Check Google SignAccount" + layoutParams = mFlexboxLayoutParams + setOnClickListener { + if (GoogleOAuthHelper.isValidGoogleSignAccount(this@DevActivity)) { + GoogleOAuthHelper.getGoogleSignAccount(this@DevActivity)?.run { + showAlertDialog(account!!.name, null, null, DialogMode.DEFAULT, false) + } + } else { + showAlertDialog("Sign account is invalid.", null) + } } - } - } - - mBinding.linearDevContainer.addView( - // GMSP - createBaseCardView("GMSP", null, Button(this).apply { + }, + Button(this).apply { text = "Full-Backup" layoutParams = mFlexboxLayoutParams setOnClickListener { @@ -106,120 +87,14 @@ class DevActivity : BaseDevActivity() { } } } - }, Button(this@DevActivity).apply { - text ="Google Calendar" - layoutParams = mFlexboxLayoutParams - setOnClickListener { - initGoogleSignAccount(this@DevActivity, mRequestGoogleSignInLauncher) { account -> - requestCalendarPermissions(account) { - val credential: GoogleAccountCredential = - GoogleAccountCredential.usingOAuth2( - this@DevActivity, - arrayListOf(CalendarScopes.CALENDAR) - ).apply { - selectedAccount = account - } - val calendarService = Calendar.Builder( - AndroidHttp.newCompatibleTransport(), - GsonFactory(), - credential - ) - .setApplicationName(getString(R.string.app_name)) - .build() - - fun fetchData(calendarId: String, nextPageToken: String?, total: Int = 0) { - var insertCount = 0 - CoroutineScope(Dispatchers.IO).launch { - val result = if (nextPageToken == null) calendarService.events().list(calendarId).setMaxResults(2000).execute() else calendarService.events().list("hanjoongcho@gmail.com").setPageToken(nextPageToken).setMaxResults(2000).execute() - withContext(Dispatchers.Main) { - val descriptions = arrayListOf() - result.items.forEachIndexed { index, item -> - Log.i(AAF_TEST, "$index ${item.start?.date} ${item.summary} ${item.start?.dateTime}") - descriptions.add(item.summary) - val timeMillis = if (item.start?.dateTime != null) item.start.dateTime.value else item.start?.date?.value ?: 0 - if (EasyDiaryDbHelper.findDiary(item.summary) - .none { diary -> diary.currentTimeMillis == timeMillis } - ) { - EasyDiaryDbHelper.insertDiary( - Diary( - BaseDiaryEditingActivity.DIARY_SEQUENCE_INIT, - timeMillis, - if (item.description != null) item.summary else "", - item.description ?: item.summary, - 10022, - item?.start?.dateTime == null - ) - ) - insertCount++ - } - } - if (result.nextPageToken != null) { - fetchData(calendarId, result.nextPageToken, total.plus(insertCount)) - } else { - makeToast("Total: ${total.plus(insertCount)}") - } - } - } - } - fun fetchCalendarList() { - var alertDialog: AlertDialog? = null - CoroutineScope(Dispatchers.IO).launch { - val result = calendarService.calendarList().list().execute() - withContext(Dispatchers.Main) { - val builder = AlertDialog.Builder(this@DevActivity) - builder.setNegativeButton(getString(android.R.string.cancel), null) - val dialogFontsBinding = DialogFontsBinding.inflate(layoutInflater) - val calendarInfo = ArrayList>() - result.items.forEach { calendar -> - calendarInfo.add(mapOf( - "optionTitle" to calendar.summary, - "optionValue" to calendar.id - )) - } - val optionItemAdapter = OptionItemAdapter(this@DevActivity, R.layout.item_check_label, calendarInfo, null, null) - dialogFontsBinding.run { - listFont.adapter = optionItemAdapter - listFont.setOnItemClickListener { parent, view, position, id -> - calendarInfo[position]["optionValue"]?.let { - fetchData(it, null) - alertDialog?.dismiss() - } - } - } - alertDialog = builder.create().apply { - updateAlertDialogWithIcon(DialogMode.INFO, this, null, dialogFontsBinding.root, "Sync Google Calendar") - } - } - } - } - fetchCalendarList() - } - } - } - }) + } + ) + mBinding.linearDevContainer.addView( + createBaseCardView("GMSP", null, *gmsButtons) ) } - private lateinit var mPermissionCallback: () -> Unit - private fun requestCalendarPermissions(account: Account, permissionCallback: () -> Unit) { - mPermissionCallback = permissionCallback - val credential: GoogleAccountCredential = - GoogleAccountCredential.usingOAuth2(this, arrayListOf(CalendarScopes.CALENDAR)) - .apply { selectedAccount = account } - val calendarService: Calendar = Calendar.Builder(AndroidHttp.newCompatibleTransport(), GsonFactory(), credential) - .setApplicationName(getString(R.string.app_name)) - .build() - CoroutineScope(Dispatchers.IO).launch { - try { - calendarService.calendarList().list().execute() - mPermissionCallback.invoke() - } catch (e: UserRecoverableAuthIOException) { - withContext(Dispatchers.Main) { - mRequestGoogleCalendarPermissions.launch(e.intent) - } - } - } - } + /*************************************************************************************************** diff --git a/app/src/gms/java/me/blog/korn123/easydiary/fragments/SettingsGMSBackupFragment.kt b/app/src/gms/java/me/blog/korn123/easydiary/fragments/SettingsGMSBackupFragment.kt index 28815f47b..25cd4393c 100644 --- a/app/src/gms/java/me/blog/korn123/easydiary/fragments/SettingsGMSBackupFragment.kt +++ b/app/src/gms/java/me/blog/korn123/easydiary/fragments/SettingsGMSBackupFragment.kt @@ -73,7 +73,10 @@ import me.blog.korn123.easydiary.helper.DriveServiceHelper import me.blog.korn123.easydiary.helper.EXTERNAL_STORAGE_PERMISSIONS import me.blog.korn123.easydiary.helper.EasyDiaryDbHelper import me.blog.korn123.easydiary.helper.GoogleOAuthHelper +import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.calendarEventToDiary import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.callAccountCallback +import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.getCalendarCredential +import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.getCalendarService import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.initGoogleSignAccount import me.blog.korn123.easydiary.helper.SETTING_FLAG_EXPORT_GOOGLE_DRIVE import me.blog.korn123.easydiary.helper.SETTING_FLAG_EXPORT_PHOTO_GOOGLE_DRIVE @@ -422,21 +425,8 @@ class SettingsGMSBackupFragment : androidx.fragment.app.Fragment() { progressContainer.visibility = View.VISIBLE initGoogleSignAccount(requireActivity(), mRequestGoogleSignInLauncher) { account -> requestCalendarPermissions(account) { - val credential: GoogleAccountCredential = - GoogleAccountCredential.usingOAuth2( - requireActivity(), - arrayListOf(CalendarScopes.CALENDAR_READONLY, CalendarScopes.CALENDAR_EVENTS_READONLY) - ).apply { - selectedAccount = account - } - val calendarService = Calendar.Builder( - AndroidHttp.newCompatibleTransport(), - GsonFactory(), - credential - ) - .setApplicationName(getString(R.string.app_name)) - .build() - + val credential = getCalendarCredential(requireContext()) + val calendarService = getCalendarService(requireContext(), credential) fun fetchData(calendarId: String, nextPageToken: String?, total: Int = 0) { var insertCount = 0 progressContainer.visibility = View.VISIBLE @@ -469,25 +459,8 @@ class SettingsGMSBackupFragment : androidx.fragment.app.Fragment() { result.items.forEachIndexed { index, item -> Log.i(AAF_TEST, "$index ${item.start?.date} ${item.summary} ${item.start?.dateTime}") // descriptions.add(item.summary) - val timeMillis = if (item.start?.dateTime != null) item.start.dateTime.value else item.start?.date?.value ?: 0 withContext(Dispatchers.Main) { - if (EasyDiaryDbHelper.findDiary(item.summary) - .none { diary -> diary.currentTimeMillis == timeMillis } - && !(item.description == null && item.summary == null)) { - EasyDiaryDbHelper.insertDiary( - Diary( - BaseDiaryEditingActivity.DIARY_SEQUENCE_INIT, - timeMillis, - if (item.description != null) item.summary else "", - item.description ?: item.summary, - SYMBOL_GOOGLE_CALENDAR, - item?.start?.dateTime == null - ).apply { isHoliday = - calendarId == "ko.south_korea#holiday@group.v.calendar.google.com" - } - ) - insertCount++ - } + insertCount += calendarEventToDiary(item, calendarId) mBinding.syncGoogleCalendarProgress.setProgressCompat(index.div(result.items.size.toFloat()).times(100).toInt(), true) } } diff --git a/app/src/gms/java/me/blog/korn123/easydiary/helper/AlarmWorkExecutor.kt b/app/src/gms/java/me/blog/korn123/easydiary/helper/AlarmWorkExecutor.kt index 096dfbf0d..00d383f30 100644 --- a/app/src/gms/java/me/blog/korn123/easydiary/helper/AlarmWorkExecutor.kt +++ b/app/src/gms/java/me/blog/korn123/easydiary/helper/AlarmWorkExecutor.kt @@ -3,12 +3,29 @@ package me.blog.korn123.easydiary.helper import android.content.Context import android.content.Intent import androidx.core.content.ContextCompat +import com.google.android.gms.auth.api.signin.GoogleSignIn +import com.google.android.gms.auth.api.signin.GoogleSignInAccount +import com.google.api.client.extensions.android.http.AndroidHttp +import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential +import com.google.api.client.json.gson.GsonFactory +import com.google.api.client.util.DateTime +import com.google.api.services.calendar.CalendarScopes +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import me.blog.korn123.commons.utils.EasyDiaryUtils +import me.blog.korn123.easydiary.activities.BaseDiaryEditingActivity import me.blog.korn123.easydiary.extensions.isScreenOn +import me.blog.korn123.easydiary.extensions.openNotification import me.blog.korn123.easydiary.extensions.reExecuteGmsBackup import me.blog.korn123.easydiary.extensions.scheduleNextAlarm import me.blog.korn123.easydiary.fragments.SettingsScheduleFragment +import me.blog.korn123.easydiary.helper.GoogleOAuthHelper.Companion.fetchData import me.blog.korn123.easydiary.models.Alarm +import me.blog.korn123.easydiary.models.Diary import me.blog.korn123.easydiary.services.FullBackupService +import java.util.Calendar class AlarmWorkExecutor(context: Context) : BaseAlarmWorkExecutor(context) { @@ -37,6 +54,17 @@ class AlarmWorkExecutor(context: Context) : BaseAlarmWorkExecutor(context) { } ?: reExecuteGmsBackup(alarm, "Authentication token is not valid.", AlarmWorkExecutor::class.java.name) } + Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC -> { + val calendarService = + GoogleOAuthHelper.getCalendarService(context, GoogleOAuthHelper.getCalendarCredential(context)) + CoroutineScope(Dispatchers.IO).launch { + val result = calendarService.calendarList().list().execute() + result.items.forEach { calendar -> + fetchData(context, calendarService, calendar.id, null) + } + } + openNotification(alarm) + } else -> {} } } diff --git a/app/src/gms/java/me/blog/korn123/easydiary/helper/GoogleOAuthHelper.kt b/app/src/gms/java/me/blog/korn123/easydiary/helper/GoogleOAuthHelper.kt index 2da79b237..cffb2028d 100644 --- a/app/src/gms/java/me/blog/korn123/easydiary/helper/GoogleOAuthHelper.kt +++ b/app/src/gms/java/me/blog/korn123/easydiary/helper/GoogleOAuthHelper.kt @@ -4,14 +4,39 @@ import android.accounts.Account import android.app.Activity import android.content.Context import android.content.Intent +import android.util.Log +import android.view.View import androidx.activity.result.ActivityResultLauncher +import androidx.appcompat.app.AlertDialog import androidx.fragment.app.Fragment import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInOptions +import com.google.api.client.extensions.android.http.AndroidHttp +import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential +import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException +import com.google.api.client.json.gson.GsonFactory +import com.google.api.client.util.DateTime +import com.google.api.services.calendar.Calendar +import com.google.api.services.calendar.CalendarScopes +import com.google.api.services.calendar.model.Event +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import me.blog.korn123.commons.utils.DateUtils +import me.blog.korn123.commons.utils.EasyDiaryUtils import me.blog.korn123.easydiary.R +import me.blog.korn123.easydiary.activities.BaseDiaryEditingActivity +import me.blog.korn123.easydiary.adapters.OptionItemAdapter +import me.blog.korn123.easydiary.databinding.DialogFontsBinding +import me.blog.korn123.easydiary.enums.DialogMode import me.blog.korn123.easydiary.extensions.config import me.blog.korn123.easydiary.extensions.makeSnackBar +import me.blog.korn123.easydiary.extensions.makeToast +import me.blog.korn123.easydiary.extensions.showAlertDialog +import me.blog.korn123.easydiary.extensions.updateAlertDialogWithIcon +import me.blog.korn123.easydiary.models.Diary class GoogleOAuthHelper { companion object { @@ -65,5 +90,91 @@ class GoogleOAuthHelper { fun callAccountCallback(account: Account) { mAccountCallback.invoke(account) } + + fun getCalendarCredential(context: Context, account: Account = getGoogleSignAccount(context)?.account!!): GoogleAccountCredential = GoogleAccountCredential.usingOAuth2( + context, + arrayListOf(CalendarScopes.CALENDAR_READONLY, CalendarScopes.CALENDAR_EVENTS_READONLY) + ).apply { + selectedAccount = account + } + + fun getCalendarService(context: Context, credential: GoogleAccountCredential): Calendar = Calendar.Builder( + AndroidHttp.newCompatibleTransport(), + GsonFactory(), + credential + ) + .setApplicationName(context.getString(R.string.app_name)) + .build() + + fun fetchData( + context: Context, + calendarService: Calendar, + calendarId: String, + nextPageToken: String?, + total: Int = 0 + ) { + var insertCount = 0 + val fromCalendar = + EasyDiaryUtils.getCalendarInstance(false, java.util.Calendar.MONTH, -1) + val toCalendar = EasyDiaryUtils.getCalendarInstance(true, java.util.Calendar.MONTH, 1) + val mTimeMin = DateTime(fromCalendar.timeInMillis) + val mTimeMax = DateTime(toCalendar.timeInMillis) + + CoroutineScope(Dispatchers.IO).launch { + val result = if (nextPageToken == null) { + calendarService + .events() + .list(calendarId) + .setMaxResults(2000) + .setTimeMin(mTimeMin) + .setTimeMax(mTimeMax) + .setSingleEvents(true) + .execute() + } else { + calendarService + .events() + .list(calendarId) + .setPageToken(nextPageToken) + .setMaxResults(2000) + .setTimeMin(mTimeMin) + .setTimeMax(mTimeMax) + .setSingleEvents(true) + .execute() + } + result.items.forEachIndexed { index, item -> + Log.i(AAF_TEST, "$index ${item.start?.date} ${item.summary} ${item.start?.dateTime}") +// descriptions.add(item.summary) + withContext(Dispatchers.Main) { + insertCount += calendarEventToDiary(item, calendarId) + } + } + if (result.nextPageToken != null) { + fetchData(context, calendarService, calendarId, result.nextPageToken, total.plus(insertCount)) + } + } + } + + fun calendarEventToDiary(item: Event, calendarId: String): Int { + var count = 0 + val timeMillis = if (item.start?.dateTime != null) item.start.dateTime.value else item.start?.date?.value ?: 0 + if (EasyDiaryDbHelper.findDiary(item.summary) + .none { diary -> diary.currentTimeMillis == timeMillis } + && !(item.description == null && item.summary == null)) { + EasyDiaryDbHelper.insertDiary( + Diary( + BaseDiaryEditingActivity.DIARY_SEQUENCE_INIT, + timeMillis, + if (item.description != null) item.summary else "", + item.description ?: item.summary, + SYMBOL_GOOGLE_CALENDAR, + item?.start?.dateTime == null + ).apply { isHoliday = + calendarId == "ko.south_korea#holiday@group.v.calendar.google.com" + } + ) + count = 1 + } + return count + } } } \ No newline at end of file diff --git a/app/src/main/java/me/blog/korn123/easydiary/adapters/AlarmAdapter.kt b/app/src/main/java/me/blog/korn123/easydiary/adapters/AlarmAdapter.kt index e8ae44675..6c392bf4e 100644 --- a/app/src/main/java/me/blog/korn123/easydiary/adapters/AlarmAdapter.kt +++ b/app/src/main/java/me/blog/korn123/easydiary/adapters/AlarmAdapter.kt @@ -77,6 +77,7 @@ class AlarmAdapter( Alarm.WORK_MODE_DIARY_WRITING -> "${prefix}diary-writing" Alarm.WORK_MODE_DIARY_BACKUP_LOCAL -> "${prefix}diary-backup-local" Alarm.WORK_MODE_DIARY_BACKUP_GMS -> "${prefix}diary-backup-gms" + Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC -> "${prefix}calendar-schedule-sync" else -> "${prefix}unclassified" } } diff --git a/app/src/main/java/me/blog/korn123/easydiary/extensions/Context.kt b/app/src/main/java/me/blog/korn123/easydiary/extensions/Context.kt index 0a0f8630e..bf1045c14 100644 --- a/app/src/main/java/me/blog/korn123/easydiary/extensions/Context.kt +++ b/app/src/main/java/me/blog/korn123/easydiary/extensions/Context.kt @@ -184,7 +184,7 @@ fun Context.getOpenAlarmTabIntent(alarm: Alarm): PendingIntent { putExtra(DIARY_EXECUTION_MODE, EXECUTION_MODE_ACCESS_FROM_OUTSIDE) } } - Alarm.WORK_MODE_DIARY_BACKUP_LOCAL, Alarm.WORK_MODE_DIARY_BACKUP_GMS -> { + Alarm.WORK_MODE_DIARY_BACKUP_LOCAL, Alarm.WORK_MODE_DIARY_BACKUP_GMS, Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC -> { Intent(this, DiaryMainActivity::class.java) } else -> null @@ -273,6 +273,10 @@ fun Context.getAlarmNotification(pendingIntent: PendingIntent, alarm: Alarm): No largeIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_googledrive_upload) description = getString(R.string.schedule_backup_gms_complete) } + Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC -> { + largeIcon = BitmapFactory.decodeResource(resources, R.drawable.logo_google_calendar) + description = "Calendar schedule has been created as a diary." + } } val builder = NotificationCompat.Builder(applicationContext, "${NOTIFICATION_CHANNEL_ID}_alarm") .setDefaults(Notification.DEFAULT_ALL) diff --git a/app/src/main/java/me/blog/korn123/easydiary/fragments/SettingsScheduleFragment.kt b/app/src/main/java/me/blog/korn123/easydiary/fragments/SettingsScheduleFragment.kt index 31105d7b3..6b3ef070c 100644 --- a/app/src/main/java/me/blog/korn123/easydiary/fragments/SettingsScheduleFragment.kt +++ b/app/src/main/java/me/blog/korn123/easydiary/fragments/SettingsScheduleFragment.kt @@ -169,12 +169,14 @@ class SettingsScheduleFragment() : androidx.fragment.app.Fragment() { Alarm.WORK_MODE_DIARY_WRITING -> radioDiaryWriting.isChecked = true Alarm.WORK_MODE_DIARY_BACKUP_LOCAL -> radioDiaryBackupLocal.isChecked = true Alarm.WORK_MODE_DIARY_BACKUP_GMS -> radioDiaryBackupGms.isChecked = true + Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC -> radioCalendarScheduleSync.isChecked = true } radioGroupWorkMode.setOnCheckedChangeListener { _, i -> when (i) { R.id.radio_diary_writing -> temporaryAlarm.workMode = Alarm.WORK_MODE_DIARY_WRITING R.id.radio_diary_backup_local -> temporaryAlarm.workMode = Alarm.WORK_MODE_DIARY_BACKUP_LOCAL R.id.radio_diary_backup_gms -> temporaryAlarm.workMode = Alarm.WORK_MODE_DIARY_BACKUP_GMS + R.id.radio_calendar_schedule_sync -> temporaryAlarm.workMode = Alarm.WORK_MODE_CALENDAR_SCHEDULE_SYNC } } diff --git a/app/src/main/java/me/blog/korn123/easydiary/helper/BaseAlarmWorkExecutor.kt b/app/src/main/java/me/blog/korn123/easydiary/helper/BaseAlarmWorkExecutor.kt index c93d37a70..9cb776f0e 100644 --- a/app/src/main/java/me/blog/korn123/easydiary/helper/BaseAlarmWorkExecutor.kt +++ b/app/src/main/java/me/blog/korn123/easydiary/helper/BaseAlarmWorkExecutor.kt @@ -1,9 +1,24 @@ package me.blog.korn123.easydiary.helper import android.content.Context +import com.google.android.gms.auth.api.signin.GoogleSignIn +import com.google.android.gms.auth.api.signin.GoogleSignInAccount +import com.google.api.client.extensions.android.http.AndroidHttp +import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential +import com.google.api.client.json.gson.GsonFactory +import com.google.api.client.util.DateTime +import com.google.api.services.calendar.CalendarScopes +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import me.blog.korn123.commons.utils.EasyDiaryUtils +import me.blog.korn123.easydiary.activities.BaseDiaryEditingActivity import me.blog.korn123.easydiary.extensions.exportRealmFile import me.blog.korn123.easydiary.extensions.openNotification import me.blog.korn123.easydiary.models.Alarm +import me.blog.korn123.easydiary.models.Diary +import java.util.Calendar open class BaseAlarmWorkExecutor(val context: Context) { open fun executeWork(alarm: Alarm) { diff --git a/app/src/main/java/me/blog/korn123/easydiary/models/Alarm.kt b/app/src/main/java/me/blog/korn123/easydiary/models/Alarm.kt index 6356b80b5..8ff5ec071 100644 --- a/app/src/main/java/me/blog/korn123/easydiary/models/Alarm.kt +++ b/app/src/main/java/me/blog/korn123/easydiary/models/Alarm.kt @@ -28,5 +28,6 @@ open class Alarm : RealmObject { const val WORK_MODE_DIARY_WRITING = 0 const val WORK_MODE_DIARY_BACKUP_GMS = 1 const val WORK_MODE_DIARY_BACKUP_LOCAL = 2 + const val WORK_MODE_CALENDAR_SCHEDULE_SYNC = 3 } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_alarm.xml b/app/src/main/res/layout/dialog_alarm.xml index 1e973171d..2d01402dc 100644 --- a/app/src/main/res/layout/dialog_alarm.xml +++ b/app/src/main/res/layout/dialog_alarm.xml @@ -123,6 +123,13 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> +