From 01a10756b97c8b119f4e4e027f25a59c90aee185 Mon Sep 17 00:00:00 2001 From: Gavriil Sitnikov Date: Thu, 14 Apr 2016 19:22:47 +0300 Subject: [PATCH] static fix --- .../telephony/IsCallingObserver.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/touchin/roboswag/components/telephony/IsCallingObserver.java b/src/main/java/ru/touchin/roboswag/components/telephony/IsCallingObserver.java index 6608a5f..a393c18 100644 --- a/src/main/java/ru/touchin/roboswag/components/telephony/IsCallingObserver.java +++ b/src/main/java/ru/touchin/roboswag/components/telephony/IsCallingObserver.java @@ -23,10 +23,10 @@ import android.Manifest; import android.content.Context; import android.support.annotation.NonNull; import android.support.annotation.RequiresPermission; -import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import rx.Observable; +import rx.Subscriber; /** * Created by Gavriil Sitnikov on 02/11/2015. @@ -44,13 +44,7 @@ public final class IsCallingObserver { isCallingObservable = Observable .create(subscriber -> { final TelephonyManager phoneStateManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - phoneStateManager.listen(new PhoneStateListener() { - @Override - public void onCallStateChanged(final int state, final String incomingNumber) { - super.onCallStateChanged(state, incomingNumber); - subscriber.onNext(isCallingState(state)); - } - }, PhoneStateListener.LISTEN_CALL_STATE); + phoneStateManager.listen(new PhoneStateListener(subscriber), PhoneStateListener.LISTEN_CALL_STATE); subscriber.onNext(isCallingState(phoneStateManager.getCallState())); }) .distinctUntilChanged() @@ -64,4 +58,22 @@ public final class IsCallingObserver { return isCallingObservable; } + private static class PhoneStateListener extends android.telephony.PhoneStateListener { + + @NonNull + private final Subscriber subscriber; + + public PhoneStateListener(@NonNull final Subscriber subscriber) { + super(); + this.subscriber = subscriber; + } + + @Override + public void onCallStateChanged(final int state, final String incomingNumber) { + super.onCallStateChanged(state, incomingNumber); + subscriber.onNext(isCallingState(state)); + } + + } + }