diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-12-11 23:41:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-12-11 23:41:47 +0000 |
commit | 8d3e0f2c0d268c1fda560577e874025b300875df (patch) | |
tree | f9bdf99f330393d3f5a8e2798ae0f97557296e46 /java | |
parent | 04e88264e69ec2b6974a4d9d6acfa7cd27934e5a (diff) | |
parent | 05b6a53db23cf8c2d90442d1c84c14fd09519390 (diff) |
Merge "Don't save UI executor in UiListener."
Diffstat (limited to 'java')
3 files changed, 11 insertions, 9 deletions
diff --git a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java index a5dccaf69..c10b52123 100644 --- a/java/com/android/dialer/calllog/ui/NewCallLogFragment.java +++ b/java/com/android/dialer/calllog/ui/NewCallLogFragment.java @@ -141,7 +141,8 @@ public final class NewCallLogFragment extends Fragment checkDirty ? refreshAnnotatedCallLogWorker.refreshWithDirtyCheck() : refreshAnnotatedCallLogWorker.refreshWithoutDirtyCheck(); - refreshAnnotatedCallLogListener.listen(future, unused -> {}, RuntimeException::new); + refreshAnnotatedCallLogListener.listen( + getContext(), future, unused -> {}, RuntimeException::new); }; ThreadUtil.getUiThreadHandler().postDelayed(refreshAnnotatedCallLogRunnable, WAIT_MILLIS); } diff --git a/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java b/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java index 7ee30a083..28abf96fd 100644 --- a/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java +++ b/java/com/android/dialer/common/concurrent/DialerExecutorComponent.java @@ -36,7 +36,7 @@ public abstract class DialerExecutorComponent { public <OutputT> UiListener<OutputT> createUiListener( FragmentManager fragmentManager, String taskId) { - return UiListener.create(uiExecutorService(), fragmentManager, taskId); + return UiListener.create(fragmentManager, taskId); } @NonUiParallel diff --git a/java/com/android/dialer/common/concurrent/UiListener.java b/java/com/android/dialer/common/concurrent/UiListener.java index 11302d299..9541dbc0c 100644 --- a/java/com/android/dialer/common/concurrent/UiListener.java +++ b/java/com/android/dialer/common/concurrent/UiListener.java @@ -18,6 +18,7 @@ package com.android.dialer.common.concurrent; import android.app.Fragment; import android.app.FragmentManager; +import android.content.Context; import android.os.Bundle; import android.support.annotation.MainThread; import android.support.annotation.NonNull; @@ -29,7 +30,6 @@ import com.android.dialer.common.concurrent.DialerExecutor.SuccessListener; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.util.concurrent.Executor; /** * A headless fragment for use in UI components that interact with ListenableFutures. @@ -53,19 +53,17 @@ import java.util.concurrent.Executor; * * private void userDidSomething() { * ListenableFuture<MyOutputType> future = callSomeMethodReturningListenableFuture(input); - * uiListener.listen(future, this::onSuccess, this::onFailure); + * uiListener.listen(this, future, this::onSuccess, this::onFailure); * } * } * </pre></code> */ public class UiListener<OutputT> extends Fragment { - private Executor uiThreadExecutor; private CallbackWrapper<OutputT> callbackWrapper; @MainThread - static <OutputT> UiListener<OutputT> create( - Executor uiThreadExecutor, FragmentManager fragmentManager, String taskId) { + static <OutputT> UiListener<OutputT> create(FragmentManager fragmentManager, String taskId) { @SuppressWarnings("unchecked") UiListener<OutputT> uiListener = (UiListener<OutputT>) fragmentManager.findFragmentByTag(taskId); @@ -73,7 +71,6 @@ public class UiListener<OutputT> extends Fragment { if (uiListener == null) { LogUtil.i("UiListener.create", "creating new UiListener for " + taskId); uiListener = new UiListener<>(); - uiListener.uiThreadExecutor = uiThreadExecutor; fragmentManager.beginTransaction().add(uiListener, taskId).commit(); } return uiListener; @@ -87,12 +84,16 @@ public class UiListener<OutputT> extends Fragment { */ @MainThread public void listen( + Context context, @NonNull ListenableFuture<OutputT> future, @NonNull SuccessListener<OutputT> successListener, @NonNull FailureListener failureListener) { callbackWrapper = new CallbackWrapper<>(Assert.isNotNull(successListener), Assert.isNotNull(failureListener)); - Futures.addCallback(Assert.isNotNull(future), callbackWrapper, uiThreadExecutor); + Futures.addCallback( + Assert.isNotNull(future), + callbackWrapper, + DialerExecutorComponent.get(context).uiExecutorService()); } private static class CallbackWrapper<OutputT> implements FutureCallback<OutputT> { |