diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-05-31 17:20:21 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-05-31 17:20:21 +0200 |
commit | ea6a008b39b0f669f66f3c8aec08b4deb3ece154 (patch) | |
tree | 9e009627ab1c2c4c86f4499e7cde6d094b4ec900 /src/main/java/eu/siacs/conversations/utils | |
parent | 1838023c88cee6aa68859ef24227cd81bc47b7f2 (diff) |
execute phone contact changes in singlethreadexecutor
Diffstat (limited to 'src/main/java/eu/siacs/conversations/utils')
3 files changed, 35 insertions, 2 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java index 6c1b4bef5..e3a24fcfa 100644 --- a/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/PhoneHelper.java @@ -13,12 +13,14 @@ import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.Profile; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.RejectedExecutionException; public class PhoneHelper { - public static void loadPhoneContacts(Context context, final List<Bundle> phoneContacts, final OnPhoneContactsLoadedListener listener) { + 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); diff --git a/src/main/java/eu/siacs/conversations/utils/ReplacingSerialSingleThreadExecutor.java b/src/main/java/eu/siacs/conversations/utils/ReplacingSerialSingleThreadExecutor.java new file mode 100644 index 000000000..dc8a0a825 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/utils/ReplacingSerialSingleThreadExecutor.java @@ -0,0 +1,14 @@ +package eu.siacs.conversations.utils; + +public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor { + + public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) { + super(prepareLooper); + } + + @Override + public synchronized void execute(final Runnable r) { + tasks.clear(); + super.execute(r); + } +} diff --git a/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java b/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java index bfb4668db..55489ee30 100644 --- a/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java +++ b/src/main/java/eu/siacs/conversations/utils/SerialSingleThreadExecutor.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.utils; +import android.os.Looper; + import java.util.ArrayDeque; import java.util.Queue; import java.util.concurrent.Executor; @@ -8,9 +10,24 @@ import java.util.concurrent.Executors; public class SerialSingleThreadExecutor implements Executor { final Executor executor = Executors.newSingleThreadExecutor(); - final Queue<Runnable> tasks = new ArrayDeque(); + protected final Queue<Runnable> tasks = new ArrayDeque(); Runnable active; + public SerialSingleThreadExecutor() { + this(false); + } + + public SerialSingleThreadExecutor(boolean prepareLooper) { + if (prepareLooper) { + execute(new Runnable() { + @Override + public void run() { + Looper.prepare(); + } + }); + } + } + public synchronized void execute(final Runnable r) { tasks.offer(new Runnable() { public void run() { |