diff --git a/src/net/i2p/android/router/activity/AddressbookActivity.java b/src/net/i2p/android/router/activity/AddressbookActivity.java index 5c8cb3984028ba20a0d758d30a705af58a900d37..3ea7ea70a4696e759fb0c2c8cdc2d2b43d464555 100644 --- a/src/net/i2p/android/router/activity/AddressbookActivity.java +++ b/src/net/i2p/android/router/activity/AddressbookActivity.java @@ -13,8 +13,8 @@ import android.view.Menu; import android.view.MenuItem; public class AddressbookActivity extends I2PActivityBase - implements AddressbookFragment.OnAddressSelectedListener, - SearchView.OnQueryTextListener { + implements AddressbookFragment.OnAddressSelectedListener, + SearchView.OnQueryTextListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/src/net/i2p/android/router/activity/I2PTunnelActivity.java b/src/net/i2p/android/router/activity/I2PTunnelActivity.java index c4e21c87294dd25d11cc22bdbe641166e5c0b011..0fe8ad0bee9e26b0bd264dac9063b663f89eae0d 100644 --- a/src/net/i2p/android/router/activity/I2PTunnelActivity.java +++ b/src/net/i2p/android/router/activity/I2PTunnelActivity.java @@ -2,12 +2,14 @@ package net.i2p.android.router.activity; import net.i2p.android.router.R; import net.i2p.android.router.fragment.I2PTunnelFragment; +import net.i2p.android.router.loader.TunnelEntry; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; -public class I2PTunnelActivity extends I2PActivityBase { +public class I2PTunnelActivity extends I2PActivityBase + implements I2PTunnelFragment.OnTunnelSelectedListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -36,4 +38,9 @@ public class I2PTunnelActivity extends I2PActivityBase { .setTabListener(new TabListener(f)); actionBar.addTab(tab); } + + // I2PTunnelFragment.OnTunnelSelectedListener + + public void onTunnelSelected(TunnelEntry tunnel) { + } } diff --git a/src/net/i2p/android/router/fragment/I2PTunnelFragment.java b/src/net/i2p/android/router/fragment/I2PTunnelFragment.java index 73227f98babb6496396d0ca19eb9f4c7aa5124cb..52e9e7c3447fabe0347646438f014e288bc8b295 100644 --- a/src/net/i2p/android/router/fragment/I2PTunnelFragment.java +++ b/src/net/i2p/android/router/fragment/I2PTunnelFragment.java @@ -7,6 +7,7 @@ import net.i2p.android.router.adapter.TunnelEntryAdapter; import net.i2p.android.router.loader.TunnelEntryLoader; import net.i2p.android.router.loader.TunnelEntry; import net.i2p.i2ptunnel.TunnelControllerGroup; +import android.app.Activity; import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.app.LoaderManager; @@ -14,6 +15,8 @@ import android.support.v4.content.Loader; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; +import android.widget.ListView; public class I2PTunnelFragment extends ListFragment implements LoaderManager.LoaderCallbacks<List<TunnelEntry>> { @@ -22,10 +25,31 @@ public class I2PTunnelFragment extends ListFragment private static final int CLIENT_LOADER_ID = 1; private static final int SERVER_LOADER_ID = 2; + OnTunnelSelectedListener mCallback; private TunnelControllerGroup mGroup; private TunnelEntryAdapter mAdapter; private boolean mClientTunnels; + // Container Activity must implement this interface + public interface OnTunnelSelectedListener { + public void onTunnelSelected(TunnelEntry host); + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + // This makes sure that the container activity has implemented + // the callback interface. If not, it throws an exception + try { + mCallback = (OnTunnelSelectedListener) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + + " must implement OnTunnelSelectedListener"); + } + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,6 +87,29 @@ public class I2PTunnelFragment extends ListFragment : SERVER_LOADER_ID, null, this); } + @Override + public void onListItemClick(ListView parent, View view, int pos, long id) { + mCallback.onTunnelSelected(mAdapter.getItem(pos)); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.fragment_i2ptunnel_actions, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle presses on the action bar items + switch (item.getItemId()) { + case R.id.action_add_tunnel: + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + // LoaderManager.LoaderCallbacks<List<TunnelEntry>> + public Loader<List<TunnelEntry>> onCreateLoader(int id, Bundle args) { return new TunnelEntryLoader(getActivity(), mGroup, mClientTunnels); } @@ -87,20 +134,4 @@ public class I2PTunnelFragment extends ListFragment mAdapter.setData(null); } } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.fragment_i2ptunnel_actions, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle presses on the action bar items - switch (item.getItemId()) { - case R.id.action_add_tunnel: - return true; - default: - return super.onOptionsItemSelected(item); - } - } }