From a5d4fa1a519804e2ed353f871d6a78fbdc6657d5 Mon Sep 17 00:00:00 2001 From: Zhanty Date: Wed, 14 Aug 2019 16:41:56 +0800 Subject: [PATCH] many improvement --- config/repository.gradle | 1 + .../android/base/app/aac/SingleLiveData.java | 26 +++++++++++++++---- .../java/com/android/base/kotlin/ViewEx.kt | 22 +++++++++++++++- .../src/main/res/values-en/base_strings.xml | 1 - lib_media_selector/README.md | 7 ++++- lib_media_selector/build.gradle | 15 +++++------ .../sdk/social/wechat/SingleLiveData.java | 24 ++++++++++++++--- 7 files changed, 75 insertions(+), 21 deletions(-) diff --git a/config/repository.gradle b/config/repository.gradle index c21208a..d31aff4 100644 --- a/config/repository.gradle +++ b/config/repository.gradle @@ -258,6 +258,7 @@ static Repository innerNewRepository() { /*image view about*/ //https://github.com/chrisbanes/PhotoView photoView : 'com.github.chrisbanes:PhotoView:2.1.3', + rotatePhotoView :'com.chensl.rotatephotoview:rotatephotoview:1.0.5', //https://github.com/davemorrissey/subsampling-scale-image-view subsamplingScaleImageView: 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0', //https://github.com/hdodenhof/CircleImageView diff --git a/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java b/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java index 7d24096..f16a126 100644 --- a/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java +++ b/lib_base/src/main/java/com/android/base/app/aac/SingleLiveData.java @@ -19,7 +19,6 @@ public class SingleLiveData extends MediatorLiveData { private final List>> mWrapperObserverList = new ArrayList<>(); - @Override public void observe(@NonNull LifecycleOwner owner, @NonNull Observer observer) { super.observe(owner, getOrNewObserver(observer, mVersion)); @@ -38,10 +37,27 @@ public class SingleLiveData extends MediatorLiveData { @Override public void removeObserver(@NonNull Observer observer) { - Observer wrapper = findWrapper(observer); - Timber.d("removeObserver() called with: observer = [" + observer + "], wrapper = [" + wrapper + "]"); - if (wrapper != null) { + if (observer instanceof ObserverWrapper) { + super.removeObserver(observer); + removeWrapper((ObserverWrapper) observer); + Timber.d("removeObserver() called with: observer = wrapper = [" + observer + "]"); + } else { + ObserverWrapper wrapper = findWrapper(observer); + Timber.d("removeObserver() called with: observer = [" + observer + "], wrapper = [" + wrapper + "]"); super.removeObserver(wrapper); + removeWrapper(wrapper); + } + } + + private void removeWrapper(ObserverWrapper observer) { + ListIterator>> iterator = mWrapperObserverList.listIterator(); + while (iterator.hasNext()) { + WeakReference> next = iterator.next(); + ObserverWrapper item = next.get(); + if (item == observer) { + iterator.remove(); + break; + } } } @@ -56,7 +72,7 @@ public class SingleLiveData extends MediatorLiveData { if (item == null) { iterator.remove(); } else if (item.mOrigin == observer) { - target = item; + target = item; } } diff --git a/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt b/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt index 98d1ec3..6dded22 100644 --- a/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt +++ b/lib_base/src/main/java/com/android/base/kotlin/ViewEx.kt @@ -5,9 +5,13 @@ import android.support.annotation.ColorRes import android.support.annotation.DrawableRes import android.support.v4.content.ContextCompat import android.support.v4.view.ViewCompat +import android.support.v4.widget.NestedScrollView import android.view.View +import android.view.View.FOCUS_DOWN +import android.view.View.FOCUS_UP import android.view.ViewGroup import android.view.ViewTreeObserver +import android.widget.ScrollView import com.android.base.rx.subscribeIgnoreError import com.android.base.utils.android.ViewUtils import com.android.base.utils.android.compat.AndroidVersion.atLeast @@ -149,4 +153,20 @@ fun View.onClickObservable(milliseconds: Long): Observable { .observeOn(AndroidSchedulers.mainThread()) } -inline val ViewGroup.views get() = (0 until childCount).map { getChildAt(it) } \ No newline at end of file +inline val ViewGroup.views get() = (0 until childCount).map { getChildAt(it) } + +fun ScrollView.scrollToBottom() { + fullScroll(FOCUS_DOWN) +} + +fun ScrollView.scrollToTop() { + fullScroll(FOCUS_UP) +} + +fun NestedScrollView.scrollToBottom() { + fullScroll(FOCUS_DOWN) +} + +fun NestedScrollView.scrollToTop() { + fullScroll(FOCUS_UP) +} \ No newline at end of file diff --git a/lib_base/src/main/res/values-en/base_strings.xml b/lib_base/src/main/res/values-en/base_strings.xml index 2e95ced..d1e1c83 100644 --- a/lib_base/src/main/res/values-en/base_strings.xml +++ b/lib_base/src/main/res/values-en/base_strings.xml @@ -3,7 +3,6 @@ Confirm Cancel - Failed to load/(ㄒoㄒ)/~~ Click me to retry diff --git a/lib_media_selector/README.md b/lib_media_selector/README.md index 6f49fcd..ad362b8 100644 --- a/lib_media_selector/README.md +++ b/lib_media_selector/README.md @@ -23,5 +23,10 @@ ## 3 其他备选参考 -  [boxing](https://github.com/Bilibili/boxing) --  [uCrop](https://github.com/Yalantis/uCrop) +-  [Matisse](https://github.com/zhihu/Matisse) -  [ImagePicker](https://github.com/jeasonlzy/ImagePicker) +-  [PictureSelector](https://github.com/LuckSiege/PictureSelector) +-  [Album](https://github.com/yanzhenjie/Album) +-  [uCrop](https://github.com/Yalantis/uCrop) +-  [smartCropper](https://github.com/pqpo/SmartCropper) +-  [simpleCropper](https:github.com/igreenwood/SimpleCropView) \ No newline at end of file diff --git a/lib_media_selector/build.gradle b/lib_media_selector/build.gradle index c8e091f..aa34461 100644 --- a/lib_media_selector/build.gradle +++ b/lib_media_selector/build.gradle @@ -32,11 +32,6 @@ dependencies { /*imageLoader*/ compileOnly thirdLibraries.glide - //other optional - //知乎 Matisse:https://github.com/zhihu/Matisse - //PictureSelector :https://github.com/LuckSiege/PictureSelector - //Album:https://github.com/yanzhenjie/Album - implementation('com.bilibili:boxing:1.0.4') { exclude group: 'com.android.support' } @@ -45,10 +40,12 @@ dependencies { exclude group: 'com.android.support' } - //other optional - //cropper about - // smartCropper:https://github.com/pqpo/SmartCropper - // simpleCropper:https:github.com/igreenwood/SimpleCropView + implementation('com.chensl.rotatephotoview:rotatephotoview:1.0.5') { + exclude group: 'com.android.support', module: 'appcompat' + exclude group: 'com.android.support', module: 'support-v4' + exclude module: 'recyclerview-v7' + } + implementation('com.yalantis:ucrop:2.2.0') { exclude group: 'com.android.support' exclude group: 'com.squareup.okio' diff --git a/lib_social/src/main/java/com/android/sdk/social/wechat/SingleLiveData.java b/lib_social/src/main/java/com/android/sdk/social/wechat/SingleLiveData.java index a0a90e3..cf4031d 100644 --- a/lib_social/src/main/java/com/android/sdk/social/wechat/SingleLiveData.java +++ b/lib_social/src/main/java/com/android/sdk/social/wechat/SingleLiveData.java @@ -19,7 +19,6 @@ public class SingleLiveData extends MediatorLiveData { private final List>> mWrapperObserverList = new ArrayList<>(); - @Override public void observe(@NonNull LifecycleOwner owner, @NonNull Observer observer) { super.observe(owner, getOrNewObserver(observer, mVersion)); @@ -38,10 +37,27 @@ public class SingleLiveData extends MediatorLiveData { @Override public void removeObserver(@NonNull Observer observer) { - Observer wrapper = findWrapper(observer); - Timber.d("removeObserver() called with: observer = [" + observer + "], wrapper = [" + wrapper + "]"); - if (wrapper != null) { + if (observer instanceof ObserverWrapper) { + super.removeObserver(observer); + removeWrapper((ObserverWrapper) observer); + Timber.d("removeObserver() called with: observer = wrapper = [" + observer + "]"); + } else { + ObserverWrapper wrapper = findWrapper(observer); + Timber.d("removeObserver() called with: observer = [" + observer + "], wrapper = [" + wrapper + "]"); super.removeObserver(wrapper); + removeWrapper(wrapper); + } + } + + private void removeWrapper(ObserverWrapper observer) { + ListIterator>> iterator = mWrapperObserverList.listIterator(); + while (iterator.hasNext()) { + WeakReference> next = iterator.next(); + ObserverWrapper item = next.get(); + if (item == observer) { + iterator.remove(); + break; + } } }