Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/TranslateCompactInfoBar.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/TranslateCompactInfoBar.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TranslateCompactInfoBar.java |
| index 0389b7f0fbc1b7b468f98c37dd2d8af3314c876d..ec7d720fc2b5af59026ed6871bd6b496a617d2a0 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/infobar/TranslateCompactInfoBar.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/TranslateCompactInfoBar.java |
| @@ -21,7 +21,7 @@ import org.chromium.chrome.browser.widget.TintedImageButton; |
| import org.chromium.ui.widget.Toast; |
| /** |
| - * Java version of the compcat translate infobar |
| + * Java version of the compact translate infobar. |
| */ |
| class TranslateCompactInfoBar extends InfoBar |
| implements TabLayout.OnTabSelectedListener, TranslateMenuHelper.TranslateMenuListener { |
| @@ -42,6 +42,7 @@ class TranslateCompactInfoBar extends InfoBar |
| private TranslateMenuHelper mLanguageMenuHelper; |
| private TintedImageButton mMenuButton; |
| private boolean mUserInteracted; |
| + private boolean mTriggeredAutoNeverByCloseButton; |
| /** The controller for translate UI snackbars. */ |
| class TranslateSnackbarController implements SnackbarController { |
| @@ -60,6 +61,13 @@ class TranslateCompactInfoBar extends InfoBar |
| public void onAction(Object actionData) { |
| // TODO(ramyasharma): Add logging metric to track cancel actions. |
| // Do nothing. |
| + |
| + // This snackbar is triggered by a close button click. Need to dismiss the infobar even |
| + // user cancels the "Never Translate". |
| + if (mTriggeredAutoNeverByCloseButton |
| + && mMenuItemId == TranslateMenu.ID_OVERFLOW_NEVER_SITE) { |
| + onCloseButtonClicked(); |
| + } |
| } |
| }; |
| @@ -174,6 +182,12 @@ class TranslateCompactInfoBar extends InfoBar |
| Snackbar.UMA_TRANSLATE_ALWAYS, TranslateMenu.ID_OVERFLOW_ALWAYS_TRANSLATE); |
| } |
| + private void setAutoNeverTranslate() { |
| + createAndShowSnackbar(getContext().getString(R.string.translate_snackbar_language_never, |
| + mOptions.sourceLanguageName()), |
| + Snackbar.UMA_TRANSLATE_NEVER, TranslateMenu.ID_OVERFLOW_NEVER_SITE); |
| + } |
| + |
| @Override |
| protected void onNativeDestroyed() { |
| mNativeTranslateInfoBarPtr = 0; |
| @@ -182,9 +196,23 @@ class TranslateCompactInfoBar extends InfoBar |
| @Override |
| public void onCloseButtonClicked() { |
| - if (!mUserInteracted) { |
| + // If mUserInteracted is true, we will not count this as a translation denied. |
| + // If mTriggeredAutoNeverByCloseButton is true, that means we did this check already and no |
| + // need to do it again. |
| + if (!mUserInteracted && !mTriggeredAutoNeverByCloseButton) { |
|
Leo
2017/05/12 05:09:07
Logic here is unclear and not straightforward. Ple
Marti Wong
2017/05/12 07:16:11
Done some refactoring. see if it's good now. thx
|
| + // This will increment the denied count. |
| onButtonClicked(ActionType.CANCEL); |
| + if (!mOptions.neverTranslateLanguageState() |
| + && nativeShouldAutoNeverTranslate(mNativeTranslateInfoBarPtr)) { |
| + mTriggeredAutoNeverByCloseButton = true; |
| + setAutoNeverTranslate(); |
| + // Postpone the infobar dismiss until the snackbar finished showing. Otherwise, the |
| + // reference to the native infobar is killed and there is no way for the snackbar to |
| + // perform the action. |
| + return; |
| + } |
| } |
| + // This line will dismiss this infobar. |
| super.onCloseButtonClicked(); |
| } |
| @@ -294,10 +322,12 @@ class TranslateCompactInfoBar extends InfoBar |
| TranslateOption.ALWAYS_TRANSLATE, mOptions.alwaysTranslateLanguageState()); |
| return; |
| case TranslateMenu.ID_OVERFLOW_NEVER_LANGUAGE: |
| + // after applying this option, the infobar will dismiss |
| nativeApplyBoolTranslateOption( |
| mNativeTranslateInfoBarPtr, TranslateOption.NEVER_TRANSLATE, true); |
| return; |
| case TranslateMenu.ID_OVERFLOW_NEVER_SITE: |
| + // after applying this option, the infobar will dismiss |
| nativeApplyBoolTranslateOption( |
| mNativeTranslateInfoBarPtr, TranslateOption.NEVER_TRANSLATE_SITE, true); |
| return; |
| @@ -308,4 +338,5 @@ class TranslateCompactInfoBar extends InfoBar |
| long nativeTranslateCompactInfoBar, int option, String value); |
| private native void nativeApplyBoolTranslateOption( |
| long nativeTranslateCompactInfoBar, int option, boolean value); |
| + private native boolean nativeShouldAutoNeverTranslate(long nativeTranslateCompactInfoBar); |
| } |