Browse Source

Integrated the auto refresh timer with its setting after @spacecowboy merge, which fixes #7.

pull/148/merge
Eric Kok 11 years ago
parent
commit
49bdde791c
  1. 4
      core/src/org/transdroid/core/app/settings/SystemSettings.java
  2. 22
      core/src/org/transdroid/core/gui/TorrentsActivity.java

4
core/src/org/transdroid/core/app/settings/SystemSettings.java

@ -50,8 +50,8 @@ public class SystemSettings {
* Returns the interval in which automatic screen refreshes should be scheduled. * Returns the interval in which automatic screen refreshes should be scheduled.
* @return The selected refresh interval in milliseconds or 0 if automatic refreshes should be disabled * @return The selected refresh interval in milliseconds or 0 if automatic refreshes should be disabled
*/ */
public int getRefreshIntervalMilliseconds() { public long getRefreshIntervalMilliseconds() {
return Integer.parseInt(prefs.getString("system_autorefresh", "0")); return Integer.parseInt(prefs.getString("system_autorefresh", "0")) * 1000;
} }
public boolean checkForUpdates() { public boolean checkForUpdates() {

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

@ -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();
} }

Loading…
Cancel
Save