|
|
@ -171,7 +171,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
@FragmentById(resName = "torrent_details") |
|
|
|
@FragmentById(resName = "torrent_details") |
|
|
|
protected DetailsFragment fragmentDetails; |
|
|
|
protected DetailsFragment fragmentDetails; |
|
|
|
|
|
|
|
|
|
|
|
// Auto refresh task. Could be replaced by @Background(id="task-id")
|
|
|
|
// Auto refresh task
|
|
|
|
private AsyncTask<Void, Void, Void> autoRefreshTask; |
|
|
|
private AsyncTask<Void, Void, Void> autoRefreshTask; |
|
|
|
// Fragment uses this to pause the refresh across restarts
|
|
|
|
// Fragment uses this to pause the refresh across restarts
|
|
|
|
public boolean stopRefresh = false; |
|
|
|
public boolean stopRefresh = false; |
|
|
@ -280,8 +280,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onResume() { |
|
|
|
protected void onResume() { |
|
|
|
super.onResume(); |
|
|
|
super.onResume(); |
|
|
|
// Start auto refresh
|
|
|
|
|
|
|
|
startAutoRefresh(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Refresh server settings
|
|
|
|
// Refresh server settings
|
|
|
|
navigationSpinnerAdapter.updateServers(applicationSettings.getAllServerSettings()); |
|
|
|
navigationSpinnerAdapter.updateServers(applicationSettings.getAllServerSettings()); |
|
|
@ -297,6 +295,10 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
filterSelected(lastUsed, true); |
|
|
|
filterSelected(lastUsed, true); |
|
|
|
else |
|
|
|
else |
|
|
|
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); |
|
|
|
currentConnection = lastUsed.createServerAdapter(connectivityHelper.getConnectedNetworkName(), this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start auto refresh
|
|
|
|
|
|
|
|
startAutoRefresh(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@OnActivityResult(RESULT_DETAILS) |
|
|
|
@OnActivityResult(RESULT_DETAILS) |
|
|
@ -313,16 +315,15 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB) |
|
|
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB) |
|
|
|
public void startAutoRefresh() { |
|
|
|
public void startAutoRefresh() { |
|
|
|
// Check if already running
|
|
|
|
// Check if already running
|
|
|
|
if (autoRefreshTask != null || stopRefresh) |
|
|
|
if (autoRefreshTask != null || stopRefresh || systemSettings.getRefreshIntervalMilliseconds() == 0) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
autoRefreshTask = new AsyncTask<Void, Void, Void>() { |
|
|
|
autoRefreshTask = new AsyncTask<Void, Void, Void>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
while (!isCancelled()) { |
|
|
|
while (!isCancelled()) { |
|
|
|
// X seconds seems reasonable if someone actually wants real time updates
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
Thread.sleep(systemSettings.getRefreshIntervalMilliseconds()); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
} catch (InterruptedException e) { |
|
|
|
// Ignore
|
|
|
|
// Ignore
|
|
|
|
} |
|
|
|
} |
|
|
@ -340,7 +341,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
}; |
|
|
|
}; |
|
|
|
// Executes serially by default on Honeycomb, was parallel before
|
|
|
|
// Executes serially by default on Honeycomb, was parallel before
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) |
|
|
|
autoRefreshTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null); |
|
|
|
autoRefreshTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
|
|
|
else |
|
|
|
else |
|
|
|
autoRefreshTask.execute(); |
|
|
|
autoRefreshTask.execute(); |
|
|
|
} |
|
|
|
} |
|
|
@ -351,12 +352,6 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
autoRefreshTask = null; |
|
|
|
autoRefreshTask = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void onPause() { |
|
|
|
|
|
|
|
stopAutoRefresh(); |
|
|
|
|
|
|
|
super.onPause(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onDestroy() { |
|
|
|
protected void onDestroy() { |
|
|
|
Crouton.cancelAllCroutons(); |
|
|
|
Crouton.cancelAllCroutons(); |
|
|
@ -628,6 +623,7 @@ public class TorrentsActivity extends SherlockFragmentActivity implements OnNavi |
|
|
|
protected void onPause() { |
|
|
|
protected void onPause() { |
|
|
|
if (searchMenu != null) |
|
|
|
if (searchMenu != null) |
|
|
|
searchMenu.collapseActionView(); |
|
|
|
searchMenu.collapseActionView(); |
|
|
|
|
|
|
|
stopAutoRefresh(); |
|
|
|
super.onPause(); |
|
|
|
super.onPause(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|