diff --git a/AndroidManifest.xml.in b/AndroidManifest.xml.in index a0d60199b854348f0f817061a582ba46346ce081..5216c23751e0885f37679a2b7f5191a5e75e6d44 100644 --- a/AndroidManifest.xml.in +++ b/AndroidManifest.xml.in @@ -101,5 +101,9 @@ android:label="NetDB" android:parentActivityName=".activity.MainActivity" > </activity> + <activity android:name=".activity.NetDbDetailActivity" + android:label="NetDB Detail" + android:parentActivityName=".activity.NetDbActivity" > + </activity> </application> </manifest> diff --git a/res/layout/fragment_netdb_leaseset_detail.xml b/res/layout/fragment_netdb_leaseset_detail.xml new file mode 100644 index 0000000000000000000000000000000000000000..8a3977e2d5e40abfb0d16fe5a19161b85ebf2e06 --- /dev/null +++ b/res/layout/fragment_netdb_leaseset_detail.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <TextView + android:id="@+id/ls_nickname" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:padding="3dp" + android:text="LeaseSet nickname" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <TextView + android:id="@+id/ls_hash" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_below="@+id/ls_nickname" + android:text="LeaseSet hash" /> + +</RelativeLayout> diff --git a/res/layout/fragment_netdb_router_detail.xml b/res/layout/fragment_netdb_router_detail.xml new file mode 100644 index 0000000000000000000000000000000000000000..f0eb57eb138c9d979de9e10cb467b03e5be9a7ec --- /dev/null +++ b/res/layout/fragment_netdb_router_detail.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" > + + <TextView + android:id="@+id/dbentry_hash" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:text="Router hash" /> + +</RelativeLayout> diff --git a/src/net/i2p/android/router/activity/NetDbActivity.java b/src/net/i2p/android/router/activity/NetDbActivity.java index d3ffde288f081459c09f3c4f08a02028d5575056..e5225648249493dbf7df24da548e3ba4f5d04796 100644 --- a/src/net/i2p/android/router/activity/NetDbActivity.java +++ b/src/net/i2p/android/router/activity/NetDbActivity.java @@ -1,9 +1,11 @@ package net.i2p.android.router.activity; import net.i2p.android.router.R; +import net.i2p.android.router.fragment.NetDbDetailFragment; import net.i2p.android.router.fragment.NetDbListFragment; import net.i2p.android.router.fragment.NetDbSummaryPagerFragment; import net.i2p.android.router.loader.NetDbEntry; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; @@ -109,5 +111,22 @@ public class NetDbActivity extends I2PActivityBase implements // NetDbListFragment.OnEntrySelectedListener public void onEntrySelected(NetDbEntry entry) { + if (mTwoPane) { + // In two-pane mode, show the detail view in this activity by + // adding or replacing the detail fragment using a + // fragment transaction. + NetDbDetailFragment detailFrag = NetDbDetailFragment.newInstance( + entry.isRouterInfo(), entry.getHash()); + getSupportFragmentManager().beginTransaction() + .replace(R.id.detail_fragment, detailFrag).commit(); + } else { + // In single-pane mode, simply start the detail activity + // for the selected item ID. + Intent detailIntent = new Intent(this, NetDbDetailActivity.class); + detailIntent.putExtra(NetDbDetailFragment.IS_RI, entry.isRouterInfo()); + detailIntent.putExtra(NetDbDetailFragment.ENTRY_HASH, + entry.getHash().toBase64()); + startActivity(detailIntent); + } } } diff --git a/src/net/i2p/android/router/activity/NetDbDetailActivity.java b/src/net/i2p/android/router/activity/NetDbDetailActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..0c9d2dc819aa692a15474075e761df4fefe4160d --- /dev/null +++ b/src/net/i2p/android/router/activity/NetDbDetailActivity.java @@ -0,0 +1,28 @@ +package net.i2p.android.router.activity; + +import net.i2p.android.router.R; +import net.i2p.android.router.fragment.NetDbDetailFragment; +import net.i2p.data.DataFormatException; +import net.i2p.data.Hash; +import android.os.Bundle; + +public class NetDbDetailActivity extends I2PActivityBase { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mDrawerToggle.setDrawerIndicatorEnabled(false); + + if (savedInstanceState == null) { + boolean isRI = getIntent().getBooleanExtra(NetDbDetailFragment.IS_RI, true); + Hash hash = new Hash(); + try { + hash.fromBase64(getIntent().getStringExtra(NetDbDetailFragment.ENTRY_HASH)); + NetDbDetailFragment detailFrag = NetDbDetailFragment.newInstance(isRI, hash); + getSupportFragmentManager().beginTransaction() + .add(R.id.main_fragment, detailFrag).commit(); + } catch (DataFormatException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/net/i2p/android/router/fragment/NetDbDetailFragment.java b/src/net/i2p/android/router/fragment/NetDbDetailFragment.java new file mode 100644 index 0000000000000000000000000000000000000000..9a999498f31c3799bc611f0a7320f1d892ee6c5f --- /dev/null +++ b/src/net/i2p/android/router/fragment/NetDbDetailFragment.java @@ -0,0 +1,68 @@ +package net.i2p.android.router.fragment; + +import net.i2p.android.router.R; +import net.i2p.android.router.loader.NetDbEntry; +import net.i2p.data.DataFormatException; +import net.i2p.data.Hash; +import net.i2p.data.LeaseSet; +import net.i2p.data.RouterInfo; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class NetDbDetailFragment extends I2PFragmentBase { + public static final String IS_RI = "is_routerinfo"; + public static final String ENTRY_HASH = "entry_hash"; + + private NetDbEntry mEntry; + + public static NetDbDetailFragment newInstance(boolean isRI, Hash hash) { + NetDbDetailFragment f = new NetDbDetailFragment(); + Bundle args = new Bundle(); + args.putBoolean(IS_RI, isRI); + args.putString(ENTRY_HASH, hash.toBase64()); + f.setArguments(args); + return f; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View v; + if (getArguments().getBoolean(IS_RI)) { + v = inflater.inflate(R.layout.fragment_netdb_router_detail, container, false); + } else { + v = inflater.inflate(R.layout.fragment_netdb_leaseset_detail, container, false); + } + return v; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + if (getRouterContext() != null && getNetDb().isInitialized()) { + Hash hash = new Hash(); + try { + hash.fromBase64(getArguments().getString(ENTRY_HASH)); + if (getArguments().getBoolean(IS_RI)) { + RouterInfo ri = getNetDb().lookupRouterInfoLocally(hash); + mEntry = NetDbEntry.fromRouterInfo(getRouterContext(), ri); + } else { + LeaseSet ls = getNetDb().lookupLeaseSetLocally(hash); + mEntry = NetDbEntry.fromLeaseSet(getRouterContext(), ls); + + TextView nickname = (TextView) getView().findViewById(R.id.ls_nickname); + nickname.setText(mEntry.getNickname()); + } + + TextView entryHash = (TextView) getView().findViewById(R.id.dbentry_hash); + entryHash.setText(hash.toBase64()); + } catch (DataFormatException e) { + e.printStackTrace(); + } + } + } +}