diff --git a/app/app.iml b/app/app.iml index bdc95ba..f520b55 100644 --- a/app/app.iml +++ b/app/app.iml @@ -97,6 +97,7 @@ + @@ -105,7 +106,6 @@ - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ccd016b..8a30559 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.kore.kolabnotes.android" minSdkVersion 16 targetSdkVersion 22 - versionCode 25 - versionName "0.3.0" + versionCode 26 + versionName "0.4.0" } buildTypes { release { @@ -29,7 +29,7 @@ android { dependencies { //compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.github.yukuku:ambilwarna:2.0' - compile 'com.github.konradrenner:kolabnotes-java:1.1.0' + compile 'com.github.konradrenner:kolabnotes-java:1.2.0' compile 'com.android.support:support-v4:22.2.0' compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:recyclerview-v7:22.2.0' diff --git a/app/src/main/java/org/kore/kolabnotes/android/Utils.java b/app/src/main/java/org/kore/kolabnotes/android/Utils.java index ca89caf..6cadd20 100755 --- a/app/src/main/java/org/kore/kolabnotes/android/Utils.java +++ b/app/src/main/java/org/kore/kolabnotes/android/Utils.java @@ -31,6 +31,7 @@ import org.kore.kolabnotes.android.widget.ListWidget; import org.kore.kolabnotes.android.widget.StickyNoteWidget; +import java.sql.Timestamp; import java.util.Objects; public class Utils { @@ -172,6 +173,26 @@ public static void configureWindowEnterExitTransition(Window w) { } */ + public static void saveLastSyncTime(Context context) { + SharedPreferences.Editor prefs = context.getSharedPreferences("org.kore.kolabnotes.android.async.KolabSyncAdapter", 0).edit(); + prefs.putLong("lastSyncTst", System.currentTimeMillis()); + prefs.commit(); + } + + public static Timestamp getLastSyncTime(Context context) { + SharedPreferences prefs = context.getSharedPreferences("org.kore.kolabnotes.android.async.KolabSyncAdapter", 0); + if(prefs == null){ + Log.d("getLastSyncTime","KolabSyncAdapter prefs are null"); + return null; + } + long millis = prefs.getLong("lastSyncTst", -1); + if(millis < 0){ + return null; + } + + return new Timestamp(millis); + } + public static void saveNoteSorting(Context context, NoteSorting noteSorting) { SharedPreferences.Editor prefs = context.getSharedPreferences("org.kore.kolabnotes.android.widget.MainActivity", 0).edit(); prefs.putString("direction", noteSorting.getDirection().toString()); diff --git a/app/src/main/java/org/kore/kolabnotes/android/async/KolabSyncAdapter.java b/app/src/main/java/org/kore/kolabnotes/android/async/KolabSyncAdapter.java index 17f7800..c52cf47 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/async/KolabSyncAdapter.java +++ b/app/src/main/java/org/kore/kolabnotes/android/async/KolabSyncAdapter.java @@ -18,11 +18,14 @@ import org.kore.kolab.notes.imap.ImapNotesRepository; import org.kore.kolab.notes.v3.KolabConfigurationParserV3; import org.kore.kolab.notes.v3.KolabNotesParserV3; +import org.kore.kolabnotes.android.MainActivity; import org.kore.kolabnotes.android.R; import org.kore.kolabnotes.android.Utils; import org.kore.kolabnotes.android.content.RepositoryManager; import org.kore.kolabnotes.android.security.AuthenticatorActivity; +import java.sql.Timestamp; + /** * Created by koni on 18.04.15. */ @@ -98,7 +101,15 @@ public void syncNow(Account account, Bundle extras, String authority, ContentPro ImapNotesRepository imapRepository = new ImapNotesRepository(new KolabNotesParserV3(), info, rootFolder, new KolabConfigurationParserV3()); try { if(doit) { - imapRepository.refresh(new RefreshListener()); + final Timestamp lastSyncTime = Utils.getLastSyncTime(context); + + Log.d("syncNow","lastSyncTime:"+lastSyncTime); + //Just load data completely, which was changed after the given date + if(lastSyncTime == null){ + imapRepository.refresh(new RefreshListener()); + }else{ + imapRepository.refresh(lastSyncTime, new RefreshListener()); + } } }catch(Exception e){ final Notification notification = new NotificationCompat.Builder(context) @@ -136,6 +147,7 @@ public void syncNow(Account account, Bundle extras, String authority, ContentPro try{ if(doit) { imapRepository.merge(); + Utils.saveLastSyncTime(context); } }catch(Exception e){ final Notification notification = new NotificationCompat.Builder(context) diff --git a/app/src/main/java/org/kore/kolabnotes/android/content/RepositoryManager.java b/app/src/main/java/org/kore/kolabnotes/android/content/RepositoryManager.java index 2e550ad..a947b1d 100644 --- a/app/src/main/java/org/kore/kolabnotes/android/content/RepositoryManager.java +++ b/app/src/main/java/org/kore/kolabnotes/android/content/RepositoryManager.java @@ -115,8 +115,12 @@ void putLocalDataIntoRepository(String email, String rootFolder){ remoteNote.addCategories(localCategories.toArray(new Tag[localCategories.size()])); remoteNote.setColor(note.getColor()); remoteNote.getAuditInformation().setLastModificationDate(note.getAuditInformation().getLastModificationDate().getTime()); + remoteNote.getAuditInformation().setCreationDate(note.getAuditInformation().getCreationDate().getTime()); } } + }else{ + //Fill the unchanged, unloaded notes, so that in the later step, everything can be replaced in the local repo with data from the remote repo + repo.fillUnloadedNote(note); } }