use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class LegacyBookmarkManager method destructiveGetBookmarks.
/**
* Gets all bookmarks from the old bookmark file
* and then deletes the file.
*
* @param application the context needed to open the file.
* @return a list of bookmarks from the old bookmark file.
*/
@WorkerThread
@NonNull
public static List<HistoryItem> destructiveGetBookmarks(@NonNull Application application) {
File filesDir = application.getFilesDir();
List<HistoryItem> bookmarks = new ArrayList<>();
final File bookmarksFile = new File(filesDir, FILE_BOOKMARKS);
BufferedReader bookmarksReader = null;
InputStream inputStream = null;
try {
if (bookmarksFile.exists() && bookmarksFile.isFile()) {
//noinspection IOResourceOpenedButNotSafelyClosed
inputStream = new FileInputStream(bookmarksFile);
} else {
return bookmarks;
}
//noinspection IOResourceOpenedButNotSafelyClosed
bookmarksReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = bookmarksReader.readLine()) != null) {
try {
JSONObject object = new JSONObject(line);
HistoryItem item = new HistoryItem();
item.setTitle(object.getString(TITLE));
item.setUrl(object.getString(URL));
item.setFolder(object.getString(FOLDER));
item.setPosition(object.getInt(ORDER));
item.setImageId(R.drawable.ic_bookmark);
bookmarks.add(item);
} catch (JSONException e) {
Log.e(TAG, "Can't parse line " + line, e);
}
}
} catch (IOException e) {
Log.e(TAG, "Error reading the bookmarks file", e);
} finally {
Utils.close(bookmarksReader);
Utils.close(inputStream);
}
bookmarksFile.delete();
return bookmarks;
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class HistoryDatabase method visitHistoryItem.
@WorkerThread
synchronized void visitHistoryItem(@NonNull String url, @Nullable String title) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, title == null ? "" : title);
values.put(KEY_TIME_VISITED, System.currentTimeMillis());
Cursor cursor = lazyDatabase().query(false, TABLE_HISTORY, new String[] { KEY_URL }, KEY_URL + " = ?", new String[] { url }, null, null, null, "1");
if (cursor.getCount() > 0) {
lazyDatabase().update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[] { url });
} else {
addHistoryItem(new HistoryItem(url, title == null ? "" : title));
}
cursor.close();
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class HistoryDatabase method fromCursor.
@NonNull
private static HistoryItem fromCursor(@NonNull Cursor cursor) {
HistoryItem historyItem = new HistoryItem();
historyItem.setUrl(cursor.getString(1));
historyItem.setTitle(cursor.getString(2));
historyItem.setImageId(R.drawable.ic_history);
return historyItem;
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class HistoryDatabase method getAllHistoryItems.
@WorkerThread
@NonNull
synchronized List<HistoryItem> getAllHistoryItems() {
List<HistoryItem> itemList = new ArrayList<>();
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, null, null, null, null, KEY_TIME_VISITED + " DESC");
while (cursor.moveToNext()) {
itemList.add(fromCursor(cursor));
}
cursor.close();
return itemList;
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class LightningDialogBuilder method showLongPressedDialogForBookmarkUrl.
/**
* Show the appropriated dialog for the long pressed link. It means that we try to understand
* if the link is relative to a bookmark or is just a folder.
*
* @param activity used to show the dialog
* @param url the long pressed url
*/
public void showLongPressedDialogForBookmarkUrl(@NonNull final Activity activity, @NonNull final UIController uiController, @NonNull final String url) {
final HistoryItem item;
if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) {
// TODO hacky, make a better bookmark mechanism in the future
final Uri uri = Uri.parse(url);
final String filename = uri.getLastPathSegment();
final String folderTitle = filename.substring(0, filename.length() - BookmarkPage.FILENAME.length() - 1);
item = new HistoryItem();
item.setIsFolder(true);
item.setTitle(folderTitle);
item.setImageId(R.drawable.ic_folder);
item.setUrl(Constants.FOLDER + folderTitle);
showBookmarkFolderLongPressedDialog(activity, uiController, item);
} else {
mBookmarkManager.findBookmarkForUrl(url).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<HistoryItem>() {
@Override
public void onItem(@Nullable HistoryItem historyItem) {
if (historyItem != null) {
showLongPressedDialogForBookmarkUrl(activity, uiController, historyItem);
}
}
});
}
}
Aggregations