Bug 913214 - Create StringUtils method to provide readable URL / title string, r=wesj, sriram

This commit is contained in:
Mark Capella 2013-09-17 23:54:48 -04:00
parent 6ebfe1f9f1
commit b7e72c7117
4 changed files with 19 additions and 10 deletions

View File

@ -20,6 +20,7 @@ import org.mozilla.gecko.util.HardwareUtils;
import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask;
import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.StringUtils;
import org.json.JSONObject;
@ -1092,8 +1093,7 @@ public class BrowserToolbar extends GeckoRelativeLayout
return;
}
url = StringUtils.stripScheme(url);
CharSequence title = StringUtils.stripCommonSubdomains(url);
CharSequence title = StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url));
String baseDomain = tab.getBaseDomain();
if (!TextUtils.isEmpty(baseDomain)) {

View File

@ -10,6 +10,7 @@ import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.util.StringUtils;
import android.content.Context;
import android.content.res.TypedArray;
@ -126,9 +127,6 @@ public class HomeListView extends ListView
*/
public static class HomeContextMenuInfo extends AdapterContextMenuInfo {
// URL to Title replacement regex.
private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?";
public int bookmarkId;
public int historyId;
public String url;
@ -200,7 +198,8 @@ public class HomeListView extends ListView
}
public String getDisplayTitle() {
return TextUtils.isEmpty(title) ? url.replaceAll(REGEX_URL_TO_TITLE, "") : title;
return TextUtils.isEmpty(title) ?
StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)) : title;
}
}
}

View File

@ -10,6 +10,7 @@ import org.mozilla.gecko.ThumbnailHelper;
import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.util.StringUtils;
import android.content.Context;
import android.content.res.TypedArray;
@ -217,9 +218,6 @@ public class TopBookmarksView extends GridView {
*/
public static class TopBookmarksContextMenuInfo extends AdapterContextMenuInfo {
// URL to Title replacement regex.
private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?";
public String url;
public String title;
public boolean isPinned;
@ -237,7 +235,8 @@ public class TopBookmarksView extends GridView {
}
public String getDisplayTitle() {
return TextUtils.isEmpty(title) ? url.replaceAll(REGEX_URL_TO_TITLE, "") : title;
return TextUtils.isEmpty(title) ?
StringUtils.stripCommonSubdomains(StringUtils.stripScheme(url, StringUtils.UrlFlags.STRIP_HTTPS)) : title;
}
}
}

View File

@ -47,7 +47,16 @@ public class StringUtils {
return wasSearchQuery;
}
public static class UrlFlags {
public static final int NONE = 0;
public static final int STRIP_HTTPS = 1;
}
public static String stripScheme(String url) {
return stripScheme(url, UrlFlags.NONE);
}
public static String stripScheme(String url, int flags) {
if (url == null) {
return url;
}
@ -57,6 +66,8 @@ public class StringUtils {
if (url.startsWith("http://")) {
start = 7;
} else if (url.startsWith("https://") && flags == UrlFlags.STRIP_HTTPS) {
start = 8;
}
if (url.endsWith("/")) {