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 { @@ -50,8 +50,8 @@ public class SystemSettings {
* 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
*/
public int getRefreshIntervalMilliseconds() {
return Integer.parseInt(prefs.getString("system_autorefresh", "0"));
public long getRefreshIntervalMilliseconds() {
return Integer.parseInt(prefs.getString("system_autorefresh", "0")) * 1000;
}
public boolean checkForUpdates() {

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

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

Loading…
Cancel
Save