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;
}
}
}
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;
}
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;
}
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);
}
}
});
}
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);
}
});
}
Aggregations