From 2fc1c7595549d938fe8059adc76527df7e4d95bc Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Fri, 14 Jun 2013 17:09:33 +0200 Subject: [PATCH] Properly show torrent action success result messages. --- core/res/values/strings.xml | 8 +-- .../app/settings/SettingsPersistence.java | 2 +- .../transdroid/core/gui/DetailsActivity.java | 47 ++++++++------- .../transdroid/core/gui/TorrentsActivity.java | 58 +++++++++---------- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/core/res/values/strings.xml b/core/res/values/strings.xml index 0bee662f..8f6beceb 100644 --- a/core/res/values/strings.xml +++ b/core/res/values/strings.xml @@ -90,12 +90,12 @@ %1$s removed %1$s removed and data deleted %1$s resumed (refreshing) - %1$s stopped + %1$s stopped (refreshing) %1$s started (refreshing) - %1$s paused - Torrents paused + %1$s paused (refreshing) + Torrents paused (refreshing) Torrents resumed (refreshing) - Torrents stopped + Torrents stopped (refreshing) Torrents started (refreshing) Trackers updated Label set to \'%1$s\' diff --git a/core/src/org/transdroid/core/app/settings/SettingsPersistence.java b/core/src/org/transdroid/core/app/settings/SettingsPersistence.java index a06cfaa1..e1bc3533 100644 --- a/core/src/org/transdroid/core/app/settings/SettingsPersistence.java +++ b/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("base_ftp_url", prefs.getString("server_ftpurl_" + 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("new_torrent_alarm", prefs.getBoolean("server_alarmnew_" + postfixi, false)); diff --git a/core/src/org/transdroid/core/gui/DetailsActivity.java b/core/src/org/transdroid/core/gui/DetailsActivity.java index 8778dc9c..9f9eaade 100644 --- a/core/src/org/transdroid/core/gui/DetailsActivity.java +++ b/core/src/org/transdroid/core/gui/DetailsActivity.java @@ -71,16 +71,16 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @FragmentById(resName = "torrent_details") protected DetailsFragment fragmentDetails; - @Override - public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); - } - super.onCreate(savedInstanceState); - } - + @Override + public void onCreate(Bundle savedInstanceState) { + // Set the theme according to the user preference + if (SystemSettings_.getInstance_(this).useDarkTheme()) { + setTheme(R.style.TransdroidTheme_Dark); + getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); + } + super.onCreate(savedInstanceState); + } + @AfterViews protected void init() { @@ -158,7 +158,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent torrent.mimicResume(); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -170,7 +170,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent torrent.mimicPause(); DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_paused); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -182,7 +182,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent torrent.mimicStart(); DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_started); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -194,7 +194,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent torrent.mimicStop(); DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_stopped); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -205,8 +205,9 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent public void removeTorrent(Torrent torrent, boolean withData) { DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, withData ? R.string.result_removed_with_data - : R.string.result_removed); + onTaskSucceeded( + (DaemonTaskSuccessResult) result, + getString(withData ? R.string.result_removed_with_data : R.string.result_removed, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -218,7 +219,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent torrent.mimicNewLabel(newLabel); DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_labelset, newLabel); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -229,7 +230,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent public void updateTrackers(Torrent torrent, List newTrackers) { DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_trackersupdated); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); } else { onCommunicationError((DaemonTaskFailureResult) result); } @@ -240,16 +241,18 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent public void updateLocation(Torrent torrent, String newLocation) { DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_locationset, newLocation); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); } else { onCommunicationError((DaemonTaskFailureResult) result); } } @UiThread - protected void onTaskSucceeded(DaemonTaskSuccessResult result, int successMessageId, String... messageParams) { - Crouton.showText(this, getString(successMessageId, (Object[]) messageParams), - navigationHelper.CROUTON_INFO_STYLE); + protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { + // Refresh the screen as well + refreshTorrent(); + refreshTorrentDetails(torrent); + Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE); } @UiThread diff --git a/core/src/org/transdroid/core/gui/TorrentsActivity.java b/core/src/org/transdroid/core/gui/TorrentsActivity.java index 9e13d1c9..44ebe7b1 100644 --- a/core/src/org/transdroid/core/gui/TorrentsActivity.java +++ b/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.ViewById; import org.transdroid.core.R; -import org.transdroid.core.app.settings.ApplicationSettings; import org.transdroid.core.app.settings.*; import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.log.*; 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.FilePickerHelper; import org.transdroid.core.gui.search.UrlEntryDialog; @@ -118,16 +113,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @FragmentById(resName = "torrent_details") protected DetailsFragment fragmentDetails; - @Override - public void onCreate(Bundle savedInstanceState) { - // Set the theme according to the user preference - if (SystemSettings_.getInstance_(this).useDarkTheme()) { - setTheme(R.style.TransdroidTheme_Dark); - getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); - } - super.onCreate(savedInstanceState); - } - + @Override + public void onCreate(Bundle savedInstanceState) { + // Set the theme according to the user preference + if (SystemSettings_.getInstance_(this).useDarkTheme()) { + setTheme(R.style.TransdroidTheme_Dark); + getSupportActionBar().setIcon(R.drawable.ic_activity_torrents); + } + super.onCreate(savedInstanceState); + } + @AfterViews protected void init() { @@ -372,7 +367,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi // Add a torrent from a local or remote data URI? if (dataUri == null) return; - + // Adding a torrent from the Android downloads manager if (dataUri.getScheme() != null && dataUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { addTorrentFromDownloads(dataUri); @@ -584,7 +579,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi public void addTorrentByUrl(String url, String title) { DaemonTaskResult result = AddByUrlTask.create(currentConnection, url, title).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); refreshTorrents(); } else { onCommunicationError((DaemonTaskFailureResult) result, false); @@ -595,7 +590,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi protected void addTorrentByMagnetUrl(String url) { DaemonTaskResult result = AddByMagnetUrlTask.create(currentConnection, url).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, "Torrent"); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, "Torrent")); refreshTorrents(); } else { onCommunicationError((DaemonTaskFailureResult) result, false); @@ -606,7 +601,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi protected void addTorrentByFile(String localFile, String title) { DaemonTaskResult result = AddByFileTask.create(currentConnection, localFile).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_added, title); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_added, title)); refreshTorrents(); } else { onCommunicationError((DaemonTaskFailureResult) result, false); @@ -656,7 +651,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi torrent.mimicResume(); DaemonTaskResult result = ResumeTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_resumed); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_resumed, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -668,7 +663,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi torrent.mimicPause(); DaemonTaskResult result = PauseTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_paused); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_paused, torrent.getName())); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -680,7 +675,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi torrent.mimicStart(); DaemonTaskResult result = StartTask.create(currentConnection, torrent, forced).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_started); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_started)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -692,7 +687,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi torrent.mimicStop(); DaemonTaskResult result = StopTask.create(currentConnection, torrent).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_stopped); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_stopped)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -703,8 +698,8 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi public void removeTorrent(Torrent torrent, boolean withData) { DaemonTaskResult result = RemoveTask.create(currentConnection, torrent, withData).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, withData ? R.string.result_removed_with_data - : R.string.result_removed); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(withData ? R.string.result_removed_with_data + : R.string.result_removed)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -716,7 +711,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi torrent.mimicNewLabel(newLabel); DaemonTaskResult result = SetLabelTask.create(currentConnection, torrent, newLabel).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_labelset, newLabel); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_labelset, newLabel)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -727,7 +722,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi public void updateTrackers(Torrent torrent, List newTrackers) { DaemonTaskResult result = SetTrackersTask.create(currentConnection, torrent, newTrackers).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_trackersupdated); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_trackersupdated)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } @@ -738,16 +733,17 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi public void updateLocation(Torrent torrent, String newLocation) { DaemonTaskResult result = SetDownloadLocationTask.create(currentConnection, torrent, newLocation).execute(); if (result instanceof DaemonTaskResult) { - onTaskSucceeded((DaemonTaskSuccessResult) result, R.string.result_locationset, newLocation); + onTaskSucceeded((DaemonTaskSuccessResult) result, getString(R.string.result_locationset, newLocation)); } else { onCommunicationError((DaemonTaskFailureResult) result, false); } } @UiThread - protected void onTaskSucceeded(DaemonTaskSuccessResult result, int successMessageId, String... messageParams) { - Crouton.showText(this, getString(successMessageId, (Object[]) messageParams), - navigationHelper.CROUTON_INFO_STYLE); + protected void onTaskSucceeded(DaemonTaskSuccessResult result, String successMessage) { + // Refresh the screen as well + refreshScreen(); + Crouton.showText(this, successMessage, navigationHelper.CROUTON_INFO_STYLE); } @UiThread