Utilize new BookmarkManager class for bookmarks
This commit is contained in:
parent
d908513dbd
commit
df51c67909
@ -9,7 +9,6 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -778,33 +777,7 @@ public class AdvancedSettingsActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void importFromStockBrowser() {
|
public void importFromStockBrowser() {
|
||||||
if (mSystemBrowser) {
|
BookmarkManager manager = new BookmarkManager(this);
|
||||||
String[] proj = new String[] { Browser.BookmarkColumns.TITLE,
|
manager.importBookmarksFromBrowser();
|
||||||
Browser.BookmarkColumns.URL };
|
|
||||||
// use 0 for history, 1 for bookmarks
|
|
||||||
String sel = Browser.BookmarkColumns.BOOKMARK + " = 1";
|
|
||||||
Cursor mCur;
|
|
||||||
mCur = getContentResolver().query(Browser.BOOKMARKS_URI, proj, sel, null, null);
|
|
||||||
|
|
||||||
String title, url;
|
|
||||||
int number = 0;
|
|
||||||
if (mCur.moveToFirst() && mCur.getCount() > 0) {
|
|
||||||
while (!mCur.isAfterLast()) {
|
|
||||||
number++;
|
|
||||||
title = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.TITLE));
|
|
||||||
url = mCur.getString(mCur.getColumnIndex(Browser.BookmarkColumns.URL));
|
|
||||||
if (title.length() < 1) {
|
|
||||||
title = Utils.getDomainName(url);
|
|
||||||
}
|
|
||||||
Utils.addBookmark(mContext, title, url);
|
|
||||||
mCur.moveToNext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Utils.showToast(mContext,
|
|
||||||
number + " " + getResources().getString(R.string.message_import));
|
|
||||||
} else {
|
|
||||||
Utils.createInformativeDialog(mContext, getResources().getString(R.string.title_error),
|
|
||||||
getResources().getString(R.string.dialog_import_error));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,11 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
*/
|
*/
|
||||||
public void addBookmark(HistoryItem item) {
|
public synchronized boolean addBookmark(HistoryItem item) {
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
|
|
||||||
if (mBookmarkMap.containsKey(item.getUrl())) {
|
if (mBookmarkMap.containsKey(item.getUrl())) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true));
|
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true));
|
||||||
@ -63,6 +63,7 @@ public class BookmarkManager {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +71,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
public void addBookmarkList(List<HistoryItem> list) {
|
public synchronized void addBookmarkList(List<HistoryItem> list) {
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true));
|
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true));
|
||||||
@ -99,11 +100,12 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param url
|
* @param url
|
||||||
*/
|
*/
|
||||||
public void deleteBookmark(String url) {
|
public synchronized boolean deleteBookmark(String url) {
|
||||||
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
||||||
mBookmarkMap.remove(url);
|
mBookmarkMap.remove(url);
|
||||||
list = getBookmarks();
|
list = getBookmarks();
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
|
boolean bookmarkDeleted = false;
|
||||||
try {
|
try {
|
||||||
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
||||||
for (HistoryItem item : list) {
|
for (HistoryItem item : list) {
|
||||||
@ -115,6 +117,8 @@ public class BookmarkManager {
|
|||||||
object.put(ORDER, item.getOrder());
|
object.put(ORDER, item.getOrder());
|
||||||
fileWriter.write(object.toString());
|
fileWriter.write(object.toString());
|
||||||
fileWriter.newLine();
|
fileWriter.newLine();
|
||||||
|
} else {
|
||||||
|
bookmarkDeleted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
@ -123,13 +127,14 @@ public class BookmarkManager {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return bookmarkDeleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method exports the stored bookmarks to a text file in the device's
|
* This method exports the stored bookmarks to a text file in the device's
|
||||||
* external download directory
|
* external download directory
|
||||||
*/
|
*/
|
||||||
public void exportBookmarks() {
|
public synchronized void exportBookmarks() {
|
||||||
List<HistoryItem> bookmarkList = getBookmarks();
|
List<HistoryItem> bookmarkList = getBookmarks();
|
||||||
File bookmarksExport = new File(
|
File bookmarksExport = new File(
|
||||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
||||||
@ -159,7 +164,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<HistoryItem> getBookmarks() {
|
public synchronized List<HistoryItem> getBookmarks() {
|
||||||
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
@ -172,6 +177,7 @@ public class BookmarkManager {
|
|||||||
item.setUrl(object.getString(URL));
|
item.setUrl(object.getString(URL));
|
||||||
item.setFolder(object.getString(FOLDER));
|
item.setFolder(object.getString(FOLDER));
|
||||||
item.setOrder(object.getInt(ORDER));
|
item.setOrder(object.getInt(ORDER));
|
||||||
|
item.setImageId(R.drawable.ic_bookmark);
|
||||||
bookmarks.add(item);
|
bookmarks.add(item);
|
||||||
}
|
}
|
||||||
bookmarksReader.close();
|
bookmarksReader.close();
|
||||||
@ -191,7 +197,7 @@ public class BookmarkManager {
|
|||||||
* @param folder
|
* @param folder
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<HistoryItem> getBookmarksFromFolder(String folder) {
|
public synchronized List<HistoryItem> getBookmarksFromFolder(String folder) {
|
||||||
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
@ -205,6 +211,7 @@ public class BookmarkManager {
|
|||||||
item.setUrl(object.getString(URL));
|
item.setUrl(object.getString(URL));
|
||||||
item.setFolder(object.getString(FOLDER));
|
item.setFolder(object.getString(FOLDER));
|
||||||
item.setOrder(object.getInt(ORDER));
|
item.setOrder(object.getInt(ORDER));
|
||||||
|
item.setImageId(R.drawable.ic_bookmark);
|
||||||
bookmarks.add(item);
|
bookmarks.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,7 +231,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private SortedMap<String, Integer> getBookmarkUrls() {
|
private synchronized SortedMap<String, Integer> getBookmarkUrls() {
|
||||||
SortedMap<String, Integer> map = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
|
SortedMap<String, Integer> map = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
@ -250,7 +257,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<HistoryItem> getFolders() {
|
public synchronized List<HistoryItem> getFolders() {
|
||||||
List<HistoryItem> folders = new ArrayList<HistoryItem>();
|
List<HistoryItem> folders = new ArrayList<HistoryItem>();
|
||||||
SortedMap<String, Integer> folderMap = new TreeMap<String, Integer>(
|
SortedMap<String, Integer> folderMap = new TreeMap<String, Integer>(
|
||||||
String.CASE_INSENSITIVE_ORDER);
|
String.CASE_INSENSITIVE_ORDER);
|
||||||
@ -284,7 +291,7 @@ public class BookmarkManager {
|
|||||||
* This method imports all bookmarks that are included in the device's
|
* This method imports all bookmarks that are included in the device's
|
||||||
* permanent bookmark storage
|
* permanent bookmark storage
|
||||||
*/
|
*/
|
||||||
public void importBookmarksFromBrowser() {
|
public synchronized void importBookmarksFromBrowser() {
|
||||||
if (mContext.getSharedPreferences(PreferenceConstants.PREFERENCES, 0).getBoolean(
|
if (mContext.getSharedPreferences(PreferenceConstants.PREFERENCES, 0).getBoolean(
|
||||||
PreferenceConstants.SYSTEM_BROWSER_PRESENT, false)) {
|
PreferenceConstants.SYSTEM_BROWSER_PRESENT, false)) {
|
||||||
|
|
||||||
@ -328,7 +335,7 @@ public class BookmarkManager {
|
|||||||
* @param dir
|
* @param dir
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
public void importBookmarksFromFile(File dir, String file) {
|
public synchronized void importBookmarksFromFile(File dir, String file) {
|
||||||
File bookmarksImport = new File(dir, file);
|
File bookmarksImport = new File(dir, file);
|
||||||
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
List<HistoryItem> list = new ArrayList<HistoryItem>();
|
||||||
try {
|
try {
|
||||||
@ -361,7 +368,7 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param list
|
* @param list
|
||||||
*/
|
*/
|
||||||
public void overwriteBookmarks(List<HistoryItem> list) {
|
public synchronized void overwriteBookmarks(List<HistoryItem> list) {
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
try {
|
try {
|
||||||
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
||||||
|
@ -117,6 +117,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
private static SearchAdapter mSearchAdapter;
|
private static SearchAdapter mSearchAdapter;
|
||||||
private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT,
|
private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
LayoutParams.MATCH_PARENT);
|
LayoutParams.MATCH_PARENT);
|
||||||
|
private BookmarkManager mBookmarkManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -144,7 +145,12 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
} else {
|
} else {
|
||||||
mWebViews = new ArrayList<LightningView>();
|
mWebViews = new ArrayList<LightningView>();
|
||||||
}
|
}
|
||||||
|
mBookmarkManager = new BookmarkManager(this);
|
||||||
|
if (!mPreferences.getBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, false)) {
|
||||||
|
List<HistoryItem> old = Utils.getOldBookmarks(this);
|
||||||
|
mBookmarkManager.addBookmarkList(old);
|
||||||
|
mEditPrefs.putBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, true).apply();
|
||||||
|
}
|
||||||
mActivity = this;
|
mActivity = this;
|
||||||
mClickHandler = new ClickHandler(this);
|
mClickHandler = new ClickHandler(this);
|
||||||
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
|
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
|
||||||
@ -179,7 +185,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
|
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
|
||||||
mDrawerList.setOnItemLongClickListener(new DrawerItemLongClickListener());
|
mDrawerList.setOnItemLongClickListener(new DrawerItemLongClickListener());
|
||||||
|
|
||||||
mBookmarkList = getBookmarks();
|
mBookmarkList = mBookmarkManager.getBookmarks();
|
||||||
mBookmarkAdapter = new BookmarkViewAdapter(this, R.layout.bookmark_list_item, mBookmarkList);
|
mBookmarkAdapter = new BookmarkViewAdapter(this, R.layout.bookmark_list_item, mBookmarkList);
|
||||||
mDrawerListRight.setAdapter(mBookmarkAdapter);
|
mDrawerListRight.setAdapter(mBookmarkAdapter);
|
||||||
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
|
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
|
||||||
@ -715,7 +721,14 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
return true;
|
return true;
|
||||||
case R.id.action_add_bookmark:
|
case R.id.action_add_bookmark:
|
||||||
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
|
if (!mCurrentView.getUrl().startsWith(Constants.FILE)) {
|
||||||
addBookmark(this, mCurrentView.getTitle(), mCurrentView.getUrl());
|
HistoryItem bookmark = new HistoryItem(mCurrentView.getUrl(),
|
||||||
|
mCurrentView.getTitle());
|
||||||
|
if (mBookmarkManager.addBookmark(bookmark)) {
|
||||||
|
mBookmarkList.add(bookmark);
|
||||||
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||||||
|
notifyBookmarkDataSetChanged();
|
||||||
|
mSearchAdapter.refreshBookmarks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_find:
|
case R.id.action_find:
|
||||||
@ -825,7 +838,13 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
deleteBookmark(mBookmarkList.get(position).getUrl());
|
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position)
|
||||||
|
.getUrl())) {
|
||||||
|
mBookmarkList.remove(position);
|
||||||
|
notifyBookmarkDataSetChanged();
|
||||||
|
mSearchAdapter.refreshBookmarks();
|
||||||
|
openBookmarks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNeutralButton(getResources().getString(R.string.action_edit),
|
.setNeutralButton(getResources().getString(R.string.action_edit),
|
||||||
@ -872,29 +891,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
mBookmarkList.get(id).setTitle(getTitle.getText().toString());
|
mBookmarkList.get(id).setTitle(getTitle.getText().toString());
|
||||||
mBookmarkList.get(id).setUrl(getUrl.getText().toString());
|
mBookmarkList.get(id).setUrl(getUrl.getText().toString());
|
||||||
notifyBookmarkDataSetChanged();
|
mBookmarkManager.overwriteBookmarks(mBookmarkList);
|
||||||
File book = new File(getFilesDir(), "bookmarks");
|
|
||||||
File bookUrl = new File(getFilesDir(), "bookurl");
|
|
||||||
try {
|
|
||||||
BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book));
|
|
||||||
BufferedWriter urlWriter = new BufferedWriter(new FileWriter(bookUrl));
|
|
||||||
Iterator<HistoryItem> iter = mBookmarkList.iterator();
|
|
||||||
HistoryItem item;
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
item = iter.next();
|
|
||||||
|
|
||||||
bookWriter.write(item.getTitle());
|
|
||||||
urlWriter.write(item.getUrl());
|
|
||||||
bookWriter.newLine();
|
|
||||||
urlWriter.newLine();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bookWriter.close();
|
|
||||||
urlWriter.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||||||
notifyBookmarkDataSetChanged();
|
notifyBookmarkDataSetChanged();
|
||||||
if (mCurrentView != null) {
|
if (mCurrentView != null) {
|
||||||
@ -1278,7 +1275,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
} else if (!mHistoryHandler.isOpen()) {
|
} else if (!mHistoryHandler.isOpen()) {
|
||||||
mHistoryHandler = new HistoryDatabaseHandler(this);
|
mHistoryHandler = new HistoryDatabaseHandler(this);
|
||||||
}
|
}
|
||||||
mBookmarkList = getBookmarks();
|
mBookmarkList = mBookmarkManager.getBookmarks();
|
||||||
notifyBookmarkDataSetChanged();
|
notifyBookmarkDataSetChanged();
|
||||||
} else {
|
} else {
|
||||||
initialize();
|
initialize();
|
||||||
@ -1343,41 +1340,6 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBookmark(String url) {
|
|
||||||
File book = new File(getFilesDir(), "bookmarks");
|
|
||||||
File bookUrl = new File(getFilesDir(), "bookurl");
|
|
||||||
try {
|
|
||||||
BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book));
|
|
||||||
BufferedWriter urlWriter = new BufferedWriter(new FileWriter(bookUrl));
|
|
||||||
Iterator<HistoryItem> iter = mBookmarkList.iterator();
|
|
||||||
HistoryItem item;
|
|
||||||
int num = 0;
|
|
||||||
int deleteIndex = -1;
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
item = iter.next();
|
|
||||||
if (!item.getUrl().equalsIgnoreCase(url)) {
|
|
||||||
bookWriter.write(item.getTitle());
|
|
||||||
urlWriter.write(item.getUrl());
|
|
||||||
bookWriter.newLine();
|
|
||||||
urlWriter.newLine();
|
|
||||||
} else {
|
|
||||||
deleteIndex = num;
|
|
||||||
}
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
if (deleteIndex != -1) {
|
|
||||||
mBookmarkList.remove(deleteIndex);
|
|
||||||
}
|
|
||||||
bookWriter.close();
|
|
||||||
urlWriter.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
notifyBookmarkDataSetChanged();
|
|
||||||
mSearchAdapter.refreshBookmarks();
|
|
||||||
openBookmarks();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int pixelsToDp(int num) {
|
private int pixelsToDp(int num) {
|
||||||
float scale = getResources().getDisplayMetrics().density;
|
float scale = getResources().getDisplayMetrics().density;
|
||||||
return (int) ((num - 0.5f) / scale);
|
return (int) ((num - 0.5f) / scale);
|
||||||
@ -1812,28 +1774,6 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Damn it, I regret not using SQLite in the first place for this
|
|
||||||
private List<HistoryItem> getBookmarks() {
|
|
||||||
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
|
||||||
File bookUrl = new File(getApplicationContext().getFilesDir(), "bookurl");
|
|
||||||
File book = new File(getApplicationContext().getFilesDir(), "bookmarks");
|
|
||||||
try {
|
|
||||||
BufferedReader readUrl = new BufferedReader(new FileReader(bookUrl));
|
|
||||||
BufferedReader readBook = new BufferedReader(new FileReader(book));
|
|
||||||
String u, t;
|
|
||||||
while ((u = readUrl.readLine()) != null && (t = readBook.readLine()) != null) {
|
|
||||||
HistoryItem map = new HistoryItem(u, t);
|
|
||||||
bookmarks.add(map);
|
|
||||||
}
|
|
||||||
readBook.close();
|
|
||||||
readUrl.close();
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
}
|
|
||||||
Collections.sort(bookmarks, new SortIgnoreCase());
|
|
||||||
return bookmarks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function that opens the HTML history page in the browser
|
* function that opens the HTML history page in the browser
|
||||||
*/
|
*/
|
||||||
@ -1876,9 +1816,8 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
HistoryItem helper;
|
HistoryItem helper;
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
helper = iter.next();
|
helper = iter.next();
|
||||||
bookmarkHtml += (BookmarkPage.PART1 + helper.getUrl()
|
bookmarkHtml += (BookmarkPage.PART1 + helper.getUrl() + BookmarkPage.PART2
|
||||||
+ BookmarkPage.PART2 + helper.getUrl() + BookmarkPage.PART3
|
+ helper.getUrl() + BookmarkPage.PART3 + helper.getTitle() + BookmarkPage.PART4);
|
||||||
+ helper.getTitle() + BookmarkPage.PART4);
|
|
||||||
}
|
}
|
||||||
bookmarkHtml += BookmarkPage.END;
|
bookmarkHtml += BookmarkPage.END;
|
||||||
File bookmarkWebPage = new File(mContext.getFilesDir(), BookmarkPage.FILENAME);
|
File bookmarkWebPage = new File(mContext.getFilesDir(), BookmarkPage.FILENAME);
|
||||||
@ -1893,48 +1832,6 @@ public class BrowserActivity extends Activity implements BrowserController {
|
|||||||
view.loadUrl(Constants.FILE + bookmarkWebPage);
|
view.loadUrl(Constants.FILE + bookmarkWebPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* adds a bookmark with a title and url. Simple.
|
|
||||||
*/
|
|
||||||
public void addBookmark(Context context, String title, String url) {
|
|
||||||
File book = new File(context.getFilesDir(), "bookmarks");
|
|
||||||
File bookUrl = new File(context.getFilesDir(), "bookurl");
|
|
||||||
HistoryItem bookmark = new HistoryItem(url, title);
|
|
||||||
|
|
||||||
try {
|
|
||||||
BufferedReader readUrlRead = new BufferedReader(new FileReader(bookUrl));
|
|
||||||
String u;
|
|
||||||
while ((u = readUrlRead.readLine()) != null) {
|
|
||||||
if (u.contentEquals(url)) {
|
|
||||||
readUrlRead.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
readUrlRead.close();
|
|
||||||
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, true));
|
|
||||||
BufferedWriter urlWriter = new BufferedWriter(new FileWriter(bookUrl, true));
|
|
||||||
bookWriter.write(title);
|
|
||||||
urlWriter.write(url);
|
|
||||||
bookWriter.newLine();
|
|
||||||
urlWriter.newLine();
|
|
||||||
bookWriter.close();
|
|
||||||
urlWriter.close();
|
|
||||||
mBookmarkList.add(bookmark);
|
|
||||||
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
|
||||||
notifyBookmarkDataSetChanged();
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
mSearchAdapter.refreshBookmarks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
mTitleAdapter.notifyDataSetChanged();
|
mTitleAdapter.notifyDataSetChanged();
|
||||||
|
@ -45,4 +45,6 @@ public final class PreferenceConstants {
|
|||||||
public static final String USE_PROXY_HOST = "useProxyHost";
|
public static final String USE_PROXY_HOST = "useProxyHost";
|
||||||
public static final String USE_PROXY_PORT = "useProxyPort";
|
public static final String USE_PROXY_PORT = "useProxyPort";
|
||||||
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
|
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
|
||||||
|
|
||||||
|
public static final String OLD_BOOKMARKS_IMPORTED = "oldBookmarksImported";
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import android.graphics.Color;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -37,6 +38,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
private boolean mUseGoogle = true;
|
private boolean mUseGoogle = true;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private boolean mIncognito;
|
private boolean mIncognito;
|
||||||
|
private BookmarkManager mBookmarkManager;
|
||||||
|
|
||||||
public SearchAdapter(Context context, boolean incognito) {
|
public SearchAdapter(Context context, boolean incognito) {
|
||||||
mDatabaseHandler = new HistoryDatabaseHandler(context);
|
mDatabaseHandler = new HistoryDatabaseHandler(context);
|
||||||
@ -44,7 +46,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
mHistory = new ArrayList<HistoryItem>();
|
mHistory = new ArrayList<HistoryItem>();
|
||||||
mBookmarks = new ArrayList<HistoryItem>();
|
mBookmarks = new ArrayList<HistoryItem>();
|
||||||
mSuggestions = new ArrayList<HistoryItem>();
|
mSuggestions = new ArrayList<HistoryItem>();
|
||||||
mAllBookmarks = Utils.getBookmarks(context);
|
mBookmarkManager = new BookmarkManager(context);
|
||||||
|
mAllBookmarks = mBookmarkManager.getBookmarks();
|
||||||
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
||||||
mUseGoogle = mPreferences.getBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true);
|
mUseGoogle = mPreferences.getBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -59,7 +62,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBookmarks() {
|
public void refreshBookmarks() {
|
||||||
mAllBookmarks = Utils.getBookmarks(mContext);
|
mAllBookmarks = mBookmarkManager.getBookmarks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -374,7 +377,8 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
filteredList.add(mSuggestions.get(n));
|
filteredList.add(mSuggestions.get(n));
|
||||||
}
|
}
|
||||||
|
Log.i("MAX", "Max: "+maxSuggestions+" "+maxBookmarks+" "+maxHistory);
|
||||||
|
Log.i("SIZE", "size: "+suggestionsSize+" "+bookmarkSize+" "+historySize);
|
||||||
return filteredList;
|
return filteredList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,42 +31,6 @@ public final class Utils {
|
|||||||
Log.i(Constants.TAG, "Downloading" + fileName);
|
Log.i(Constants.TAG, "Downloading" + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void addBookmark(Context context, String title, String url) {
|
|
||||||
File book = new File(context.getFilesDir(), "bookmarks");
|
|
||||||
File bookUrl = new File(context.getFilesDir(), "bookurl");
|
|
||||||
if (("Bookmarks".equals(title) || "History".equals(title)) && url.startsWith("file://")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
BufferedReader readUrlRead = new BufferedReader(new FileReader(bookUrl));
|
|
||||||
String u;
|
|
||||||
while ((u = readUrlRead.readLine()) != null) {
|
|
||||||
if (u.contentEquals(url)) {
|
|
||||||
readUrlRead.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
readUrlRead.close();
|
|
||||||
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
BufferedWriter bookWriter = new BufferedWriter(new FileWriter(book, true));
|
|
||||||
BufferedWriter urlWriter = new BufferedWriter(new FileWriter(bookUrl, true));
|
|
||||||
bookWriter.write(title);
|
|
||||||
urlWriter.write(url);
|
|
||||||
bookWriter.newLine();
|
|
||||||
urlWriter.newLine();
|
|
||||||
bookWriter.close();
|
|
||||||
urlWriter.close();
|
|
||||||
} catch (FileNotFoundException ignored) {
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Intent newEmailIntent(Context context, String address, String subject,
|
public static Intent newEmailIntent(Context context, String address, String subject,
|
||||||
String body, String cc) {
|
String body, String cc) {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
@ -119,7 +83,7 @@ public final class Utils {
|
|||||||
return domain.startsWith("www.") ? domain.substring(4) : domain;
|
return domain.startsWith("www.") ? domain.substring(4) : domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<HistoryItem> getBookmarks(Context context) {
|
public static List<HistoryItem> getOldBookmarks(Context context) {
|
||||||
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
List<HistoryItem> bookmarks = new ArrayList<HistoryItem>();
|
||||||
File bookUrl = new File(context.getFilesDir(), "bookurl");
|
File bookUrl = new File(context.getFilesDir(), "bookurl");
|
||||||
File book = new File(context.getFilesDir(), "bookmarks");
|
File book = new File(context.getFilesDir(), "bookmarks");
|
||||||
|
Loading…
Reference in New Issue
Block a user