-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b34c97f
commit 4e0d8b2
Showing
7 changed files
with
228 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
app/src/main/java/com/android/calendar/calendar/ical4android/LocalEvent.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
/* | ||
* Copyright (c) Ricki Hirner (bitfire web engineering). | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the GNU Public License v3.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.gnu.org/licenses/gpl.html | ||
* Copyright (C) 2020 Dominik Schürmann <[email protected]> | ||
* Copyright (c) Ricki Hirner (bitfire web engineering) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.android.calendar.ical4android | ||
|
@@ -20,13 +30,13 @@ import at.bitfire.ical4android.AndroidCalendarFactory | |
import at.bitfire.ical4android.CalendarStorageException | ||
|
||
/** | ||
* Based on ICSx5 | ||
* Based on LocalCalendar in ICSx5 | ||
*/ | ||
class LocalCalendar private constructor( | ||
class AndroidStorageCalendar private constructor( | ||
account: Account, | ||
provider: ContentProviderClient, | ||
id: Long | ||
): AndroidCalendar<LocalEvent>(account, provider, LocalEvent.Factory, id) { | ||
): AndroidCalendar<AndroidStorageEvent>(account, provider, AndroidStorageEvent.Factory, id) { | ||
|
||
companion object { | ||
|
||
|
@@ -134,10 +144,10 @@ class LocalCalendar private constructor( | |
} | ||
|
||
|
||
object Factory: AndroidCalendarFactory<LocalCalendar> { | ||
object Factory: AndroidCalendarFactory<AndroidStorageCalendar> { | ||
|
||
override fun newInstance(account: Account, provider: ContentProviderClient, id: Long) = | ||
LocalCalendar(account, provider, id) | ||
AndroidStorageCalendar(account, provider, id) | ||
|
||
} | ||
|
||
|
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/android/calendar/ical4android/AndroidStorageEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2020 Dominik Schürmann <[email protected]> | ||
* Copyright (c) Ricki Hirner (bitfire web engineering) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.android.calendar.ical4android | ||
|
||
import android.content.ContentProviderOperation.Builder | ||
import android.content.ContentValues | ||
import android.provider.CalendarContract | ||
import at.bitfire.ical4android.AndroidCalendar | ||
import at.bitfire.ical4android.AndroidEvent | ||
import at.bitfire.ical4android.AndroidEventFactory | ||
import at.bitfire.ical4android.Event | ||
|
||
/** | ||
* Based on LocalEvent in ICSx5 | ||
*/ | ||
class AndroidStorageEvent: AndroidEvent { | ||
|
||
// companion object { | ||
// const val COLUMN_LAST_MODIFIED = CalendarContract.Events.SYNC_DATA2 | ||
// } | ||
|
||
var uid: String? = null | ||
// var lastModified = 0L | ||
|
||
private constructor(calendar: AndroidCalendar<AndroidEvent>, values: ContentValues): super(calendar, values) { | ||
uid = values.getAsString(CalendarContract.Events._SYNC_ID) | ||
// lastModified = values.getAsLong(COLUMN_LAST_MODIFIED) ?: 0 | ||
} | ||
|
||
constructor(calendar: AndroidCalendar<AndroidEvent>, event: Event): super(calendar, event) { | ||
uid = event.uid | ||
// lastModified = event.lastModified?.dateTime?.time ?: 0 | ||
} | ||
|
||
override fun populateEvent(row: ContentValues) { | ||
super.populateEvent(row) | ||
|
||
val event = requireNotNull(event) | ||
event.uid = row.getAsString(CalendarContract.Events._SYNC_ID) | ||
|
||
// row.getAsLong(COLUMN_LAST_MODIFIED).let { | ||
// lastModified = it | ||
// event.lastModified = LastModified(DateTime(it)) | ||
// } | ||
} | ||
|
||
override fun buildEvent(recurrence: Event?, builder: Builder) { | ||
super.buildEvent(recurrence, builder) | ||
|
||
if (recurrence == null) { | ||
// master event | ||
builder .withValue(CalendarContract.Events._SYNC_ID, uid) | ||
// .withValue(COLUMN_LAST_MODIFIED, lastModified) | ||
} else { | ||
// exception | ||
builder.withValue(CalendarContract.Events.ORIGINAL_SYNC_ID, uid) | ||
} | ||
} | ||
|
||
|
||
object Factory: AndroidEventFactory<AndroidStorageEvent> { | ||
|
||
override fun fromProvider(calendar: AndroidCalendar<AndroidEvent>, values: ContentValues) = | ||
AndroidStorageEvent(calendar, values) | ||
|
||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/android/calendar/ical4android/IcalExporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (C) 2020 Dominik Schürmann <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.android.calendar.ical4android | ||
|
||
class IcalExporter |
100 changes: 100 additions & 0 deletions
100
app/src/main/java/com/android/calendar/ical4android/IcalImporter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (C) 2020 Dominik Schürmann <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.android.calendar.ical4android | ||
|
||
import android.accounts.Account | ||
import android.content.ContentProviderClient | ||
import android.content.Context | ||
import android.provider.CalendarContract | ||
import at.bitfire.ical4android.Event | ||
import java.io.InputStream | ||
import java.io.InputStreamReader | ||
import java.util.HashSet | ||
|
||
/** | ||
* TODO: | ||
* - don't use _SYNC_ID, https://developer.android.com/reference/android/provider/CalendarContract.SyncColumns | ||
* - use UID_2445? https://github.com/SufficientlySecure/calendar-import-export/search?q=generateUid&unscoped_q=generateUid | ||
* - still detect duplicates and replace them, but without modified time | ||
* | ||
* | ||
* - exporter: work on EventInfoFragment.shareEvent | ||
*/ | ||
class IcalImporter(val context: Context) { | ||
|
||
fun import(inputStream: InputStream, account: Account, calendarId: Long) { | ||
InputStreamReader(inputStream, Charsets.UTF_8).use { reader -> | ||
try { | ||
val events = Event.eventsFromReader(reader) | ||
processEvents(events, account, calendarId) | ||
|
||
// Log.i(Constants.TAG, "Calendar sync successful, ETag=$eTag, lastModified=$lastModified") | ||
// calendar.updateStatusSuccess(eTag, lastModified ?: 0L) | ||
} catch (e: Exception) { | ||
// Log.e(Constants.TAG, "Couldn't process events", e) | ||
// errorMessage = e.localizedMessage | ||
} | ||
} | ||
} | ||
|
||
private fun processEvents(events: List<Event>, account: Account, calendarId: Long) { | ||
// Log.i(Constants.TAG, "Processing ${events.size} events") | ||
val uids = HashSet<String>(events.size) | ||
|
||
for (event in events) { | ||
val uid = event.uid!! | ||
// Log.d(Constants.TAG, "Found VEVENT: $uid") | ||
uids += uid | ||
|
||
// val localEvents = calendar.queryByUID(uid) | ||
// if (localEvents.isEmpty()) { | ||
// Log.d(Constants.TAG, "$uid not in local calendar, adding") | ||
|
||
val client: ContentProviderClient? = context.contentResolver.acquireContentProviderClient(CalendarContract.AUTHORITY) | ||
val calendar = AndroidStorageCalendar.findById(account, client!!, calendarId) | ||
AndroidStorageEvent(calendar, event).add() | ||
|
||
// } else { | ||
// val localEvent = localEvents.first() | ||
// var lastModified = event.lastModified | ||
// | ||
// if (lastModified != null) { | ||
// // process LAST-MODIFIED of exceptions | ||
// for (exception in event.exceptions) { | ||
// val exLastModified = exception.lastModified | ||
// if (exLastModified == null) { | ||
// lastModified = null | ||
// break | ||
// } else if (lastModified != null && exLastModified.dateTime.after(lastModified.date)) | ||
// lastModified = exLastModified | ||
// } | ||
// } | ||
// | ||
// if (lastModified == null || lastModified.dateTime.time > localEvent.lastModified) | ||
// // either there is no LAST-MODIFIED, or LAST-MODIFIED has been increased | ||
// localEvent.update(event) | ||
// else | ||
// Log.d(Constants.TAG, "$uid has not been modified since last sync") | ||
// } | ||
} | ||
|
||
// Log.i(Constants.TAG, "Deleting old events (retaining ${uids.size} events by UID) …") | ||
// val deleted = calendar.retainByUID(uids) | ||
// Log.i(Constants.TAG, "… $deleted events deleted") | ||
} | ||
} |
Oops, something went wrong.