Add suggestions to naming a folder in edit bookmark dialog

This commit is contained in:
Anthony Restaino 2015-07-31 21:37:26 -04:00
parent 0f9a69ba17
commit 24a99deb52
2 changed files with 35 additions and 1 deletions

View File

@ -1014,10 +1014,14 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
getUrl.setHint(R.string.hint_url);
getUrl.setText(mBookmarkList.get(id).getUrl());
getUrl.setSingleLine();
final EditText getFolder = new EditText(mActivity);
final AutoCompleteTextView getFolder = new AutoCompleteTextView(mActivity);
getFolder.setHint(R.string.folder);
getFolder.setText(mBookmarkList.get(id).getFolder());
getFolder.setSingleLine();
List<String> folders = mBookmarkManager.getFolderTitles();
ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, folders);
getFolder.setThreshold(1);
getFolder.setAdapter(suggestionsAdapter);
LinearLayout layout = new LinearLayout(mActivity);
layout.setOrientation(LinearLayout.VERTICAL);
int padding = Utils.convertDpToPixels(10);

View File

@ -365,6 +365,36 @@ public class BookmarkManager {
return folders;
}
/**
* returns a list of folder titles that can be used for suggestions in a
* simple list adapter
*
* @return a list of folder title strings
*/
public synchronized List<String> getFolderTitles() {
List<String> folders = new ArrayList<>();
Set<String> folderMap = new HashSet<>();
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
BufferedReader bookmarksReader = null;
try {
bookmarksReader = new BufferedReader(new FileReader(bookmarksFile));
String line;
while ((line = bookmarksReader.readLine()) != null) {
JSONObject object = new JSONObject(line);
String folderName = object.getString(FOLDER);
if (!folderName.isEmpty() && !folderMap.contains(folderName)) {
folders.add(folderName);
folderMap.add(folderName);
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
} finally {
Utils.close(bookmarksReader);
}
return folders;
}
/**
* This method imports all bookmarks that are included in the device's
* permanent bookmark storage