|
|
@ -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,8 +55,9 @@ 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 url the long pressed url |
|
|
|
* @param context used to show the dialog |
|
|
|
|
|
|
|
* @param url the long pressed url |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void showLongPressedDialogForBookmarkUrl(final Context context, final String url) { |
|
|
|
public void showLongPressedDialogForBookmarkUrl(final Context context, final String url) { |
|
|
|
final HistoryItem item; |
|
|
|
final HistoryItem item; |
|
|
@ -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; |
|
|
@ -245,20 +245,19 @@ public class LightningDialogBuilder { |
|
|
|
|
|
|
|
|
|
|
|
// TODO There should be a way in which we do not need an activity reference to dowload a file
|
|
|
|
// TODO There should be a way in which we do not need an activity reference to dowload a file
|
|
|
|
public void showLongPressImageDialog(@NonNull final Activity activity, @NonNull final String url, |
|
|
|
public void showLongPressImageDialog(@NonNull final Activity activity, @NonNull final String url, |
|
|
|
@NonNull final String userAgent) { |
|
|
|
@NonNull final String userAgent) { |
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
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: |
|
|
|