I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 7794a7db authored by str4d's avatar str4d
Browse files

Use manual action to refresh NetDB list instead of timer

parent c03debf3
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
<string name="action_i2ptunnel_stop_all">Stop all tunnels</string> <string name="action_i2ptunnel_stop_all">Stop all tunnels</string>
<string name="action_i2ptunnel_restart_all">Restart all tunnels</string> <string name="action_i2ptunnel_restart_all">Restart all tunnels</string>
<string name="action_reload">Reload</string> <string name="action_reload">Reload</string>
<string name="action_refresh">Refresh</string>
<string name="hint_search_addressbook">Search addressbook</string> <string name="hint_search_addressbook">Search addressbook</string>
<string name="router_not_running">The router is not running.</string> <string name="router_not_running">The router is not running.</string>
......
...@@ -13,8 +13,12 @@ import android.os.Bundle; ...@@ -13,8 +13,12 @@ import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader; import android.support.v4.content.Loader;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast;
public class NetDbListFragment extends ListFragment public class NetDbListFragment extends ListFragment
implements LoaderManager.LoaderCallbacks<List<NetDbEntry>> { implements LoaderManager.LoaderCallbacks<List<NetDbEntry>> {
...@@ -72,6 +76,12 @@ public class NetDbListFragment extends ListFragment ...@@ -72,6 +76,12 @@ public class NetDbListFragment extends ListFragment
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
...@@ -127,6 +137,25 @@ public class NetDbListFragment extends ListFragment ...@@ -127,6 +137,25 @@ public class NetDbListFragment extends ListFragment
} }
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_netdb_list_actions, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_refresh:
setListShown(false);
getLoaderManager().restartLoader(mRouters ? ROUTER_LOADER_ID
: LEASESET_LOADER_ID, null, this);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/** /**
* Turns on activate-on-click mode. When this mode is on, list items will be * Turns on activate-on-click mode. When this mode is on, list items will be
* given the 'activated' state when touched. * given the 'activated' state when touched.
......
...@@ -13,21 +13,17 @@ import net.i2p.router.RouterContext; ...@@ -13,21 +13,17 @@ import net.i2p.router.RouterContext;
import net.i2p.router.TunnelPoolSettings; import net.i2p.router.TunnelPoolSettings;
import android.content.Context; import android.content.Context;
import android.os.Handler;
import android.support.v4.content.AsyncTaskLoader; import android.support.v4.content.AsyncTaskLoader;
public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> { public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> {
private RouterContext mRContext; private RouterContext mRContext;
private boolean mRouters; private boolean mRouters;
private List<NetDbEntry> mData; private List<NetDbEntry> mData;
private Handler mHandler;
private NetDbMonitor mMonitor;
public NetDbEntryLoader(Context context, RouterContext rContext, boolean routers) { public NetDbEntryLoader(Context context, RouterContext rContext, boolean routers) {
super(context); super(context);
mRContext = rContext; mRContext = rContext;
mRouters = routers; mRouters = routers;
mHandler = new Handler();
} }
private static class RouterInfoComparator implements Comparator<RouterInfo> { private static class RouterInfoComparator implements Comparator<RouterInfo> {
...@@ -122,10 +118,6 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> { ...@@ -122,10 +118,6 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> {
deliverResult(mData); deliverResult(mData);
} }
// Begin monitoring the underlying data source.
mMonitor = new NetDbMonitor();
mHandler.postDelayed(mMonitor, 50);
if (takeContentChanged() || mData == null) { if (takeContentChanged() || mData == null) {
// When the observer detects a change, it should call onContentChanged() // When the observer detects a change, it should call onContentChanged()
// on the Loader, which will cause the next call to takeContentChanged() // on the Loader, which will cause the next call to takeContentChanged()
...@@ -156,12 +148,6 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> { ...@@ -156,12 +148,6 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> {
releaseResources(mData); releaseResources(mData);
mData = null; mData = null;
} }
// The Loader is being reset, so we should stop monitoring for changes.
if (mMonitor != null) {
mHandler.removeCallbacks(mMonitor);
mMonitor = null;
}
} }
@Override @Override
...@@ -179,13 +165,4 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> { ...@@ -179,13 +165,4 @@ public class NetDbEntryLoader extends AsyncTaskLoader<List<NetDbEntry>> {
// would close it in this method. All resources associated with the Loader // would close it in this method. All resources associated with the Loader
// should be released here. // should be released here.
} }
private class NetDbMonitor implements Runnable {
public void run() {
// There is no way (yet) to monitor for changes to the NetDB,
// so just force a refresh every 10 seconds.
onContentChanged();
mHandler.postDelayed(this, 10 * 1000);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment