diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d19981..fbb6828 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/README.md b/README.md
index 16b446e..1caf472 100644
--- a/README.md
+++ b/README.md
@@ -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)
```
## 控制页面状态
@@ -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();
@@ -128,5 +130,4 @@ Add it in your root build.gradle at the end of repositories:
}
},2000);
}
-
```
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 3aab3cc..cdb0b2f 100644
--- a/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java
+++ b/app/src/main/java/com/hss01248/pagestate/demo/MainActivity.java
@@ -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();
diff --git a/lib/src/main/java/com/hss01248/pagestate/PageManager.java b/lib/src/main/java/com/hss01248/pagestate/PageManager.java
index fc3e1ed..7641cb0 100644
--- a/lib/src/main/java/com/hss01248/pagestate/PageManager.java
+++ b/lib/src/main/java/com/hss01248/pagestate/PageManager.java
@@ -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() {
@@ -87,6 +87,14 @@ public void onClick(View v) {
});
}
});
+ if(isShowLoadingOrContent){
+ manager.showLoading();
+ }else {
+ manager.showContent();
+ }
+
+
+ return manager;
}
/**
@@ -94,10 +102,11 @@ public void onClick(View v) {
* @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() {
@@ -117,6 +126,15 @@ public View generateEmptyLayout() {
return generateCustomEmptyView(emptyMsg);
}
});
+
+ if(isShowLoadingOrContent){
+ manager.showLoading();
+ }else {
+ manager.showContent();
+ }
+
+
+ return manager;
}
@@ -126,7 +144,7 @@ public void showLoading()
}
- //todo 每次显示实时的错误信息
+
public void showError()
{
mLoadingAndRetryLayout.showRetry();
@@ -141,7 +159,7 @@ public void showEmpty()
{
mLoadingAndRetryLayout.showEmpty();
}
-
+ //每次显示实时的错误信息
public void showError(CharSequence errorMsg){
if(tvError != null){
@@ -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
@@ -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