Skip to content

Commit

Permalink
optimized sync because of GitHub issue 65
Browse files Browse the repository at this point in the history
  • Loading branch information
konradrenner committed Sep 10, 2015
1 parent cc4b125 commit de6adf8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="richeditor-android-0.1" level="project" />
<orderEntry type="library" exported="" name="kolabnotes-java-1.2.0" level="project" />
<orderEntry type="library" exported="" name="materialdrawer-3.1.2" level="project" />
<orderEntry type="library" exported="" name="kore-javamail-1.0.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
Expand All @@ -105,7 +106,6 @@
<orderEntry type="library" exported="" name="iconics-1.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="kolabnotes-java-1.1.0" level="project" />
<orderEntry type="library" exported="" name="ambilwarna-2.0" level="project" />
</component>
</module>
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/org/kore/kolabnotes/android/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit de6adf8

Please sign in to comment.