diff --git a/app/src/main/java/org/ntlab/developrx/DebugSubscriber.java b/app/src/main/java/org/ntlab/developrx/DebugSubscriber.java new file mode 100644 index 0000000..d20a5c2 --- /dev/null +++ b/app/src/main/java/org/ntlab/developrx/DebugSubscriber.java @@ -0,0 +1,47 @@ +package org.ntlab.developrx; + +import org.ntlab.developrx.utils.ThreadUtil; + +import io.reactivex.subscribers.DisposableSubscriber; + +/** + * デバッグ用のSubscriber + * + * Created by matsumoto_k on 2017/11/12. + */ + +public class DebugSubscriber extends DisposableSubscriber { + + private String label; + + public DebugSubscriber(String label) { + this.label = label; + } + + @Override + public void onNext(T data) { + if (label == null) { + System.out.println(ThreadUtil.getCurrentThreadName() + ": " + data); + } else { + System.out.println(ThreadUtil.getCurrentThreadName() + ": " + label + ": " + data); + } + } + + @Override + public void onError(Throwable throwable) { + if (label == null) { + System.out.println(ThreadUtil.getCurrentThreadName() + ": エラー=" + throwable); + } else { + System.out.println(ThreadUtil.getCurrentThreadName() + ": " + label + ": エラー= " + throwable); + } + } + + @Override + public void onComplete() { + if (label == null) { + System.out.println(ThreadUtil.getCurrentThreadName() + ": 完了"); + } else { + System.out.println(ThreadUtil.getCurrentThreadName() + ": " + label + ": 完了"); + } + } +}