diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 3575f37..d405347 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -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 folders = mBookmarkManager.getFolderTitles(); + ArrayAdapter 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); diff --git a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java index f6f41f2..f0bc33f 100644 --- a/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java +++ b/app/src/main/java/acr/browser/lightning/database/BookmarkManager.java @@ -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 getFolderTitles() { + List folders = new ArrayList<>(); + Set 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