diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 95dd657..58b87e2 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -9,7 +9,6 @@ import android.animation.LayoutTransition; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.app.Activity; -import android.app.Dialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -109,10 +108,7 @@ import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; import java.util.List; -import java.util.Locale; import acr.browser.lightning.R; import acr.browser.lightning.constant.BookmarkPage; @@ -202,8 +198,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse abstract void closeActivity(); - abstract int getMenu(); - public abstract void updateHistory(final String title, final String url); abstract void updateCookiePreference(); @@ -974,7 +968,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - if (mBookmarkList.get(position).getIsFolder()) { + if (mBookmarkList.get(position).isFolder()) { setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(mBookmarkList.get(position).getTitle(), true), true); return; } @@ -1723,7 +1717,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse HistoryItem web = data.get(position); holder.txtTitle.setText(web.getTitle()); holder.favicon.setImageBitmap(mWebpageBitmap); - if (web.getIsFolder()) { + if (web.isFolder()) { holder.favicon.setImageBitmap(this.folderIcon); } else if (web.getBitmap() == null) { getImage(holder.favicon, web); @@ -2058,28 +2052,46 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse } finally { Utils.close(outputStream); } - StringBuilder bookmarkBuilder = new StringBuilder(); - bookmarkBuilder.append(BookmarkPage.HEADING); - Iterator iter = mBookmarkList.iterator(); - HistoryItem helper; - String folderPath = Constants.FILE + mActivity.getCacheDir() + "/folder.png"; - while (iter.hasNext()) { - helper = iter.next(); + File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME); + + buildBookmarkPage(null, mBookmarkManager.getBookmarksFromFolder(null, true)); + view.loadUrl(Constants.FILE + bookmarkWebPage); + } + + private void buildBookmarkPage(final String folder, final List list) { + File bookmarkWebPage; + if (folder == null || folder.length() == 0) { + bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME); + } else { + bookmarkWebPage = new File(mActivity.getFilesDir(), folder + '-' + BookmarkPage.FILENAME); + } + final StringBuilder bookmarkBuilder = new StringBuilder(BookmarkPage.HEADING); + + String folderIconPath = Constants.FILE + mActivity.getCacheDir() + "/folder.png"; + for (int n = 0; n < list.size(); n++) { + final HistoryItem item = list.get(n); bookmarkBuilder.append(BookmarkPage.PART1); - bookmarkBuilder.append(helper.getUrl()); - bookmarkBuilder.append(BookmarkPage.PART2); - if (helper.getIsFolder()) { - bookmarkBuilder.append(folderPath); + if (item.isFolder()) { + File folderPage = new File(mActivity.getFilesDir(), item.getTitle() + '-' + BookmarkPage.FILENAME); + bookmarkBuilder.append(Constants.FILE).append(folderPage); + bookmarkBuilder.append(BookmarkPage.PART2); + bookmarkBuilder.append(folderIconPath); + new Thread(new Runnable() { + @Override + public void run() { + buildBookmarkPage(item.getTitle(), mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true)); + } + }).run(); } else { - bookmarkBuilder.append(BookmarkPage.PART3); - bookmarkBuilder.append(helper.getUrl()); + bookmarkBuilder.append(item.getUrl()); + bookmarkBuilder.append(BookmarkPage.PART2).append(BookmarkPage.PART3); + bookmarkBuilder.append(item.getUrl()); } bookmarkBuilder.append(BookmarkPage.PART4); - bookmarkBuilder.append(helper.getTitle()); + bookmarkBuilder.append(item.getTitle()); bookmarkBuilder.append(BookmarkPage.PART5); } bookmarkBuilder.append(BookmarkPage.END); - File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME); FileWriter bookWriter = null; try { bookWriter = new FileWriter(bookmarkWebPage, false); @@ -2089,8 +2101,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse } finally { Utils.close(bookWriter); } - - view.loadUrl(Constants.FILE + bookmarkWebPage); } @Override @@ -2526,7 +2536,14 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse } private void longPressFolder(String url) { - final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, url); + // We are getting the title from the url + // Strip '-bookmarks.html' from the end of the url + String title = url.substring(0, url.length() - BookmarkPage.FILENAME.length() - 1); + + // Strip the beginning of the url off and leave only the title + title = title.substring(Constants.FILE.length() + mActivity.getFilesDir().toString().length() + 1); + + final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, Constants.FOLDER + title); if (position == -1) { return; } @@ -2565,7 +2582,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse } private void longPressBookmarkLink(final String url) { - if (url.startsWith(Constants.FOLDER)) { + if (url.startsWith(Constants.FILE)) { longPressFolder(url); return; } @@ -2838,7 +2855,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); } - private NetworkReceiver mNetworkReceiver = new NetworkReceiver() { + private final NetworkReceiver mNetworkReceiver = new NetworkReceiver() { @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); diff --git a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java b/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java index 46a4f15..b7be9d3 100644 --- a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java @@ -59,9 +59,4 @@ public class IncognitoActivity extends BrowserActivity { closeDrawers(); finish(); } - - @Override - public int getMenu() { - return R.menu.incognito; - } } diff --git a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java index 59d1f42..32a867d 100644 --- a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java @@ -55,11 +55,6 @@ public class MainActivity extends BrowserActivity { return false; } - @Override - public int getMenu() { - return R.menu.main; - } - @Override public void closeActivity() { closeDrawers(); diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index fdfdc25..20e0ff7 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -21,12 +21,11 @@ public class BookmarkPage { "\n" + "\n" + - "\n" + - "
"; + "
"; - public static final String PART1 = "
\n" + "
\n" + "
\n" + "

\n" + diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java index 69e52cb..f6f41f2 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java @@ -129,7 +129,7 @@ public class BookmarkManager { * @param deleteItem the bookmark item to delete */ public synchronized boolean deleteBookmark(HistoryItem deleteItem) { - if (deleteItem == null || deleteItem.getIsFolder()) { + if (deleteItem == null || deleteItem.isFolder()) { return false; } mBookmarkSearchSet.remove(deleteItem.getUrl()); @@ -151,7 +151,7 @@ public class BookmarkManager { for (int n = 0; n < mBookmarkList.size(); n++) { if (mBookmarkList.get(n).getFolder().equals(oldName)) { mBookmarkList.get(n).setFolder(newName); - } else if (mBookmarkList.get(n).getIsFolder() && mBookmarkList.get(n).getTitle().equals(oldName)) { + } else if (mBookmarkList.get(n).isFolder() && mBookmarkList.get(n).getTitle().equals(oldName)) { mBookmarkList.get(n).setTitle(newName); mBookmarkList.get(n).setUrl(Constants.FOLDER + newName); } @@ -168,7 +168,7 @@ public class BookmarkManager { Iterator iterator = mBookmarkList.iterator(); while (iterator.hasNext()) { HistoryItem item = iterator.next(); - if (!item.getIsFolder() && item.getFolder().equals(name)) { + if (!item.isFolder() && item.getFolder().equals(name)) { item.setFolder(""); } else if (item.getTitle().equals(name)) { iterator.remove(); @@ -184,7 +184,7 @@ public class BookmarkManager { * @param newItem This is the new item that will overwrite the old item */ public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) { - if (oldItem == null || newItem == null || oldItem.getIsFolder()) { + if (oldItem == null || newItem == null || oldItem.isFolder()) { return; } mBookmarkList.remove(oldItem); @@ -321,7 +321,7 @@ public class BookmarkManager { private static Set getBookmarkUrls(List list) { Set set = new HashSet<>(); for (int n = 0; n < list.size(); n++) { - if (!mBookmarkList.get(n).getIsFolder()) + if (!mBookmarkList.get(n).isFolder()) set.add(mBookmarkList.get(n).getUrl()); } return set; @@ -455,7 +455,7 @@ public class BookmarkManager { JSONObject object = new JSONObject(); for (int n = 0; n < list.size(); n++) { HistoryItem item = list.get(n); - if (!item.getIsFolder()) { + if (!item.isFolder()) { object.put(TITLE, item.getTitle()); object.put(URL, item.getUrl()); object.put(FOLDER, item.getFolder()); @@ -496,12 +496,12 @@ public class BookmarkManager { if (o1 == null || o2 == null || o1.getTitle() == null || o2.getTitle() == null) { return 0; } - if (o1.getIsFolder() == o2.getIsFolder()) { + if (o1.isFolder() == o2.isFolder()) { return o1.getTitle().toLowerCase(Locale.getDefault()) .compareTo(o2.getTitle().toLowerCase(Locale.getDefault())); } else { - return o1.getIsFolder() ? 1 : -1; + return o1.isFolder() ? 1 : -1; } } diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index 6bb3c00..b4a4309 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -120,7 +120,7 @@ public class HistoryItem implements Comparable { mIsFolder = isFolder; } - public boolean getIsFolder() { + public boolean isFolder() { return mIsFolder; }