Bug 1386902: Use "subdomain.domain" in top sites title. r=liuche draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 10 Aug 2017 15:23:06 -0700
changeset 646217 02e1f1224854df4006f275a6877eb5cd6ecf8a78
parent 646216 eed9361fef02609776c772d21a004004a1d9d543
child 646232 83de391ae827409f8798d2fd00749b4137ba0a88
push id74029
push usermichael.l.comella@gmail.com
push dateTue, 15 Aug 2017 00:19:33 +0000
reviewersliuche
bugs1386902
milestone57.0a1
Bug 1386902: Use "subdomain.domain" in top sites title. r=liuche Additionally, we strip common subdomains like "m." or "www.". MozReview-Commit-ID: IObzp6LBovx
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesCard.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesCard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topsites/TopSitesCard.java
@@ -20,16 +20,17 @@ import org.mozilla.gecko.TelemetryContra
 import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 import org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu;
 import org.mozilla.gecko.activitystream.homepanel.model.TopSite;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.icons.IconCallback;
 import org.mozilla.gecko.icons.IconResponse;
 import org.mozilla.gecko.icons.Icons;
 import org.mozilla.gecko.util.DrawableUtil;
+import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.util.TouchTargetUtil;
 import org.mozilla.gecko.util.URIUtils;
 import org.mozilla.gecko.util.ViewUtil;
 import org.mozilla.gecko.widget.FaviconView;
 
 import java.lang.ref.WeakReference;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -104,36 +105,31 @@ import java.util.concurrent.Future;
         final Drawable pinDrawable;
         if (topSite.isPinned()) {
             pinDrawable = DrawableUtil.tintDrawable(itemView.getContext(), R.drawable.as_pin, Color.WHITE);
         } else {
             pinDrawable = null;
         }
         TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, pinDrawable, null, null, null);
 
-        final String provider = topSite.getMetadata().getProvider();
-        if (!TextUtils.isEmpty(provider)) {
-            title.setText(provider.toLowerCase());
-        } else {
-            final URI topSiteURI;
-            try {
-                topSiteURI = new URI(topSite.getUrl());
-            } catch (final URISyntaxException e) {
-                // If this is not a valid URI, there is not much processing we can do on it.
-                // Also, see comment below regarding setCenteredText.
-                setTopSiteTitle(title, topSite.getUrl());
-                return;
-            }
+        final URI topSiteURI;
+        try {
+            topSiteURI = new URI(topSite.getUrl());
+        } catch (final URISyntaxException e) {
+            // If this is not a valid URI, there is not much processing we can do on it.
+            // Also, see comment below regarding setCenteredText.
+            setTopSiteTitle(title, topSite.getUrl());
+            return;
+        }
 
-            // Our AsyncTask calls setCenteredText(), which needs to have all drawable's in place to correctly
-            // layout the text, so we need to wait with requesting the title until we've set our pin icon.
-            final UpdateCardTitleAsyncTask titleAsyncTask = new UpdateCardTitleAsyncTask(itemView.getContext(),
-                    topSiteURI, title);
-            titleAsyncTask.execute();
-        }
+        // Our AsyncTask calls setCenteredText(), which needs to have all drawable's in place to correctly
+        // layout the text, so we need to wait with requesting the title until we've set our pin icon.
+        final UpdateCardTitleAsyncTask titleAsyncTask = new UpdateCardTitleAsyncTask(itemView.getContext(),
+                topSiteURI, title);
+        titleAsyncTask.execute();
     }
 
     private static void setTopSiteTitle(final TextView textView, final String title) {
         // We use consistent padding all around the title, and the top padding is never modified,
         // so we can pass that in as the default padding:
         ViewUtil.setCenteredText(textView, title, textView.getPaddingTop());
     }
 
@@ -145,33 +141,38 @@ import java.util.concurrent.Future;
     /** Updates the text of the given view to the page domain. */
     private static class UpdateCardTitleAsyncTask extends URIUtils.GetFormattedDomainAsyncTask {
         private static final int VIEW_TAG_ID = R.id.title; // same as the view.
 
         private final WeakReference<TextView> titleViewWeakReference;
         private final UUID viewTagAtStart;
 
         UpdateCardTitleAsyncTask(final Context contextReference, final URI uri, final TextView titleView) {
-            super(contextReference, uri, false, 0); // hostSLD.
+            super(contextReference, uri, false, 1); // subdomain.domain.
             this.titleViewWeakReference = new WeakReference<>(titleView);
 
             // See isTagSameAsStartTag for details.
             viewTagAtStart = UUID.randomUUID();
             titleView.setTag(VIEW_TAG_ID, viewTagAtStart);
         }
 
         @Override
-        protected void onPostExecute(final String hostSLD) {
-            super.onPostExecute(hostSLD);
+        protected void onPostExecute(final String hostText) {
+            super.onPostExecute(hostText);
             final TextView titleView = titleViewWeakReference.get();
             if (titleView == null || !isTagSameAsStartTag(titleView)) {
                 return;
             }
 
-            final String updateText = !TextUtils.isEmpty(hostSLD) ? hostSLD : uri.toString();
+            final String updateText;
+            if (TextUtils.isEmpty(hostText)) {
+                updateText = "";
+            } else {
+                updateText = StringUtils.stripCommonSubdomains(hostText);
+            }
             setTopSiteTitle(titleView, updateText);
         }
 
         /**
          * Returns true if the tag on the given view matches the tag from the constructor. We do this to ensure
          * the View we're making this request for hasn't been re-used by the time this request completes.
          */
         @UiThread