Browse Source

Properly show torrent action success result messages.

pull/11/head
Eric Kok 11 years ago
parent
commit
2fc1c75955
  1. 8
      core/res/values/strings.xml
  2. 2
      core/src/org/transdroid/core/app/settings/SettingsPersistence.java
  3. 47
      core/src/org/transdroid/core/gui/DetailsActivity.java
  4. 58
      core/src/org/transdroid/core/gui/TorrentsActivity.java

8
core/res/values/strings.xml

@ -90,12 +90,12 @@
<string name="result_removed">%1$s removed</string> <string name="result_removed">%1$s removed</string>
<string name="result_removed_with_data">%1$s removed and data deleted</string> <string name="result_removed_with_data">%1$s removed and data deleted</string>
<string name="result_resumed">%1$s resumed (refreshing)</string> <string name="result_resumed">%1$s resumed (refreshing)</string>
<string name="result_stopped">%1$s stopped</string> <string name="result_stopped">%1$s stopped (refreshing)</string>
<string name="result_started">%1$s started (refreshing)</string> <string name="result_started">%1$s started (refreshing)</string>
<string name="result_paused">%1$s paused</string> <string name="result_paused">%1$s paused (refreshing)</string>
<string name="result_paused_all">Torrents paused</string> <string name="result_paused_all">Torrents paused (refreshing)</string>
<string name="result_resumed_all">Torrents resumed (refreshing)</string> <string name="result_resumed_all">Torrents resumed (refreshing)</string>
<string name="result_stopped_all">Torrents stopped</string> <string name="result_stopped_all">Torrents stopped (refreshing)</string>
<string name="result_started_all">Torrents started (refreshing)</string> <string name="result_started_all">Torrents started (refreshing)</string>
<string name="result_trackersupdated">Trackers updated</string> <string name="result_trackersupdated">Trackers updated</string>
<string name="result_labelset">Label set to \'%1$s\'</string> <string name="result_labelset">Label set to \'%1$s\'</string>

2
core/src/org/transdroid/core/app/settings/SettingsPersistence.java

@ -194,7 +194,7 @@ public class SettingsPersistence {
server.put("downloads_dir", prefs.getString("server_downloaddir_" + postfixi, null)); server.put("downloads_dir", prefs.getString("server_downloaddir_" + postfixi, null));
server.put("base_ftp_url", prefs.getString("server_ftpurl_" + postfixi, null)); server.put("base_ftp_url", prefs.getString("server_ftpurl_" + postfixi, null));
server.put("ftp_password", prefs.getString("server_ftppass_" + postfixi, null)); server.put("ftp_password", prefs.getString("server_ftppass_" + postfixi, null));
server.put("server_timeout", prefs.getString("server_ftppass_" + postfixi, null)); server.put("server_timeout", prefs.getString("server_timeout_" + postfixi, null));
server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false)); server.put("download_alarm", prefs.getBoolean("server_alarmfinished_" + postfixi, false));
server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false)); server.put("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false));

47
core/src/org/transdroid/core/gui/DetailsActivity.java

@ -71,16 +71,16 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@FragmentById(resName = "torrent_details") @FragmentById(resName = "torrent_details")
protected DetailsFragment fragmentDetails; protected DetailsFragment fragmentDetails;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
// Set the theme according to the user preference // Set the theme according to the user preference
if (SystemSettings_.getInstance_(this).useDarkTheme()) { if (SystemSettings_.getInstance_(this).useDarkTheme()) {
setTheme(R.style.TransdroidTheme_Dark); setTheme(R.style.TransdroidTheme_Dark);
getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); getSupportActionBar().setIcon(R.drawable.ic_activity_torrents);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@AfterViews @AfterViews
protected void init() { protected void init() {
@ -158,7 +158,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
torrent.mimicResume(); torrent.mimicResume();
DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -170,7 +170,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
torrent.mimicPause(); torrent.mimicPause();
DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_paused); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -182,7 +182,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
torrent.mimicStart(); torrent.mimicStart();
DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(); DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_started); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -194,7 +194,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
torrent.mimicStop(); torrent.mimicStop();
DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_stopped); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -205,8 +205,9 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
public void removeTorrent(Torrent torrent, boolean withData) { public void removeTorrent(Torrent torrent, boolean withData) {
DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(); DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, withData ? R.string.result_removed_with_data onTaskSucceeded(
: R.string.result_removed); (DaemonTaskSuccessResult) result,
getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -218,7 +219,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
torrent.mimicNewLabel(newLabel); torrent.mimicNewLabel(newLabel);
DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute(); DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_labelset, newLabel); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -229,7 +230,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
public void updateTrackers(Torrent torrent, List<String> newTrackers) { public void updateTrackers(Torrent torrent, List<String> newTrackers) {
DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(); DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_trackersupdated); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
@ -240,16 +241,18 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
public void updateLocation(Torrent torrent, String newLocation) { public void updateLocation(Torrent torrent, String newLocation) {
DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(); DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_locationset, newLocation); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result); onCommunicationError((DaemonTaskFailureResult) result);
} }
} }
@UiThread @UiThread
protected void onTaskSucceeded(DaemonTaskSuccessResult result, int successMessageId, String... messageParams) { protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
Crouton.showText(this, getString(successMessageId, (Object[]) messageParams), // Refresh the screen as well
navigationHelper.CROUTON_INFO_STYLE); refreshTorrent();
refreshTorrentDetails(torrent);
Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE);
} }
@UiThread @UiThread

58
core/src/org/transdroid/core/gui/TorrentsActivity.java

@ -20,16 +20,11 @@ import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.UiThread; import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById; import org.androidannotations.annotations.ViewById;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.*; import org.transdroid.core.app.settings.*;
import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*; import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.*; import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.navigation.Label;
import org.transdroid.core.gui.navigation.NavigationFilter;
import org.transdroid.core.gui.navigation.NavigationHelper;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.search.BarcodeHelper; import org.transdroid.core.gui.search.BarcodeHelper;
import org.transdroid.core.gui.search.FilePickerHelper; import org.transdroid.core.gui.search.FilePickerHelper;
import org.transdroid.core.gui.search.UrlEntryDialog; import org.transdroid.core.gui.search.UrlEntryDialog;
@ -118,16 +113,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
@FragmentById(resName = "torrent_details") @FragmentById(resName = "torrent_details")
protected DetailsFragment fragmentDetails; protected DetailsFragment fragmentDetails;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
// Set the theme according to the user preference // Set the theme according to the user preference
if (SystemSettings_.getInstance_(this).useDarkTheme()) { if (SystemSettings_.getInstance_(this).useDarkTheme()) {
setTheme(R.style.TransdroidTheme_Dark); setTheme(R.style.TransdroidTheme_Dark);
getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); getSupportActionBar().setIcon(R.drawable.ic_activity_torrents);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@AfterViews @AfterViews
protected void init() { protected void init() {
@ -372,7 +367,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
// Add a torrent from a local or remote data URI? // Add a torrent from a local or remote data URI?
if (dataUri == null) if (dataUri == null)
return; return;
// Adding a torrent from the Android downloads manager // Adding a torrent from the Android downloads manager
if (dataUri.getScheme() != null && dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { if (dataUri.getScheme() != null && dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
addTorrentFromDownloads(dataUri); addTorrentFromDownloads(dataUri);
@ -584,7 +579,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
public void addTorrentByUrl(String url, String title) { public void addTorrentByUrl(String url, String title) {
DaemonTaskResult result = AddByUrlTask.create(currentConnection, url, title).execute(); DaemonTaskResult result = AddByUrlTask.create(currentConnection, url, title).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
@ -595,7 +590,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
protected void addTorrentByMagnetUrl(String url) { protected void addTorrentByMagnetUrl(String url) {
DaemonTaskResult result = AddByMagnetUrlTask.create(currentConnection, url).execute(); DaemonTaskResult result = AddByMagnetUrlTask.create(currentConnection, url).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, "Torrent"); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, "Torrent"));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
@ -606,7 +601,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
protected void addTorrentByFile(String localFile, String title) { protected void addTorrentByFile(String localFile, String title) {
DaemonTaskResult result = AddByFileTask.create(currentConnection, localFile).execute(); DaemonTaskResult result = AddByFileTask.create(currentConnection, localFile).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title));
refreshTorrents(); refreshTorrents();
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
@ -656,7 +651,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent.mimicResume(); torrent.mimicResume();
DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -668,7 +663,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent.mimicPause(); torrent.mimicPause();
DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_paused); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName()));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -680,7 +675,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent.mimicStart(); torrent.mimicStart();
DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(); DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_started); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -692,7 +687,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent.mimicStop(); torrent.mimicStop();
DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(); DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_stopped); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -703,8 +698,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
public void removeTorrent(Torrent torrent, boolean withData) { public void removeTorrent(Torrent torrent, boolean withData) {
DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(); DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, withData ? R.string.result_removed_with_data onTaskSucceeded((DaemonTaskSuccessResult) result, getString(withData ? R.string.result_removed_with_data
: R.string.result_removed); : R.string.result_removed));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -716,7 +711,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
torrent.mimicNewLabel(newLabel); torrent.mimicNewLabel(newLabel);
DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute(); DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_labelset, newLabel); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -727,7 +722,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
public void updateTrackers(Torrent torrent, List<String> newTrackers) { public void updateTrackers(Torrent torrent, List<String> newTrackers) {
DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(); DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_trackersupdated); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
@ -738,16 +733,17 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
public void updateLocation(Torrent torrent, String newLocation) { public void updateLocation(Torrent torrent, String newLocation) {
DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(); DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute();
if (result instanceof DaemonTaskResult) { if (result instanceof DaemonTaskResult) {
onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_locationset, newLocation); onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation));
} else { } else {
onCommunicationError((DaemonTaskFailureResult) result, false); onCommunicationError((DaemonTaskFailureResult) result, false);
} }
} }
@UiThread @UiThread
protected void onTaskSucceeded(DaemonTaskSuccessResult result, int successMessageId, String... messageParams) { protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) {
Crouton.showText(this, getString(successMessageId, (Object[]) messageParams), // Refresh the screen as well
navigationHelper.CROUTON_INFO_STYLE); refreshScreen();
Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE);
} }
@UiThread @UiThread

Loading…
Cancel
Save