Skip to content

Commit

Permalink
使用时增加指定第一次界面是loading还是content的字段
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshuisheng committed Nov 28, 2016
1 parent e6bf478 commit 284b938
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public static void initInApp(Context appContext)//使用默认提供的几个状

```
/**
*
* @param container 必须为activity,fragment或者view.如果是view,则该view对象必须有parent
* @param retryAction 点击重试的动作,注意,只需要关注有网络的情况,无网络状态时已经封装好:弹出对话框询问用户是否去设置网络
* @param isShowLoadingOrContent 第一次是显示loading(true)还是content(false)
* @return 当前页面的状态管理器
*/
public static PageManager init(final Object container, final Runnable retryAction)
public static PageManager init(final Object container, boolean isShowLoadingOrContent ,final Runnable retryAction)
//如果当前页面的空白状态下,提示语需要自定义,则调用此方法
public static PageManager init(final Object container, final CharSequence emptyMsg, final Runnable retryAction)
public static PageManager init(final Object container, final CharSequence emptyMsg, boolean isShowLoadingOrContent ,final Runnable retryAction)
```

## 控制页面状态
Expand Down Expand Up @@ -95,7 +97,7 @@ Add it in your root build.gradle at the end of repositories:
## 示例代码

```
pageStateManager = PageManager.init(this, "空空快快快快快快快快快快快快",new Runnable() {
pageStateManager = PageManager.init(this, "空空快快快快快快快快快快快快",true,new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"点击重试了...",Toast.LENGTH_LONG).show();
Expand Down Expand Up @@ -128,5 +130,4 @@ Add it in your root build.gradle at the end of repositories:
}
},2000);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {

PageManager.initInApp(getApplicationContext());

pageStateManager = PageManager.init(this, "空空快快快快快快快快快快快快",new Runnable() {
pageStateManager = PageManager.init(this, "空空快快快快快快快快快快快快",true,new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this,"点击重试了...",Toast.LENGTH_LONG).show();
Expand Down
39 changes: 28 additions & 11 deletions lib/src/main/java/com/hss01248/pagestate/PageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public static void initInApp(Context appContext,int layoutIdOfEmpty,int layoutId
*
* @param container 必须为activity,fragment或者view.如果是view,则该view对象必须有parent
* @param retryAction 点击重试的动作,注意,只需要关注有网络的情况,无网络状态时已经封装好:弹出对话框询问用户是否去设置网络
* @param isShowLoadingOrContent 第一次是显示loading(true)还是content(false)
* @return 当前页面的状态管理器
*/
public static PageManager init(final Object container, final Runnable retryAction) {

return generate(container, new PageListener() {
public static PageManager init(final Object container, boolean isShowLoadingOrContent ,final Runnable retryAction) {
PageManager manager = generate(container, new PageListener() {
@Override
public void setRetryEvent(View retryView) {
retryView.setOnClickListener(new View.OnClickListener() {
Expand All @@ -87,17 +87,26 @@ public void onClick(View v) {
});
}
});
if(isShowLoadingOrContent){
manager.showLoading();
}else {
manager.showContent();
}


return manager;
}

/**
*
* @param container 必须为activity,fragment或者view.如果是view,则该view对象必须有parent
* @param emptyMsg 自定义空白String
* @param retryAction
* @param isShowLoadingOrContent 第一次是显示loading(true)还是content(false)
* @return
*/
public static PageManager init(final Object container, final CharSequence emptyMsg, final Runnable retryAction){
return generate(container, new PageListener() {
public static PageManager init(final Object container, final CharSequence emptyMsg, boolean isShowLoadingOrContent ,final Runnable retryAction){
PageManager manager = generate(container, new PageListener() {
@Override
public void setRetryEvent(View retryView) {
retryView.setOnClickListener(new View.OnClickListener() {
Expand All @@ -117,6 +126,15 @@ public View generateEmptyLayout() {
return generateCustomEmptyView(emptyMsg);
}
});

if(isShowLoadingOrContent){
manager.showLoading();
}else {
manager.showContent();
}


return manager;
}


Expand All @@ -126,7 +144,7 @@ public void showLoading()
}


//todo 每次显示实时的错误信息

public void showError()
{
mLoadingAndRetryLayout.showRetry();
Expand All @@ -141,7 +159,7 @@ public void showEmpty()
{
mLoadingAndRetryLayout.showEmpty();
}

//每次显示实时的错误信息
public void showError(CharSequence errorMsg){

if(tvError != null){
Expand Down Expand Up @@ -203,7 +221,7 @@ private static AlertDialog showNoNetWorkDlg(final Object container) {
final Activity finalActivity = (Activity) context;

dialog = builder //
.setTitle("无网络") //
.setTitle("提示") //
.setMessage("当前无网络").setPositiveButton("去设置", new DialogInterface.OnClickListener() {

@Override
Expand Down Expand Up @@ -275,9 +293,8 @@ public PageManager(Object activityOrFragmentOrView, PageListener listener)
View view = (View) activityOrFragmentOrView;
contentParent = (ViewGroup) (view.getParent());
context = view.getContext();
} else
{
throw new IllegalArgumentException("the argument's type must be Fragment or Activity: init(context)");
} else{
throw new IllegalArgumentException("the container's type must be Fragment or Activity or a view which already has a parent ");
}
int childCount = contentParent.getChildCount();
//get contentParent
Expand Down

0 comments on commit 284b938

Please sign in to comment.