Search in sources :

Example 1 with HistoryItem

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

the class BaiduSuggestionsModel method parseResults.

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

Example 2 with HistoryItem

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

the class BaseSuggestionsModel method getResults.

@NonNull
List<HistoryItem> getResults(@NonNull String query) {
    List<HistoryItem> filter = new ArrayList<>(5);
    try {
        query = URLEncoder.encode(query, mEncoding);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Unable to encode the URL", e);
    }
    InputStream inputStream = downloadSuggestionsForQuery(query, mLanguage);
    if (inputStream == null) {
        // There are no suggestions for this query, return an empty list.
        return filter;
    }
    try {
        parseResults(inputStream, filter);
    } catch (Exception e) {
        Log.e(TAG, "Unable to parse results", e);
        return filter;
    } finally {
        Utils.close(inputStream);
    }
    return filter;
}
Also used : InputStream(java.io.InputStream) HistoryItem(acr.browser.lightning.database.HistoryItem) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NonNull(android.support.annotation.NonNull)

Example 3 with HistoryItem

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

the class SuggestionsAdapter method getView.

@Nullable
@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
    SuggestionHolder holder;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        convertView = inflater.inflate(R.layout.two_line_autocomplete, parent, false);
        holder = new SuggestionHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (SuggestionHolder) convertView.getTag();
    }
    HistoryItem web;
    web = mFilteredList.get(position);
    holder.mTitle.setText(web.getTitle());
    holder.mUrl.setText(web.getUrl());
    if (mDarkTheme) {
        holder.mTitle.setTextColor(Color.WHITE);
    }
    Drawable image;
    switch(web.getImageId()) {
        case R.drawable.ic_bookmark:
            {
                image = mBookmarkDrawable;
                break;
            }
        case R.drawable.ic_search:
            {
                image = mSearchDrawable;
                break;
            }
        case R.drawable.ic_history:
            {
                image = mHistoryDrawable;
                break;
            }
        default:
            image = mSearchDrawable;
            break;
    }
    holder.mImage.setImageDrawable(image);
    return convertView;
}
Also used : LayoutInflater(android.view.LayoutInflater) HistoryItem(acr.browser.lightning.database.HistoryItem) Drawable(android.graphics.drawable.Drawable) Nullable(android.support.annotation.Nullable)

Example 4 with HistoryItem

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

the class BrowserActivity method deleteBookmark.

private void deleteBookmark(final String title, final String url) {
    final HistoryItem item = new HistoryItem(url, title);
    mBookmarkManager.deleteBookmark(item).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<Boolean>() {

        @Override
        public void onItem(@Nullable Boolean item) {
            if (Boolean.TRUE.equals(item)) {
                mSuggestionsAdapter.refreshBookmarks();
                mBookmarksView.handleUpdatedUrl(url);
            }
        }
    });
}
Also used : HistoryItem(acr.browser.lightning.database.HistoryItem)

Example 5 with HistoryItem

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

the class LightningDialogBuilder method showEditBookmarkDialog.

private void showEditBookmarkDialog(@NonNull final Activity activity, @NonNull final UIController uiController, @NonNull final HistoryItem item) {
    final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity);
    editBookmarkDialog.setTitle(R.string.title_edit_bookmark);
    final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null);
    final EditText getTitle = (EditText) dialogLayout.findViewById(R.id.bookmark_title);
    getTitle.setText(item.getTitle());
    final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url);
    getUrl.setText(item.getUrl());
    final AutoCompleteTextView getFolder = (AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder);
    getFolder.setHint(R.string.folder);
    getFolder.setText(item.getFolder());
    mBookmarkManager.getFolderNames().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<List<String>>() {

        @Override
        public void onItem(@Nullable List<String> folders) {
            Preconditions.checkNonNull(folders);
            final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_dropdown_item_1line, folders);
            getFolder.setThreshold(1);
            getFolder.setAdapter(suggestionsAdapter);
            editBookmarkDialog.setView(dialogLayout);
            editBookmarkDialog.setPositiveButton(activity.getString(R.string.action_ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    HistoryItem editedItem = new HistoryItem();
                    editedItem.setTitle(getTitle.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setUrl(getUrl.getText().toString());
                    editedItem.setFolder(getFolder.getText().toString());
                    mBookmarkManager.editBookmark(item, editedItem).subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new CompletableOnSubscribe() {

                        @Override
                        public void onComplete() {
                            uiController.handleBookmarksChange();
                        }
                    });
                }
            });
            Dialog dialog = editBookmarkDialog.show();
            BrowserDialog.setDialogSize(activity, dialog);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) HistoryItem(acr.browser.lightning.database.HistoryItem) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) List(java.util.List) CompletableOnSubscribe(com.anthonycr.bonsai.CompletableOnSubscribe) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

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