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

Skip to content
Snippets Groups Projects
Commit 8c0e2228 authored by str4d's avatar str4d
Browse files

Communicate between Fragments via the container Activity, not directly

parent 4dafc3e5
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package net.i2p.android.router.activity;
import net.i2p.android.router.R;
import net.i2p.android.router.fragment.AddressbookFragment;
import net.i2p.android.router.fragment.WebFragment;
import android.app.SearchManager;
import android.content.Context;
import android.os.Bundle;
......@@ -12,7 +13,8 @@ import android.view.Menu;
import android.view.MenuItem;
public class AddressbookActivity extends I2PActivityBase
implements SearchView.OnQueryTextListener {
implements AddressbookFragment.OnAddressSelectedListener,
SearchView.OnQueryTextListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -36,6 +38,22 @@ public class AddressbookActivity extends I2PActivityBase
return super.onCreateOptionsMenu(menu);
}
// AddressbookFragment.OnAddressSelectedListener
public void onAddressSelected(CharSequence host) {
WebFragment f = new WebFragment();
Bundle args = new Bundle();
args.putString(WebFragment.HTML_URI, "http://" + host + '/');
f.setArguments(args);
getSupportFragmentManager().beginTransaction()
.replace(R.id.main_content, f)
.addToBackStack(null)
.commit();
}
// SearchView.OnQueryTextListener
public boolean onQueryTextChange(String newText) {
filterAddresses(newText);
return true;
......
package net.i2p.android.router.fragment;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
......@@ -27,8 +25,29 @@ import net.i2p.android.router.activity.AddressbookSettingsActivity;
import net.i2p.client.naming.NamingService;
public class AddressbookFragment extends ListFragment {
OnAddressSelectedListener mCallback;
private ArrayAdapter<String> mAdapter;
// Container Activity must implement this interface
public interface OnAddressSelectedListener {
public void onAddressSelected(CharSequence 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 = (OnAddressSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnAddressSelectedListener");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -76,15 +95,7 @@ public class AddressbookFragment extends ListFragment {
@Override
public void onListItemClick(ListView parent, View view, int pos, long id) {
CharSequence host = ((TextView) view).getText();
WebFragment f = new WebFragment();
Bundle args = new Bundle();
args.putString(WebFragment.HTML_URI, "http://" + host + '/');
f.setArguments(args);
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_content, f)
.addToBackStack(null)
.commit();
mCallback.onAddressSelected(host);
}
@Override
......
......@@ -19,7 +19,7 @@ public class WebFragment extends I2PFragmentBase {
private I2PWebViewClient _wvClient;
final static String HTML_URI = "html_url";
public final static String HTML_URI = "html_url";
final static String HTML_RESOURCE_ID = "html_resource_id";
private static final String WARNING = "Warning - " +
"any non-I2P links visited in this window are fetched over the regular internet and are " +
......
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