Browse Source

Force refresh in main screen after a torrent was deleted in the details screen. (Also added some debug logging for lcoal network connections.)

pull/82/head
Eric Kok 11 years ago
parent
commit
a052e7f4c7
  1. 13
      core/src/org/transdroid/core/app/settings/ServerSetting.java
  2. 4
      core/src/org/transdroid/core/gui/DetailsActivity.java
  3. 40
      core/src/org/transdroid/core/gui/TorrentsActivity.java
  4. 2
      core/src/org/transdroid/core/service/ServerCheckerService.java
  5. 2
      core/src/org/transdroid/core/widget/WidgetConfigActivity.java
  6. 2
      core/src/org/transdroid/core/widget/WidgetService.java

13
core/src/org/transdroid/core/app/settings/ServerSetting.java

@ -17,11 +17,13 @@
package org.transdroid.core.app.settings; package org.transdroid.core.app.settings;
import org.transdroid.core.gui.lists.SimpleListItem; import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.Log;
import org.transdroid.daemon.Daemon; import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonSettings; import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter; import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.OS; import org.transdroid.daemon.OS;
import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
@ -252,22 +254,27 @@ public class ServerSetting implements SimpleListItem {
* Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings * Returns the appropriate daemon adapter to which tasks can be executed, in accordance with this server's settings
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined * be determined
* @param context
* @return An IDaemonAdapter instance of the specific torrent client daemon type * @return An IDaemonAdapter instance of the specific torrent client daemon type
*/ */
public IDaemonAdapter createServerAdapter(String connectedToNetwork) { public IDaemonAdapter createServerAdapter(String connectedToNetwork, Context context) {
return type.createAdapter(convertToDaemonSettings(connectedToNetwork)); return type.createAdapter(convertToDaemonSettings(connectedToNetwork, context));
} }
/** /**
* Converts local server settings into an old-style {@link DaemonSettings} object. * Converts local server settings into an old-style {@link DaemonSettings} object.
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not * @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined * be determined
* @param caller
* @return A {@link DaemonSettings} object to execute server commands against * @return A {@link DaemonSettings} object to execute server commands against
*/ */
private DaemonSettings convertToDaemonSettings(String connectedToNetwork) { private DaemonSettings convertToDaemonSettings(String connectedToNetwork, Context caller) {
// The local integer key is converted to the idString string. // The local integer key is converted to the idString string.
// The host name address used is dependent on the network that we are currently connected to (to allow a // The host name address used is dependent on the network that we are currently connected to (to allow a
// distinct connection IP or host name when connected to a local network). // distinct connection IP or host name when connected to a local network).
if (localNetwork != null)
Log.d(caller, "Creating adapter for " + name + " of type " + type.name() + ": connected to "
+ connectedToNetwork + " and configured local network is " + localNetwork);
return new DaemonSettings(name, type, return new DaemonSettings(name, type,
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, port, connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, port,
ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os, ssl, sslTrustAll, sslTrustKey, folder, useAuthentication, username, password, extraPass, os,

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

@ -135,7 +135,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Connect to the last used server // Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer(); ServerSetting lastUsed = applicationSettings.getLastUsedServer();
fragmentDetails.setCurrentServerSettings(lastUsed); fragmentDetails.setCurrentServerSettings(lastUsed);
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName()); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
// Show details and load fine stats and torrent files // Show details and load fine stats and torrent files
fragmentDetails.updateTorrent(torrent); fragmentDetails.updateTorrent(torrent);
@ -283,6 +283,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@UiThread @UiThread
protected void closeActivity(String closeText) { protected void closeActivity(String closeText) {
// The activity result RESULT_CANCELED means that the torrent no longer exists
setResult(RESULT_OK, new Intent().putExtra("torrent_removed", true));
finish(); finish();
if (closeText != null) if (closeText != null)
Toast.makeText(this, closeText, Toast.LENGTH_LONG).show(); Toast.makeText(this, closeText, Toast.LENGTH_LONG).show();

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

@ -44,17 +44,29 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie; import org.apache.http.impl.cookie.BasicClientCookie;
import org.transdroid.core.R; import org.transdroid.core.R;
import org.transdroid.core.app.settings.*; import org.transdroid.core.app.settings.ApplicationSettings;
import org.transdroid.core.app.settings.ServerSetting;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.WebsearchSetting;
import org.transdroid.core.gui.lists.LocalTorrent; import org.transdroid.core.gui.lists.LocalTorrent;
import org.transdroid.core.gui.lists.NoProgressHeaderTransformer; import org.transdroid.core.gui.lists.NoProgressHeaderTransformer;
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.Log;
import org.transdroid.core.gui.navigation.*; import org.transdroid.core.gui.log.Log_;
import org.transdroid.core.gui.rss.*; import org.transdroid.core.gui.navigation.FilterListAdapter;
import org.transdroid.core.gui.navigation.FilterListAdapter_;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter;
import org.transdroid.core.gui.navigation.FilterListDropDownAdapter_;
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.RefreshableActivity;
import org.transdroid.core.gui.navigation.StatusType;
import org.transdroid.core.gui.rss.RssfeedsActivity_;
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;
import org.transdroid.core.gui.settings.*; import org.transdroid.core.gui.settings.MainSettingsActivity_;
import org.transdroid.core.service.BootReceiver; import org.transdroid.core.service.BootReceiver;
import org.transdroid.core.service.ConnectivityHelper; import org.transdroid.core.service.ConnectivityHelper;
import org.transdroid.core.widget.WidgetProvider; import org.transdroid.core.widget.WidgetProvider;
@ -96,7 +108,6 @@ import org.transdroid.daemon.util.HttpHelper;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher; import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener; import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.Options; import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.Options;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -130,6 +141,8 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor, public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor,
RefreshableActivity { RefreshableActivity {
private static final int RESULT_DETAILS = 0;
// Navigation components // Navigation components
@Bean @Bean
protected NavigationHelper navigationHelper; protected NavigationHelper navigationHelper;
@ -252,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
} else { } else {
// Resume after instead of fully loading the torrents list; create connection and set action bar title // Resume after instead of fully loading the torrents list; create connection and set action bar title
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName()); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
navigationSpinnerAdapter.updateCurrentServer(currentConnection); navigationSpinnerAdapter.updateCurrentServer(currentConnection);
navigationSpinnerAdapter.updateCurrentFilter(currentFilter); navigationSpinnerAdapter.updateCurrentFilter(currentFilter);
} }
@ -281,9 +294,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (currentConnection == null) if (currentConnection == null)
filterSelected(lastUsed, true); filterSelected(lastUsed, true);
else else
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName()); currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
} }
@OnActivityResult(RESULT_DETAILS)
protected void onDetailsScreenResult(Intent result) {
// If the details activity returns whether the torrent was removed, refresh the screen
if (result != null && result.getBooleanExtra("torrent_removed", false))
refreshScreen();
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
Crouton.cancelAllCroutons(); Crouton.cancelAllCroutons();
@ -399,7 +419,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
} }
// Update connection to the newly selected server and refresh // Update connection to the newly selected server and refresh
currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName()); currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
applicationSettings.setLastUsedServer(server); applicationSettings.setLastUsedServer(server);
navigationSpinnerAdapter.updateCurrentServer(currentConnection); navigationSpinnerAdapter.updateCurrentServer(currentConnection);
if (forceNewConnection) if (forceNewConnection)
@ -684,7 +704,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (fragmentDetails != null) { if (fragmentDetails != null) {
fragmentDetails.updateTorrent(torrent); fragmentDetails.updateTorrent(torrent);
} else { } else {
DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels).start(); DetailsActivity_.intent(this).torrent(torrent).currentLabels(lastNavigationLabels).startForResult(RESULT_DETAILS);
} }
} }

2
core/src/org/transdroid/core/service/ServerCheckerService.java

@ -88,7 +88,7 @@ public class ServerCheckerService extends IntentService {
JSONArray lastStats = applicationSettings.getServerLastStats(server); JSONArray lastStats = applicationSettings.getServerLastStats(server);
// Synchronously retrieve torrents listing // Synchronously retrieve torrents listing
IDaemonAdapter adapter = server.createServerAdapter(connectivityHelper.getConnectedNetworkName()); IDaemonAdapter adapter = server.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
DaemonTaskResult result = RetrieveTask.create(adapter).execute(); DaemonTaskResult result = RetrieveTask.create(adapter).execute();
if (!(result instanceof RetrieveTaskSuccessResult)) { if (!(result instanceof RetrieveTaskSuccessResult)) {
// Cannot retrieve torrents at this time // Cannot retrieve torrents at this time

2
core/src/org/transdroid/core/widget/WidgetConfigActivity.java

@ -163,7 +163,7 @@ public class WidgetConfigActivity extends SherlockActivity {
// Create a connection object and retrieve the live torrents // Create a connection object and retrieve the live torrents
IDaemonAdapter connection = ((ServerSetting) serverSpinner.getSelectedItem()) IDaemonAdapter connection = ((ServerSetting) serverSpinner.getSelectedItem())
.createServerAdapter(connectivityHelper.getConnectedNetworkName()); .createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
DaemonTaskResult result = RetrieveTask.create(connection).execute(); DaemonTaskResult result = RetrieveTask.create(connection).execute();
if (result instanceof RetrieveTaskSuccessResult) { if (result instanceof RetrieveTaskSuccessResult) {
// Success; show the active torrents in the widget preview // Success; show the active torrents in the widget preview

2
core/src/org/transdroid/core/widget/WidgetService.java

@ -94,7 +94,7 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
// Load the torrents; synchronously // Load the torrents; synchronously
IDaemonAdapter connection = server.createServerAdapter(ConnectivityHelper_.getInstance_(context) IDaemonAdapter connection = server.createServerAdapter(ConnectivityHelper_.getInstance_(context)
.getConnectedNetworkName()); .getConnectedNetworkName(), context);
DaemonTaskResult result = RetrieveTask.create(connection).execute(); DaemonTaskResult result = RetrieveTask.create(connection).execute();
if (!(result instanceof RetrieveTaskSuccessResult)) { if (!(result instanceof RetrieveTaskSuccessResult)) {
// TODO: Show error text somehow in the remote view, perhaps via the EmptyView's text? // TODO: Show error text somehow in the remote view, perhaps via the EmptyView's text?

Loading…
Cancel
Save