Browse Source

long-press on a folder on the bookmarks page works correctly now + other cleanup

master
Anthony Restaino 9 years ago
parent
commit
73e8f7c314
  1. 73
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 5
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  3. 5
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  4. 7
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  5. 16
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java
  6. 2
      app/src/main/java/acr/browser/lightning/database/HistoryItem.java

73
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;
import android.animation.ValueAnimator.AnimatorUpdateListener; import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
@ -109,10 +108,7 @@ import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.BookmarkPage;
@ -202,8 +198,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
abstract void closeActivity(); abstract void closeActivity();
abstract int getMenu();
public abstract void updateHistory(final String title, final String url); public abstract void updateHistory(final String title, final String url);
abstract void updateCookiePreference(); abstract void updateCookiePreference();
@ -974,7 +968,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 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); setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(mBookmarkList.get(position).getTitle(), true), true);
return; return;
} }
@ -1723,7 +1717,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
HistoryItem web = data.get(position); HistoryItem web = data.get(position);
holder.txtTitle.setText(web.getTitle()); holder.txtTitle.setText(web.getTitle());
holder.favicon.setImageBitmap(mWebpageBitmap); holder.favicon.setImageBitmap(mWebpageBitmap);
if (web.getIsFolder()) { if (web.isFolder()) {
holder.favicon.setImageBitmap(this.folderIcon); holder.favicon.setImageBitmap(this.folderIcon);
} else if (web.getBitmap() == null) { } else if (web.getBitmap() == null) {
getImage(holder.favicon, web); getImage(holder.favicon, web);
@ -2058,28 +2052,46 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} finally { } finally {
Utils.close(outputStream); Utils.close(outputStream);
} }
StringBuilder bookmarkBuilder = new StringBuilder(); File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
bookmarkBuilder.append(BookmarkPage.HEADING);
Iterator<HistoryItem> iter = mBookmarkList.iterator(); buildBookmarkPage(null, mBookmarkManager.getBookmarksFromFolder(null, true));
HistoryItem helper; view.loadUrl(Constants.FILE + bookmarkWebPage);
String folderPath = Constants.FILE + mActivity.getCacheDir() + "/folder.png"; }
while (iter.hasNext()) {
helper = iter.next(); private void buildBookmarkPage(final String folder, final List<HistoryItem> 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(BookmarkPage.PART1);
bookmarkBuilder.append(helper.getUrl()); if (item.isFolder()) {
bookmarkBuilder.append(BookmarkPage.PART2); File folderPage = new File(mActivity.getFilesDir(), item.getTitle() + '-' + BookmarkPage.FILENAME);
if (helper.getIsFolder()) { bookmarkBuilder.append(Constants.FILE).append(folderPage);
bookmarkBuilder.append(folderPath); 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 { } else {
bookmarkBuilder.append(BookmarkPage.PART3); bookmarkBuilder.append(item.getUrl());
bookmarkBuilder.append(helper.getUrl()); bookmarkBuilder.append(BookmarkPage.PART2).append(BookmarkPage.PART3);
bookmarkBuilder.append(item.getUrl());
} }
bookmarkBuilder.append(BookmarkPage.PART4); bookmarkBuilder.append(BookmarkPage.PART4);
bookmarkBuilder.append(helper.getTitle()); bookmarkBuilder.append(item.getTitle());
bookmarkBuilder.append(BookmarkPage.PART5); bookmarkBuilder.append(BookmarkPage.PART5);
} }
bookmarkBuilder.append(BookmarkPage.END); bookmarkBuilder.append(BookmarkPage.END);
File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
FileWriter bookWriter = null; FileWriter bookWriter = null;
try { try {
bookWriter = new FileWriter(bookmarkWebPage, false); bookWriter = new FileWriter(bookmarkWebPage, false);
@ -2089,8 +2101,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} finally { } finally {
Utils.close(bookWriter); Utils.close(bookWriter);
} }
view.loadUrl(Constants.FILE + bookmarkWebPage);
} }
@Override @Override
@ -2526,7 +2536,14 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} }
private void longPressFolder(String url) { 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) { if (position == -1) {
return; return;
} }
@ -2565,7 +2582,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
} }
private void longPressBookmarkLink(final String url) { private void longPressBookmarkLink(final String url) {
if (url.startsWith(Constants.FOLDER)) { if (url.startsWith(Constants.FILE)) {
longPressFolder(url); longPressFolder(url);
return; return;
} }
@ -2838,7 +2855,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
} }
private NetworkReceiver mNetworkReceiver = new NetworkReceiver() { private final NetworkReceiver mNetworkReceiver = new NetworkReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent); super.onReceive(context, intent);

5
app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java

@ -59,9 +59,4 @@ public class IncognitoActivity extends BrowserActivity {
closeDrawers(); closeDrawers();
finish(); finish();
} }
@Override
public int getMenu() {
return R.menu.incognito;
}
} }

5
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -55,11 +55,6 @@ public class MainActivity extends BrowserActivity {
return false; return false;
} }
@Override
public int getMenu() {
return R.menu.main;
}
@Override @Override
public void closeActivity() { public void closeActivity() {
closeDrawers(); closeDrawers();

7
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -21,12 +21,11 @@ public class BookmarkPage {
"</head>\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{" + "<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" + "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" + "<body><div id=content>";
"<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>\n" + public static final String PART2 = "'></a>\n" +
"<div class=margin>\n" + "<div class=margin>\n" +
"<div class=box-content>\n" + "<div class=box-content>\n" +
"<p class=ellipses>\n" + "<p class=ellipses>\n" +

16
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -129,7 +129,7 @@ public class BookmarkManager {
* @param deleteItem the bookmark item to delete * @param deleteItem the bookmark item to delete
*/ */
public synchronized boolean deleteBookmark(HistoryItem deleteItem) { public synchronized boolean deleteBookmark(HistoryItem deleteItem) {
if (deleteItem == null || deleteItem.getIsFolder()) { if (deleteItem == null || deleteItem.isFolder()) {
return false; return false;
} }
mBookmarkSearchSet.remove(deleteItem.getUrl()); mBookmarkSearchSet.remove(deleteItem.getUrl());
@ -151,7 +151,7 @@ public class BookmarkManager {
for (int n = 0; n < mBookmarkList.size(); n++) { for (int n = 0; n < mBookmarkList.size(); n++) {
if (mBookmarkList.get(n).getFolder().equals(oldName)) { if (mBookmarkList.get(n).getFolder().equals(oldName)) {
mBookmarkList.get(n).setFolder(newName); 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).setTitle(newName);
mBookmarkList.get(n).setUrl(Constants.FOLDER + newName); mBookmarkList.get(n).setUrl(Constants.FOLDER + newName);
} }
@ -168,7 +168,7 @@ public class BookmarkManager {
Iterator<HistoryItem> iterator = mBookmarkList.iterator(); Iterator<HistoryItem> iterator = mBookmarkList.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
HistoryItem item = iterator.next(); HistoryItem item = iterator.next();
if (!item.getIsFolder() && item.getFolder().equals(name)) { if (!item.isFolder() && item.getFolder().equals(name)) {
item.setFolder(""); item.setFolder("");
} else if (item.getTitle().equals(name)) { } else if (item.getTitle().equals(name)) {
iterator.remove(); iterator.remove();
@ -184,7 +184,7 @@ public class BookmarkManager {
* @param newItem This is the new item that will overwrite the old item * @param newItem This is the new item that will overwrite the old item
*/ */
public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) { public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) {
if (oldItem == null || newItem == null || oldItem.getIsFolder()) { if (oldItem == null || newItem == null || oldItem.isFolder()) {
return; return;
} }
mBookmarkList.remove(oldItem); mBookmarkList.remove(oldItem);
@ -321,7 +321,7 @@ public class BookmarkManager {
private static Set<String> getBookmarkUrls(List<HistoryItem> list) { private static Set<String> getBookmarkUrls(List<HistoryItem> list) {
Set<String> set = new HashSet<>(); Set<String> set = new HashSet<>();
for (int n = 0; n < list.size(); n++) { for (int n = 0; n < list.size(); n++) {
if (!mBookmarkList.get(n).getIsFolder()) if (!mBookmarkList.get(n).isFolder())
set.add(mBookmarkList.get(n).getUrl()); set.add(mBookmarkList.get(n).getUrl());
} }
return set; return set;
@ -455,7 +455,7 @@ public class BookmarkManager {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
for (int n = 0; n < list.size(); n++) { for (int n = 0; n < list.size(); n++) {
HistoryItem item = list.get(n); HistoryItem item = list.get(n);
if (!item.getIsFolder()) { if (!item.isFolder()) {
object.put(TITLE, item.getTitle()); object.put(TITLE, item.getTitle());
object.put(URL, item.getUrl()); object.put(URL, item.getUrl());
object.put(FOLDER, item.getFolder()); object.put(FOLDER, item.getFolder());
@ -496,12 +496,12 @@ public class BookmarkManager {
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()) { if (o1.isFolder() == o2.isFolder()) {
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 { } else {
return o1.getIsFolder() ? 1 : -1; return o1.isFolder() ? 1 : -1;
} }
} }

2
app/src/main/java/acr/browser/lightning/database/HistoryItem.java

@ -120,7 +120,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
mIsFolder = isFolder; mIsFolder = isFolder;
} }
public boolean getIsFolder() { public boolean isFolder() {
return mIsFolder; return mIsFolder;
} }

Loading…
Cancel
Save