Browse Source

add delete downloads dialog

master
DF1E 8 years ago
parent
commit
c3df776771
  1. 12
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 2
      app/src/main/java/acr/browser/lightning/controller/UIController.java
  3. 4
      app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java
  4. 4
      app/src/main/java/acr/browser/lightning/database/downloads/DownloadsModel.java
  5. 41
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  6. 26
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  7. 2
      app/src/main/res/values/strings.xml

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

@ -2130,6 +2130,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
} }
@Override
public void handleDownloadDeleted() {
final LightningView currentTab = mTabsManager.getCurrentTab();
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
&& currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) {
currentTab.loadDownloadspage();
}
if (currentTab != null) {
mBookmarksView.handleUpdatedUrl(currentTab.getUrl());
}
}
@Override @Override
public void handleBookmarkDeleted(@NonNull HistoryItem item) { public void handleBookmarkDeleted(@NonNull HistoryItem item) {
mBookmarksView.handleBookmarkDeleted(item); mBookmarksView.handleBookmarkDeleted(item);

2
app/src/main/java/acr/browser/lightning/controller/UIController.java

@ -86,6 +86,8 @@ public interface UIController {
void handleBookmarksChange(); void handleBookmarksChange();
void handleDownloadDeleted();
void handleBookmarkDeleted(@NonNull HistoryItem item); void handleBookmarkDeleted(@NonNull HistoryItem item);
void handleNewTab(@NonNull LightningDialogBuilder.NewTab newTabType, @NonNull String url); void handleNewTab(@NonNull LightningDialogBuilder.NewTab newTabType, @NonNull String url);

4
app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java

@ -214,11 +214,11 @@ public class DownloadsDatabase extends SQLiteOpenHelper implements DownloadsMode
@NonNull @NonNull
@Override @Override
public Single<Boolean> deleteDownload(@NonNull final DownloadItem bookmark) { public Single<Boolean> deleteDownload(@NonNull final String url) {
return Single.create(new SingleAction<Boolean>() { return Single.create(new SingleAction<Boolean>() {
@Override @Override
public void onSubscribe(@NonNull SingleSubscriber<Boolean> subscriber) { public void onSubscribe(@NonNull SingleSubscriber<Boolean> subscriber) {
int rows = lazyDatabase().delete(TABLE_DOWNLOADS, KEY_URL + "=?", new String[]{bookmark.getUrl()}); int rows = lazyDatabase().delete(TABLE_DOWNLOADS, KEY_URL + "=?", new String[]{url});
subscriber.onItem(rows > 0); subscriber.onItem(rows > 0);
subscriber.onComplete(); subscriber.onComplete();

4
app/src/main/java/acr/browser/lightning/database/downloads/DownloadsModel.java

@ -60,12 +60,12 @@ public interface DownloadsModel {
/** /**
* Deletes a download from the database. * Deletes a download from the database.
* *
* @param download the download to delete. * @param url the download url to delete.
* @return an observable that emits true when * @return an observable that emits true when
* the download is deleted, false otherwise. * the download is deleted, false otherwise.
*/ */
@NonNull @NonNull
Single<Boolean> deleteDownload(@NonNull DownloadItem download); Single<Boolean> deleteDownload(@NonNull String url);
/** /**
* Deletes all downloads in the database. * Deletes all downloads in the database.

41
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -8,6 +8,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
@ -26,15 +27,20 @@ import acr.browser.lightning.activity.MainActivity;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
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.DownloadsPage;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.database.bookmark.BookmarkModel;
import acr.browser.lightning.database.downloads.DownloadItem;
import acr.browser.lightning.database.downloads.DownloadsModel;
import acr.browser.lightning.database.history.HistoryModel; import acr.browser.lightning.database.history.HistoryModel;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.Preconditions;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
import static android.content.ContentValues.TAG;
/** /**
* 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/> * <p/>
@ -49,6 +55,7 @@ public class LightningDialogBuilder {
} }
@Inject BookmarkModel mBookmarkManager; @Inject BookmarkModel mBookmarkManager;
@Inject DownloadsModel mDownloadsModel;
@Inject PreferenceManager mPreferenceManager; @Inject PreferenceManager mPreferenceManager;
@Inject @Inject
@ -152,6 +159,40 @@ public class LightningDialogBuilder {
}); });
} }
/**
* Show the appropriated dialog for the long pressed link.
*
* @param activity used to show the dialog
* @param url the long pressed url
*/
public void showLongPressedDialogForDownloadUrl(@NonNull final Activity activity,
@NonNull final UIController uiController,
@NonNull final String url) {
BrowserDialog.show(activity, R.string.action_bookmarks,
new BrowserDialog.Item(R.string.dialog_delete_download) {
@Override
public void onClick() {
mDownloadsModel.deleteDownload(url).subscribe(new SingleOnSubscribe<Boolean>() {
@Override
public void onItem(@Nullable Boolean item) {
if (item != null && !item)
Log.i(TAG, "error deleting download from database");
else
uiController.handleDownloadDeleted();
}
});
}
},
new BrowserDialog.Item(R.string.dialog_delete_all_downloads) {
@Override
public void onClick() {
// TODO: fix refreshing downloads page
mDownloadsModel.deleteAllDownloads().subscribeOn(Schedulers.io()).subscribe();
}
});
}
private void showEditBookmarkDialog(@NonNull final Activity activity, private void showEditBookmarkDialog(@NonNull final Activity activity,
@NonNull final UIController uiController, @NonNull final UIController uiController,
@NonNull final HistoryItem item) { @NonNull final HistoryItem item) {

26
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -47,6 +47,7 @@ import javax.inject.Inject;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
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.DownloadsPage;
import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.constant.StartPage; import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.controller.UIController; import acr.browser.lightning.controller.UIController;
@ -242,6 +243,24 @@ public class LightningView {
}); });
} }
/**
* This method gets the bookmark page URL from the {@link BookmarkPage}
* class asynchronously and loads the URL in the WebView on the
* UI thread. It also caches the default folder icon locally.
*/
public void loadDownloadspage() {
new DownloadsPage().getDownloadsPage()
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<String>() {
@Override
public void onItem(@Nullable String item) {
Preconditions.checkNonNull(item);
loadUrl(item);
}
});
}
/** /**
* Initialize the preference driven settings of the WebView. This method * Initialize the preference driven settings of the WebView. This method
* must be called whenever the preferences are changed within SharedPreferences. * must be called whenever the preferences are changed within SharedPreferences.
@ -984,6 +1003,13 @@ public class LightningView {
final String newUrl = result.getExtra(); final String newUrl = result.getExtra();
mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl); mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl);
} }
} else if (currentUrl.endsWith(DownloadsPage.FILENAME)) {
if (url != null) {
mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url);
} else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra();
mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, newUrl);
}
} }
} else { } else {
if (url != null) { if (url != null) {

2
app/src/main/res/values/strings.xml

@ -246,4 +246,6 @@
<string name="dialog_rename_folder">Rename folder</string> <string name="dialog_rename_folder">Rename folder</string>
<string name="dialog_remove_folder">Remove folder</string> <string name="dialog_remove_folder">Remove folder</string>
<string name="dialog_title_close_browser">Close browser</string> <string name="dialog_title_close_browser">Close browser</string>
<string name="dialog_delete_download">Delete download</string>
<string name="dialog_delete_all_downloads">Delete all downloads</string>
</resources> </resources>

Loading…
Cancel
Save