From a4702b2d444b31a7ac856bb5f4a532f984f8e79c Mon Sep 17 00:00:00 2001 From: Cecily Jiang Date: Mon, 20 Apr 2020 17:51:51 -0700 Subject: [PATCH] Get button text again for prediction when click Reviewed By: dreamolight Differential Revision: D21145826 fbshipit-source-id: 69196ff9c6dac12c8e0bdc36ecf5d53a6bd576f7 --- .../appevents/suggestedevents/ViewObserver.java | 2 +- .../suggestedevents/ViewOnClickListener.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewObserver.java b/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewObserver.java index 5556db6001..2093fadae4 100644 --- a/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewObserver.java +++ b/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewObserver.java @@ -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) { diff --git a/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewOnClickListener.java b/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewOnClickListener.java index 8dceae67be..0ee9560048 100644 --- a/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewOnClickListener.java +++ b/facebook-core/src/main/java/com/facebook/appevents/suggestedevents/ViewOnClickListener.java @@ -57,23 +57,21 @@ public final class ViewOnClickListener implements View.OnClickListener { private WeakReference rootViewWeakReference; private WeakReference 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 @@ -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) { @@ -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*/ } @@ -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() {