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

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

Changed AddressbookFragment to a ListFragment

Previous commit was not broken, a clean build fixed the problem.
parent 5b9203f7
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
...@@ -2,7 +2,7 @@ package net.i2p.android.router.fragment; ...@@ -2,7 +2,7 @@ package net.i2p.android.router.fragment;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.ListFragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
...@@ -23,7 +23,7 @@ import net.i2p.android.router.R; ...@@ -23,7 +23,7 @@ import net.i2p.android.router.R;
import net.i2p.android.router.activity.AddressbookSettingsActivity; import net.i2p.android.router.activity.AddressbookSettingsActivity;
import net.i2p.client.naming.NamingService; import net.i2p.client.naming.NamingService;
public class AddressbookFragment extends Fragment { public class AddressbookFragment extends ListFragment {
private ArrayAdapter<String> mAdapter; private ArrayAdapter<String> mAdapter;
@Override @Override
...@@ -33,9 +33,8 @@ public class AddressbookFragment extends Fragment { ...@@ -33,9 +33,8 @@ public class AddressbookFragment extends Fragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public void onActivityCreated(Bundle savedInstanceState) {
Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState);
View v = inflater.inflate(R.layout.fragment_listview, container, false);
// Grab context if router has started, otherwise create new // Grab context if router has started, otherwise create new
// FIXME dup contexts, locking, ... // FIXME dup contexts, locking, ...
...@@ -54,40 +53,37 @@ public class AddressbookFragment extends Fragment { ...@@ -54,40 +53,37 @@ public class AddressbookFragment extends Fragment {
Set<String> names = ns.getNames(); Set<String> names = ns.getNames();
// set the header // set the header
TextView tv = (TextView) inflater.inflate(R.layout.addressbook_header, null);
int sz = names.size(); int sz = names.size();
if (sz > 1) if (sz > 0) {
tv.setText(sz + " hosts in address book."); TextView tv = (TextView) getActivity().getLayoutInflater().inflate(R.layout.addressbook_header, null);
else if (sz > 0) if (sz > 1)
tv.setText("1 host in address book."); tv.setText(sz + " hosts in address book.");
else else
tv.setText("No hosts in address book, or your router is not up."); tv.setText("1 host in address book.");
ListView lv = (ListView) v.findViewById(R.id.listview); getListView().addHeaderView(tv, "", false);
lv.addHeaderView(tv, "", false); }
// set the empty text
setEmptyText("No hosts in address book, or your router is not up.");
// set the list // set the list
List<String> nameList = new ArrayList<String>(names); List<String> nameList = new ArrayList<String>(names);
Collections.sort(nameList); Collections.sort(nameList);
mAdapter = new ArrayAdapter<String>(getActivity(), R.layout.addressbook_list_item, nameList); mAdapter = new ArrayAdapter<String>(getActivity(), R.layout.addressbook_list_item, nameList);
lv.setAdapter(mAdapter); setListAdapter(mAdapter);
}
// set the callback
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView 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();
}
});
return v; @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();
} }
@Override @Override
...@@ -98,6 +94,7 @@ public class AddressbookFragment extends Fragment { ...@@ -98,6 +94,7 @@ public class AddressbookFragment extends Fragment {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items // Handle presses on the action bar items
switch (item.getItemId()) { switch (item.getItemId()) {
//case R.id.action_add_to_addressbook: //case R.id.action_add_to_addressbook:
// return true; // return true;
......
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