Skip to content

Commit

Permalink
loading支持显示进度
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Aug 10, 2021
1 parent b0daa1d commit e21f6d2
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,29 @@ public void onEmtptyViewClicked(View emptyView) {

doNet();
}

@Override
public boolean isFirstStateLoading() {
return false;
}
});
doNet();

}

@Override
protected void onResume() {
super.onResume();

doNet();
// doNet();




}

private void doNet() {
pageStateManager.showLoading();
pageStateManager.showLoading(50);

handler.postDelayed(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public int customEmptyLayoutId() {
return PageStateManager.BASE_EMPTY_LAYOUT_ID;
}

public boolean showProgress(View emptyView,int progress){
return false;
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void showLoading() {

@Override
public void showLoading(int progress) {
mLoadingAndRetryLayout.showLoading();
mLoadingAndRetryLayout.showLoading(progress);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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为空,则不设置
Expand Down
3 changes: 2 additions & 1 deletion pagestate/src/main/res/layout/pager_loading.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
/>

<TextView
android:id="@+id/tv_msg_loading"
android:text="@string/page_loading"
android:layout_marginTop="20dp"
android:layout_marginTop="6dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/progressbar"
android:textSize="16sp"
Expand Down

0 comments on commit e21f6d2

Please sign in to comment.