Search in sources :

Example 6 with HistoryItem

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;
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 7 with HistoryItem

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;
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 8 with HistoryItem

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();
                }
            });
        }
    });
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) FileWriter(java.io.FileWriter) SingleOnSubscribe(com.anthonycr.bonsai.SingleOnSubscribe) IOException(java.io.IOException) List(java.util.List) File(java.io.File) Nullable(android.support.annotation.Nullable) NonNull(android.support.annotation.NonNull)

Example 9 with HistoryItem

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;
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) NonNull(android.support.annotation.NonNull)

Example 10 with HistoryItem

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;
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) NonNull(android.support.annotation.NonNull)

Aggregations

HistoryItem (acr.browser.lightning.database.HistoryItem)22 NonNull (android.support.annotation.NonNull)11 ArrayList (java.util.ArrayList)9 Cursor (android.database.Cursor)5 WorkerThread (android.support.annotation.WorkerThread)5 Nullable (android.support.annotation.Nullable)4 IOException (java.io.IOException)4 List (java.util.List)4 CompletableOnSubscribe (com.anthonycr.bonsai.CompletableOnSubscribe)3 SingleOnSubscribe (com.anthonycr.bonsai.SingleOnSubscribe)3 File (java.io.File)3 InputStream (java.io.InputStream)3 JSONObject (org.json.JSONObject)3 Activity (android.app.Activity)2 Dialog (android.app.Dialog)2 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 JSONArray (org.json.JSONArray)2