Sort bookmarks so folders are at the end of the list, updated bookmarks page to better utilize space
This commit is contained in:
parent
69deb5b5a2
commit
aced4a3cc7
@ -335,7 +335,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
mBookmarkList.add(bookmark);
|
mBookmarkList.add(bookmark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
Collections.sort(mBookmarkList, new BookmarkManager.SortIgnoreCase());
|
||||||
mPreferences.setDefaultBookmarks(false);
|
mPreferences.setDefaultBookmarks(false);
|
||||||
}
|
}
|
||||||
mBookmarkAdapter = new BookmarkViewAdapter(mActivity, R.layout.bookmark_list_item,
|
mBookmarkAdapter = new BookmarkViewAdapter(mActivity, R.layout.bookmark_list_item,
|
||||||
@ -822,7 +822,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
HistoryItem bookmark = new HistoryItem(url, title);
|
HistoryItem bookmark = new HistoryItem(url, title);
|
||||||
if (mBookmarkManager.addBookmark(bookmark)) {
|
if (mBookmarkManager.addBookmark(bookmark)) {
|
||||||
mBookmarkList.add(bookmark);
|
mBookmarkList.add(bookmark);
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
Collections.sort(mBookmarkList, new BookmarkManager.SortIgnoreCase());
|
||||||
notifyBookmarkDataSetChanged();
|
notifyBookmarkDataSetChanged();
|
||||||
mSearchAdapter.refreshBookmarks();
|
mSearchAdapter.refreshBookmarks();
|
||||||
updateBookmarkIndicator(mCurrentView.getUrl());
|
updateBookmarkIndicator(mCurrentView.getUrl());
|
||||||
@ -1041,6 +1041,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
String currentFolder = mBookmarkList.get(id).getFolder();
|
String currentFolder = mBookmarkList.get(id).getFolder();
|
||||||
item.setTitle(getTitle.getText().toString());
|
item.setTitle(getTitle.getText().toString());
|
||||||
item.setUrl(getUrl.getText().toString());
|
item.setUrl(getUrl.getText().toString());
|
||||||
|
item.setUrl(getUrl.getText().toString());
|
||||||
item.setFolder(getFolder.getText().toString());
|
item.setFolder(getFolder.getText().toString());
|
||||||
mBookmarkManager.editBookmark(mBookmarkList.get(id), item);
|
mBookmarkManager.editBookmark(mBookmarkList.get(id), item);
|
||||||
|
|
||||||
@ -1051,7 +1052,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
setBookmarkDataSet(list, false);
|
setBookmarkDataSet(list, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
|
||||||
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||||
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
openBookmarkPage(mWebView);
|
openBookmarkPage(mWebView);
|
||||||
@ -1094,7 +1094,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
|
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
|
||||||
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||||
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
openBookmarkPage(mWebView);
|
openBookmarkPage(mWebView);
|
||||||
@ -2544,7 +2543,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
|
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
|
||||||
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||||
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
openBookmarkPage(mWebView);
|
openBookmarkPage(mWebView);
|
||||||
@ -2760,15 +2758,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SortIgnoreCase implements Comparator<HistoryItem> {
|
|
||||||
|
|
||||||
public int compare(HistoryItem o1, HistoryItem o2) {
|
|
||||||
return o1.getTitle().toLowerCase(Locale.getDefault())
|
|
||||||
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
|
@ -10,19 +10,33 @@ public class BookmarkPage {
|
|||||||
|
|
||||||
public static final String FILENAME = "bookmarks.html";
|
public static final String FILENAME = "bookmarks.html";
|
||||||
|
|
||||||
public static final String HEADING = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"><title>"
|
public static final String HEADING = "<!DOCTYPE html><html xmlns=http://www.w3.org/1999/xhtml>\n" +
|
||||||
+ BrowserApp.getAppContext().getString(R.string.action_bookmarks)
|
"<head>\n" +
|
||||||
+ "</title></head><style>body { background: #e1e1e1; max-width:100%; min-height:100%;}#content {width:100%; max-width:800px; margin:0 auto; text-align:center;}.box { vertical-align:middle;text-align:center;position:relative; display: inline-block; height: 100px; width: 100px; margin: 10px; background-color:#fff;box-shadow: 0px 2px 3px rgba( 0, 0, 0, 0.25 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.stuff {height: 100px; width: 100px;vertical-align:middle;text-align:center; display: table-cell;}p.ellipses {width:90px; white-space: nowrap; overflow: hidden;text-align:center;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}</style><body> <div id=\"content\">";
|
"<meta content=en-us http-equiv=Content-Language />\n" +
|
||||||
|
"<meta content='text/html; charset=utf-8' http-equiv=Content-Type />\n" +
|
||||||
|
"<meta name=viewport content='width=device-width, initial-scale=1.0'>\n" +
|
||||||
|
"<title>" +
|
||||||
|
BrowserApp.getAppContext().getString(R.string.action_bookmarks) +
|
||||||
|
"</title>\n" +
|
||||||
|
"</head>\n" +
|
||||||
|
"<style>body{background:#e1e1e1;max-width:100%;min-height:100%}#content{width:100%;max-width:800px;margin:0 auto;text-align:center}.box{vertical-align:middle;text-align:center;position:relative;display:inline-block;height:45px;width:150px;margin:10px;background-color:#fff;box-shadow:0 3px 6px rgba(0,0,0,0.25);font-family:Arial;color:#444;font-size:12px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px}.box-content{height:25px;width:100%;vertical-align:middle;text-align:center;display:table-cell}p.ellipses{" +
|
||||||
|
"width:130px;font-size: small;font-family: Arial, Helvetica, 'sans-serif';white-space:nowrap;overflow:hidden;text-align:left;vertical-align:middle;margin:auto;text-overflow:ellipsis;-o-text-overflow:ellipsis;-ms-text-overflow:ellipsis}.box a{width:100%;height:100%;position:absolute;left:0;top:0}img{vertical-align:middle;margin-right:10px;width:20px;height:20px;}.margin{margin:10px}</style>\n" +
|
||||||
|
"<body>\n" +
|
||||||
|
"<div id=content>";
|
||||||
|
|
||||||
public static final String PART1 = "<div class=\"box\"><a href=\"";
|
public static final String PART1 = "<div class=box><a href=";
|
||||||
|
|
||||||
public static final String PART2 = "\" ></a><div class=\"stuff\" ><img height=\"20\" width=\"20\" src='";
|
public static final String PART2 = "></a>\n" +
|
||||||
|
"<div class=margin>\n" +
|
||||||
|
"<div class=box-content>\n" +
|
||||||
|
"<p class=ellipses>\n" +
|
||||||
|
"<img src='";
|
||||||
|
|
||||||
public static final String PART3 = "http://www.google.com/s2/favicons?domain=";
|
public static final String PART3 = "http://www.google.com/s2/favicons?domain=";
|
||||||
|
|
||||||
public static final String PART4 = "' /><p class=\"ellipses\">";
|
public static final String PART4 = "' />";
|
||||||
|
|
||||||
public static final String PART5 = "</p></div></div>";
|
public static final String PART5 = "</p></div></div></div>";
|
||||||
|
|
||||||
public static final String END = "</div></body></html>";
|
public static final String END = "</div></body></html>";
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import android.support.annotation.NonNull;
|
|||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.w3c.dom.ls.LSInput;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -290,8 +289,6 @@ public class BookmarkManager {
|
|||||||
*/
|
*/
|
||||||
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder, boolean sort) {
|
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder, boolean sort) {
|
||||||
List<HistoryItem> bookmarks = new ArrayList<>();
|
List<HistoryItem> bookmarks = new ArrayList<>();
|
||||||
// File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
|
||||||
// BufferedReader bookmarksReader = null;
|
|
||||||
if (folder == null || folder.length() == 0) {
|
if (folder == null || folder.length() == 0) {
|
||||||
bookmarks.addAll(getFolders(sort));
|
bookmarks.addAll(getFolders(sort));
|
||||||
folder = "";
|
folder = "";
|
||||||
@ -301,26 +298,6 @@ public class BookmarkManager {
|
|||||||
if (mBookmarkList.get(n).getFolder().equals(folder))
|
if (mBookmarkList.get(n).getFolder().equals(folder))
|
||||||
bookmarks.add(mBookmarkList.get(n));
|
bookmarks.add(mBookmarkList.get(n));
|
||||||
}
|
}
|
||||||
// try {
|
|
||||||
// bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
|
|
||||||
// String line;
|
|
||||||
// while ((line = bookmarksReader.readLine()) != null) {
|
|
||||||
// JSONObject object = new JSONObject(line);
|
|
||||||
// if (object.getString(FOLDER).equals(folder)) {
|
|
||||||
// HistoryItem item = new HistoryItem();
|
|
||||||
// item.setTitle(object.getString(TITLE));
|
|
||||||
// item.setUrl(object.getString(URL));
|
|
||||||
// item.setFolder(object.getString(FOLDER));
|
|
||||||
// item.setOrder(object.getInt(ORDER));
|
|
||||||
// item.setImageId(R.drawable.ic_bookmark);
|
|
||||||
// bookmarks.add(item);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } catch (IOException | JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// } finally {
|
|
||||||
// Utils.close(bookmarksReader);
|
|
||||||
// }
|
|
||||||
if (sort) {
|
if (sort) {
|
||||||
Collections.sort(bookmarks, new SortIgnoreCase());
|
Collections.sort(bookmarks, new SortIgnoreCase());
|
||||||
}
|
}
|
||||||
@ -510,14 +487,22 @@ public class BookmarkManager {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SortIgnoreCase implements Comparator<HistoryItem> {
|
/**
|
||||||
|
* This class sorts bookmarks alphabetically, with folders coming after bookmarks
|
||||||
|
*/
|
||||||
|
public static class SortIgnoreCase implements Comparator<HistoryItem> {
|
||||||
|
|
||||||
public int compare(HistoryItem o1, HistoryItem o2) {
|
public int compare(HistoryItem o1, HistoryItem o2) {
|
||||||
if (o1 == null || o2 == null || o1.getTitle() == null || o2.getTitle() == null) {
|
if (o1 == null || o2 == null || o1.getTitle() == null || o2.getTitle() == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (o1.getIsFolder() == o2.getIsFolder()) {
|
||||||
return o1.getTitle().toLowerCase(Locale.getDefault())
|
return o1.getTitle().toLowerCase(Locale.getDefault())
|
||||||
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
|
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return o1.getIsFolder() ? 1 : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user