diff --git a/app/src/main/java/org/transdroid/core/gui/ConfirmRemoveDialog.java b/app/src/main/java/org/transdroid/core/gui/ConfirmRemoveDialog.java new file mode 100644 index 00000000..89aa3593 --- /dev/null +++ b/app/src/main/java/org/transdroid/core/gui/ConfirmRemoveDialog.java @@ -0,0 +1,53 @@ +package org.transdroid.core.gui; + +import android.app.AlertDialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; + +import org.transdroid.R; +import org.transdroid.daemon.Torrent; + +import java.util.List; + +public class ConfirmRemoveDialog { + + /** + * Opens a dialog that confirms the removal of a torrent, along with an option for with deleting downloaded files + * @param activity The torrents activity from which the dialog is started (and which received the callback) + * @param torrents List of torrents to be removed + */ + public static void startConfirmRemove(final TorrentsActivity activity, final List torrents) { + final CharSequence checkboxItems[] = {activity.getString(R.string.navigation_confirmdataremoval)}; + final boolean[] isRemoveDataChecked = {false}; + + new DialogFragment() { + public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { + return new AlertDialog.Builder(activity).setTitle(R.string.navigation_confirmremove) + .setMultiChoiceItems(checkboxItems, null, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + isRemoveDataChecked[0] = isChecked; + } + }) + .setPositiveButton(android.R.string.ok, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + for (Torrent torrent : torrents) { + activity.removeTorrent(torrent, isRemoveDataChecked[0]); + } + dialog.dismiss(); + } + }) + .setNegativeButton(android.R.string.cancel, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }) + .create(); + }; + }.show(activity.getFragmentManager(), "confirmremoval"); + } + +} diff --git a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java index 013bbbab..93860d8a 100644 --- a/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/DetailsFragment.java @@ -17,6 +17,7 @@ package org.transdroid.core.gui; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -258,7 +259,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen menu.findItem(R.id.action_start_direct).setVisible(false); menu.findItem(R.id.action_stop).setVisible(false); menu.findItem(R.id.action_remove).setVisible(false); - menu.findItem(R.id.action_remove_withdata).setVisible(false); menu.findItem(R.id.action_setlabel).setVisible(false); menu.findItem(R.id.action_forcerecheck).setVisible(false); menu.findItem(R.id.action_updatetrackers).setVisible(false); @@ -274,8 +274,6 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen menu.findItem(R.id.action_start_direct).setVisible(startStop && !forcedStart && torrent.canStart()); menu.findItem(R.id.action_stop).setVisible(startStop && torrent.canStop()); menu.findItem(R.id.action_remove).setVisible(true); - boolean removeWithData = Daemon.supportsRemoveWithData(torrent.getDaemon()); - menu.findItem(R.id.action_remove_withdata).setVisible(removeWithData); boolean setLabel = Daemon.supportsSetLabel(torrent.getDaemon()); menu.findItem(R.id.action_setlabel).setVisible(setLabel); boolean forceRecheck = Daemon.supportsForceRecheck(torrent.getDaemon()); @@ -317,14 +315,9 @@ public class DetailsFragment extends Fragment implements OnTrackersUpdatedListen getTasksExecutor().stopTorrent(torrent); } - @OptionsItem(resName = "action_remove_default") + @OptionsItem(resName = "action_remove") protected void removeTorrentDefault() { - getTasksExecutor().removeTorrent(torrent, false); - } - - @OptionsItem(resName = "action_remove_withdata") - protected void removeTorrentWithData() { - getTasksExecutor().removeTorrent(torrent, true); + ConfirmRemoveDialog.startConfirmRemove((TorrentsActivity) getActivity(), Arrays.asList(torrent)); } @OptionsItem(resName = "action_setlabel") diff --git a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java index 6bb7a267..cc6d0c84 100644 --- a/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java +++ b/app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java @@ -302,16 +302,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener } mode.finish(); return true; - } else if (itemId == R.id.action_remove_default) { - for (Torrent torrent : checked) { - getTasksExecutor().removeTorrent(torrent, false); - } - mode.finish(); - return true; - } else if (itemId == R.id.action_remove_withdata) { - for (Torrent torrent : checked) { - getTasksExecutor().removeTorrent(torrent, true); - } + } else if (itemId == R.id.action_remove) { + ConfirmRemoveDialog.startConfirmRemove((TorrentsActivity) getActivity(), checked); mode.finish(); return true; } else if (itemId == R.id.action_setlabel) { diff --git a/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java b/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java index 53b1584c..2f7f7d0e 100644 --- a/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java @@ -26,7 +26,7 @@ import android.text.Spannable; import android.text.SpannableString; import android.text.style.TypefaceSpan; -import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache; +import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache; import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; @@ -78,8 +78,8 @@ public class NavigationHelper { if (imageCache == null) { imageCache = ImageLoader.getInstance(); try { - LruDiscCache diskCache = - new LruDiscCache(context.getCacheDir(), null, new Md5FileNameGenerator(), 640000, 25); + LruDiskCache diskCache = + new LruDiskCache(context.getCacheDir(), null, new Md5FileNameGenerator(), 640000, 25); // @formatter:off Builder imageCacheBuilder = new Builder(context) .defaultDisplayImageOptions( diff --git a/app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java b/app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java index 930472df..b3c6edb5 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java +++ b/app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java @@ -28,7 +28,7 @@ import org.transdroid.BuildConfig; */ public class SearchHistoryProvider extends SearchRecentSuggestionsProvider { - public final static String AUTHORITY = BuildConfig.PACKAGE_NAME + ".search.SearchHistoryProvider"; + public final static String AUTHORITY = BuildConfig.APPLICATION_ID + ".search.SearchHistoryProvider"; public final static int MODE = DATABASE_MODE_QUERIES; public SearchHistoryProvider() { diff --git a/app/src/main/res/menu/fragment_details.xml b/app/src/main/res/menu/fragment_details.xml index 75a6043f..666121d3 100644 --- a/app/src/main/res/menu/fragment_details.xml +++ b/app/src/main/res/menu/fragment_details.xml @@ -57,10 +57,6 @@ android:showAsAction="always" android:title="@string/action_remove" android:orderInCategory="204"> - - - - - - - - Select finished Invert selection Add torrent to… - - STATUS: %1$s + Confirm torrent removal? + Also remove downloaded files? + + STATUS: %1$s Waiting to check… Verifying local data… Waiting to download %s