2012-09-11 10:51:43 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2013-12-17 22:43:31 -08:00
|
|
|
import org.mozilla.gecko.util.StringUtils;
|
|
|
|
|
2012-09-11 10:51:43 -07:00
|
|
|
import android.net.Uri;
|
|
|
|
|
|
|
|
public class ReaderModeUtils {
|
|
|
|
private static final String LOGTAG = "ReaderModeUtils";
|
|
|
|
|
2012-09-11 10:51:44 -07:00
|
|
|
public static String getUrlFromAboutReader(String aboutReaderUrl) {
|
2013-12-17 22:43:31 -08:00
|
|
|
return StringUtils.getQueryParameter(aboutReaderUrl, "url");
|
2012-09-11 10:51:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isEnteringReaderMode(String currentUrl, String newUrl) {
|
2013-11-21 23:33:28 -08:00
|
|
|
if (currentUrl == null || newUrl == null) {
|
2012-09-11 10:51:44 -07:00
|
|
|
return false;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
if (!AboutPages.isAboutReader(newUrl)) {
|
2012-09-11 10:51:44 -07:00
|
|
|
return false;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
|
|
|
String urlFromAboutReader = getUrlFromAboutReader(newUrl);
|
2013-11-21 23:33:28 -08:00
|
|
|
if (urlFromAboutReader == null) {
|
2012-09-11 10:51:44 -07:00
|
|
|
return false;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
|
|
|
return urlFromAboutReader.equals(currentUrl);
|
|
|
|
}
|
|
|
|
|
2013-10-14 06:58:16 -07:00
|
|
|
public static String getAboutReaderForUrl(String url) {
|
|
|
|
return getAboutReaderForUrl(url, -1);
|
2012-09-11 10:51:43 -07:00
|
|
|
}
|
|
|
|
|
2013-10-14 06:58:16 -07:00
|
|
|
public static String getAboutReaderForUrl(String url, int tabId) {
|
2013-11-21 23:33:28 -08:00
|
|
|
String aboutReaderUrl = AboutPages.READER + "?url=" + Uri.encode(url);
|
2012-09-11 10:51:43 -07:00
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
if (tabId >= 0) {
|
2012-09-11 10:51:43 -07:00
|
|
|
aboutReaderUrl += "&tabId=" + tabId;
|
2013-11-21 23:33:28 -08:00
|
|
|
}
|
2012-09-11 10:51:43 -07:00
|
|
|
|
|
|
|
return aboutReaderUrl;
|
|
|
|
}
|
|
|
|
}
|