Java Code Examples for io.reactivex.disposables.Disposable#isDisposed()

The following examples show how to use io.reactivex.disposables.Disposable#isDisposed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BindingUtils.java    From android-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingAdapter("adapter")
public static void bindAdapter(@NonNull ViewPager viewPager, @Nullable PagerAdapter adapter) {
    PagerAdapter oldAdapter = viewPager.getAdapter();

    // Disconnect previous adapter if its Connectable
    if (oldAdapter != null && oldAdapter instanceof Connectable) {
        Disposable subscription = (Disposable) viewPager.getTag(R.integer.tag_subscription);
        if (subscription != null && !subscription.isDisposed()) {
            subscription.dispose();
        }
        viewPager.setTag(R.integer.tag_subscription, null);
    }

    // Store connection (Subscription) if new adapter is Connectable
    if (adapter != null && adapter instanceof Connectable) {
        viewPager.setTag(R.integer.tag_subscription, ((Connectable) adapter).connect());
    }
    viewPager.setAdapter(adapter);
}
 
Example 2
Source File: HeaderAdapter.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
void disposeLoad(final ViewHolder holder) {
  //
  final ViewGroup parent =
      holder.itemView instanceof ViewGroup ? (ViewGroup) holder.itemView : null;
  if (parent != null) {
    for (int i = 0; i < parent.getChildCount(); i++) {
      final View childView = parent.getChildAt(i);
      if (childView instanceof SimpleDraweeView) {
        final Object tag = childView.getTag();
        if (tag instanceof Disposable) {
          final Disposable disposable = (Disposable) tag;
          if (!disposable.isDisposed()) {
            disposable.dispose();
          }
          childView.setTag(null);
        }
      }
    }
  }
}
 
Example 3
Source File: Web3jService.java    From eventeum with Apache License 2.0 5 votes vote down vote up
/**
 * {inheritDoc}
 */
@Override
public FilterSubscription registerEventListener(
        ContractEventFilter eventFilter, ContractEventListener eventListener) {
    log.debug("Registering event filter for event: {}", eventFilter.getId());
    final ContractEventSpecification eventSpec = eventFilter.getEventSpecification();

    final BigInteger startBlock = getStartBlockForEventFilter(eventFilter);

    EthFilter ethFilter = new EthFilter(
            new DefaultBlockParameterNumber(startBlock),
            DefaultBlockParameterName.LATEST, eventFilter.getContractAddress());

    if (eventFilter.getEventSpecification() != null) {
        ethFilter = ethFilter.addSingleTopic(Web3jUtil.getSignature(eventSpec));
    }

    final Flowable<Log> flowable = web3j.ethLogFlowable(ethFilter);

    final Disposable sub = flowable.subscribe(theLog -> {
        asyncTaskService.execute(ExecutorNameFactory.build(EVENT_EXECUTOR_NAME, eventFilter.getNode()), () -> {
            log.debug("Dispatching log: {}", theLog);
            eventListener.onEvent(
                    eventDetailsFactory.createEventDetails(eventFilter, theLog));
        });
    });

    if (sub.isDisposed()) {
        //There was an error subscribing
        throw new BlockchainException(String.format(
                "Failed to subcribe for filter %s.  The subscription is disposed.", eventFilter.getId()));
    }

    return new FilterSubscription(eventFilter, sub, startBlock);
}
 
Example 4
Source File: PubSubBlockSubscriptionStrategy.java    From eventeum with Apache License 2.0 5 votes vote down vote up
private Disposable subscribeToNewHeads() {
    final Disposable disposable = web3j.newHeadsNotifications().subscribe(newHead -> {
        //Need to execute this is a seperate thread to workaround websocket thread deadlock
        asyncService.execute(ExecutorNameFactory.build(PUB_SUB_EXECUTOR_NAME, nodeName),
                () -> triggerListeners(newHead.getParams().getResult()));
    });

    if (disposable.isDisposed()) {
        throw new BlockchainException("Error when subscribing to newheads.  Disposable already disposed.");
    }

    return disposable;
}
 
Example 5
Source File: ProgressObserver.java    From MaoWanAndoidClient with Apache License 2.0 5 votes vote down vote up
@Override
public void onSubscribe(Disposable d) {
    if(!d.isDisposed()){
        progressDialog = new ProgressDialog(mContext);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setMessage(mLoadingText == null ? "正在加载中..." : mLoadingText);
        progressDialog.show();
    }
}
 
Example 6
Source File: RxBus.java    From RxBus2 with Apache License 2.0 5 votes vote down vote up
/**
 * subscriptions unsubscribe
 *
 * @param eventType eventType
 */
private void unSubscribeByEventType(Class eventType) {
    List<Disposable> disposables = subscriptionsByEventType.get(eventType);
    if (disposables != null) {
        Iterator<Disposable> iterator = disposables.iterator();
        while (iterator.hasNext()) {
            Disposable disposable = iterator.next();
            if (disposable != null && !disposable.isDisposed()) {
                disposable.dispose();
                iterator.remove();
            }
        }
    }
}
 
Example 7
Source File: RxJavaHelper.java    From DataBindingAdapter with MIT License 5 votes vote down vote up
public static void disposeObserver(Disposable disposable)
{
    if (disposable != null && !disposable.isDisposed())
    {
        disposable.dispose();
    }
}
 
Example 8
Source File: RxBus.java    From YiZhi with Apache License 2.0 5 votes vote down vote up
/**
 * subscriptions unsubscribe
 *
 * @param eventType eventType
 */
private void unSubscribeByEventType(Class eventType) {
    List<Disposable> disposables = subscriptionsByEventType.get(eventType);
    if (disposables != null) {
        Iterator<Disposable> iterator = disposables.iterator();
        while (iterator.hasNext()) {
            Disposable disposable = iterator.next();
            if (disposable != null && !disposable.isDisposed()) {
                disposable.dispose();
                iterator.remove();
            }
        }
    }
}
 
Example 9
Source File: CacheUtils.java    From RxBus with Apache License 2.0 5 votes vote down vote up
void removeDisposables(final Object subscriber) {
    synchronized (disposablesMap) {
        List<Disposable> disposables = disposablesMap.get(subscriber);
        if (disposables == null) return;
        for (Disposable disposable : disposables) {
            if (disposable != null && !disposable.isDisposed()) {
                disposable.dispose();
            }
        }
        disposables.clear();
        disposablesMap.remove(subscriber);
    }
}
 
Example 10
Source File: BasePresenter.java    From RxJava2RetrofitDemo with Apache License 2.0 5 votes vote down vote up
@Override
public void detachView() {
    for (Disposable disposable : disposables) {
        if (!disposable.isDisposed()) disposable.dispose();
    }
    mView = null;
}
 
Example 11
Source File: BaseRxPresenter.java    From GankGirl with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@CallSuper
@Override
protected void onSave(Bundle state) {
    for (int i = requested.size() - 1; i >= 0; i--) {
        int restartableId = requested.get(i);
        Disposable disposable = restartableDisposables.get(restartableId);
        if (disposable != null && disposable.isDisposed())
            requested.remove(i);
    }
    state.putIntegerArrayList(REQUESTED_KEY, requested);
}
 
Example 12
Source File: ReadOnlyField.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
    super.removeOnPropertyChangedCallback(callback);
    Disposable subscription = subscriptions.remove(callback);
    if (subscription != null && !subscription.isDisposed()) {
        subscription.dispose();
    }
}
 
Example 13
Source File: RecyclerViewAdapter.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Override
public void unregisterAdapterDataObserver(RecyclerView.AdapterDataObserver observer) {
    super.unregisterAdapterDataObserver(observer);
    Disposable subscription = subscriptions.remove(observer);
    if (subscription != null && !subscription.isDisposed()) {
        subscription.dispose();
    }
}
 
Example 14
Source File: SearchAdapter.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewRecycled(@NonNull SearchAdapter.SearchResHolder holder) {
  super.onViewRecycled(holder);
  if ((holder).mImage.getTag() != null) {
    Disposable disposable = (Disposable) (holder).mImage.getTag();
    if (!disposable.isDisposed()) {
      disposable.dispose();
    }
  }
  holder.mImage.setImageURI(Uri.EMPTY);
}
 
Example 15
Source File: RxUtils.java    From MovieGuide with MIT License 4 votes vote down vote up
public static void unsubscribe(Disposable subscription) {
    if (subscription != null && !subscription.isDisposed()) {
        subscription.dispose();
    } // else subscription doesn't exist or already unsubscribed
}
 
Example 16
Source File: Rx.java    From klingar with Apache License 2.0 4 votes vote down vote up
public static void dispose(Disposable disposable) {
  if (disposable != null && !disposable.isDisposed()) {
    disposable.dispose();
  }
}
 
Example 17
Source File: RxUtil.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
public static void safeUnsubscribe(Disposable subscription) {
    if (subscription != null && !subscription.isDisposed()) {
        subscription.dispose();
    }
}
 
Example 18
Source File: EasyHttp.java    From RxEasyHttp with Apache License 2.0 4 votes vote down vote up
/**
 * 取消订阅
 */
public static void cancelSubscription(Disposable disposable) {
    if (disposable != null && !disposable.isDisposed()) {
        disposable.dispose();
    }
}
 
Example 19
Source File: RxUtils.java    From Mount with GNU General Public License v3.0 4 votes vote down vote up
public static void disposeSafety(Disposable disposable) {
    if (disposable != null && !disposable.isDisposed()) {
        disposable.dispose();
    }
}
 
Example 20
Source File: BaseRxPresenter.java    From GankGirl with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 检查如果取消订阅可重新开始的。
 *
 * @param restartableId 重新请求ID
 * @return 如果订阅是null或unsubscribed 返回true 否则false 。
 */
public boolean isUnsubscribed(int restartableId) {
    Disposable disposable = restartableDisposables.get(restartableId);
    return disposable == null || disposable.isDisposed();
}