diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-09-13 17:37:20 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-09-13 17:37:20 +0200 |
commit | c0b3c63f2784b58aaea199c01ee8bef65c3ad97c (patch) | |
tree | 5a46e2d799831e6fdde0b923eee52d0f5cee92e5 /src/main/java/de/pixart | |
parent | 6aaeb5f952cc04b99e2d205db6c60de25b1564d8 (diff) |
load contacts and start observer after giving permissions
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 26 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/StartConversationActivity.java | 18 |
2 files changed, 18 insertions, 26 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index af94d017b..d9181aa95 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -241,15 +241,6 @@ public class XmppConnectionService extends Service { public HttpConnectionManager mHttpConnectionManager = new HttpConnectionManager(this); private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true); private long mLastActivity = 0; - private ContentObserver contactObserver = new ContentObserver(null) { - @Override - public void onChange(boolean selfChange) { - super.onChange(selfChange); - if (restoredFromDatabaseLatch.getCount() == 0) { - loadPhoneContacts(); - } - } - }; private MemorizingTrustManager mMemorizingTrustManager; private NotificationService mNotificationService = new NotificationService(this); private ShortcutService mShortcutService = new ShortcutService(this); @@ -1119,8 +1110,7 @@ public class XmppConnectionService extends Service { restoreFromDatabase(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) { - //TODO get this restarted if users gives permission - getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver); + startContactObserver(); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { Log.d(Config.LOGTAG, "starting file observer"); @@ -1162,6 +1152,18 @@ public class XmppConnectionService extends Service { } } + public void startContactObserver() { + getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new ContentObserver(null) { + @Override + public void onChange(boolean selfChange) { + super.onChange(selfChange); + if (restoredFromDatabaseLatch.getCount() == 0) { + loadPhoneContacts(); + } + } + }); + } + @Override public void onTrimMemory(int level) { super.onTrimMemory(level); @@ -1729,7 +1731,7 @@ public class XmppConnectionService extends Service { } Log.d(Config.LOGTAG, "finished merging phone contacts"); mShortcutService.refresh(mInitialAddressbookSyncCompleted.compareAndSet(false, true)); - updateAccountUi(); + updateRosterUi(); } })); } diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index f9d373b27..52bff613c 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -690,21 +690,11 @@ public class StartConversationActivity extends XmppActivity implements XmppConne AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.sync_with_contacts); builder.setMessage(R.string.sync_with_contacts_long); - builder.setPositiveButton(R.string.next, (dialog, which) -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS); - } - }); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - builder.setOnDismissListener(dialog -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS); - } - }); - } + builder.setPositiveButton(R.string.next, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS)); + builder.setOnDismissListener(dialog -> requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS)); builder.create().show(); } else { - requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, 0); + requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_SYNC_CONTACTS); } } } @@ -717,7 +707,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) { - xmppConnectionService.loadPhoneContacts(); + xmppConnectionService.startContactObserver(); } } } |