diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-11-23 08:30:12 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-11-23 08:51:39 +0100 |
commit | 35d5d97544cd6abc45809a19324898dfbf457467 (patch) | |
tree | 0d358bcb048a3de2aa99f18d1baa71d71b0c29de /src/main/java/de/pixart/messenger/utils | |
parent | 9ec0a87cc28d134c974e8ca0e0b3fda3d89bca7a (diff) |
refactored phone contact loading in preperation for sync
Diffstat (limited to '')
5 files changed, 7 insertions, 83 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java index 146a9784d..71906cd4a 100644 --- a/src/main/java/de/pixart/messenger/utils/Namespace.java +++ b/src/main/java/de/pixart/messenger/utils/Namespace.java @@ -22,4 +22,5 @@ public final class Namespace { public static final String P1_S3_FILE_TRANSFER = "p1:s3filetransfer"; public static final String BOOKMARKS_CONVERSION = "urn:xmpp:bookmarks-conversion:0"; public static final String BOOKMARKS = "storage:bookmarks"; + public static final String SYNCHRONIZATION = "im.quicksy.synchronization"; } diff --git a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java index f5e2ffde1..327ae1904 100644 --- a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java +++ b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java @@ -24,55 +24,6 @@ public class PhoneHelper { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } - public static void loadPhoneContacts(Context context, final OnPhoneContactsLoadedListener listener) { - final List<Bundle> phoneContacts = new ArrayList<>(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { - listener.onPhoneContactsLoaded(phoneContacts); - return; - } - final String[] PROJECTION = new String[]{ContactsContract.Data._ID, - ContactsContract.Data.DISPLAY_NAME, - ContactsContract.Data.PHOTO_URI, - ContactsContract.Data.LOOKUP_KEY, - ContactsContract.CommonDataKinds.Im.DATA}; - - final String SELECTION = "(" + ContactsContract.Data.MIMETYPE + "=\"" - + ContactsContract.CommonDataKinds.Im.CONTENT_ITEM_TYPE - + "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL - + "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER - + "\")"; - - CursorLoader mCursorLoader = new NotThrowCursorLoader(context, - ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null, - null); - mCursorLoader.registerListener(0, (arg0, c) -> { - if (c != null) { - while (c.moveToNext()) { - Bundle contact = new Bundle(); - contact.putInt("phoneid", c.getInt(c.getColumnIndex(ContactsContract.Data._ID))); - contact.putString("displayname", c.getString(c.getColumnIndex(ContactsContract.Data.DISPLAY_NAME))); - contact.putString("photouri", c.getString(c.getColumnIndex(ContactsContract.Data.PHOTO_URI))); - contact.putString("lookup", c.getString(c.getColumnIndex(ContactsContract.Data.LOOKUP_KEY))); - contact.putString("jid", c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA))); - phoneContacts.add(contact); - } - c.close(); - } - - if (listener != null) { - listener.onPhoneContactsLoaded(phoneContacts); - } - }); - try { - mCursorLoader.startLoading(); - } catch (RejectedExecutionException e) { - if (listener != null) { - listener.onPhoneContactsLoaded(phoneContacts); - } - } - } - public static Uri getProfilePictureUri(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { return null; @@ -106,24 +57,6 @@ public class PhoneHelper { } } - private static class NotThrowCursorLoader extends CursorLoader { - - private NotThrowCursorLoader(Context c, Uri u, String[] p, String s, String[] sa, String so) { - super(c, u, p, s, sa, so); - } - - @Override - public Cursor loadInBackground() { - - try { - return (super.loadInBackground()); - } catch (Throwable e) { - return (null); - } - } - - } - public static String getOSVersion(Context context) { return "Android/" + android.os.Build.MODEL + "/" + android.os.Build.VERSION.RELEASE; } diff --git a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java index bf4d6e8c2..79e5126b2 100644 --- a/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java +++ b/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java @@ -3,17 +3,13 @@ package de.pixart.messenger.utils; public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor { public ReplacingSerialSingleThreadExecutor(String name) { - super(name, false); - } - - public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) { - super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper); + super(name); } @Override public synchronized void execute(final Runnable r) { tasks.clear(); - if (active != null && active instanceof Cancellable) { + if (active instanceof Cancellable) { ((Cancellable) active).cancel(); } super.execute(r); @@ -21,8 +17,8 @@ public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecu public synchronized void cancelRunningTasks() { tasks.clear(); - if (active != null && active instanceof Cancellable) { + if (active instanceof Cancellable) { ((Cancellable) active).cancel(); } } -} +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java b/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java index 3c9f386cd..c25c6fce4 100644 --- a/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java +++ b/src/main/java/de/pixart/messenger/utils/ReplacingTaskManager.java @@ -41,7 +41,7 @@ public class ReplacingTaskManager { synchronized (this.executors) { executor = this.executors.get(account); if (executor == null) { - executor = new ReplacingSerialSingleThreadExecutor(false); + executor = new ReplacingSerialSingleThreadExecutor(ReplacingTaskManager.class.getSimpleName()); this.executors.put(account, executor); } executor.execute(runnable); diff --git a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java index 500b03c5b..9846146a8 100644 --- a/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java +++ b/src/main/java/de/pixart/messenger/utils/SerialSingleThreadExecutor.java @@ -16,14 +16,8 @@ public class SerialSingleThreadExecutor implements Executor { private final String name; protected Runnable active; - public SerialSingleThreadExecutor(String name) { - this(name, false); - } - SerialSingleThreadExecutor(String name, boolean prepareLooper) { - if (prepareLooper) { - execute(Looper::prepare); - } + public SerialSingleThreadExecutor(String name) { this.name = name; } |