Skip to content

Commit

Permalink
code-quality: remove CDATA and <u> tags from string.xml (#3310)
Browse files Browse the repository at this point in the history
Remove CDATA and <u> tags from string resources. Instead use setUnderlinedText() method added in Utils to create underlined string resources.
  • Loading branch information
bistaastha authored Feb 17, 2020
1 parent 75d4891 commit 4038519
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
24 changes: 9 additions & 15 deletions app/src/main/java/fr/free/nrw/commons/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class AboutActivity extends NavigationBaseActivity {
@BindView(R.id.about_license) HtmlTextView aboutLicenseText;
@BindView(R.id.about_faq) TextView faqText;
@BindView(R.id.about_improve) HtmlTextView improve;

@BindView(R.id.about_rate_us) TextView rateUsText;
@BindView(R.id.about_privacy_policy) TextView privacyPolicyText;
@BindView(R.id.about_translate) TextView translateText;
@BindView(R.id.about_credits) TextView creditsText;
/**
* This method helps in the creation About screen
*
Expand All @@ -54,22 +57,13 @@ public void onCreate(Bundle savedInstanceState) {
String improveText = String.format(getString(R.string.about_improve), Urls.NEW_ISSUE_URL);
improve.setHtmlText(improveText);

SpannableString content = new SpannableString(getString(R.string.about_faq));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
faqText.setText(content);

versionText.setText(ConfigUtils.getVersionNameWithSha(getApplicationContext()));

TextView rate_us = findViewById(R.id.about_rate_us);
TextView privacy_policy = findViewById(R.id.about_privacy_policy);
TextView translate = findViewById(R.id.about_translate);
TextView credits = findViewById(R.id.about_credits);
TextView faq = findViewById(R.id.about_faq);
rate_us.setText(StringUtil.fromHtml(getString(R.string.about_rate_us)));
privacy_policy.setText(StringUtil.fromHtml(getString(R.string.about_privacy_policy)));
translate.setText(StringUtil.fromHtml(getString(R.string.about_translate)));
credits.setText(StringUtil.fromHtml(getString(R.string.about_credits)));
faq.setText(StringUtil.fromHtml(getString(R.string.about_faq)));
Utils.setUnderlinedText(faqText, R.string.about_faq, getApplicationContext());
Utils.setUnderlinedText(rateUsText, R.string.about_rate_us, getApplicationContext());
Utils.setUnderlinedText(privacyPolicyText, R.string.about_privacy_policy, getApplicationContext());
Utils.setUnderlinedText(translateText, R.string.about_translate, getApplicationContext());
Utils.setUnderlinedText(creditsText, R.string.about_credits, getApplicationContext());

initDrawer();
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand Down Expand Up @@ -185,4 +188,17 @@ public static void copy(String label,String text, Context context){
clipboard.setPrimaryClip(clip);
}

/**
* This method sets underlined string text to a TextView
*
* @param textView TextView associated with string resource
* @param stringResourceName string resource name
* @param context
*/
public static void setUnderlinedText(TextView textView, int stringResourceName, Context context) {
SpannableString content = new SpannableString(context.getString(stringResourceName));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Object instantiateItem(ViewGroup container, int position) {
if (position == PAGE_LAYOUTS.length - 1) {
// Add link to more information
TextView moreInfo = layout.findViewById(R.id.welcomeInfo);
moreInfo.setText(Html.fromHtml(container.getContext().getString(R.string.welcome_help_button_text)));
Utils.setUnderlinedText(moreInfo, R.string.welcome_help_button_text, container.getContext());
moreInfo.setOnClickListener(view -> Utils.handleWebUrl(
container.getContext(),
Uri.parse("https://commons.wikimedia.org/wiki/Help:Contents")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ && getParentFragment() instanceof MediaDetailPagerFragment) {
final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);

ButterKnife.bind(this,view);
seeMore.setText(StringUtil.fromHtml(getString(R.string.nominated_see_more)));
Utils.setUnderlinedText(seeMore, R.string.nominated_see_more, container.getContext());

if (isCategoryImage){
authorLayout.setVisibility(VISIBLE);
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
<string name="about_license">The Wikimedia Commons app is an open-source app created and maintained by grantees and volunteers of the Wikimedia community. The Wikimedia Foundation is not involved in the creation, development, or maintenance of the app. </string>
<string name="trademarked_name" translatable="false">Wikimedia Commons</string>
<string name="about_improve">Create a new &lt;a href=\"%1$s\"&gt;GitHub issue&lt;/a&gt; for bug reports and suggestions.</string>
<string name="about_privacy_policy"><![CDATA[<u>Privacy policy</u>]]></string>
<string name="about_credits"><![CDATA[<u>Credits</u>]]></string>
<string name="about_privacy_policy">Privacy policy</string>
<string name="about_credits">Credits</string>
<string name="title_activity_about">About</string>
<string name="menu_feedback">Send Feedback (via Email)</string>
<string name="no_email_client">No email client installed</string>
Expand Down Expand Up @@ -155,7 +155,7 @@
<string name="welcome_copyright_subtext">Avoid copyrighted materials you found from the Internet as well as images of posters, book covers, etc.</string>
<string name="welcome_final_text">You think you got it?</string>
<string name="welcome_final_button_text">Yes!</string>
<string name="welcome_help_button_text"><![CDATA[<u>More Information</u>]]></string>
<string name="welcome_help_button_text">More Information</string>
<string name="detail_panel_cats_label">Categories</string>
<string name="detail_panel_cats_loading">Loading…</string>
<string name="detail_panel_cats_none">None selected</string>
Expand Down Expand Up @@ -264,7 +264,7 @@
<string name="null_url">Error! URL not found</string>
<string name="nominate_deletion">Nominate for Deletion</string>
<string name="nominated_for_deletion">This image has been nominated for deletion.</string>
<string name="nominated_see_more"><![CDATA[<u>See webpage for details</u>]]></string>
<string name="nominated_see_more">See webpage for details</string>
<string name="nominating_file_for_deletion">Nominating %1$s for deletion.</string>
<string name="nominating_for_deletion_status">Nominating file for deletion: %1$s</string>
<string name="view_browser">View in Browser</string>
Expand All @@ -291,16 +291,16 @@
<string name="nearby_wikidata">Wikidata</string>
<string name="nearby_wikipedia">Wikipedia</string>
<string name="nearby_commons">Commons</string>
<string name="about_rate_us"><![CDATA[<u>Rate us</u>]]></string>
<string name="about_faq"><![CDATA[<u>FAQ</u>]]></string>
<string name="about_rate_us">Rate us</string>
<string name="about_faq">FAQ</string>
<string name="welcome_skip_button">Skip Tutorial</string>
<string name="no_internet">Internet unavailable</string>
<string name="internet_established">Internet available</string>
<string name="error_notifications">Error fetching notifications</string>
<string name="error_review">Error fetching image for review. Press refresh to try again.</string>
<string name="error_review_categories">Error fetching image categories for review. Press refresh to try again.</string>
<string name="no_notifications">No notifications found</string>
<string name="about_translate"><![CDATA[<u>Translate</u>]]></string>
<string name="about_translate">Translate</string>
<string name="about_translate_title">Languages</string>
<string name="about_translate_message">Select the language that you would like to submit translations for</string>
<string name="about_translate_proceed">Proceed</string>
Expand Down

0 comments on commit 4038519

Please sign in to comment.