Skip to content

Commit

Permalink
Simplify Android Report Broken Site language and point to external li…
Browse files Browse the repository at this point in the history
…nk (#25488)

Simplify Android Report Broken Site language and point to external link
(brave/brave-browser#36483)
---------

Signed-off-by: Vadym Struts <vstruts@brave.com>
  • Loading branch information
vadimstruts authored Sep 12, 2024
1 parent f9d6306 commit c582a2a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
35 changes: 33 additions & 2 deletions android/java/org/chromium/chrome/browser/BraveRewardsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.jni_zero.CalledByNative;

import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.BraveActivity;
Expand Down Expand Up @@ -587,8 +588,38 @@ public static SpannableString tosSpannableString(String text, int colorRes) {
return textSpannableString;
}

public static void setSpan(Context context, String text, SpannableString tosTextSS,
int stringId, ClickableSpan clickableSpan) {
public static SpannableString toSpannableString(
String text,
int colorRes,
int clickableSubstringResId,
Callback<Context> onSubstringClicked) {
Context context = ContextUtils.getApplicationContext();
Spanned textSpanned = spannedFromHtmlString(text);
SpannableString textSpannableString = new SpannableString(textSpanned.toString());

NoUnderlineClickableSpan substringClickableSpan =
new NoUnderlineClickableSpan(
context,
colorRes,
(textView) -> {
onSubstringClicked.onResult(context);
});

setSpan(
context,
text,
textSpannableString,
clickableSubstringResId,
substringClickableSpan);
return textSpannableString;
}

public static void setSpan(
Context context,
String text,
SpannableString tosTextSS,
int stringId,
ClickableSpan clickableSpan) {
String spanString = context.getResources().getString(stringId);
int spanLength = spanString.length();
int index = text.indexOf(spanString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ public abstract class BraveActivity extends ChromeActivity
"https://basicattentiontoken.org/user-terms-of-service/";
public static final String BRAVE_PRIVACY_POLICY = "https://brave.com/privacy/browser/#rewards";
public static final String OPEN_URL = "open_url";
public static final String BRAVE_WEBCOMPAT_INFO_WIKI_URL =
"https://github.com/brave/brave-browser/wiki/Web-compatibility-reports";

private static final int DAYS_1 = 1;
private static final int DAYS_4 = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* You can obtain one at https://mozilla.org/MPL/2.0/. */

package org.chromium.chrome.browser.shields;

import android.animation.AnimatorSet;
import android.app.Activity;
import android.content.Context;
Expand All @@ -17,6 +18,7 @@
import android.net.Uri;
import android.os.Build;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.text.style.StyleSpan;
import android.view.ContextThemeWrapper;
Expand Down Expand Up @@ -44,6 +46,7 @@
import org.chromium.chrome.browser.BraveRewardsNativeWorker;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.brave_stats.BraveStatsUtil;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.night_mode.GlobalNightModeStateProviderHolder;
import org.chromium.chrome.browser.ntp_background_images.NTPBackgroundImagesBridge;
Expand Down Expand Up @@ -114,6 +117,7 @@ public BlockersInfo() {

private BraveRewardsNativeWorker mBraveRewardsNativeWorker;
private BraveRewardsHelper mIconFetcher;
private TextView mReportBrokenSiteDisclaimerView;

private String mUrlSpec;
private String mHost;
Expand Down Expand Up @@ -741,13 +745,32 @@ private void setUpReportBrokenSiteLayout() {
mReportSiteUrlText.setText(siteUrl);
mReportSiteUrlText.setMovementMethod(new ScrollingMovementMethod());

mReportBrokenSiteDisclaimerView =
mReportBrokenSiteLayout.findViewById(R.id.report_broken_site_disclaimer_text);
String reportBrokenSiteDisclaimerText =
String.format(
mContext.getResources().getString(R.string.report_broken_site_text_2),
mContext.getResources().getString(R.string.report_broken_site_text_link));

mReportBrokenSiteDisclaimerView.setText(
BraveRewardsHelper.toSpannableString(
reportBrokenSiteDisclaimerText,
R.color.brave_link,
R.string.report_broken_site_text_link,
(context) -> {
CustomTabActivity.showInfoPage(
context, BraveActivity.BRAVE_WEBCOMPAT_INFO_WIKI_URL);
}));
mReportBrokenSiteDisclaimerView.setMovementMethod(LinkMovementMethod.getInstance());

Button mCancelButton = mReportBrokenSiteLayout.findViewById(R.id.btn_cancel);
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
hideBraveShieldsMenu();
}
});
mCancelButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
hideBraveShieldsMenu();
}
});

Button mSubmitButton = mReportBrokenSiteLayout.findViewById(R.id.btn_submit);
mSubmitButton.setOnClickListener(
Expand Down
4 changes: 2 additions & 2 deletions android/java/res/layout/report_broken_site_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
android:layout_marginBottom="14dp"/>

<TextView
android:id="@+id/report_broken_site_disclaimer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textColor="@color/default_icon_color_tint_list"
android:text="@string/report_broken_site_text_2"/>
android:textColor="@color/default_icon_color_tint_list"/>

<LinearLayout
android:layout_width="wrap_content"
Expand Down
5 changes: 4 additions & 1 deletion browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,10 @@ Are you sure you want to do this?
Let Brave's developers know that this site doesn't work properly with Shields:
</message>
<message name="IDS_REPORT_BROKEN_SITE_TEXT_2" desc="Shields text for broken text warning message.">
Note: This site address will be submitted with your Brave version number and your IP address(which will not be stored).
Thank you for helping make Brave better for all. This report will only contain information necessary for us to fix this site. <ph name="LEARN_MORE">%1$s</ph>
</message>
<message name="IDS_REPORT_BROKEN_SITE_TEXT_LINK" desc="Text for link to webcompat report wiki page.">
Learn more.
</message>
<message name="IDS_REPORT_ERROR_PAGE_EXPLANATION" desc="Notifies the user that the error page cannot be reported">
This is an error page. It cannot be reported as a broken site.
Expand Down
2 changes: 1 addition & 1 deletion components/resources/brave_components_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_NON_HTTP_EXPLANATION" desc="Notifies the user that non-HTTP/HTTPS browser pages cannot be reported">This page cannot be reported because it was not served over HTTP/HTTPS.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_LOCAL_EXPLANATION" desc="Notifies the user that local pages (i.e. via localhost) cannot be reported">This page is a local web page and is not eligible for reporting.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_ERROR_PAGE_EXPLANATION" desc="Notifies the user that the error page cannot be reported">This is an error page. It cannot be reported as a broken site.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_DISCLAIMER2" desc="Thanks the user for sending the report, and informs them that relevant website information will be reported to Brave servers.">Thank you for helping make Brave better for all. This report will only send information necessary for us to fix this site.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_DISCLAIMER2" desc="Thanks the user for sending the report, and informs them that relevant website information will be reported to Brave servers.">Thank you for helping make Brave better for all. This report will only contain information necessary for us to fix this site.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_INFO_LINK" desc="Text for link to webcompat report wiki page.">Learn more.</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_DETAILS" desc="Placeholder text for the optional details field in the broken website report">Additional details (optional)</message>
<message name="IDS_BRAVE_WEBCOMPATREPORTER_REPORT_CONTACT_LABEL" desc="Label for the optional contact information field in the broken website report">Contact me at: (optional)</message>
Expand Down

0 comments on commit c582a2a

Please sign in to comment.