update UIKit

androidx
Ztiany 5 years ago
parent 5bc68bb48e
commit 5c8f152686
  1. 81
      lib_base/src/main/java/com/android/base/app/aac/LiveStateHandler.kt
  2. 11
      lib_base/src/main/java/com/android/base/app/ui/LiveStateHandler.kt
  3. 219
      lib_base/src/main/java/com/android/base/app/ui/UIKit.kt
  4. 2
      lib_base/src/main/java/com/android/base/utils/android/SoftKeyboardUtils.java
  5. 6
      lib_base/src/main/java/com/android/base/widget/pulltozoom/PullToZoomScrollView.java

@ -1,81 +0,0 @@
package com.android.base.app.aac
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.android.base.app.Sword
import com.android.base.app.ui.LoadingView
import com.android.base.data.State
import timber.log.Timber
interface LiveStateHandler {
/**处理异常*/
fun handleError(throwable: Throwable)
}
fun <H, T> H.handleLiveState(
liveData: LiveData<State<T>>,
forceLoading: Boolean = true,
onSuccess: (T?) -> Unit
) where H : LiveStateHandler, H : LoadingView, H : LifecycleOwner {
liveData.observe(this, Observer {
when {
it.isError -> {
Timber.d("handleLiveState -> isError")
dismissLoadingDialog()
handleError(it.error())
}
it.isLoading -> {
Timber.d("handleLiveState -> isLoading")
showLoadingDialog(!forceLoading)
}
it.isSuccess -> {
Timber.d("handleLiveState -> isSuccess")
val minimumShowingDialogMills = Sword.get().minimumShowingDialogMills()
dismissLoadingDialog(minimumShowingDialogMills) {
onSuccess(it.get())
}
}//success end
}
})
}
fun <H, T> H.handleLiveStateWithData(
liveData: LiveData<State<T>>,
forceLoading: Boolean = true,
onEmpty: (() -> Unit)? = null,
onSuccess: (T) -> Unit
) where H : LiveStateHandler, H : LoadingView, H : LifecycleOwner {
liveData.observe(this, Observer {
when {
it.isError -> {
Timber.d("handleLiveStateWithData -> isError")
dismissLoadingDialog()
handleError(it.error())
}
it.isLoading -> {
Timber.d("handleLiveStateWithData -> isLoading")
showLoadingDialog(!forceLoading)
}
it.isSuccess -> {
Timber.d("handleLiveStateWithData -> isSuccess")
val minimumShowingDialogMills = Sword.get().minimumShowingDialogMills()
dismissLoadingDialog(minimumShowingDialogMills) {
if (it.hasData()) {
onSuccess(it.data())
} else {
onEmpty?.invoke()
}
}
}//success end
}
})
}

@ -0,0 +1,11 @@
package com.android.base.app.ui
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.android.base.app.Sword
import com.android.base.data.State
import timber.log.Timber

@ -2,11 +2,89 @@
package com.android.base.app.ui
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import com.android.base.app.Sword
import com.android.base.data.State
import com.android.base.data.StateHandler
import com.android.base.utils.common.isEmpty
import timber.log.Timber
fun <T> RefreshListLayout<T>.handleListResultWithStatus(list: List<T>?, onEmpty: (() -> Unit)? = null) {
//----------------------------------------------Common->Loading->Dialog ----------------------------------------------
interface UIErrorHandler {
/**处理异常*/
fun handleError(throwable: Throwable)
/**异常描述*/
fun generateErrorMessage(throwable: Throwable)
}
fun <H, T> H.handleLiveState(
liveData: LiveData<State<T>>,
forceLoading: Boolean = true,
onSuccess: (T?) -> Unit
) where H : UIErrorHandler, H : LoadingView, H : LifecycleOwner {
liveData.observe(this, Observer { state ->
when {
state.isError -> {
Timber.d("handleLiveState -> isError")
dismissLoadingDialog()
handleError(state.error())
}
state.isLoading -> {
Timber.d("handleLiveState -> isLoading")
showLoadingDialog(!forceLoading)
}
state.isSuccess -> {
Timber.d("handleLiveState -> isSuccess")
val minimumShowingDialogMills = Sword.get().minimumShowingDialogMills()
dismissLoadingDialog(minimumShowingDialogMills) {
onSuccess(state.get())
}
}//success end
}
})
}
fun <T> LoadingView.handleState(
state: State<T>,
forceLoading: Boolean = true,
handler: StateHandler<T>.() -> Unit
) {
val stateHandler = StateHandler<T>()
handler(stateHandler)
when {
state.isError -> {
Timber.d("handleState -> isError")
dismissLoadingDialog()
stateHandler.onError?.invoke(state.error())
}
state.isLoading -> {
Timber.d("handleState -> isLoading")
showLoadingDialog(!forceLoading)
}
state.isSuccess -> {
Timber.d("handleState -> isSuccess")
val minimumShowingDialogMills = Sword.get().minimumShowingDialogMills()
dismissLoadingDialog(minimumShowingDialogMills) {
stateHandler.onSuccess?.invoke(state.get())
if (state.hasData()) {
stateHandler.onSuccessWithData?.invoke(state.data())
} else {
stateHandler.onEmpty?.invoke()
}
}
}//success end
}
}
//----------------------------------------------Loading In List----------------------------------------------
fun <T> RefreshListLayout<T>.handleListResult(list: List<T>?, onEmpty: (() -> Unit)? = null) {
if (isLoadingMore) {
if (!isEmpty(list)) {
addData(list)
@ -31,27 +109,30 @@ fun <T> RefreshListLayout<T>.handleListResultWithStatus(list: List<T>?, onEmpty:
}
}
fun <T> RefreshListLayout<T>.handleListResultWithoutStatus(list: List<T>?, onEmpty: (() -> Unit)? = null) {
if (isLoadingMore) {
if (!isEmpty(list)) {
addData(list)
}
} else {
replaceData(list)
fun RefreshListLayout<*>.handleListError(throwable: Throwable) {
if (isRefreshing) {
refreshCompleted()
}
if (pager != null) {
loadMoreCompleted(list != null && pager.hasMore(list.size))
if (isLoadingMore) {
loadMoreFailed()
}
if (onEmpty != null && isEmpty) {
onEmpty()
if (isEmpty) {
val errorTypeClassifier = Sword.get().errorClassifier()
if (errorTypeClassifier != null) {
when {
errorTypeClassifier.isNetworkError(throwable) -> showNetErrorLayout()
errorTypeClassifier.isServerError(throwable) -> showServerErrorLayout()
else -> showErrorLayout()
}
} else {
showErrorLayout()
}
} else {
showContentLayout()
}
}
fun <T> RefreshListLayout<T>.submitListResultWithStatus(list: List<T>?, hasMore: Boolean, onEmpty: (() -> Unit)? = null) {
fun <T> RefreshListLayout<T>.submitListResult(list: List<T>?, hasMore: Boolean, onEmpty: (() -> Unit)? = null) {
if (isRefreshing) {
refreshCompleted()
}
@ -70,75 +151,119 @@ fun <T> RefreshListLayout<T>.submitListResultWithStatus(list: List<T>?, hasMore:
}
}
fun <T> RefreshListLayout<T>.submitListResultWithoutStatus(list: List<T>?, hasMore: Boolean, onEmpty: (() -> Unit)? = null) {
if (isRefreshing) {
fun <T> RefreshListLayout<T>.handleStateList(state: State<List<T>>, onEmpty: (() -> Unit)? = null) {
when {
state.isLoading -> {
showLoadingIfEmpty()
}
state.isError -> {
handleListError(state.error())
}
state.isSuccess -> {
handleListResult(state.get(), onEmpty)
}
}
}
fun <T> RefreshListLayout<T>.handleStateFullList(state: State<List<T>>, hasMore: Boolean, onEmpty: (() -> Unit)? = null) {
when {
state.isLoading -> {
showLoadingIfEmpty()
}
state.isError -> {
handleListError(state.error())
}
state.isSuccess -> {
submitListResult(state.get(), hasMore, onEmpty)
}
}
}
fun RefreshListLayout<*>.showLoadingIfEmpty() {
if (isEmpty) {
if (isRefreshing) {
showBlank()
} else {
showLoadingLayout()
}
}
}
//----------------------------------------------Loading In List And Without State----------------------------------------------
fun <T> RefreshListLayout<T>.handleListResultWithoutState(list: List<T>?, onEmpty: (() -> Unit)? = null) {
if (isLoadingMore) {
if (!isEmpty(list)) {
addData(list)
}
} else {
replaceData(list)
refreshCompleted()
}
replaceData(list)
loadMoreCompleted(hasMore)
if (pager != null) {
loadMoreCompleted(list != null && pager.hasMore(list.size))
}
if (onEmpty != null && isEmpty) {
onEmpty()
}
}
fun RefreshListLayout<*>.handleListErrorWithStatus(throwable: Throwable) {
fun RefreshListLayout<*>.handleListErrorWithoutState() {
if (isRefreshing) {
refreshCompleted()
}
if (isLoadingMore) {
loadMoreFailed()
}
if (isEmpty) {
val errorTypeClassifier = Sword.get().errorClassifier()
if (errorTypeClassifier != null) {
when {
errorTypeClassifier.isNetworkError(throwable) -> showNetErrorLayout()
errorTypeClassifier.isServerError(throwable) -> showServerErrorLayout()
else -> showErrorLayout()
}
} else {
showErrorLayout()
}
} else {
showContentLayout()
}
}
fun RefreshListLayout<*>.handleListErrorWithoutStatus() {
fun <T> RefreshListLayout<T>.submitListResultWithoutState(list: List<T>?, hasMore: Boolean, onEmpty: (() -> Unit)? = null) {
if (isRefreshing) {
refreshCompleted()
}
if (isLoadingMore) {
loadMoreFailed()
replaceData(list)
loadMoreCompleted(hasMore)
if (onEmpty != null && isEmpty) {
onEmpty()
}
}
fun RefreshListLayout<*>.showLoadingIfEmpty() {
if (isEmpty) {
if (isRefreshing) {
showBlank()
} else {
//----------------------------------------------Loading In StateView----------------------------------------------
fun <T> RefreshStateLayout.handleStateResult(state: State<T>, onEmpty: (() -> Unit)? = null, onResult: ((T) -> Unit)) {
when {
state.isLoading -> {
showLoadingLayout()
}
state.isError -> {
handleResultError(state.error())
}
state.isSuccess -> {
handleResult(state.get(), onEmpty, onResult)
}
}
}
fun <T> RefreshStateLayout.handleResultWithStatus(t: T?, onResult: ((T) -> Unit)) {
fun <T> RefreshStateLayout.handleResult(t: T?, onEmpty: (() -> Unit)? = null, onResult: ((T) -> Unit)) {
if (isRefreshing) {
refreshCompleted()
}
if (t == null || (t is Collection<*> && t.isEmpty()) || (t is Map<*, *> && t.isEmpty())) {
showEmptyLayout()
if (onEmpty != null) {
onEmpty()
} else {
showEmptyLayout()
}
} else {
onResult.invoke(t)
showContentLayout()
}
}
fun RefreshStateLayout.handleErrorWithStatus(throwable: Throwable) {
fun RefreshStateLayout.handleResultError(throwable: Throwable) {
if (isRefreshing) {
refreshCompleted()
}

@ -42,7 +42,7 @@ public class SoftKeyboardUtils {
}
public static boolean hideSoftInput(Activity activity) {
if (activity.getCurrentFocus() != null) {
if (activity != null && activity.getCurrentFocus() != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
return imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

@ -229,8 +229,10 @@ public class PullToZoomScrollView extends NestedScrollView {
mZoomView.setPivotY(mOriginContainerViewHeight / 3F);
float addOffset = (height - mOriginContainerViewHeight) * mZoomFactory / mOriginContainerViewHeight;
float scale = height * 1.0F / mOriginContainerViewHeight + addOffset;
mZoomView.setScaleX(scale);
mZoomView.setScaleY(scale);
if (!Float.isInfinite(scale)) {
mZoomView.setScaleX(scale);
mZoomView.setScaleY(scale);
}
}
private void getInnerViewHeight() {

Loading…
Cancel
Save