From 0ae032b9ba450a8f7f6a314d90ce702ae10041f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=A7=8B?= <1273378004@qq.com>
Date: Tue, 9 Nov 2021 15:19:36 +0800
Subject: [PATCH 1/5] style: xml format
---
.../resources/base/layout/activity_custom.xml | 21 ++-
.../resources/base/layout/activity_list.xml | 18 +--
.../resources/base/layout/activity_main.xml | 152 +++++++++---------
.../resources/base/layout/activity_simple.xml | 17 +-
.../base/layout/activity_simple2.xml | 27 ++--
.../base/layout/activity_simple3.xml | 44 +++--
6 files changed, 133 insertions(+), 146 deletions(-)
diff --git a/entry/src/main/resources/base/layout/activity_custom.xml b/entry/src/main/resources/base/layout/activity_custom.xml
index 3ed2d27..4bc697f 100644
--- a/entry/src/main/resources/base/layout/activity_custom.xml
+++ b/entry/src/main/resources/base/layout/activity_custom.xml
@@ -1,23 +1,20 @@
-
-
-
+ ohos:height="match_parent"
+ ohos:width="match_parent">
+ ohos:width="match_parent"
+ ohos:contentView="$layout:content_text"
+ ohos:menu_animationDelayPerItem="100"/>
-
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/activity_list.xml b/entry/src/main/resources/base/layout/activity_list.xml
index a14ecf2..42a6eb7 100644
--- a/entry/src/main/resources/base/layout/activity_list.xml
+++ b/entry/src/main/resources/base/layout/activity_list.xml
@@ -1,28 +1,26 @@
-
-
-
+ />
-
+
diff --git a/entry/src/main/resources/base/layout/activity_main.xml b/entry/src/main/resources/base/layout/activity_main.xml
index a9e0d64..8e458eb 100644
--- a/entry/src/main/resources/base/layout/activity_main.xml
+++ b/entry/src/main/resources/base/layout/activity_main.xml
@@ -1,99 +1,99 @@
+
-
+ ohos:padding="16vp">
+ ohos:id="$+id:main_simple"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:bottom_padding="16vp"
+ ohos:multiple_lines="false"
+ ohos:text="简单布局1"
+ ohos:text_color="$color:color_item_intro"
+ ohos:text_size="24fp"
+ ohos:top_padding="16vp"/>
+ ohos:height="1vp"
+ ohos:width="match_parent"
+ ohos:background_element="#E6E6E6"/>
+ ohos:id="$+id:main_simple2"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:bottom_padding="16vp"
+ ohos:multiple_lines="false"
+ ohos:text="简单布局2"
+ ohos:text_color="$color:color_item_intro"
+ ohos:text_size="24fp"
+ ohos:top_padding="16vp"
+ />
-
+
+ ohos:id="$+id:main_simple3"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:bottom_padding="16vp"
+ ohos:multiple_lines="false"
+ ohos:text="简单布局3"
+ ohos:text_color="$color:color_item_intro"
+ ohos:text_size="24fp"
+ ohos:top_padding="16vp"
+ />
-
+
+ ohos:id="$+id:main_custom"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:bottom_padding="16vp"
+ ohos:multiple_lines="false"
+ ohos:text="自定义布局"
+ ohos:text_color="$color:color_item_intro"
+ ohos:text_size="24fp"
+ ohos:top_padding="16vp"
+ />
-
+
-
+ ohos:id="$+id:main_list"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:bottom_padding="16vp"
+ ohos:multiple_lines="false"
+ ohos:text="列表展示"
+ ohos:text_color="$color:color_item_intro"
+ ohos:text_size="24fp"
+ ohos:top_padding="16vp"
+ />
-
+
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/activity_simple.xml b/entry/src/main/resources/base/layout/activity_simple.xml
index a2a3e22..abefa83 100644
--- a/entry/src/main/resources/base/layout/activity_simple.xml
+++ b/entry/src/main/resources/base/layout/activity_simple.xml
@@ -1,26 +1,23 @@
-
-
+ ohos:height="match_parent"
+ ohos:width="match_parent">
+ ohos:layout_alignment="bottom|right"
+ ohos:margin="16vp"
+ layout="$layout:fab_menu"/>
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/activity_simple2.xml b/entry/src/main/resources/base/layout/activity_simple2.xml
index ff46ed8..2aaf7bd 100644
--- a/entry/src/main/resources/base/layout/activity_simple2.xml
+++ b/entry/src/main/resources/base/layout/activity_simple2.xml
@@ -1,36 +1,33 @@
-
-
+ ohos:height="match_parent"
+ ohos:width="match_parent">
+ ohos:layout_alignment="bottom|right"
+ ohos:margin="16vp"
+ layout="$layout:fab_menu"/>
\ No newline at end of file
diff --git a/entry/src/main/resources/base/layout/activity_simple3.xml b/entry/src/main/resources/base/layout/activity_simple3.xml
index 818952f..4d11830 100644
--- a/entry/src/main/resources/base/layout/activity_simple3.xml
+++ b/entry/src/main/resources/base/layout/activity_simple3.xml
@@ -1,38 +1,36 @@
-
-
+ xmlns:ohos="http://schemas.huawei.com/res/ohos"
+ ohos:id="$+id:root"
+ ohos:height="match_parent"
+ ohos:width="match_parent"
+ ohos:orientation="vertical"
+ >
+ ohos:height="match_parent"
+ ohos:width="match_parent">
+ ohos:id="$+id:ll_content"
+ ohos:height="match_parent"
+ ohos:width="match_parent"
+ ohos:alignment="center"
+ ohos:orientation="vertical">
+ ohos:id="$+id:tv_content"
+ ohos:height="match_content"
+ ohos:width="match_content"
+ ohos:text="内容视图"
+ ohos:text_size="20fp"/>
+ ohos:layout_alignment="bottom|right"
+ ohos:margin="16vp"
+ layout="$layout:fab_menu"/>
--
Gitee
From be52194d271ba38510945ac9e54368866e254825 Mon Sep 17 00:00:00 2001
From: hzjust <1273378004@qq.com>
Date: Tue, 9 Nov 2021 15:38:25 +0800
Subject: [PATCH 2/5] feat: string.json
---
entry/src/main/config.json | 22 +++++++++----------
.../main/resources/base/element/string.json | 20 +++++++++++++++++
2 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/entry/src/main/config.json b/entry/src/main/config.json
index fd08836..6c057e5 100644
--- a/entry/src/main/config.json
+++ b/entry/src/main/config.json
@@ -7,9 +7,8 @@
"name": "1.0"
},
"apiVersion": {
- "compatible": 5,
- "target": 5,
- "releaseType": "Beta1"
+ "compatible": 6,
+ "target": 6
}
},
"deviceConfig": {},
@@ -23,7 +22,8 @@
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
- "moduleType": "entry"
+ "moduleType": "entry",
+ "installationFree": false
},
"abilities": [
{
@@ -41,9 +41,9 @@
"name": "com.classic.common.simple.MainAbility",
"icon": "$media:icon",
"description": "",
- "label": "MultipleStatusView",
+ "label": "$string:app_name",
"type": "page",
- "visible": false,
+ "visible": true,
"launchType": "standard"
},
{
@@ -51,7 +51,7 @@
"name": "com.classic.common.simple.CustomActivity",
"icon": "$media:icon",
"description": "",
- "label": "CustomActivity",
+ "label": "$string:ability_cust",
"type": "page",
"launchType": "standard"
},
@@ -60,7 +60,7 @@
"name": "com.classic.common.simple.SimpleActivity",
"icon": "$media:icon",
"description": "",
- "label": "CustomActivity",
+ "label": "$string:ability_sim1",
"type": "page",
"launchType": "standard"
},
@@ -69,7 +69,7 @@
"name": "com.classic.common.simple.Simple2Activity",
"icon": "$media:icon",
"description": "",
- "label": "CustomActivity",
+ "label": "$string:ability_sim2",
"type": "page",
"launchType": "standard"
},
@@ -78,7 +78,7 @@
"name": "com.classic.common.simple.Simple3Activity",
"icon": "$media:icon",
"description": "",
- "label": "CustomActivity",
+ "label": "$string:ability_sim3",
"type": "page",
"launchType": "standard"
},
@@ -87,7 +87,7 @@
"name": "com.classic.common.simple.ListActivity",
"icon": "$media:icon",
"description": "",
- "label": "CustomActivity",
+ "label": "$string:ability_list",
"type": "page",
"launchType": "standard"
}
diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json
index 3d31a25..9cd777c 100644
--- a/entry/src/main/resources/base/element/string.json
+++ b/entry/src/main/resources/base/element/string.json
@@ -19,6 +19,26 @@
{
"name": "no_network_view_hint",
"value": "网络异常"
+ },
+ {
+ "name": "ability_cust",
+ "value": "CustomActivity"
+ },
+ {
+ "name": "ability_sim1",
+ "value": "SimpleActivity"
+ },
+ {
+ "name": "ability_sim2",
+ "value": "Simple2Activity"
+ },
+ {
+ "name": "ability_sim3",
+ "value": "Simple3Activity"
+ },
+ {
+ "name": "ability_list",
+ "value": "ListActivity"
}
]
}
\ No newline at end of file
--
Gitee
From f752125f176d9d91d52eab690df6df9a2debc04d Mon Sep 17 00:00:00 2001
From: hzjust <1273378004@qq.com>
Date: Tue, 9 Nov 2021 15:57:55 +0800
Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9statusview?=
=?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=88=B7=E6=96=B0bug,=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E5=90=84=E7=8A=B6=E6=80=81=E8=B5=84=E6=BA=90id=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=EF=BC=8C=E4=BF=AE=E6=94=B9readme?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 37 ++--
build.gradle | 8 +-
entry/build.gradle | 4 +-
.../classic/common/simple/AbsActivity.java | 9 +-
.../classic/common/simple/CustomActivity.java | 13 +-
.../classic/common/simple/ListActivity.java | 4 -
.../common/simple/Simple3Activity.java | 9 +-
multiple_status_view/build.gradle | 4 +-
.../classic/common/MultipleStatusView.java | 171 ++++++++++++------
9 files changed, 166 insertions(+), 93 deletions(-)
diff --git a/README.md b/README.md
index f383bc9..e20c48a 100644
--- a/README.md
+++ b/README.md
@@ -50,25 +50,34 @@ multipleStatusView.showLoading();
// multipleStatusView.showLoading(customView, layoutParams);
//显示空视图
-multipleStatusView.showEmpty(ResourceTable.Id_empty_retry_view);
-// mMultipleStatusView.showEmpty("自定义提示内容",ResourceTable.Id_empty_retry_view);
-// mMultipleStatusView.showEmpty(ResourceTable.String_custom_hint_content, ResourceTable.Id_empty_retry_view,"占位符1", "占位符2", "...");
-// multipleStatusView.showEmpty(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_empty_retry_view);
-// multipleStatusView.showEmpty(customView, layoutParams,ResourceTable.Id_empty_retry_view);
+首先先调用
+multipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view)设置空视图资源id
+再次调用以下方法:
+multipleStatusView.showEmpty();
+// mMultipleStatusView.showEmpty("自定义提示内容");
+// mMultipleStatusView.showEmpty(ResourceTable.String_custom_hint_content,"占位符1", "占位符2", "...");
+// multipleStatusView.showEmpty(ResourceTable.Layout_xxx, layoutParams);
+// multipleStatusView.showEmpty(customView, layoutParams);
//显示错误视图
-multipleStatusView.showError(ResourceTable.Id_error_retry_view);
-// mMultipleStatusView.showError("自定义提示内容",ResourceTable.Id_error_retry_view);
-// mMultipleStatusView.showError(ResourceTable.String_custom_hint_content, ResourceTable.Id_error_retry_view,"占位符1", "占位符2", "...");
-// multipleStatusView.showError(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_error_retry_view);
-// multipleStatusView.showError(customView, layoutParams,ResourceTable.Id_error_retry_view);
+首先先调用
+multipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view)设置错误视图资源id
+再次调用以下方法:
+multipleStatusView.showError();
+// mMultipleStatusView.showError("自定义提示内容");
+// mMultipleStatusView.showError(ResourceTable.String_custom_hint_content,"占位符1", "占位符2", "...");
+// multipleStatusView.showError(ResourceTable.Layout_xxx, layoutParams);
+// multipleStatusView.showError(customView, layoutParams);
//显示无网络视图
-multipleStatusView.showNoNetwork(ResourceTable.Id_no_network_retry_view);
+首先先调用
+multipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view)设置无网络视图资源id
+再次调用以下方法:
+multipleStatusView.showNoNetwork();
// mMultipleStatusView.showNoNetwork("自定义提示内容");
-// mMultipleStatusView.showNoNetwork(ResourceTable.String_custom_hint_content,ResourceTable.Id_no_network_retry_view, "占位符1", "占位符2", "...");
-// multipleStatusView.showNoNetwork(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_no_network_retry_view);
-// multipleStatusView.showNoNetwork(customView, layoutParams,ResourceTable.Id_no_network_retry_view);
+// mMultipleStatusView.showNoNetwork(ResourceTable.String_custom_hint_content, "占位符1", "占位符2", "...");
+// multipleStatusView.showNoNetwork(ResourceTable.Layout_xxx, layoutParams);
+// multipleStatusView.showNoNetwork(customView, layoutParams);
//显示内容视图
multipleStatusView.showContent();
diff --git a/build.gradle b/build.gradle
index ef3f577..2f6ae02 100644
--- a/build.gradle
+++ b/build.gradle
@@ -2,9 +2,9 @@
apply plugin: 'com.huawei.ohos.app'
ohos {
- compileSdkVersion 5
+ compileSdkVersion 6
defaultConfig {
- compatibleSdkVersion 5
+ compatibleSdkVersion 6
}
}
@@ -19,8 +19,8 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.huawei.ohos:hap:2.4.2.5'
- classpath 'com.huawei.ohos:decctest:1.0.0.6'
+ classpath 'com.huawei.ohos:hap:2.4.5.5'
+ classpath 'com.huawei.ohos:decctest:1.2.5.1'
}
}
diff --git a/entry/build.gradle b/entry/build.gradle
index e9bd1fa..617391f 100644
--- a/entry/build.gradle
+++ b/entry/build.gradle
@@ -1,9 +1,9 @@
apply plugin: 'com.huawei.ohos.hap'
apply plugin: 'com.huawei.ohos.decctest'
ohos {
- compileSdkVersion 5
+ compileSdkVersion 6
defaultConfig {
- compatibleSdkVersion 5
+ compatibleSdkVersion 6
}
}
diff --git a/entry/src/main/java/com/classic/common/simple/AbsActivity.java b/entry/src/main/java/com/classic/common/simple/AbsActivity.java
index 52c6479..35a9375 100644
--- a/entry/src/main/java/com/classic/common/simple/AbsActivity.java
+++ b/entry/src/main/java/com/classic/common/simple/AbsActivity.java
@@ -89,13 +89,16 @@ public abstract class AbsActivity extends Ability implements Component.ClickedLi
loading();
break;
case ResourceTable.Id_fab_empty:
- mMultipleStatusView.showEmpty(ResourceTable.String_test_hint_content, ResourceTable.Id_empty_retry_view, "aa", "bb");
+ mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view);
+ mMultipleStatusView.showEmpty(ResourceTable.String_test_hint_content, "aa", "bb");
break;
case ResourceTable.Id_fab_error:
- mMultipleStatusView.showError("自定义错误文本", ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.showError("自定义错误文本");
break;
case ResourceTable.Id_fab_no_network:
- mMultipleStatusView.showNoNetwork("自定义无网络文本", ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.showNoNetwork("自定义无网络文本");
break;
case ResourceTable.Id_fab_content:
mMultipleStatusView.showContent();
diff --git a/entry/src/main/java/com/classic/common/simple/CustomActivity.java b/entry/src/main/java/com/classic/common/simple/CustomActivity.java
index a09aa51..5cd2343 100644
--- a/entry/src/main/java/com/classic/common/simple/CustomActivity.java
+++ b/entry/src/main/java/com/classic/common/simple/CustomActivity.java
@@ -21,7 +21,6 @@ public class CustomActivity extends AbsActivity {
setUIContent(ResourceTable.Layout_activity_custom);
mMultipleStatusView = (MultipleStatusView) findComponentById(ResourceTable.Id_custom_multiple_status_view);
mMultipleStatusView.setOnRetryClickListener(mRetryClickListener);
- mMultipleStatusView.showContent();
mLayoutParams.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
}
@@ -32,25 +31,29 @@ public class CustomActivity extends AbsActivity {
if (null == mLoadingView) {
mLoadingView = createCustomView("自定义加载中视图");
}
- mMultipleStatusView.showLoading(mLoadingView, mLayoutParams);
+// mMultipleStatusView.showLoading(mLoadingView, mLayoutParams);
+ mMultipleStatusView.showLoading("Show loading hint");
break;
case ResourceTable.Id_fab_empty:
if (null == mEmptyView) {
mEmptyView = createCustomView("自定义空视图");
}
- mMultipleStatusView.showEmpty(mEmptyView, mLayoutParams, ResourceTable.Id_empty_retry_view);
+ mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view);
+ mMultipleStatusView.showEmpty(mEmptyView, mLayoutParams);
break;
case ResourceTable.Id_fab_error:
if (null == mErrorView) {
mErrorView = createCustomView("自定义错误视图");
}
- mMultipleStatusView.showError(mErrorView, mLayoutParams, ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.showError(mErrorView, mLayoutParams);
break;
case ResourceTable.Id_fab_no_network:
if (null == mNoNetworkView) {
mNoNetworkView = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_no_network, null, false);
}
- mMultipleStatusView.showNoNetwork(mNoNetworkView, mLayoutParams, ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.showNoNetwork(mNoNetworkView, mLayoutParams);
break;
case ResourceTable.Id_fab_content:
mMultipleStatusView.showContent(ResourceTable.Layout_custom_content_view, mLayoutParams);
diff --git a/entry/src/main/java/com/classic/common/simple/ListActivity.java b/entry/src/main/java/com/classic/common/simple/ListActivity.java
index fd7e2f6..d5d927b 100644
--- a/entry/src/main/java/com/classic/common/simple/ListActivity.java
+++ b/entry/src/main/java/com/classic/common/simple/ListActivity.java
@@ -14,10 +14,6 @@ public class ListActivity extends AbsActivity {
void initView() {
setUIContent(ResourceTable.Layout_activity_list);
mMultipleStatusView = (MultipleStatusView) findComponentById(ResourceTable.Id_list_multiple_status_view);
- /**
- * 如果不showContent(),mRecyclerView的获取是null
- */
- mMultipleStatusView.showContent();
mRecyclerView = (ListContainer) mMultipleStatusView.findComponentById(ResourceTable.Id_recycler_view);
mNewsAdapter = new EasyListProvider(this, Arrays.asList(data));
mRecyclerView.setItemProvider(mNewsAdapter);
diff --git a/entry/src/main/java/com/classic/common/simple/Simple3Activity.java b/entry/src/main/java/com/classic/common/simple/Simple3Activity.java
index 39698e8..48207a1 100644
--- a/entry/src/main/java/com/classic/common/simple/Simple3Activity.java
+++ b/entry/src/main/java/com/classic/common/simple/Simple3Activity.java
@@ -19,13 +19,16 @@ public class Simple3Activity extends AbsActivity {
loading();
break;
case ResourceTable.Id_fab_empty:
- mMultipleStatusView.showEmpty(ResourceTable.Id_empty_retry_view);
+ mMultipleStatusView.setEmptyResId(ResourceTable.Id_empty_retry_view);
+ mMultipleStatusView.showEmpty();
break;
case ResourceTable.Id_fab_error:
- mMultipleStatusView.showError(ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.setErrorResId(ResourceTable.Id_error_retry_view);
+ mMultipleStatusView.showError();
break;
case ResourceTable.Id_fab_no_network:
- mMultipleStatusView.showNoNetwork(ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.setNetWorkResId(ResourceTable.Id_no_network_retry_view);
+ mMultipleStatusView.showNoNetwork();
break;
case ResourceTable.Id_fab_content:
mMultipleStatusView.showContent();
diff --git a/multiple_status_view/build.gradle b/multiple_status_view/build.gradle
index 115ec9d..8687866 100644
--- a/multiple_status_view/build.gradle
+++ b/multiple_status_view/build.gradle
@@ -1,8 +1,8 @@
apply plugin: 'com.huawei.ohos.library'
ohos {
- compileSdkVersion 5
+ compileSdkVersion 6
defaultConfig {
- compatibleSdkVersion 5
+ compatibleSdkVersion 6
}
}
diff --git a/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java b/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java
index 1c6cd0c..e193573 100644
--- a/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java
+++ b/multiple_status_view/src/main/java/com/classic/common/MultipleStatusView.java
@@ -1,6 +1,7 @@
package com.classic.common;
import ohos.aafwk.ability.Ability;
+import ohos.aafwk.ability.fraction.Fraction;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
@@ -22,7 +23,7 @@ import java.util.logging.Logger;
* 创建时间: 2016/1/15 10:20.
*/
@SuppressWarnings("unused")
-public class MultipleStatusView extends DependentLayout {
+public class MultipleStatusView extends DependentLayout implements Component.BindStateChangedListener {
private static final String TAG = "MultipleStatusView";
private static final String VIEW_EMPTY = "emptyView";
private static final String VIEW_ERROR = "errorView";
@@ -54,6 +55,11 @@ public class MultipleStatusView extends DependentLayout {
private ClickedListener mOnRetryClickListener;
private OnViewStatusChangeListener mViewStatusListener;
private EventHandler handler;
+ // 新增资源根目录id
+ private static int xmlRootLayoutResId = -1;
+ private int emptyResId = -1;
+ private int errorResId = -1;
+ private int networkResId = -1;
private final ArrayList mOtherIds = new ArrayList<>();
@@ -107,6 +113,12 @@ public class MultipleStatusView extends DependentLayout {
}
}
mInflater = LayoutScatter.getInstance(getContext());
+ setBindStateChangedListener(this);
+ onFinishInflate();
+ }
+
+ private void onFinishInflate(){
+ showContent();
}
/**
@@ -127,35 +139,35 @@ public class MultipleStatusView extends DependentLayout {
this.mOnRetryClickListener = onRetryClickListener;
}
+ public void setEmptyResId(int resId) {
+ emptyResId = resId;
+ }
+
/**
* 显示空视图
- *
- * @param viewId 资源Id
*/
- public final void showEmpty(int viewId) {
- showEmpty(mEmptyViewResId, DEFAULT_LAYOUT_PARAMS, viewId);
+ public final void showEmpty() {
+ showEmpty(mEmptyViewResId, DEFAULT_LAYOUT_PARAMS);
}
/**
* 显示空视图
*
* @param hintResId 自定义提示文本内容
- * @param viewId 资源Id
* @param formatArgs 占位符参数
*/
- public final void showEmpty(int hintResId, int viewId, Object... formatArgs) {
- showEmpty(viewId);
+ public final void showEmpty(int hintResId, Object... formatArgs) {
+ showEmpty();
setStatusHintContent(mEmptyView, hintResId, formatArgs);
}
/**
* 显示空视图
*
- * @param hint 自定义提示文本内容
- * @param viewId 资源Id
+ * @param hint 自定义提示文本内容
*/
- public final void showEmpty(String hint, int viewId) {
- showEmpty(viewId);
+ public final void showEmpty(String hint) {
+ showEmpty();
setStatusHintContent(mEmptyView, hint);
}
@@ -164,10 +176,9 @@ public class MultipleStatusView extends DependentLayout {
*
* @param layoutId 自定义布局文件
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showEmpty(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) {
- showEmpty(null == mEmptyView ? inflateView(layoutId) : mEmptyView, layoutParams, viewId);
+ public final void showEmpty(int layoutId, ComponentContainer.LayoutConfig layoutParams) {
+ showEmpty(null == mEmptyView ? inflateView(layoutId) : mEmptyView, layoutParams);
}
/**
@@ -175,15 +186,17 @@ public class MultipleStatusView extends DependentLayout {
*
* @param view 自定义视图
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showEmpty(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) {
+ public final void showEmpty(Component view, ComponentContainer.LayoutConfig layoutParams) {
checkNull(view, "Empty view is null.");
checkNull(layoutParams, "Layout params is null.");
+ if (emptyResId == -1) {
+ throw new NullPointerException("emptyResId is invalid,ues setEmptyResId(int resId)");
+ }
changeViewStatus(STATUS_EMPTY);
if (null == mEmptyView) {
mEmptyView = view;
- Component emptyRetryView = mEmptyView.findComponentById(viewId);
+ Component emptyRetryView = mEmptyView.findComponentById(emptyResId);
if (null != mOnRetryClickListener && null != emptyRetryView) {
emptyRetryView.setClickedListener(mOnRetryClickListener);
}
@@ -193,35 +206,35 @@ public class MultipleStatusView extends DependentLayout {
showViewById(mEmptyView.getId());
}
+ public void setErrorResId(int resId) {
+ errorResId = resId;
+ }
+
/**
* 显示错误视图
- *
- * @param viewId 资源Id
*/
- public final void showError(int viewId) {
- showError(mErrorViewResId, DEFAULT_LAYOUT_PARAMS, viewId);
+ public final void showError() {
+ showError(mErrorViewResId, DEFAULT_LAYOUT_PARAMS);
}
/**
* 显示错误视图
*
* @param hintResId 自定义提示文本内容
- * @param viewId 资源Id
* @param formatArgs 占位符参数
*/
- public final void showError(int hintResId, int viewId, Object... formatArgs) {
- showError(viewId);
+ public final void showError(int hintResId, Object... formatArgs) {
+ showError();
setStatusHintContent(mErrorView, hintResId, formatArgs);
}
/**
* 显示错误视图
*
- * @param hint 自定义提示文本内容
- * @param viewId 资源Id
+ * @param hint 自定义提示文本内容
*/
- public final void showError(String hint, int viewId) {
- showError(viewId);
+ public final void showError(String hint) {
+ showError();
setStatusHintContent(mErrorView, hint);
}
@@ -230,10 +243,9 @@ public class MultipleStatusView extends DependentLayout {
*
* @param layoutId 自定义布局文件
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showError(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) {
- showError(null == mErrorView ? inflateView(layoutId) : mErrorView, layoutParams, viewId);
+ public final void showError(int layoutId, ComponentContainer.LayoutConfig layoutParams) {
+ showError(null == mErrorView ? inflateView(layoutId) : mErrorView, layoutParams);
}
/**
@@ -241,15 +253,17 @@ public class MultipleStatusView extends DependentLayout {
*
* @param view 自定义视图
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showError(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) {
+ public final void showError(Component view, ComponentContainer.LayoutConfig layoutParams) {
checkNull(view, "Error view is null.");
checkNull(layoutParams, "Layout params is null.");
+ if (errorResId == -1) {
+ throw new NullPointerException("errorResId is invalid,ues setErrorResId(int resId)");
+ }
changeViewStatus(STATUS_ERROR);
if (null == mErrorView) {
mErrorView = view;
- Component errorRetryView = mErrorView.findComponentById(viewId);
+ Component errorRetryView = mErrorView.findComponentById(errorResId);
if (null != mOnRetryClickListener && null != errorRetryView) {
errorRetryView.setClickedListener(mOnRetryClickListener);
}
@@ -315,35 +329,35 @@ public class MultipleStatusView extends DependentLayout {
showViewById(mLoadingView.getId());
}
+ public void setNetWorkResId(int resId) {
+ networkResId = resId;
+ }
+
/**
* 显示无网络视图
- *
- * @param viewId 资源Id
*/
- public final void showNoNetwork(int viewId) {
- showNoNetwork(mNoNetworkViewResId, DEFAULT_LAYOUT_PARAMS, viewId);
+ public final void showNoNetwork() {
+ showNoNetwork(mNoNetworkViewResId, DEFAULT_LAYOUT_PARAMS);
}
/**
* 显示无网络视图
*
* @param hintResId 自定义提示文本内容
- * @param viewId 资源Id
* @param formatArgs 占位符参数
*/
- public final void showNoNetwork(int hintResId, int viewId, Object... formatArgs) {
- showNoNetwork(viewId);
+ public final void showNoNetwork(int hintResId, Object... formatArgs) {
+ showNoNetwork();
setStatusHintContent(mNoNetworkView, hintResId, formatArgs);
}
/**
* 显示无网络视图
*
- * @param hint 自定义提示文本内容
- * @param viewId 资源Id
+ * @param hint 自定义提示文本内容
*/
- public final void showNoNetwork(String hint, int viewId) {
- showNoNetwork(viewId);
+ public final void showNoNetwork(String hint) {
+ showNoNetwork();
setStatusHintContent(mNoNetworkView, hint);
}
@@ -352,10 +366,9 @@ public class MultipleStatusView extends DependentLayout {
*
* @param layoutId 自定义布局文件
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showNoNetwork(int layoutId, ComponentContainer.LayoutConfig layoutParams, int viewId) {
- showNoNetwork(null == mNoNetworkView ? inflateView(layoutId) : mNoNetworkView, layoutParams, viewId);
+ public final void showNoNetwork(int layoutId, ComponentContainer.LayoutConfig layoutParams) {
+ showNoNetwork(null == mNoNetworkView ? inflateView(layoutId) : mNoNetworkView, layoutParams);
}
/**
@@ -363,15 +376,17 @@ public class MultipleStatusView extends DependentLayout {
*
* @param view 自定义视图
* @param layoutParams 布局参数
- * @param viewId 资源Id
*/
- public final void showNoNetwork(Component view, ComponentContainer.LayoutConfig layoutParams, int viewId) {
+ public final void showNoNetwork(Component view, ComponentContainer.LayoutConfig layoutParams) {
checkNull(view, "No network view is null.");
checkNull(layoutParams, "Layout params is null.");
+ if (networkResId == -1) {
+ throw new NullPointerException("networkResId is invalid,ues setNetWorkResId(int resId)");
+ }
changeViewStatus(STATUS_NO_NETWORK);
if (null == mNoNetworkView) {
mNoNetworkView = view;
- Component noNetworkRetryView = mNoNetworkView.findComponentById(viewId);
+ Component noNetworkRetryView = mNoNetworkView.findComponentById(networkResId);
if (null != mOnRetryClickListener && null != noNetworkRetryView) {
noNetworkRetryView.setClickedListener(mOnRetryClickListener);
}
@@ -430,12 +445,16 @@ public class MultipleStatusView extends DependentLayout {
private void setStatusHintContent(Component view, String hint) {
checkNull(view, "Target view is null.");
-
if (mhintResId != -1) {
Text hintView = (Text) view.findComponentById(mhintResId);
- hintView.setText(hint);
+ if (null != hintView) {
+ hintView.setText(hint);
+ } else {
+ throw new NullPointerException("Not find the view ID status hint content");
+ }
+
} else {
- throw new NullPointerException("Not find the view ID `status_hint_content`");
+ throw new NullPointerException("Hint view is not set,use setStatusHintRes(int hintRes)");
}
}
@@ -480,6 +499,25 @@ public class MultipleStatusView extends DependentLayout {
}
}
+ @Override
+ public void onComponentBoundToWindow(Component component) {
+
+ }
+
+ @Override
+ public void onComponentUnboundFromWindow(Component component) {
+ clear(mEmptyView, mLoadingView, mErrorView, mNoNetworkView);
+ if (!mOtherIds.isEmpty()) {
+ mOtherIds.clear();
+ }
+ if (null != mOnRetryClickListener) {
+ mOnRetryClickListener = null;
+ }
+ if (null != mViewStatusListener) {
+ mViewStatusListener = null;
+ }
+ }
+
/**
* 视图状态改变接口
*/
@@ -530,7 +568,24 @@ public class MultipleStatusView extends DependentLayout {
addComponent(mContentView, 0, DEFAULT_LAYOUT_PARAMS);
}
- public static MultipleStatusView attach(Ability activity, int rootAnchor, int xmlRootLayoutResId) {
+ public static MultipleStatusView attach(Fraction fraction, int rootAnchor) {
+ if (xmlRootLayoutResId == -1) {
+ throw new NullPointerException("xmlRootLayoutResId is invalid,use setXmlRootLayoutResId(int rootId)");
+ }
+ if (-1 != rootAnchor) {
+ ComponentContainer contentAnchor = (ComponentContainer) fraction.getComponent().findComponentById(xmlRootLayoutResId);
+ if (null != contentAnchor) {
+ attach(contentAnchor);
+ }
+ }
+ ComponentContainer defaultAnchor = (ComponentContainer) fraction.getComponent().findComponentById(xmlRootLayoutResId);
+ return attach(defaultAnchor);
+ }
+
+ public static MultipleStatusView attach(Ability activity, int rootAnchor) {
+ if (xmlRootLayoutResId == -1) {
+ throw new NullPointerException("xmlRootLayoutResId is invalid,use setXmlRootLayoutResId(int rootId)");
+ }
if (-1 != rootAnchor) {
ComponentContainer contentAnchor = (ComponentContainer) activity.findComponentById(rootAnchor);
if (null != contentAnchor) {
@@ -558,6 +613,10 @@ public class MultipleStatusView extends DependentLayout {
return null;
}
+ public void setXmlRootLayoutResId(int rootId) {
+ xmlRootLayoutResId = rootId;
+ }
+
public void removeCallbacks(Runnable runnable) {
handler.removeTask(runnable);
}
--
Gitee
From 41fc1e3cac24b31bf3fc7366b20267712a3eae45 Mon Sep 17 00:00:00 2001
From: hzjust <1273378004@qq.com>
Date: Tue, 9 Nov 2021 16:53:45 +0800
Subject: [PATCH 4/5] =?UTF-8?q?docs:=20=E6=96=B0=E5=A2=9E1.0.3=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E8=AF=B4=E6=98=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49b66c6..53dc537 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+# 1.0.3
+
+和原组件保持接口一致性,新增空视图、错误视图、无网络视图的视图资源ID,
+新增onFinishInflate()方法
+
# 1.0.2
增加组件效果动态图
--
Gitee
From 6f499c261ad7c3258cbdb0d19e27d76a36ca5fe6 Mon Sep 17 00:00:00 2001
From: hzjust <380861714@qq.com>
Date: Tue, 16 Nov 2021 06:08:11 +0000
Subject: [PATCH 5/5] =?UTF-8?q?update=20README.md.=20=E4=BF=AE=E6=94=B9gif?=
=?UTF-8?q?=E5=9C=B0=E5=9D=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index e20c48a..a43fe8f 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
- 网络异常视图
- 内容视图
-
+
## 依赖
```
--
Gitee