Renaming and Deleting bookmark folders is now available yay
This commit is contained in:
parent
645b98cd50
commit
69deb5b5a2
@ -9,6 +9,7 @@ import android.animation.LayoutTransition;
|
|||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
import android.animation.ValueAnimator.AnimatorUpdateListener;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -16,7 +17,6 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources.Theme;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@ -95,7 +95,6 @@ import android.widget.TextView;
|
|||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
import android.widget.VideoView;
|
import android.widget.VideoView;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -119,7 +118,6 @@ import acr.browser.lightning.R;
|
|||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.constant.HistoryPage;
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
import acr.browser.lightning.constant.StartPage;
|
|
||||||
import acr.browser.lightning.controller.BrowserController;
|
import acr.browser.lightning.controller.BrowserController;
|
||||||
import acr.browser.lightning.database.BookmarkManager;
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
import acr.browser.lightning.database.HistoryDatabase;
|
import acr.browser.lightning.database.HistoryDatabase;
|
||||||
@ -324,7 +322,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
mSearch.setOnTouchListener(search.new TouchListener());
|
mSearch.setOnTouchListener(search.new TouchListener());
|
||||||
|
|
||||||
mSystemBrowser = getSystemBrowser();
|
mSystemBrowser = getSystemBrowser();
|
||||||
Thread initialize = new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -346,8 +344,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
initializeSearchSuggestions(mSearch);
|
initializeSearchSuggestions(mSearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
}).run();
|
||||||
initialize.run();
|
|
||||||
|
|
||||||
View view = findViewById(R.id.bookmark_back_button);
|
View view = findViewById(R.id.bookmark_back_button);
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
@ -817,9 +814,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
* adapter doesn't always change when notifyDataChanged gets called.
|
* adapter doesn't always change when notifyDataChanged gets called.
|
||||||
*/
|
*/
|
||||||
private void notifyBookmarkDataSetChanged() {
|
private void notifyBookmarkDataSetChanged() {
|
||||||
if (mBookmarkAdapter == null)
|
if (mBookmarkAdapter != null)
|
||||||
return;
|
mBookmarkAdapter.notifyDataSetChanged();
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBookmark(String title, String url) {
|
private void addBookmark(String title, String url) {
|
||||||
@ -836,8 +832,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) {
|
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) {
|
||||||
mBookmarkList.clear();
|
mBookmarkList.clear();
|
||||||
mBookmarkList.addAll(items);
|
mBookmarkList.addAll(items);
|
||||||
if (mBookmarkAdapter != null)
|
notifyBookmarkDataSetChanged();
|
||||||
mBookmarkAdapter.notifyDataSetChanged();
|
|
||||||
final int resource;
|
final int resource;
|
||||||
if (mBookmarkManager.isRootFolder())
|
if (mBookmarkManager.isRootFolder())
|
||||||
resource = R.drawable.ic_action_star;
|
resource = R.drawable.ic_action_star;
|
||||||
@ -876,10 +871,11 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
startRotation.setDuration(250);
|
startRotation.setDuration(250);
|
||||||
finishRotation.setDuration(250);
|
finishRotation.setDuration(250);
|
||||||
|
|
||||||
if (animate)
|
if (animate) {
|
||||||
mBookmarkTitleImage.startAnimation(startRotation);
|
mBookmarkTitleImage.startAnimation(startRotation);
|
||||||
else
|
} else {
|
||||||
mBookmarkTitleImage.setImageResource(resource);
|
mBookmarkTitleImage.setImageResource(resource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -979,7 +975,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if (mBookmarkList.get(position).getIsFolder()) {
|
if (mBookmarkList.get(position).getIsFolder()) {
|
||||||
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(mBookmarkList.get(position).getUrl(), true), true);
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(mBookmarkList.get(position).getTitle(), true), true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mCurrentView != null) {
|
if (mCurrentView != null) {
|
||||||
@ -1001,49 +997,10 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
|
||||||
|
longPressBookmarkLink(mBookmarkList.get(position).getUrl());
|
||||||
if (mBookmarkList.get(position).getIsFolder())
|
|
||||||
return true;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
|
||||||
builder.setTitle(mActivity.getResources().getString(R.string.action_bookmarks));
|
|
||||||
builder.setMessage(getResources().getString(R.string.dialog_bookmark))
|
|
||||||
.setCancelable(true)
|
|
||||||
.setPositiveButton(getResources().getString(R.string.action_new_tab),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
newTab(mBookmarkList.get(position).getUrl(), false);
|
|
||||||
mDrawerLayout.closeDrawers();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(getResources().getString(R.string.action_delete),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position))) {
|
|
||||||
mBookmarkList.remove(position);
|
|
||||||
notifyBookmarkDataSetChanged();
|
|
||||||
mSearchAdapter.refreshBookmarks();
|
|
||||||
openBookmarks();
|
|
||||||
if (mCurrentView != null) {
|
|
||||||
updateBookmarkIndicator(mCurrentView.getUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNeutralButton(getResources().getString(R.string.action_edit),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
editBookmark(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AlertDialog alert = builder.create();
|
|
||||||
alert.show();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1107,6 +1064,49 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
editBookmarkDialog.show();
|
editBookmarkDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a dialog to rename a folder
|
||||||
|
*
|
||||||
|
* @param id the position of the HistoryItem (folder) in the bookmark list
|
||||||
|
*/
|
||||||
|
private synchronized void renameFolder(final int id) {
|
||||||
|
final AlertDialog.Builder editFolderDialog = new AlertDialog.Builder(mActivity);
|
||||||
|
editFolderDialog.setTitle(R.string.title_rename_folder);
|
||||||
|
final EditText getTitle = new EditText(mActivity);
|
||||||
|
getTitle.setHint(R.string.hint_title);
|
||||||
|
getTitle.setText(mBookmarkList.get(id).getTitle());
|
||||||
|
getTitle.setSingleLine();
|
||||||
|
LinearLayout layout = new LinearLayout(mActivity);
|
||||||
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
int padding = Utils.convertDpToPixels(10);
|
||||||
|
layout.setPadding(padding, padding, padding, padding);
|
||||||
|
layout.addView(getTitle);
|
||||||
|
editFolderDialog.setView(layout);
|
||||||
|
editFolderDialog.setPositiveButton(getResources().getString(R.string.action_ok),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String oldTitle = mBookmarkList.get(id).getTitle();
|
||||||
|
String newTitle = getTitle.getText().toString();
|
||||||
|
|
||||||
|
mBookmarkManager.renameFolder(oldTitle, newTitle);
|
||||||
|
|
||||||
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
|
||||||
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||||||
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||||
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
|
openBookmarkPage(mWebView);
|
||||||
|
}
|
||||||
|
if (mCurrentView != null) {
|
||||||
|
updateBookmarkIndicator(mCurrentView.getUrl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
editFolderDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays the WebView contained in the LightningView Also handles the
|
* displays the WebView contained in the LightningView Also handles the
|
||||||
* removal of previous views
|
* removal of previous views
|
||||||
@ -1366,7 +1366,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void clearHistory() {
|
private void clearHistory() {
|
||||||
this.deleteDatabase(HistoryDatabase.DATABASE_NAME);
|
this.deleteDatabase(HistoryDatabase.DATABASE_NAME);
|
||||||
WebViewDatabase m = WebViewDatabase.getInstance(this);
|
WebViewDatabase m = WebViewDatabase.getInstance(this);
|
||||||
@ -1385,7 +1384,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
Utils.trimCache(this);
|
Utils.trimCache(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void clearCookies() {
|
private void clearCookies() {
|
||||||
// TODO Break out web storage deletion into its own option/action
|
// TODO Break out web storage deletion into its own option/action
|
||||||
// TODO clear web storage for all sites that are visited in Incognito mode
|
// TODO clear web storage for all sites that are visited in Incognito mode
|
||||||
@ -2528,7 +2526,51 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void longPressFolder(String url) {
|
||||||
|
final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, url);
|
||||||
|
if (position == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
switch (which) {
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
renameFolder(position);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
mBookmarkManager.deleteFolder(mBookmarkList.get(position).getTitle());
|
||||||
|
|
||||||
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
||||||
|
|
||||||
|
Collections.sort(mBookmarkList, new SortIgnoreCase());
|
||||||
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE)
|
||||||
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
|
openBookmarkPage(mWebView);
|
||||||
|
}
|
||||||
|
if (mCurrentView != null) {
|
||||||
|
updateBookmarkIndicator(mCurrentView.getUrl());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
|
builder.setTitle(R.string.action_folder)
|
||||||
|
.setMessage(R.string.dialog_folder)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton(R.string.action_rename, dialogClickListener)
|
||||||
|
.setNegativeButton(R.string.action_delete, dialogClickListener)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void longPressBookmarkLink(final String url) {
|
private void longPressBookmarkLink(final String url) {
|
||||||
|
if (url.startsWith(Constants.FOLDER)) {
|
||||||
|
longPressFolder(url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, url);
|
final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, url);
|
||||||
if (position == -1) {
|
if (position == -1) {
|
||||||
return;
|
return;
|
||||||
@ -2541,7 +2583,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
newTab(mBookmarkList.get(position).getUrl(), false);
|
newTab(mBookmarkList.get(position).getUrl(), false);
|
||||||
mDrawerLayout.closeDrawers();
|
mDrawerLayout.closeDrawers();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DialogInterface.BUTTON_NEGATIVE:
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position))) {
|
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position))) {
|
||||||
mBookmarkList.remove(position);
|
mBookmarkList.remove(position);
|
||||||
@ -2553,7 +2594,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DialogInterface.BUTTON_NEUTRAL:
|
case DialogInterface.BUTTON_NEUTRAL:
|
||||||
editBookmark(position);
|
editBookmark(position);
|
||||||
break;
|
break;
|
||||||
@ -2562,8 +2602,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
};
|
};
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
builder.setTitle(R.string.action_bookmarks);
|
builder.setTitle(R.string.action_bookmarks)
|
||||||
builder.setMessage(R.string.dialog_bookmark)
|
.setMessage(R.string.dialog_bookmark)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.action_new_tab, dialogClickListener)
|
.setPositiveButton(R.string.action_new_tab, dialogClickListener)
|
||||||
.setNegativeButton(R.string.action_delete, dialogClickListener)
|
.setNegativeButton(R.string.action_delete, dialogClickListener)
|
||||||
@ -2596,8 +2636,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
};
|
};
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
||||||
builder.setTitle(R.string.action_history);
|
builder.setTitle(R.string.action_history)
|
||||||
builder.setMessage(R.string.dialog_history_long_press)
|
.setMessage(R.string.dialog_history_long_press)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.action_new_tab, dialogClickListener)
|
.setPositiveButton(R.string.action_new_tab, dialogClickListener)
|
||||||
.setNegativeButton(R.string.action_delete, dialogClickListener)
|
.setNegativeButton(R.string.action_delete, dialogClickListener)
|
||||||
@ -2814,7 +2854,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
boolean isConnected = isConnected(context);
|
boolean isConnected = isConnected(context);
|
||||||
Log.d("Lightning", "Network Connected: " + String.valueOf(isConnected));
|
Log.d(Constants.TAG, "Network Connected: " + String.valueOf(isConnected));
|
||||||
for (int n = 0; n < mWebViewList.size(); n++) {
|
for (int n = 0; n < mWebViewList.size(); n++) {
|
||||||
WebView view = mWebViewList.get(n).getWebView();
|
WebView view = mWebViewList.get(n).getWebView();
|
||||||
if (view != null)
|
if (view != null)
|
||||||
|
@ -5,9 +5,11 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.w3c.dom.ls.LSInput;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -19,11 +21,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
|
import acr.browser.lightning.constant.Constants;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
@ -126,38 +130,52 @@ public class BookmarkManager {
|
|||||||
* @param deleteItem the bookmark item to delete
|
* @param deleteItem the bookmark item to delete
|
||||||
*/
|
*/
|
||||||
public synchronized boolean deleteBookmark(HistoryItem deleteItem) {
|
public synchronized boolean deleteBookmark(HistoryItem deleteItem) {
|
||||||
List<HistoryItem> list;
|
|
||||||
if (deleteItem == null || deleteItem.getIsFolder()) {
|
if (deleteItem == null || deleteItem.getIsFolder()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mBookmarkSearchSet.remove(deleteItem.getUrl());
|
mBookmarkSearchSet.remove(deleteItem.getUrl());
|
||||||
mBookmarkList.remove(deleteItem);
|
mBookmarkList.remove(deleteItem);
|
||||||
list = getAllBookmarks(false);
|
overwriteBookmarks(mBookmarkList);
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
return true;
|
||||||
boolean bookmarkDeleted = false;
|
}
|
||||||
BufferedWriter fileWriter = null;
|
|
||||||
String url = deleteItem.getUrl();
|
/**
|
||||||
try {
|
* renames a folder and moves all it's contents to that folder
|
||||||
fileWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
*
|
||||||
JSONObject object = new JSONObject();
|
* @param oldName the folder to be renamed
|
||||||
for (HistoryItem item : list) {
|
* @param newName the new name of the folder
|
||||||
if (!item.getUrl().equalsIgnoreCase(url)) {
|
*/
|
||||||
object.put(TITLE, item.getTitle());
|
public synchronized void renameFolder(@NonNull String oldName, @NonNull String newName) {
|
||||||
object.put(URL, item.getUrl());
|
if (newName.length() == 0) {
|
||||||
object.put(FOLDER, item.getFolder());
|
return;
|
||||||
object.put(ORDER, item.getOrder());
|
|
||||||
fileWriter.write(object.toString());
|
|
||||||
fileWriter.newLine();
|
|
||||||
} else {
|
|
||||||
bookmarkDeleted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException | JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
Utils.close(fileWriter);
|
|
||||||
}
|
}
|
||||||
return bookmarkDeleted;
|
for (int n = 0; n < mBookmarkList.size(); n++) {
|
||||||
|
if (mBookmarkList.get(n).getFolder().equals(oldName)) {
|
||||||
|
mBookmarkList.get(n).setFolder(newName);
|
||||||
|
} else if (mBookmarkList.get(n).getIsFolder() && mBookmarkList.get(n).getTitle().equals(oldName)) {
|
||||||
|
mBookmarkList.get(n).setTitle(newName);
|
||||||
|
mBookmarkList.get(n).setUrl(Constants.FOLDER + newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
overwriteBookmarks(mBookmarkList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the folder and move all bookmarks to the top level
|
||||||
|
*
|
||||||
|
* @param name the name of the folder to be deleted
|
||||||
|
*/
|
||||||
|
public synchronized void deleteFolder(@NonNull String name) {
|
||||||
|
Iterator<HistoryItem> iterator = mBookmarkList.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
HistoryItem item = iterator.next();
|
||||||
|
if (!item.getIsFolder() && item.getFolder().equals(name)) {
|
||||||
|
item.setFolder("");
|
||||||
|
} else if (item.getTitle().equals(name)) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
overwriteBookmarks(mBookmarkList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,7 +185,6 @@ public class BookmarkManager {
|
|||||||
* @param newItem This is the new item that will overwrite the old item
|
* @param newItem This is the new item that will overwrite the old item
|
||||||
*/
|
*/
|
||||||
public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) {
|
public synchronized void editBookmark(HistoryItem oldItem, HistoryItem newItem) {
|
||||||
List<HistoryItem> list;
|
|
||||||
if (oldItem == null || newItem == null || oldItem.getIsFolder()) {
|
if (oldItem == null || newItem == null || oldItem.getIsFolder()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -185,33 +202,7 @@ public class BookmarkManager {
|
|||||||
if (newItem.getTitle().length() == 0) {
|
if (newItem.getTitle().length() == 0) {
|
||||||
newItem.setTitle(mContext.getString(R.string.untitled));
|
newItem.setTitle(mContext.getString(R.string.untitled));
|
||||||
}
|
}
|
||||||
list = getAllBookmarks(false);
|
overwriteBookmarks(mBookmarkList);
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
|
||||||
BufferedWriter fileWriter = null;
|
|
||||||
try {
|
|
||||||
fileWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
|
||||||
JSONObject object = new JSONObject();
|
|
||||||
final String url = oldItem.getUrl();
|
|
||||||
for (HistoryItem item : list) {
|
|
||||||
if (!item.getUrl().equalsIgnoreCase(url)) {
|
|
||||||
object.put(TITLE, item.getTitle());
|
|
||||||
object.put(URL, item.getUrl());
|
|
||||||
object.put(FOLDER, item.getFolder());
|
|
||||||
object.put(ORDER, item.getOrder());
|
|
||||||
} else {
|
|
||||||
object.put(TITLE, newItem.getTitle());
|
|
||||||
object.put(URL, newItem.getUrl());
|
|
||||||
object.put(FOLDER, newItem.getFolder());
|
|
||||||
object.put(ORDER, newItem.getOrder());
|
|
||||||
}
|
|
||||||
fileWriter.write(object.toString());
|
|
||||||
fileWriter.newLine();
|
|
||||||
}
|
|
||||||
} catch (IOException | JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
Utils.close(fileWriter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -380,7 +371,7 @@ public class BookmarkManager {
|
|||||||
if (!folderName.isEmpty() && !folderMap.contains(folderName)) {
|
if (!folderName.isEmpty() && !folderMap.contains(folderName)) {
|
||||||
HistoryItem item = new HistoryItem();
|
HistoryItem item = new HistoryItem();
|
||||||
item.setTitle(folderName);
|
item.setTitle(folderName);
|
||||||
item.setUrl(folderName);
|
item.setUrl(Constants.FOLDER + folderName);
|
||||||
item.setIsFolder(true);
|
item.setIsFolder(true);
|
||||||
folderMap.add(folderName);
|
folderMap.add(folderName);
|
||||||
folders.add(item);
|
folders.add(item);
|
||||||
@ -431,9 +422,7 @@ public class BookmarkManager {
|
|||||||
|
|
||||||
Utils.showSnackbar(activity, number + " " + mContext.getResources().getString(R.string.message_import));
|
Utils.showSnackbar(activity, number + " " + mContext.getResources().getString(R.string.message_import));
|
||||||
} else {
|
} else {
|
||||||
String title = activity.getResources().getString(R.string.title_error);
|
Utils.createInformativeDialog(activity, R.string.title_error, R.string.dialog_import_error);
|
||||||
String message = activity.getResources().getString(R.string.dialog_import_error);
|
|
||||||
Utils.createInformativeDialog(activity, title, message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,9 +457,7 @@ public class BookmarkManager {
|
|||||||
Utils.showSnackbar(activity, number + " " + message);
|
Utils.showSnackbar(activity, number + " " + message);
|
||||||
} catch (IOException | JSONException e) {
|
} catch (IOException | JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
String title = activity.getResources().getString(R.string.title_error);
|
Utils.createInformativeDialog(activity, R.string.title_error, R.string.import_bookmark_error);
|
||||||
String message = activity.getResources().getString(R.string.import_bookmark_error);
|
|
||||||
Utils.createInformativeDialog(activity, title, message);
|
|
||||||
} finally {
|
} finally {
|
||||||
Utils.close(bookmarksReader);
|
Utils.close(bookmarksReader);
|
||||||
}
|
}
|
||||||
@ -483,13 +470,14 @@ public class BookmarkManager {
|
|||||||
*
|
*
|
||||||
* @param list the list of bookmarks to overwrite the old ones with
|
* @param list the list of bookmarks to overwrite the old ones with
|
||||||
*/
|
*/
|
||||||
public synchronized void overwriteBookmarks(List<HistoryItem> list) {
|
private synchronized void overwriteBookmarks(List<HistoryItem> list) {
|
||||||
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
|
||||||
BufferedWriter bookmarkWriter = null;
|
BufferedWriter bookmarkWriter = null;
|
||||||
try {
|
try {
|
||||||
bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, false));
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
for (HistoryItem item : list) {
|
for (int n = 0; n < list.size(); n++) {
|
||||||
|
HistoryItem item = list.get(n);
|
||||||
if (!item.getIsFolder()) {
|
if (!item.getIsFolder()) {
|
||||||
object.put(TITLE, item.getTitle());
|
object.put(TITLE, item.getTitle());
|
||||||
object.put(URL, item.getUrl());
|
object.put(URL, item.getUrl());
|
||||||
|
@ -565,9 +565,7 @@ public class GeneralSettingsFragment extends PreferenceFragment implements Prefe
|
|||||||
mPreferences.setFlashSupport(0);
|
mPreferences.setFlashSupport(0);
|
||||||
}
|
}
|
||||||
if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) {
|
if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) {
|
||||||
Utils.createInformativeDialog(mActivity,
|
Utils.createInformativeDialog(mActivity, R.string.title_warning, R.string.dialog_adobe_not_installed);
|
||||||
mActivity.getResources().getString(R.string.title_warning),
|
|
||||||
mActivity.getResources().getString(R.string.dialog_adobe_not_installed));
|
|
||||||
cbFlash.setEnabled(false);
|
cbFlash.setEnabled(false);
|
||||||
mPreferences.setFlashSupport(0);
|
mPreferences.setFlashSupport(0);
|
||||||
}
|
}
|
||||||
|
@ -82,21 +82,9 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
int color = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(context) : ThemeUtils.getIconLightThemeColor(context);
|
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
||||||
mSearchDrawable = context.getDrawable(R.drawable.ic_search);
|
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
||||||
mBookmarkDrawable = context.getDrawable(R.drawable.ic_bookmark);
|
|
||||||
mHistoryDrawable = context.getDrawable(R.drawable.ic_history);
|
|
||||||
} else {
|
|
||||||
mSearchDrawable = context.getResources().getDrawable(R.drawable.ic_search);
|
|
||||||
mBookmarkDrawable = context.getResources().getDrawable(R.drawable.ic_bookmark);
|
|
||||||
mHistoryDrawable = context.getResources().getDrawable(R.drawable.ic_history);
|
|
||||||
}
|
|
||||||
if (mSearchDrawable != null && mBookmarkDrawable != null && mHistoryDrawable != null) {
|
|
||||||
mSearchDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
|
||||||
mBookmarkDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
|
||||||
mHistoryDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
|
||||||
}
|
|
||||||
delete.start();
|
delete.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +71,22 @@ public class ThemeUtils {
|
|||||||
return resultBitmap;
|
return resultBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Drawable getThemedDrawable(@NonNull Context context, @DrawableRes int res, boolean dark){
|
||||||
|
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
|
||||||
|
final Drawable drawable;
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
drawable = context.getResources().getDrawable(res);
|
||||||
|
} else {
|
||||||
|
drawable = context.getDrawable(res);
|
||||||
|
}
|
||||||
|
if (drawable == null)
|
||||||
|
return null;
|
||||||
|
drawable.mutate();
|
||||||
|
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
|
||||||
|
return drawable;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Drawable getLightThemedDrawable(@NonNull Context context, @DrawableRes int res){
|
public static Drawable getLightThemedDrawable(@NonNull Context context, @DrawableRes int res){
|
||||||
final Drawable drawable;
|
final Drawable drawable;
|
||||||
|
@ -62,7 +62,7 @@ public final class Utils {
|
|||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createInformativeDialog(Context context, String title, String message) {
|
public static void createInformativeDialog(Context context, @StringRes int title, @StringRes int message) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(title);
|
builder.setTitle(title);
|
||||||
builder.setMessage(message)
|
builder.setMessage(message)
|
||||||
|
@ -205,4 +205,8 @@
|
|||||||
<string name="light_theme">Light Theme</string>
|
<string name="light_theme">Light Theme</string>
|
||||||
<string name="black_theme">Black Theme (AMOLED)</string>
|
<string name="black_theme">Black Theme (AMOLED)</string>
|
||||||
<string name="folder">Folder Name</string>
|
<string name="folder">Folder Name</string>
|
||||||
|
<string name="action_folder">Folder</string>
|
||||||
|
<string name="action_rename">Rename</string>
|
||||||
|
<string name="title_rename_folder">Rename Folder</string>
|
||||||
|
<string name="dialog_folder">What would you like to do with this folder?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user