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 @@ @@ -17,11 +17,13 @@
package org.transdroid.core.app.settings;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.Log;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.IDaemonAdapter;
import org.transdroid.daemon.OS;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
@ -252,22 +254,27 @@ public class ServerSetting implements SimpleListItem { @@ -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
* @param connectedToNetwork The name of the (wifi) network we are currently connected to, or null if this could not
* be determined
* @param context
* @return An IDaemonAdapter instance of the specific torrent client daemon type
*/
public IDaemonAdapter createServerAdapter(String connectedToNetwork) {
return type.createAdapter(convertToDaemonSettings(connectedToNetwork));
public IDaemonAdapter createServerAdapter(String connectedToNetwork, Context context) {
return type.createAdapter(convertToDaemonSettings(connectedToNetwork, context));
}
/**
* 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
* be determined
* @param caller
* @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 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).
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,
connectedToNetwork != null && connectedToNetwork.equals(localNetwork) ? localAddress : address, port,
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 @@ -135,7 +135,7 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
// Connect to the last used server
ServerSetting lastUsed = applicationSettings.getLastUsedServer();
fragmentDetails.setCurrentServerSettings(lastUsed);
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName());
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
// Show details and load fine stats and torrent files
fragmentDetails.updateTorrent(torrent);
@ -283,6 +283,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent @@ -283,6 +283,8 @@ public class DetailsActivity extends SherlockFragmentActivity implements Torrent
@UiThread
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();
if (closeText != null)
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; @@ -44,17 +44,29 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.cookie.BasicClientCookie;
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.NoProgressHeaderTransformer;
import org.transdroid.core.gui.lists.SimpleListItem;
import org.transdroid.core.gui.log.*;
import org.transdroid.core.gui.navigation.*;
import org.transdroid.core.gui.rss.*;
import org.transdroid.core.gui.log.Log;
import org.transdroid.core.gui.log.Log_;
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.FilePickerHelper;
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.ConnectivityHelper;
import org.transdroid.core.widget.WidgetProvider;
@ -96,7 +108,6 @@ import org.transdroid.daemon.util.HttpHelper; @@ -96,7 +108,6 @@ import org.transdroid.daemon.util.HttpHelper;
import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.OnRefreshListener;
import uk.co.senab.actionbarpulltorefresh.library.PullToRefreshAttacher.Options;
import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.ContentResolver;
@ -130,6 +141,8 @@ import de.keyboardsurfer.android.widget.crouton.Crouton; @@ -130,6 +141,8 @@ import de.keyboardsurfer.android.widget.crouton.Crouton;
public class TorrentsActivity extends SherlockFragmentActivity implements OnNavigationListener, TorrentTasksExecutor,
RefreshableActivity {
private static final int RESULT_DETAILS = 0;
// Navigation components
@Bean
protected NavigationHelper navigationHelper;
@ -252,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -252,7 +265,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
} else {
// 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.updateCurrentFilter(currentFilter);
}
@ -281,9 +294,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -281,9 +294,16 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (currentConnection == null)
filterSelected(lastUsed, true);
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
protected void onDestroy() {
Crouton.cancelAllCroutons();
@ -399,7 +419,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -399,7 +419,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
}
// Update connection to the newly selected server and refresh
currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName());
currentConnection = server.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
applicationSettings.setLastUsedServer(server);
navigationSpinnerAdapter.updateCurrentServer(currentConnection);
if (forceNewConnection)
@ -684,7 +704,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi @@ -684,7 +704,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi
if (fragmentDetails != null) {
fragmentDetails.updateTorrent(torrent);
} 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 { @@ -88,7 +88,7 @@ public class ServerCheckerService extends IntentService {
JSONArray lastStats = applicationSettings.getServerLastStats(server);
// Synchronously retrieve torrents listing
IDaemonAdapter adapter = server.createServerAdapter(connectivityHelper.getConnectedNetworkName());
IDaemonAdapter adapter = server.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
DaemonTaskResult result = RetrieveTask.create(adapter).execute();
if (!(result instanceof RetrieveTaskSuccessResult)) {
// Cannot retrieve torrents at this time

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

@ -163,7 +163,7 @@ public class WidgetConfigActivity extends SherlockActivity { @@ -163,7 +163,7 @@ public class WidgetConfigActivity extends SherlockActivity {
// Create a connection object and retrieve the live torrents
IDaemonAdapter connection = ((ServerSetting) serverSpinner.getSelectedItem())
.createServerAdapter(connectivityHelper.getConnectedNetworkName());
.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this);
DaemonTaskResult result = RetrieveTask.create(connection).execute();
if (result instanceof RetrieveTaskSuccessResult) {
// 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 { @@ -94,7 +94,7 @@ class WidgetViewsFactory implements RemoteViewsService.RemoteViewsFactory {
// Load the torrents; synchronously
IDaemonAdapter connection = server.createServerAdapter(ConnectivityHelper_.getInstance_(context)
.getConnectedNetworkName());
.getConnectedNetworkName(), context);
DaemonTaskResult result = RetrieveTask.create(connection).execute();
if (!(result instanceof RetrieveTaskSuccessResult)) {
// TODO: Show error text somehow in the remote view, perhaps via the EmptyView's text?

Loading…
Cancel
Save