diff options
author | iNPUTmice <daniel@gultsch.de> | 2015-02-17 11:51:11 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2015-02-17 11:51:11 +0100 |
commit | 67d5ee6b71d036206df03ec09f6188f2fe2f5918 (patch) | |
tree | 33f7e21d09d620c632a4886e6b41fe32cdb919a2 /src/main/java/eu/siacs/conversations/services | |
parent | 62b15a5d26fe5dc52a16b86c1c2658d1b7b5aa1b (diff) |
moved roster loading to async task as well
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services')
-rw-r--r-- | src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 53abd5752..44d77b457 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -16,6 +16,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.FileObserver; import android.os.IBinder; +import android.os.Looper; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.SystemClock; @@ -277,9 +278,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa private LruCache<String, Bitmap> mBitmapCache; private Thread mPhoneContactMergerThread; - private boolean mMessagesInitialized = false; + private boolean mRestoredFromDatabase = false; public boolean areMessagesInitialized() { - return this.mMessagesInitialized; + return this.mRestoredFromDatabase; } public PgpEngine getPgpEngine() { @@ -393,7 +394,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa if (action != null) { switch (action) { case ACTION_MERGE_PHONE_CONTACTS: - PhoneHelper.loadPhoneContacts(getApplicationContext(), new CopyOnWriteArrayList<Bundle>(), this); + if (mRestoredFromDatabase) { + PhoneHelper.loadPhoneContacts(getApplicationContext(), + new CopyOnWriteArrayList<Bundle>(), + this); + } return START_STICKY; case Intent.ACTION_SHUTDOWN: logoutAndSave(); @@ -528,10 +533,8 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa for (final Account account : this.accounts) { account.initOtrEngine(this); - this.databaseBackend.readRoster(account.getRoster()); } - initConversations(); - PhoneHelper.loadPhoneContacts(getApplicationContext(),new CopyOnWriteArrayList<Bundle>(), this); + restoreFromDatabase(); getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); this.fileObserver.startWatching(); @@ -884,7 +887,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa mPhoneContactMergerThread.start(); } - private void initConversations() { + private void restoreFromDatabase() { synchronized (this.conversations) { final Map<String, Account> accountLookupTable = new Hashtable<>(); for (Account account : this.accounts) { @@ -898,13 +901,22 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa new Thread(new Runnable() { @Override public void run() { - Log.d(Config.LOGTAG,"start initilizing messages"); + Log.d(Config.LOGTAG,"restoring roster"); + for(Account account : accounts) { + databaseBackend.readRoster(account.getRoster()); + } + getBitmapCache().evictAll(); + Looper.prepare(); + PhoneHelper.loadPhoneContacts(getApplicationContext(), + new CopyOnWriteArrayList<Bundle>(), + XmppConnectionService.this); + Log.d(Config.LOGTAG,"restoring messages"); for (Conversation conversation : conversations) { conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE)); checkDeletedFiles(conversation); } - mMessagesInitialized = true; - Log.d(Config.LOGTAG,"done intilizing old messages"); + mRestoredFromDatabase = true; + Log.d(Config.LOGTAG,"restored all messages"); updateConversationUi(); } }).start(); |