Search in sources :

Example 21 with HistoryItem

use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.

the class GoogleSuggestionsModel method parseResults.

@Override
protected void parseResults(@NonNull InputStream inputStream, @NonNull List<HistoryItem> results) throws Exception {
    BufferedInputStream bufferedInput = new BufferedInputStream(inputStream);
    XmlPullParser parser = getParser();
    parser.setInput(bufferedInput, ENCODING);
    int eventType = parser.getEventType();
    int counter = 0;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG && "suggestion".equals(parser.getName())) {
            String suggestion = parser.getAttributeValue(null, "data");
            results.add(new HistoryItem(mSearchSubtitle + " \"" + suggestion + '"', suggestion, R.drawable.ic_search));
            counter++;
            if (counter >= MAX_RESULTS) {
                break;
            }
        }
        eventType = parser.next();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) HistoryItem(acr.browser.lightning.database.HistoryItem) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 22 with HistoryItem

use of acr.browser.lightning.database.HistoryItem in project Lightning-Browser by anthonycr.

the class DuckSuggestionsModel method parseResults.

@Override
protected void parseResults(@NonNull InputStream inputStream, @NonNull List<HistoryItem> results) throws Exception {
    String content = FileUtils.readStringFromStream(inputStream, ENCODING);
    JSONArray jsonArray = new JSONArray(content);
    int counter = 0;
    for (int n = 0, size = jsonArray.length(); n < size; n++) {
        JSONObject object = jsonArray.getJSONObject(n);
        String suggestion = object.getString("phrase");
        results.add(new HistoryItem(mSearchSubtitle + " \"" + suggestion + '"', suggestion, R.drawable.ic_search));
        counter++;
        if (counter >= MAX_RESULTS) {
            break;
        }
    }
}
Also used : JSONObject(org.json.JSONObject) HistoryItem(acr.browser.lightning.database.HistoryItem) JSONArray(org.json.JSONArray)

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