mirror of
https://github.com/alibaba/Tangram-Android.git
synced 2026-10-17 05:07:05 +08:00
Remove rx support.
This commit is contained in:
@@ -510,14 +510,6 @@ public class BaseTangramEngine<O, T> implements ServiceManager {
|
||||
return type.cast(service);
|
||||
}
|
||||
|
||||
public void setSupportRx(boolean supportRx) {
|
||||
isSupportRx = supportRx;
|
||||
TimerSupport timerSupport = getService(TimerSupport.class);
|
||||
if (timerSupport != null) {
|
||||
timerSupport.setSupportRx(supportRx);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportRx() {
|
||||
return isSupportRx;
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/14.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/14
|
||||
*/
|
||||
|
||||
public class BannerScrollStateChangedObservable extends Observable<Integer> {
|
||||
|
||||
private final RxBannerListener mBannerListener;
|
||||
|
||||
public BannerScrollStateChangedObservable(RxBannerScrollStateChangedListener bannerListener) {
|
||||
mBannerListener = bannerListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeActual(Observer<? super Integer> observer) {
|
||||
observer.onSubscribe(mBannerListener);
|
||||
mBannerListener.addObserver(observer);
|
||||
}
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import com.tmall.wireless.tangram3.support.RxBannerScrolledListener.ScrollEvent;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/14.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/14
|
||||
*/
|
||||
|
||||
public class BannerScrolledObservable extends Observable<ScrollEvent> {
|
||||
|
||||
private final RxBannerListener mBannerListener;
|
||||
|
||||
public BannerScrolledObservable(RxBannerScrolledListener bannerListener) {
|
||||
mBannerListener = bannerListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeActual(Observer<? super ScrollEvent> observer) {
|
||||
observer.onSubscribe(mBannerListener);
|
||||
mBannerListener.addObserver(observer);
|
||||
}
|
||||
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/9.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/09
|
||||
*/
|
||||
|
||||
public class BannerSelectedObservable extends Observable<Integer> {
|
||||
|
||||
private final RxBannerListener mBannerListener;
|
||||
|
||||
public BannerSelectedObservable(RxBannerSelectedListener bannerListener) {
|
||||
mBannerListener = bannerListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeActual(Observer<? super Integer> observer) {
|
||||
observer.onSubscribe(mBannerListener);
|
||||
mBannerListener.addObserver(observer);
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,11 @@ package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import android.support.v4.util.ArrayMap;
|
||||
|
||||
import com.tmall.wireless.tangram3.support.RxBannerScrolledListener.ScrollEvent;
|
||||
import com.tmall.wireless.tangram3.ext.BannerListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
||||
/**
|
||||
* You can get banner scroll info from this support
|
||||
* Created by mikeafc on 17/4/9.
|
||||
@@ -78,42 +75,6 @@ public class BannerSupport {
|
||||
return mScrollStateListenerArrayMap.get(id);
|
||||
}
|
||||
|
||||
public Observable<Integer> observeSelected(String id) {
|
||||
List<BannerListener> list = mSelectedListenerArrayMap.get(id);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
mSelectedListenerArrayMap.put(id, list);
|
||||
}
|
||||
RxBannerSelectedListener rxBannerSelectedListener = new RxBannerSelectedListener();
|
||||
list.add(rxBannerSelectedListener);
|
||||
BannerSelectedObservable bannerSupportObservable = new BannerSelectedObservable(rxBannerSelectedListener);
|
||||
return bannerSupportObservable;
|
||||
}
|
||||
|
||||
public Observable<ScrollEvent> observeScrolled(String id) {
|
||||
List<BannerListener> list = mScrolledListenerArrayMap.get(id);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
mScrolledListenerArrayMap.put(id, list);
|
||||
}
|
||||
RxBannerScrolledListener rxBannerSelectedListener = new RxBannerScrolledListener();
|
||||
list.add(rxBannerSelectedListener);
|
||||
BannerScrolledObservable bannerSupportObservable = new BannerScrolledObservable(rxBannerSelectedListener);
|
||||
return bannerSupportObservable;
|
||||
}
|
||||
|
||||
public Observable<Integer> observeScrollStateChanged(String id) {
|
||||
List<BannerListener> list = mScrollStateListenerArrayMap.get(id);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
mScrollStateListenerArrayMap.put(id, list);
|
||||
}
|
||||
RxBannerScrollStateChangedListener rxBannerSelectedListener = new RxBannerScrollStateChangedListener();
|
||||
list.add(rxBannerSelectedListener);
|
||||
BannerScrollStateChangedObservable bannerSupportObservable = new BannerScrollStateChangedObservable(rxBannerSelectedListener);
|
||||
return bannerSupportObservable;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
destroyBannerSelected();
|
||||
destroyBannerScrolled();
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import com.tmall.wireless.tangram3.op.ClickExposureCellOp;
|
||||
import com.tmall.wireless.tangram3.util.Preconditions;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/7.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/07
|
||||
*/
|
||||
|
||||
public class CellClickObservable extends Observable<ClickExposureCellOp> {
|
||||
|
||||
private ClickExposureCellOp mRxClickExposureEvent;
|
||||
|
||||
private RxClickListener mListener;
|
||||
|
||||
public CellClickObservable(ClickExposureCellOp rxClickExposureEvent) {
|
||||
Preconditions.checkNotNull(rxClickExposureEvent);
|
||||
Preconditions.checkNotNull(rxClickExposureEvent.getArg1());
|
||||
this.mRxClickExposureEvent = rxClickExposureEvent;
|
||||
}
|
||||
|
||||
public void setRxClickExposureEvent(ClickExposureCellOp rxClickExposureEvent) {
|
||||
mRxClickExposureEvent = rxClickExposureEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeActual(Observer<? super ClickExposureCellOp> observer) {
|
||||
if (!Preconditions.checkMainThread(observer)) {
|
||||
return;
|
||||
}
|
||||
if (mListener == null) {
|
||||
mListener = new RxClickListener(mRxClickExposureEvent, observer);
|
||||
} else {
|
||||
mListener.setRxClickExposureEvent(mRxClickExposureEvent);
|
||||
mListener.setObserver(observer);
|
||||
}
|
||||
observer.onSubscribe(mListener);
|
||||
mRxClickExposureEvent.getArg1().setOnClickListener(mListener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import com.tmall.wireless.tangram3.op.ClickExposureCellOp;
|
||||
import com.tmall.wireless.tangram3.util.Preconditions;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/7.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/07
|
||||
*/
|
||||
|
||||
public class CellExposureObservable extends Observable<ClickExposureCellOp> {
|
||||
|
||||
private ClickExposureCellOp mRxClickExposureEvent;
|
||||
|
||||
private ExposureDispose mExposureDispose;
|
||||
|
||||
public CellExposureObservable(ClickExposureCellOp rxClickExposureEvent) {
|
||||
Preconditions.checkNotNull(rxClickExposureEvent);
|
||||
Preconditions.checkNotNull(rxClickExposureEvent.getArg1());
|
||||
this.mRxClickExposureEvent = rxClickExposureEvent;
|
||||
}
|
||||
|
||||
public void setRxClickExposureEvent(ClickExposureCellOp rxClickExposureEvent) {
|
||||
mRxClickExposureEvent = rxClickExposureEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeActual(Observer<? super ClickExposureCellOp> observer) {
|
||||
if (mExposureDispose == null) {
|
||||
mExposureDispose = new ExposureDispose();
|
||||
}
|
||||
observer.onSubscribe(mExposureDispose);
|
||||
if (!mExposureDispose.isDisposed()) {
|
||||
observer.onNext(mRxClickExposureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExposureDispose implements Disposable {
|
||||
|
||||
private final AtomicBoolean unsubscribed = new AtomicBoolean();
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
unsubscribed.compareAndSet(false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisposed() {
|
||||
return unsubscribed.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import com.tmall.wireless.tangram3.ext.BannerListener;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.MainThreadDisposable;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/9.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/09
|
||||
*/
|
||||
|
||||
public abstract class RxBannerListener<T> extends MainThreadDisposable implements BannerListener {
|
||||
|
||||
protected Observer<? super T> mObserver;
|
||||
|
||||
public void addObserver(Observer<? super T> observer) {
|
||||
mObserver = observer;
|
||||
}
|
||||
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels, int direction) {
|
||||
|
||||
}
|
||||
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
}
|
||||
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
public void onItemPositionInBanner(int position) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDispose() {
|
||||
mObserver = null;
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/9.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/09
|
||||
*/
|
||||
|
||||
public class RxBannerScrollStateChangedListener extends RxBannerListener<Integer> {
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(final int state) {
|
||||
if (!isDisposed()) {
|
||||
mObserver.onNext(state);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import com.tmall.wireless.tangram3.support.RxBannerScrolledListener.ScrollEvent;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/9.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/09
|
||||
*/
|
||||
|
||||
public class RxBannerScrolledListener extends RxBannerListener<ScrollEvent> {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels, int direction) {
|
||||
if (!isDisposed()) {
|
||||
mObserver.onNext(new ScrollEvent(position, positionOffset, positionOffsetPixels));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
|
||||
public static class ScrollEvent {
|
||||
|
||||
public final int position;
|
||||
public final float positionOffset;
|
||||
public final int positionOffsetPixels;
|
||||
|
||||
public ScrollEvent(int position, float positionOffset, int positionOffsetPixels) {
|
||||
this.position = position;
|
||||
this.positionOffset = positionOffset;
|
||||
this.positionOffsetPixels = positionOffsetPixels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ScrollEvent{" +
|
||||
"position=" + position +
|
||||
", positionOffset=" + positionOffset +
|
||||
", positionOffsetPixels=" + positionOffsetPixels +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/9.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/09
|
||||
*/
|
||||
|
||||
public class RxBannerSelectedListener extends RxBannerListener<Integer> {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(final int position) {
|
||||
if (!isDisposed()) {
|
||||
mObserver.onNext(position);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.tmall.wireless.tangram3.op.ClickExposureCellOp;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.MainThreadDisposable;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/7.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/07
|
||||
*/
|
||||
|
||||
public class RxClickListener extends MainThreadDisposable implements View.OnClickListener {
|
||||
|
||||
private ClickExposureCellOp mRxClickExposureEvent;
|
||||
|
||||
private Observer<? super ClickExposureCellOp> mObserver;
|
||||
|
||||
public RxClickListener(ClickExposureCellOp rxClickExposureEvent, Observer<? super ClickExposureCellOp> observer) {
|
||||
this.mRxClickExposureEvent = rxClickExposureEvent;
|
||||
this.mObserver = observer;
|
||||
}
|
||||
|
||||
public void setRxClickExposureEvent(ClickExposureCellOp rxClickExposureEvent) {
|
||||
mRxClickExposureEvent = rxClickExposureEvent;
|
||||
}
|
||||
|
||||
public void setObserver(Observer<? super ClickExposureCellOp> observer) {
|
||||
mObserver = observer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!isDisposed()) {
|
||||
mObserver.onNext(mRxClickExposureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDispose() {
|
||||
mRxClickExposureEvent.getArg1().setOnClickListener(null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Alibaba Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.tmall.wireless.tangram3.support;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.tmall.wireless.tangram3.support.HandlerTimer.TimerStatus;
|
||||
import com.tmall.wireless.tangram3.support.TimerSupport.OnTickListener;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Action;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Predicate;
|
||||
|
||||
/**
|
||||
* Created by longerian on 2018/3/8.
|
||||
*
|
||||
* @author longerian
|
||||
* @date 2018/03/08
|
||||
*/
|
||||
|
||||
public class RxTimer implements ITimer {
|
||||
|
||||
private long mInterval;
|
||||
|
||||
private TimerStatus mStatus;
|
||||
|
||||
private boolean pause;
|
||||
|
||||
private Observable<Long> mIntervalObservable;
|
||||
|
||||
private ArrayMap<OnTickListener, Disposable> tickCache = new ArrayMap<>();
|
||||
|
||||
public RxTimer(long interval) {
|
||||
this.mInterval = interval;
|
||||
this.mStatus = TimerStatus.Waiting;
|
||||
this.mIntervalObservable = Observable
|
||||
.interval(0, this.mInterval, TimeUnit.MILLISECONDS)
|
||||
.doOnSubscribe(new Consumer<Disposable>() {
|
||||
@Override
|
||||
public void accept(Disposable disposable) throws Exception {
|
||||
mStatus = TimerStatus.Running;
|
||||
Log.d("RxTimerSupportTest", "accept " + disposable + " status " + mStatus);
|
||||
}
|
||||
})
|
||||
.doOnDispose(new Action() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
mStatus = TimerStatus.Paused;
|
||||
Log.d("RxTimerSupportTest", "on dispose " + " status " + mStatus);
|
||||
}
|
||||
})
|
||||
.doOnTerminate(new Action() {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
mStatus = TimerStatus.Stopped;
|
||||
Log.d("RxTimerSupportTest", "on terminate " + " status " + mStatus);
|
||||
}
|
||||
})
|
||||
.share();
|
||||
}
|
||||
|
||||
public void register(final int interval, @NonNull final OnTickListener onTickListener, boolean intermediate) {
|
||||
Disposable disposable = this.mIntervalObservable.delaySubscription(intermediate ? 0 : interval * mInterval, TimeUnit.MILLISECONDS).skipWhile(
|
||||
|
||||
new Predicate<Long>() {
|
||||
@Override
|
||||
public boolean test(Long aLong) throws Exception {
|
||||
return pause;
|
||||
}
|
||||
}).observeOn(
|
||||
AndroidSchedulers.mainThread()).subscribe(new Consumer<Long>() {
|
||||
|
||||
@Override
|
||||
public void accept(Long count) throws Exception {
|
||||
Log.d("RxTimerSupportTest", "accept " + " value " + count);
|
||||
if (count % interval == 0) {
|
||||
if (onTickListener != null) {
|
||||
onTickListener.onTick();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
tickCache.put(onTickListener, disposable);
|
||||
}
|
||||
|
||||
public void unregister(OnTickListener onTickListener) {
|
||||
Disposable disposable = tickCache.get(onTickListener);
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
tickCache.remove(onTickListener);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRegistered(@NonNull OnTickListener onTickListener) {
|
||||
return tickCache.containsKey(onTickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
//no need
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(boolean bySecond) {
|
||||
//no need
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
pause = true;
|
||||
mStatus = TimerStatus.Paused;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restart() {
|
||||
pause = false;
|
||||
if (mStatus == TimerStatus.Paused) {
|
||||
mStatus = TimerStatus.Running;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
for (int i = 0, size = tickCache.size(); i < size; i++) {
|
||||
Disposable disposable = tickCache.valueAt(i);
|
||||
disposable.dispose();
|
||||
}
|
||||
tickCache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
//no need
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
tickCache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimerStatus getStatus() {
|
||||
return mStatus;
|
||||
}
|
||||
}
|
||||
@@ -42,18 +42,6 @@ public class TimerSupport {
|
||||
|
||||
private ITimer mDefaultTimer = new HandlerTimer(MILLISECOND);
|
||||
|
||||
public void setSupportRx(boolean supportRx) {
|
||||
if (supportRx) {
|
||||
if (!(mDefaultTimer instanceof RxTimer)) {
|
||||
mDefaultTimer = new RxTimer(MILLISECOND);
|
||||
}
|
||||
} else {
|
||||
if (!(mDefaultTimer instanceof HandlerTimer)) {
|
||||
mDefaultTimer = new HandlerTimer(MILLISECOND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void register(int interval, @NonNull OnTickListener onTickListener) {
|
||||
register(interval, onTickListener, false);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ package com.tmall.wireless.tangram3.support.async;
|
||||
|
||||
import com.tmall.wireless.tangram3.TangramEngine;
|
||||
import com.tmall.wireless.tangram3.dataparser.concrete.Card;
|
||||
import com.tmall.wireless.tangram3.op.LoadGroupOp;
|
||||
import com.tmall.wireless.tangram3.op.LoadMoreOp;
|
||||
import com.tmall.wireless.tangram3.structure.BaseCell;
|
||||
|
||||
import java.util.List;
|
||||
@@ -225,30 +223,6 @@ public class CardLoadSupport {
|
||||
mLoadCardObserver.onNext(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine with {@link #observeCardLoading()}, use this method as success consumer to subscribe to the Observable.<br />
|
||||
* If your request success, provide a {@link LoadGroupOp} with original card and non-empty List<BaseCell>.<br />
|
||||
* Otherwise, provide a {@link LoadGroupOp} with original card and empty List<BaseCell>.
|
||||
* @return A consumer to consume load event.
|
||||
*/
|
||||
public Consumer<LoadGroupOp> asDoLoadFinishConsumer() {
|
||||
return new Consumer<LoadGroupOp>() {
|
||||
@Override
|
||||
public void accept(LoadGroupOp result) throws Exception {
|
||||
Card card = result.getArg1();
|
||||
card.loading = false;
|
||||
List<BaseCell> cells = result.getArg2();
|
||||
if (cells != null && !cells.isEmpty()) {
|
||||
card.loaded = true;
|
||||
card.setCells(cells);
|
||||
card.notifyDataChange();
|
||||
} else {
|
||||
card.loaded = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return An observable start loading more for a card
|
||||
@@ -293,38 +267,4 @@ public class CardLoadSupport {
|
||||
}
|
||||
mLoadMoreObserver.onNext(card);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Combine with {@link #observeCardLoadingMore()}, use this method as success consumer to subscribe to the Observable.<br />
|
||||
* If your request success, provide a {@link LoadMoreOp} with original card, non-empty List<BaseCell> and boolean value to indicate whether there is more.<br />
|
||||
* Otherwise, provide a {@link LoadMoreOp} with original card, empty List<BaseCell> and boolean value to indicate whether there is more.
|
||||
* @return A consumer to consume load more event.
|
||||
*/
|
||||
public Consumer<LoadMoreOp> asDoLoadMoreFinishConsumer() {
|
||||
return new Consumer<LoadMoreOp>() {
|
||||
@Override
|
||||
public void accept(LoadMoreOp result) throws Exception {
|
||||
Card card = result.getArg1();
|
||||
card.loading = false;
|
||||
card.loaded = true;
|
||||
List<BaseCell> cells = result.getArg2();
|
||||
boolean hasMore = result.getArg3();
|
||||
if (cells != null && !cells.isEmpty()) {
|
||||
if (card.page == sInitialPage) {
|
||||
card.setCells(cells);
|
||||
} else {
|
||||
card.addCells(cells);
|
||||
}
|
||||
card.page++;
|
||||
card.hasMore = hasMore;
|
||||
card.notifyDataChange();
|
||||
} else {
|
||||
card.hasMore = hasMore;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user