Skip to content

Commit

Permalink
feat(tracker): viewPath支持正则表达式,使用正则表达式时,一个viewPath可匹配多个控件
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdan committed Mar 8, 2018
1 parent bd2933d commit 92d45b9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions buildsrc/buildsrc.iml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="annotations-25.2.2" level="project" />
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" name="gradle-api-2.14.1" level="project" />
<orderEntry type="library" exported="" name="groovy-all-2.4.4" level="project" />
<orderEntry type="library" exported="" name="gradle-installation-beacon-2.14.1" level="project" />
<orderEntry type="library" exported="" name="gradle-api-3.3" level="project" />
<orderEntry type="library" exported="" name="groovy-all-2.4.7" level="project" />
<orderEntry type="library" exported="" name="gradle-installation-beacon-3.3" level="project" />
</component>
</module>
6 changes: 6 additions & 0 deletions tracker/src/main/assets/configure.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"viewPath": "/MainWindow/ContentFrameLayout[0]#android:content/LinearLayout[0]#root_view/FrameLayout[0]#content_view/FrameLayout[0]#fragment_container/NNFeedsFragment[0]/FrameLayout[0]#content_view/LinearLayout[0]/NoScrollViewPager[0]#view_pager/NNFNewsListFragment[0]/FrameLayout[0]#content_view/FrameLayout[0]#list_fragment_container/NNFSmartRefreshLayout[0]#refreshLayout/RecyclerView[0]#rrv_news_infos/LinearLayout[0]",
"eventType": "viewClick",
"dataPath": "item.mNewsInfo.title"
},
{
"pageName": "SampleFeedsActivity",
"viewPath": ".*rrv_news_infos/(LinearLayout|RelativeLayout)\\[[0-9]+\\]$",
"eventType": "viewClick",
"dataPath": "item.mNewsInfo.title"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void onClick(View view) {
for (int i = 0; i < nodesArr.size(); i++) {
JSONObject nodeObj = nodesArr.getJSONObject(i);
String viewPath = nodeObj.getString(ConfigConstants.VIEWPATH);
if (currViewPath.equals(viewPath)) {
if (currViewPath.equals(viewPath) || PathUtil.match(currViewPath, viewPath)) {
// 按照路径dataPath搜集数据
Object businessData = PathUtil.getDataObj(view, nodeObj);
Map<String, Object> attributes = new HashMap<>();
Expand Down
23 changes: 23 additions & 0 deletions tracker/src/main/java/com/codeless/tracker/utils/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Created by zhangdan on 2018/3/5.
Expand Down Expand Up @@ -307,4 +309,25 @@ public static boolean hasClassName(Object o, String className) {
public static String getMainWindowType() {
return "/MainWindow";
}

/**
* 当条件满足时,将返回true,否则返回false
*
* @param currViewPath
* @param viewPath
* @return
*/
public static boolean match(String currViewPath, String viewPath) {
if (TextUtils.isEmpty(currViewPath) || TextUtils.isEmpty(viewPath)) {
return false;
}
try {
Pattern pattern = Pattern.compile(viewPath);
Matcher matcher = pattern.matcher(currViewPath);
return matcher.matches();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}

0 comments on commit 92d45b9

Please sign in to comment.