Avoid starting the phone-book-sync-thread twice at the same time.

This commit is contained in:
B. Petersen
2016-11-20 21:56:54 +01:00
parent b2714a195f
commit 4f6c374597
5 changed files with 48 additions and 25 deletions
@@ -53,7 +53,8 @@ public class ContactsController {
return "";
}
ContentResolver cr = ApplicationLoader.applicationContext.getContentResolver();
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projectionNames, null, null, null);
Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, // <-- this works, but I do not understand it (did not got the time, yet (bp))
projectionNames, null, null, null);
if (pCur != null && pCur.getCount() > 0) {
while (pCur.moveToNext()) {
String display_name = pCur.getString(0);
@@ -655,14 +655,17 @@ public class NotificationsController {
return;
}
lastBadgeCount = count;
// support icon unread counts of "Nova Launcher", see http://novalauncher.com/teslaunread-api/
try {
ContentValues cv = new ContentValues();
cv.put("tag", "org.telegram.messenger/org.telegram.ui.LaunchActivity");
cv.put("count", count);
ApplicationLoader.applicationContext.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"), cv);
} catch (Throwable e) {
//ignore
}
try {
if (launcherClassName == null) {
launcherClassName = getLauncherClassName(ApplicationLoader.applicationContext);
@@ -148,44 +148,61 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter
delegate = null;
}
private volatile boolean m_in_sync = false;
@Override
public View createView(Context context) {
// do sync?
boolean do_sync_now = true;
if( m_in_sync ) {
do_sync_now = false;
}
else {
m_in_sync = true;
}
// initialize action
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if( title != null ) {
actionBar.setTitle(title);
if( subtitle != null ) {
actionBar.setSubtitle("Synchronizing, please wait ...");
actionBar.setSubtitle(do_sync_now? LocaleController.getString("OneMomentPlease", R.string.OneMomentPlease) : subtitle);
}
}
// sync phone book (the globalQueue is in the main thread)
Utilities.searchQueue.postRunnable(new Runnable() {
@Override
public void run() {
String pbcontacts = ContactsController.getInstance().readContactsFromPhoneBook();
if( !pbcontacts.isEmpty() ) {
if( MrMailbox.MrMailboxAddAddressBook(MrMailbox.hMailbox, pbcontacts) > 0 ) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.contactsDidLoaded);
}
});
}
}
if( do_sync_now ) {
Utilities.searchQueue.postRunnable(new Runnable() {
@Override
public void run() {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if( subtitle != null ) {
actionBar.setSubtitle(subtitle);
String pbcontacts = ContactsController.getInstance().readContactsFromPhoneBook();
if (!pbcontacts.isEmpty()) {
if (MrMailbox.MrMailboxAddAddressBook(MrMailbox.hMailbox, pbcontacts) > 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.contactsDidLoaded);
}
});
}
}
});
}
});
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (subtitle != null) {
actionBar.setSubtitle(subtitle);
}
}
});
m_in_sync = false;
}
});
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
@@ -722,4 +722,5 @@
<string name="ContactDeleted">Benutzer gelöscht.</string>
<string name="ContactCreated">Benutzer angelegt.</string>
<string name="ViewProfile">Profil anzeigen</string>
<string name="OneMomentPlease">Einen Moment, bitte...</string>
</resources>
@@ -722,4 +722,5 @@
<string name="ContactDeleted">User deleted.</string>
<string name="ContactCreated">User created.</string>
<string name="ViewProfile">View profile</string>
<string name="OneMomentPlease">One moment, please...</string>
</resources>