Browse Source

Add suggestions to naming a folder in edit bookmark dialog

master
Anthony Restaino 9 years ago
parent
commit
24a99deb52
  1. 6
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 30
      app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

6
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -1014,10 +1014,14 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -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);

30
app/src/main/java/acr/browser/lightning/database/BookmarkManager.java

@ -365,6 +365,36 @@ public class BookmarkManager { @@ -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

Loading…
Cancel
Save