Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
unify mobile. links and m. links and remove crap #89
Browse files Browse the repository at this point in the history
  • Loading branch information
indywidualny committed Feb 9, 2016
1 parent da5bb79 commit 5a8c467
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 17 additions & 8 deletions app/src/main/java/org/indywidualni/fblite/util/Offline.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ public Offline() {
}

public String getPage(String url) throws SQLException {
url = removeRefID(url);
url = removeEndingSlash(url);
url = cleanUrl(url);
//Log.v(getClass().getSimpleName(), "Getting: " + url);
return dataSource.getPage(url);
}

public void savePage(String url) throws SQLException {
url = removeRefID(url);
url = removeEndingSlash(url);
url = cleanUrl(url);
//Log.v(getClass().getSimpleName(), "Saving: " + url);
new SaveTask().execute(url);
}
Expand Down Expand Up @@ -101,15 +99,26 @@ private void syncCookies() {
}
}

public static String removeEndingSlash(String url) {
private static String removeEndingSlash(String url) {
if (url.length() > 0 && url.charAt(url.length()-1)=='/')
url = url.substring(0, url.length()-1);
return url;
}

public static String removeRefID(String url) {
url = url.replaceAll("\\?refid=.*", "");
return url.replace("home.php", "");
public static String cleanUrl(String url) {
/**
* remove ?refid=* it's always first and nothing is later
* remove ?hrc=* it's always first and nothing important is later
* remove &refsrc=* it's always last and nothing important is later
* remove home.php it's always first and nothing is later (main page)
* replace mobile. to m.
* remove ?_rdr it's always last and nothing is later
* remove &_rdr it's always last and nothing is later
* remove / it's always last and nothing is later
*/
url = url.replaceAll("\\?refid=.*", "").replaceAll("\\?hrc=.*", "").replaceAll("&refsrc=.*", "");
url = url.replace("home.php", "").replace("mobile.", "m.").replace("?_rdr", "").replace("&_rdr", "");
return removeEndingSlash(url);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
} else
offline = null;


/* // todo: remove it, it's just for testing
if (offline != null) {
try {
List<String> pages = offline.getDataSource().getAllPages();
Log.i("OfflineMode", "Pages");
for (String pageUrl : pages) {
Log.i("Page", pageUrl);
}
} catch (Exception ignore) {}
}*/


// save the currently loaded page (needed for a reliable refreshing)
currentlyLoadedPage = url;
}
Expand Down

0 comments on commit 5a8c467

Please sign in to comment.