|
|
@ -26,27 +26,26 @@ import acr.browser.lightning.bus.BookmarkEvents; |
|
|
|
import acr.browser.lightning.bus.BrowserEvents; |
|
|
|
import acr.browser.lightning.bus.BrowserEvents; |
|
|
|
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.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.BookmarkManager; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
import acr.browser.lightning.database.HistoryDatabase; |
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
import acr.browser.lightning.database.HistoryItem; |
|
|
|
|
|
|
|
import acr.browser.lightning.preference.PreferenceManager; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* TODO Rename this class it doesn't build dialogs only for bookmarks |
|
|
|
* TODO Rename this class it doesn't build dialogs only for bookmarks |
|
|
|
* |
|
|
|
* <p/> |
|
|
|
* Created by Stefano Pacifici on 02/09/15, based on Anthony C. Restaino's code. |
|
|
|
* Created by Stefano Pacifici on 02/09/15, based on Anthony C. Restaino's code. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class LightningDialogBuilder { |
|
|
|
public class LightningDialogBuilder { |
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject BookmarkManager mBookmarkManager; |
|
|
|
BookmarkManager bookmarkManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject PreferenceManager mPreferenceManager; |
|
|
|
HistoryDatabase mHistoryDatabase; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject HistoryDatabase mHistoryDatabase; |
|
|
|
Bus eventBus; |
|
|
|
|
|
|
|
|
|
|
|
@Inject Bus mEventBus; |
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject |
|
|
|
public LightningDialogBuilder() { |
|
|
|
public LightningDialogBuilder() { |
|
|
@ -56,6 +55,7 @@ public class LightningDialogBuilder { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Show the appropriated dialog for the long pressed link. It means that we try to understand |
|
|
|
* Show the appropriated dialog for the long pressed link. It means that we try to understand |
|
|
|
* if the link is relative to a bookmark or is just a folder. |
|
|
|
* if the link is relative to a bookmark or is just a folder. |
|
|
|
|
|
|
|
* |
|
|
|
* @param context used to show the dialog |
|
|
|
* @param context used to show the dialog |
|
|
|
* @param url the long pressed url |
|
|
|
* @param url the long pressed url |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -72,7 +72,7 @@ public class LightningDialogBuilder { |
|
|
|
item.setImageId(R.drawable.ic_folder); |
|
|
|
item.setImageId(R.drawable.ic_folder); |
|
|
|
item.setUrl(Constants.FOLDER + folderTitle); |
|
|
|
item.setUrl(Constants.FOLDER + folderTitle); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
item = bookmarkManager.findBookmarkForUrl(url); |
|
|
|
item = mBookmarkManager.findBookmarkForUrl(url); |
|
|
|
} |
|
|
|
} |
|
|
|
if (item != null) { |
|
|
|
if (item != null) { |
|
|
|
if (item.isFolder()) { |
|
|
|
if (item.isFolder()) { |
|
|
@ -90,11 +90,11 @@ public class LightningDialogBuilder { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
switch (which) { |
|
|
|
switch (which) { |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl())); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(item.getUrl())); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
if (bookmarkManager.deleteBookmark(item)) { |
|
|
|
if (mBookmarkManager.deleteBookmark(item)) { |
|
|
|
eventBus.post(new BookmarkEvents.Deleted(item)); |
|
|
|
mEventBus.post(new BookmarkEvents.Deleted(item)); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
@ -126,7 +126,7 @@ public class LightningDialogBuilder { |
|
|
|
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder); |
|
|
|
(AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder); |
|
|
|
getFolder.setHint(R.string.folder); |
|
|
|
getFolder.setHint(R.string.folder); |
|
|
|
getFolder.setText(item.getFolder()); |
|
|
|
getFolder.setText(item.getFolder()); |
|
|
|
final List<String> folders = bookmarkManager.getFolderTitles(); |
|
|
|
final List<String> folders = mBookmarkManager.getFolderTitles(); |
|
|
|
final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(context, |
|
|
|
final ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(context, |
|
|
|
android.R.layout.simple_dropdown_item_1line, folders); |
|
|
|
android.R.layout.simple_dropdown_item_1line, folders); |
|
|
|
getFolder.setThreshold(1); |
|
|
|
getFolder.setThreshold(1); |
|
|
@ -142,8 +142,8 @@ public class LightningDialogBuilder { |
|
|
|
editedItem.setUrl(getUrl.getText().toString()); |
|
|
|
editedItem.setUrl(getUrl.getText().toString()); |
|
|
|
editedItem.setUrl(getUrl.getText().toString()); |
|
|
|
editedItem.setUrl(getUrl.getText().toString()); |
|
|
|
editedItem.setFolder(getFolder.getText().toString()); |
|
|
|
editedItem.setFolder(getFolder.getText().toString()); |
|
|
|
bookmarkManager.editBookmark(item, editedItem); |
|
|
|
mBookmarkManager.editBookmark(item, editedItem); |
|
|
|
eventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem)); |
|
|
|
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
editBookmarkDialog.show(); |
|
|
|
editBookmarkDialog.show(); |
|
|
@ -161,9 +161,9 @@ public class LightningDialogBuilder { |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
bookmarkManager.deleteFolder(item.getTitle()); |
|
|
|
mBookmarkManager.deleteFolder(item.getTitle()); |
|
|
|
// setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
|
|
|
// setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false);
|
|
|
|
eventBus.post(new BookmarkEvents.Deleted(item)); |
|
|
|
mEventBus.post(new BookmarkEvents.Deleted(item)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -204,8 +204,8 @@ public class LightningDialogBuilder { |
|
|
|
editedItem.setUrl(Constants.FOLDER + newTitle); |
|
|
|
editedItem.setUrl(Constants.FOLDER + newTitle); |
|
|
|
editedItem.setFolder(item.getFolder()); |
|
|
|
editedItem.setFolder(item.getFolder()); |
|
|
|
editedItem.setIsFolder(true); |
|
|
|
editedItem.setIsFolder(true); |
|
|
|
bookmarkManager.renameFolder(oldTitle, newTitle); |
|
|
|
mBookmarkManager.renameFolder(oldTitle, newTitle); |
|
|
|
eventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem)); |
|
|
|
mEventBus.post(new BookmarkEvents.BookmarkChanged(item, editedItem)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
editFolderDialog.show(); |
|
|
|
editFolderDialog.show(); |
|
|
@ -217,15 +217,15 @@ public class LightningDialogBuilder { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
switch (which) { |
|
|
|
switch (which) { |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
mHistoryDatabase.deleteHistoryItem(url); |
|
|
|
mHistoryDatabase.deleteHistoryItem(url); |
|
|
|
// openHistory();
|
|
|
|
// openHistory();
|
|
|
|
eventBus.post(new BrowserEvents.OpenHistoryInCurrentTab()); |
|
|
|
mEventBus.post(new BrowserEvents.OpenHistoryInCurrentTab()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; |
|
|
|
break; |
|
|
@ -251,14 +251,13 @@ public class LightningDialogBuilder { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
switch (which) { |
|
|
|
switch (which) { |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
Utils.downloadFile(activity, url, |
|
|
|
Utils.downloadFile(activity, mPreferenceManager, url, userAgent, "attachment"); |
|
|
|
userAgent, "attachment"); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -280,11 +279,11 @@ public class LightningDialogBuilder { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
switch (which) { |
|
|
|
switch (which) { |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInNewTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
eventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
mEventBus.post(new BrowserEvents.OpenUrlInCurrentTab(url)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|