Skip to content

Commit

Permalink
Get button text again for prediction when click
Browse files Browse the repository at this point in the history
Reviewed By: dreamolight

Differential Revision: D21145826

fbshipit-source-id: 69196ff9c6dac12c8e0bdc36ecf5d53a6bd576f7
  • Loading branch information
Cecily Jiang authored and facebook-github-bot committed Apr 21, 2020
1 parent 42d25ae commit a4702b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void run() {
.getTextOfViewRecursively(view);
if (!text.isEmpty() && text.length() <= MAX_TEXT_LENGTH) {
ViewOnClickListener.attachListener(view, rootView,
activity.getLocalClassName(), text);
activity.getLocalClassName());
}
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,21 @@ public final class ViewOnClickListener implements View.OnClickListener {
private WeakReference<View> rootViewWeakReference;
private WeakReference<View> hostViewWeakReference;
private String activityName;
private String buttonText;

static void attachListener(View hostView, View rootView, String activityName, String buttonText) {
static void attachListener(View hostView, View rootView, String activityName) {
int key = hostView.hashCode();
if (!viewsAttachedListener.contains(key)) {
ViewHierarchy.setOnClickListener(hostView,
new ViewOnClickListener(hostView, rootView, activityName, buttonText));
new ViewOnClickListener(hostView, rootView, activityName));
viewsAttachedListener.add(key);
}
}

private ViewOnClickListener(View hostView, View rootView, String activityName, String buttonText) {
private ViewOnClickListener(View hostView, View rootView, String activityName) {
baseListener = ViewHierarchy.getExistingOnClickListener(hostView);
hostViewWeakReference = new WeakReference<>(hostView);
rootViewWeakReference = new WeakReference<>(rootView);
this.activityName = activityName.toLowerCase().replace("activity", "");
this.buttonText = buttonText;
}

@Override
Expand All @@ -92,6 +90,7 @@ private void process() {
}

try {
String buttonText = SuggestedEventViewHierarchy.getTextOfViewRecursively(hostView);
// query history
@Nullable String pathID = PredictionHistoryManager.getPathID(hostView, buttonText);
if (pathID == null) {
Expand All @@ -105,7 +104,7 @@ private void process() {
final JSONObject data = new JSONObject();
data.put(VIEW_KEY, SuggestedEventViewHierarchy.getDictionaryOfView(rootView, hostView));
data.put(SCREEN_NAME_KEY, activityName);
predictAndProcess(pathID, data);
predictAndProcess(pathID, buttonText, data);
} catch (Exception e) {
/*no op*/
}
Expand All @@ -131,7 +130,7 @@ public void run() {
return true;
}

private void predictAndProcess(final String pathID, final JSONObject viewData) {
private void predictAndProcess(final String pathID, final String buttonText, final JSONObject viewData) {
Utility.runOnNonUiThread(new Runnable() {
@Override
public void run() {
Expand Down

0 comments on commit a4702b2

Please sign in to comment.