diff --git a/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java b/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java index 1de8150..0eb8663 100644 --- a/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java +++ b/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java @@ -44,7 +44,13 @@ public void onEmtptyViewClicked(View emptyView) { doNet(); } + + @Override + public boolean isFirstStateLoading() { + return false; + } }); + doNet(); } @@ -52,7 +58,7 @@ public void onEmtptyViewClicked(View emptyView) { protected void onResume() { super.onResume(); - doNet(); + // doNet(); @@ -60,7 +66,7 @@ protected void onResume() { } private void doNet() { - pageStateManager.showLoading(); + pageStateManager.showLoading(50); handler.postDelayed(new Runnable() { @Override diff --git a/pagestate/src/main/java/com/hss01248/pagestate/PageStateConfig.java b/pagestate/src/main/java/com/hss01248/pagestate/PageStateConfig.java index 0788ab6..646c522 100644 --- a/pagestate/src/main/java/com/hss01248/pagestate/PageStateConfig.java +++ b/pagestate/src/main/java/com/hss01248/pagestate/PageStateConfig.java @@ -30,6 +30,10 @@ public int customEmptyLayoutId() { return PageStateManager.BASE_EMPTY_LAYOUT_ID; } + public boolean showProgress(View emptyView,int progress){ + return false; + } + diff --git a/pagestate/src/main/java/com/hss01248/pagestate/PageStateManager.java b/pagestate/src/main/java/com/hss01248/pagestate/PageStateManager.java index a44408b..d25da25 100644 --- a/pagestate/src/main/java/com/hss01248/pagestate/PageStateManager.java +++ b/pagestate/src/main/java/com/hss01248/pagestate/PageStateManager.java @@ -138,7 +138,7 @@ public void showLoading() { @Override public void showLoading(int progress) { - mLoadingAndRetryLayout.showLoading(); + mLoadingAndRetryLayout.showLoading(progress); } @Override diff --git a/pagestate/src/main/java/com/hss01248/pagestate/StatefulFrameLayout.java b/pagestate/src/main/java/com/hss01248/pagestate/StatefulFrameLayout.java index 1266a52..f0ce735 100644 --- a/pagestate/src/main/java/com/hss01248/pagestate/StatefulFrameLayout.java +++ b/pagestate/src/main/java/com/hss01248/pagestate/StatefulFrameLayout.java @@ -6,6 +6,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; +import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; @@ -88,21 +89,51 @@ public void run() { } } - TextView tvLoading; @Override public void showLoading(int progress) { if (isMainThread()) { showView(mLoadingView, STATUS_LOADING); + showProgress(mLoadingView,progress); } else { post(new Runnable() { @Override public void run() { showView(mLoadingView,STATUS_LOADING); + showProgress(mLoadingView,progress); } }); } } + TextView tvLoading; + private void showProgress(View mLoadingView, int progress) { + try { + if(manager == null || manager.pageListener == null){ + showP(mLoadingView,progress+"%"); + return; + } + if(!manager.pageListener.showProgress(mEmptyView,progress)){ + showP(mLoadingView,progress+"%"); + } + }catch (Throwable throwable){ + throwable.printStackTrace(); + } + + + } + + private void showP(View mLoadingView, String str) { + if(tvLoading != null){ + tvLoading.setText(str); + return; + } + View tv = mLoadingView.findViewById(R.id.tv_msg_loading); + if(tv instanceof TextView){ + tvLoading = (TextView) tv; + tvLoading.setText(str); + } + + } /** * 会找到第一个textview,设置text. 如果msg为空,则不设置 diff --git a/pagestate/src/main/res/layout/pager_loading.xml b/pagestate/src/main/res/layout/pager_loading.xml index d6afd69..337e815 100644 --- a/pagestate/src/main/res/layout/pager_loading.xml +++ b/pagestate/src/main/res/layout/pager_loading.xml @@ -16,8 +16,9 @@ />