Browse Source

Adding confirm dialog for removing torrents

pull/222/head
Kumaresan Rajeswaran 9 years ago
parent
commit
8ae1abfdb0
  1. 53
      app/src/main/java/org/transdroid/core/gui/ConfirmRemoveDialog.java
  2. 13
      app/src/main/java/org/transdroid/core/gui/DetailsFragment.java
  3. 12
      app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java
  4. 6
      app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java
  5. 2
      app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java
  6. 4
      app/src/main/res/menu/fragment_details.xml
  7. 4
      app/src/main/res/menu/fragment_torrents_cab.xml
  8. 6
      app/src/main/res/values/strings.xml

53
app/src/main/java/org/transdroid/core/gui/ConfirmRemoveDialog.java

@ -0,0 +1,53 @@ @@ -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<Torrent> 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");
}
}

13
app/src/main/java/org/transdroid/core/gui/DetailsFragment.java

@ -17,6 +17,7 @@ @@ -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 @@ -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 @@ -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 @@ -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")

12
app/src/main/java/org/transdroid/core/gui/TorrentsFragment.java

@ -302,16 +302,8 @@ public class TorrentsFragment extends Fragment implements OnLabelPickedListener @@ -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) {

6
app/src/main/java/org/transdroid/core/gui/navigation/NavigationHelper.java

@ -26,7 +26,7 @@ import android.text.Spannable; @@ -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 { @@ -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(

2
app/src/main/java/org/transdroid/core/gui/search/SearchHistoryProvider.java

@ -28,7 +28,7 @@ import org.transdroid.BuildConfig; @@ -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() {

4
app/src/main/res/menu/fragment_details.xml

@ -57,10 +57,6 @@ @@ -57,10 +57,6 @@
android:showAsAction="always"
android:title="@string/action_remove"
android:orderInCategory="204">
<menu>
<item android:id="@+id/action_remove_default" android:title="@string/action_remove_default" />
<item android:id="@+id/action_remove_withdata" android:title="@string/action_remove_withdata" />
</menu>
</item>
<item
android:id="@+id/action_setlabel"

4
app/src/main/res/menu/fragment_torrents_cab.xml

@ -41,10 +41,6 @@ @@ -41,10 +41,6 @@
android:icon="?attr/ic_action_remove"
android:showAsAction="always"
android:title="@string/action_remove">
<menu>
<item android:id="@+id/action_remove_default" android:title="@string/action_remove_default" />
<item android:id="@+id/action_remove_withdata" android:title="@string/action_remove_withdata" />
</menu>
</item>
<item
android:id="@+id/action_setlabel"

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

@ -94,8 +94,10 @@ @@ -94,8 +94,10 @@
<string name="navigation_selectfinished">Select finished</string>
<string name="navigation_invertselection">Invert selection</string>
<string name="navigation_pickserver">Add torrent to&#8230;</string>
<string name="status_status">STATUS: %1$s</string>
<string name="navigation_confirmremove">Confirm torrent removal?</string>
<string name="navigation_confirmdataremoval">Also remove downloaded files?</string>
<string name="status_status">STATUS: %1$s</string>
<string name="status_waiting">Waiting to check&#8230;</string>
<string name="status_checking">Verifying local data&#8230;</string>
<string name="status_waitingtodl">Waiting to download %s</string>

Loading…
Cancel
Save