use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class HistoryDatabase method findItemsContaining.
@WorkerThread
@NonNull
synchronized List<HistoryItem> findItemsContaining(@Nullable String search) {
List<HistoryItem> itemList = new ArrayList<>(5);
if (search == null) {
return itemList;
}
search = '%' + search + '%';
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, KEY_TITLE + " LIKE ? OR " + KEY_URL + " LIKE ?", new String[] { search, search }, null, null, KEY_TIME_VISITED + " DESC", "5");
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 HistoryDatabase method getLastHundredItems.
@WorkerThread
@NonNull
synchronized List<HistoryItem> getLastHundredItems() {
List<HistoryItem> itemList = new ArrayList<>(100);
Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, null, null, null, null, KEY_TIME_VISITED + " DESC", "100");
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 HistoryPage method getHistoryPage.
@NonNull
public Single<String> getHistoryPage() {
return Single.create(new SingleAction<String>() {
@Override
public void onSubscribe(@NonNull final SingleSubscriber<String> subscriber) {
final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2);
HistoryModel.lastHundredVisitedHistoryItems().subscribe(new SingleOnSubscribe<List<HistoryItem>>() {
@Override
public void onItem(@Nullable List<HistoryItem> item) {
Preconditions.checkNonNull(item);
Iterator<HistoryItem> it = item.iterator();
HistoryItem helper;
while (it.hasNext()) {
helper = it.next();
historyBuilder.append(PART1);
historyBuilder.append(helper.getUrl());
historyBuilder.append(PART2);
historyBuilder.append(helper.getTitle());
historyBuilder.append(PART3);
historyBuilder.append(helper.getUrl());
historyBuilder.append(PART4);
}
historyBuilder.append(END);
File historyWebPage = new File(mApp.getFilesDir(), FILENAME);
FileWriter historyWriter = null;
try {
//noinspection IOResourceOpenedButNotSafelyClosed
historyWriter = new FileWriter(historyWebPage, false);
historyWriter.write(historyBuilder.toString());
} catch (IOException e) {
Log.e(TAG, "Unable to write history page to disk", e);
} finally {
Utils.close(historyWriter);
}
subscriber.onItem(Constants.FILE + historyWebPage);
subscriber.onComplete();
}
});
}
});
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class BookmarkDatabase method bindCursorToHistoryItem.
@NonNull
private static HistoryItem bindCursorToHistoryItem(@NonNull Cursor cursor) {
HistoryItem bookmark = new HistoryItem();
bookmark.setImageId(R.drawable.ic_bookmark);
bookmark.setUrl(cursor.getString(cursor.getColumnIndex(KEY_URL)));
bookmark.setTitle(cursor.getString(cursor.getColumnIndex(KEY_TITLE)));
bookmark.setFolder(cursor.getString(cursor.getColumnIndex(KEY_FOLDER)));
bookmark.setPosition(cursor.getInt(cursor.getColumnIndex(KEY_POSITION)));
return bookmark;
}
use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.
the class BookmarkLocalSync method getBookmarksFromContentUri.
@NonNull
private List<HistoryItem> getBookmarksFromContentUri(String contentUri) {
List<HistoryItem> list = new ArrayList<>();
Cursor cursor = getBrowserCursor(contentUri);
try {
if (cursor != null) {
for (int n = 0; n < cursor.getColumnCount(); n++) {
Log.d(TAG, cursor.getColumnName(n));
}
while (cursor.moveToNext()) {
if (cursor.getInt(2) == 1) {
String url = cursor.getString(0);
String title = cursor.getString(1);
if (url.isEmpty()) {
continue;
}
if (title == null || title.isEmpty()) {
title = Utils.getDomainName(url);
}
if (title != null) {
list.add(new HistoryItem(url, title));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
Utils.close(cursor);
return list;
}
Aggregations