diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java b/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java index d54170b..3c43aae 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java +++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseFragment.java @@ -245,12 +245,19 @@ public class BaseFragment extends Fragment implements LoadingView, OnBackPressLi } private LoadingView getLoadingViewImpl() { + if (mLoadingViewImpl == null) { + mLoadingViewImpl = onCreateLoadingView(); + } if (mLoadingViewImpl == null) { mLoadingViewImpl = BaseKit.get().getLoadingViewFactory().createLoadingDelegate(getContext()); } return mLoadingViewImpl; } + protected LoadingView onCreateLoadingView() { + return null; + } + @Override public void showLoadingDialog() { getLoadingViewImpl().showLoadingDialog(true); diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseListV2Fragment.kt b/lib_base/src/main/java/com/android/base/app/fragment/BaseListV2Fragment.kt index aecb072..57d15de 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/BaseListV2Fragment.kt +++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseListV2Fragment.kt @@ -98,5 +98,6 @@ abstract class BaseListV2Fragment : BaseFragment(), RefreshListLayout { override fun showNetErrorLayout() = stateLayout.showNetErrorLayout() override fun showServerErrorLayout() = stateLayout.showServerErrorLayout() override fun isLoadingMore() = stateLayout.refreshView.isLoadingMore + override fun currentStatus() = stateLayout.currentStatus() } \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseStateDialogFragment.java b/lib_base/src/main/java/com/android/base/app/fragment/BaseStateDialogFragment.java index 136719d..c61db2c 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/BaseStateDialogFragment.java +++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseStateDialogFragment.java @@ -59,7 +59,7 @@ public abstract class BaseStateDialogFragment extends BaseDialogFragment impleme return mStateLayout.getRefreshView(); } - protected void onRetry(int state) { + protected void onRetry(@StateLayoutConfig.RetryableState int state) { if (getRefreshView() != null) { if (!getRefreshView().isRefreshing()) { autoRefresh(); @@ -142,4 +142,9 @@ public abstract class BaseStateDialogFragment extends BaseDialogFragment impleme getStateLayout().showServerErrorLayout(); } -} + @Override + public int currentStatus() { + return mStateLayout.currentStatus(); + } + +} \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/app/fragment/BaseStateFragment.java b/lib_base/src/main/java/com/android/base/app/fragment/BaseStateFragment.java index e9b2885..a6b55f9 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/BaseStateFragment.java +++ b/lib_base/src/main/java/com/android/base/app/fragment/BaseStateFragment.java @@ -65,7 +65,7 @@ public abstract class BaseStateFragment extends BaseFragment implements RefreshS return mStateLayout.getRefreshView(); } - protected void onRetry(int state) { + protected void onRetry(@StateLayoutConfig.RetryableState int state) { if (getRefreshView() != null) { if (!getRefreshView().isRefreshing()) { autoRefresh(); @@ -149,4 +149,9 @@ public abstract class BaseStateFragment extends BaseFragment implements RefreshS getStateLayout().showServerErrorLayout(); } + @Override + public int currentStatus() { + return mStateLayout.currentStatus(); + } + } diff --git a/lib_base/src/main/java/com/android/base/app/fragment/RefreshLoadMoreStateLayoutImpl.kt b/lib_base/src/main/java/com/android/base/app/fragment/RefreshLoadMoreStateLayoutImpl.kt index 59c6599..9274dac 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/RefreshLoadMoreStateLayoutImpl.kt +++ b/lib_base/src/main/java/com/android/base/app/fragment/RefreshLoadMoreStateLayoutImpl.kt @@ -34,6 +34,7 @@ internal class RefreshLoadMoreStateLayoutImpl private constructor(layout: View) override fun showBlank() = checkMultiStateView().showBlank() override fun showNetErrorLayout() = checkMultiStateView().showNetErrorLayout() override fun showServerErrorLayout() = checkMultiStateView().showServerErrorLayout() + override fun currentStatus() = checkMultiStateView().currentStatus() override fun getStateLayoutConfig(): StateLayoutConfig = checkMultiStateView().stateLayoutConfig diff --git a/lib_base/src/main/java/com/android/base/app/fragment/RefreshableStateLayoutImpl.java b/lib_base/src/main/java/com/android/base/app/fragment/RefreshableStateLayoutImpl.java index e088fa4..da3b8a5 100644 --- a/lib_base/src/main/java/com/android/base/app/fragment/RefreshableStateLayoutImpl.java +++ b/lib_base/src/main/java/com/android/base/app/fragment/RefreshableStateLayoutImpl.java @@ -129,6 +129,11 @@ final class RefreshableStateLayoutImpl implements RefreshStateLayout, StateLayou return this; } + @Override + public int currentStatus() { + return mMultiStateView.currentStatus(); + } + @Override public void refreshCompleted() { if (mRefreshView != null) { diff --git a/lib_base/src/main/java/com/android/base/app/ui/StateLayout.java b/lib_base/src/main/java/com/android/base/app/ui/StateLayout.java index 44f7fb3..be80d03 100644 --- a/lib_base/src/main/java/com/android/base/app/ui/StateLayout.java +++ b/lib_base/src/main/java/com/android/base/app/ui/StateLayout.java @@ -24,4 +24,8 @@ public interface StateLayout { void showServerErrorLayout(); StateLayoutConfig getStateLayoutConfig(); + + @StateLayoutConfig.ViewState + int currentStatus(); + } diff --git a/lib_base/src/main/java/com/android/base/app/ui/StateLayoutConfig.java b/lib_base/src/main/java/com/android/base/app/ui/StateLayoutConfig.java index 7c5d154..d2f029b 100644 --- a/lib_base/src/main/java/com/android/base/app/ui/StateLayoutConfig.java +++ b/lib_base/src/main/java/com/android/base/app/ui/StateLayoutConfig.java @@ -29,6 +29,7 @@ public interface StateLayoutConfig { EMPTY, ERROR, NET_ERROR, + SERVER_ERROR, }) @Retention(RetentionPolicy.SOURCE) @interface RetryableState { diff --git a/lib_base/src/main/java/com/android/base/kotlin/DialogEx.kt b/lib_base/src/main/java/com/android/base/kotlin/DialogEx.kt index 353d45b..f5f6076 100644 --- a/lib_base/src/main/java/com/android/base/kotlin/DialogEx.kt +++ b/lib_base/src/main/java/com/android/base/kotlin/DialogEx.kt @@ -2,12 +2,14 @@ package com.android.base.kotlin import android.app.Dialog -/** - *@author Ztiany - * Email: ztiany3@gmail.com - * Date : 2019-03-04 10:46 - */ -fun Dialog.noCancelable(): Dialog { +fun Dialog.notCancelable(): Dialog { this.setCancelable(false) return this +} + +fun Dialog.onDismiss(action: () -> Unit): Dialog { + setOnDismissListener { + action() + } + return this } \ No newline at end of file diff --git a/lib_base/src/main/java/com/android/base/widget/SimpleMultiStateView.java b/lib_base/src/main/java/com/android/base/widget/SimpleMultiStateView.java index f981ddb..9142b3b 100644 --- a/lib_base/src/main/java/com/android/base/widget/SimpleMultiStateView.java +++ b/lib_base/src/main/java/com/android/base/widget/SimpleMultiStateView.java @@ -142,4 +142,10 @@ public class SimpleMultiStateView extends MultiStateView implements StateLayout return mStateProcessor.getStateLayoutConfigImpl(); } + @Override + @ViewState + public int currentStatus() { + return getViewState(); + } + } diff --git a/lib_base/src/main/java/com/android/base/widget/StateActionProcessor.java b/lib_base/src/main/java/com/android/base/widget/StateActionProcessor.java index ba2032a..c1cfe31 100644 --- a/lib_base/src/main/java/com/android/base/widget/StateActionProcessor.java +++ b/lib_base/src/main/java/com/android/base/widget/StateActionProcessor.java @@ -6,6 +6,7 @@ import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.text.TextUtils; +import android.view.Gravity; import android.view.View; import android.widget.Button; import android.widget.ImageView; @@ -102,7 +103,7 @@ public class StateActionProcessor extends StateProcessor { private final int mState; private Drawable mDrawable; private CharSequence mMessage; - private int mMessageGravity; + private int mMessageGravity = Gravity.CENTER; private CharSequence mActionText; private View mStateView; private TextView mMessageTv;