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

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

I2PTunnel secondary action to open linkable tunnels

parent 2c7ce0b7
No related branches found
No related tags found
No related merge requests found
...@@ -97,10 +97,10 @@ public class TunnelDetailFragment extends Fragment { ...@@ -97,10 +97,10 @@ public class TunnelDetailFragment extends Fragment {
description.setText(mTunnel.getDescription()); description.setText(mTunnel.getDescription());
TextView targetIfacePort = (TextView) v.findViewById(R.id.tunnel_target_interface_port); TextView targetIfacePort = (TextView) v.findViewById(R.id.tunnel_target_interface_port);
targetIfacePort.setText(mTunnel.getIfacePort()); targetIfacePort.setText(mTunnel.getTunnelLink(false));
TextView accessIfacePort = (TextView) v.findViewById(R.id.tunnel_access_interface_port); TextView accessIfacePort = (TextView) v.findViewById(R.id.tunnel_access_interface_port);
accessIfacePort.setText(mTunnel.getIfacePort()); accessIfacePort.setText(mTunnel.getTunnelLink(false));
CheckBox autoStart = (CheckBox) v.findViewById(R.id.tunnel_autostart); CheckBox autoStart = (CheckBox) v.findViewById(R.id.tunnel_autostart);
autoStart.setChecked(mTunnel.startAutomatically()); autoStart.setChecked(mTunnel.startAutomatically());
......
...@@ -90,6 +90,16 @@ public class TunnelEntry { ...@@ -90,6 +90,16 @@ public class TunnelEntry {
else return NOT_RUNNING; else return NOT_RUNNING;
} }
public boolean isRunning() {
switch (getStatus()) {
case STANDBY:
case RUNNING:
return true;
default:
return false;
}
}
public boolean isClient() { public boolean isClient() {
return TunnelUtil.isClient(mController.getType()); return TunnelUtil.isClient(mController.getType());
} }
...@@ -100,18 +110,42 @@ public class TunnelEntry { ...@@ -100,18 +110,42 @@ public class TunnelEntry {
return Boolean.parseBoolean(mController.getSharedClient()); return Boolean.parseBoolean(mController.getSharedClient());
} }
/**
* Call this to see if it is okay to linkify getClientLink()
* @return true if getClientLink() can be linkified, false otherwise.
*/
public boolean isClientLinkValid() {
return ("ircclient".equals(mController.getType())) &&
mController.getListenOnInterface() != null &&
mController.getListenPort() != null;
}
/**
* @return valid host:port only if isClientLinkValid() is true
*/
public String getClientLink(boolean linkify) {
String host = getClientInterface();
String port = getClientPort();
String link = host + ":" + port;
if (linkify) {
if ("ircclient".equals(mController.getType()))
link = "irc://" + link;
}
return link;
}
public String getClientInterface() { public String getClientInterface() {
String rv;
if ("streamrclient".equals(mController.getType())) if ("streamrclient".equals(mController.getType()))
return mController.getTargetHost(); rv = mController.getTargetHost();
else else
return mController.getListenOnInterface(); rv = mController.getListenOnInterface();
return rv != null ? rv : "";
} }
public String getClientPort() { public String getClientPort() {
String rv = mController.getListenPort(); String rv = mController.getListenPort();
if (rv != null) return rv != null ? rv : "";
return rv;
return "";
} }
public String getClientDestination() { public String getClientDestination() {
...@@ -128,10 +162,10 @@ public class TunnelEntry { ...@@ -128,10 +162,10 @@ public class TunnelEntry {
/* Server tunnel data */ /* Server tunnel data */
/** /**
* Call this to see if it is okay to linkify getServerTarget() * Call this to see if it is okay to linkify getServerLink()
* @return true if getServerTarget() can be linkified, false otherwise. * @return true if getServerLink() can be linkified, false otherwise.
*/ */
public boolean isServerTargetLinkValid() { public boolean isServerLinkValid() {
return ("httpserver".equals(mController.getType()) || return ("httpserver".equals(mController.getType()) ||
"httpbidirserver".equals(mController.getType())) && "httpbidirserver".equals(mController.getType())) &&
mController.getTargetHost() != null && mController.getTargetHost() != null &&
...@@ -139,9 +173,9 @@ public class TunnelEntry { ...@@ -139,9 +173,9 @@ public class TunnelEntry {
} }
/** /**
* @return valid host:port only if isServerTargetLinkValid() is true * @return valid host:port only if isServerLinkValid() is true
*/ */
public String getServerTarget() { public String getServerLink(boolean linkify) {
String host; String host;
if ("streamrserver".equals(getInternalType())) if ("streamrserver".equals(getInternalType()))
host = mController.getListenOnInterface(); host = mController.getListenOnInterface();
...@@ -152,7 +186,13 @@ public class TunnelEntry { ...@@ -152,7 +186,13 @@ public class TunnelEntry {
if (port == null) port = ""; if (port == null) port = "";
if (host.indexOf(':') >= 0) if (host.indexOf(':') >= 0)
host = '[' + host + ']'; host = '[' + host + ']';
return host + ":" + port; String link = host + ":" + port;
if (linkify) {
if ("httpserver".equals(mController.getType()) ||
"httpbidirserver".equals(mController.getType()))
link = "http://" + link;
}
return link;
} }
public String getDestinationBase64() { public String getDestinationBase64() {
...@@ -183,18 +223,14 @@ public class TunnelEntry { ...@@ -183,18 +223,14 @@ public class TunnelEntry {
/* Other output formats */ /* Other output formats */
public String getIfacePort() { public boolean isTunnelLinkValid() {
if (isClient()) { if (isClient()) return isClientLinkValid();
String host; else return isServerLinkValid();
if ("streamrclient".equals(getInternalType())) }
host = mController.getTargetHost();
else public String getTunnelLink(boolean linkify) {
host = mController.getListenOnInterface(); if (isClient()) return getClientLink(linkify);
String port = mController.getListenPort(); else return getServerLink(linkify);
if (host == null) host = "";
if (port == null) port = "";
return host + ":" + port;
} else return getServerTarget();
} }
public String getDetails() { public String getDetails() {
......
package net.i2p.android.i2ptunnel; package net.i2p.android.i2ptunnel;
import java.util.List;
import net.i2p.android.router.R;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -11,6 +11,10 @@ import android.widget.ArrayAdapter; ...@@ -11,6 +11,10 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.i2p.android.router.R;
import java.util.List;
public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> { public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> {
private final LayoutInflater mInflater; private final LayoutInflater mInflater;
...@@ -31,11 +35,14 @@ public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> { ...@@ -31,11 +35,14 @@ public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> {
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
View v = mInflater.inflate(R.layout.listitem_i2ptunnel, parent, false); View v = mInflater.inflate(R.layout.listitem_i2ptunnel, parent, false);
TunnelEntry tunnel = getItem(position); final TunnelEntry tunnel = getItem(position);
ImageView status = (ImageView) v.findViewById(R.id.tunnel_status); ImageView status = (ImageView) v.findViewById(R.id.tunnel_status);
status.setImageDrawable(tunnel.getStatusIcon()); status.setImageDrawable(tunnel.getStatusIcon());
status.setBackground(tunnel.getStatusBackground()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
status.setBackgroundDrawable(tunnel.getStatusBackground());
else
status.setBackground(tunnel.getStatusBackground());
TextView name = (TextView) v.findViewById(R.id.tunnel_name); TextView name = (TextView) v.findViewById(R.id.tunnel_name);
name.setText(tunnel.getName()); name.setText(tunnel.getName());
...@@ -44,7 +51,20 @@ public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> { ...@@ -44,7 +51,20 @@ public class TunnelEntryAdapter extends ArrayAdapter<TunnelEntry> {
type.setText(tunnel.getDescription()); type.setText(tunnel.getDescription());
TextView ifacePort = (TextView) v.findViewById(R.id.tunnel_interface_port); TextView ifacePort = (TextView) v.findViewById(R.id.tunnel_interface_port);
ifacePort.setText(tunnel.getIfacePort()); ifacePort.setText(tunnel.getTunnelLink(false));
if (tunnel.isRunning() && tunnel.isTunnelLinkValid()) {
View open = v.findViewById(R.id.tunnel_open);
open.setVisibility(View.VISIBLE);
open.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(tunnel.getTunnelLink(true)));
getContext().startActivity(i);
}
});
}
return v; return v;
} }
......
app/src/main/res/drawable-hdpi/ic_open_in_browser_white_24dp.png

276 B

app/src/main/res/drawable-mdpi/ic_open_in_browser_white_24dp.png

234 B

app/src/main/res/drawable-xhdpi/ic_open_in_browser_white_24dp.png

348 B

app/src/main/res/drawable-xxhdpi/ic_open_in_browser_white_24dp.png

480 B

...@@ -30,18 +30,32 @@ ...@@ -30,18 +30,32 @@
android:text="Tunnel name" android:text="Tunnel name"
android:textAppearance="@style/TextAppearance.AppCompat.Primary" /> android:textAppearance="@style/TextAppearance.AppCompat.Primary" />
<!-- Open link -->
<ImageView
android:id="@+id/tunnel_open"
android:layout_width="@dimen/listitem_icon_size"
android:layout_height="@dimen/listitem_icon_size"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/listitem_horizontal_margin"
android:layout_marginStart="@dimen/listitem_horizontal_margin"
android:contentDescription="Open"
android:src="@drawable/ic_open_in_browser_white_24dp"
android:visibility="gone" />
<!-- Interface:port the tunnel listens on or points to --> <!-- Interface:port the tunnel listens on or points to -->
<TextView <TextView
android:id="@+id/tunnel_interface_port" android:id="@+id/tunnel_interface_port"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/tunnel_name" android:layout_alignTop="@id/tunnel_name"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
android:layout_toEndOf="@id/tunnel_name" android:layout_toEndOf="@id/tunnel_name"
android:layout_toLeftOf="@id/tunnel_open"
android:layout_toRightOf="@id/tunnel_name" android:layout_toRightOf="@id/tunnel_name"
android:layout_toStartOf="@id/tunnel_open"
android:ellipsize="start" android:ellipsize="start"
android:gravity="right" android:gravity="right"
android:maxLines="1" android:maxLines="1"
...@@ -57,6 +71,8 @@ ...@@ -57,6 +71,8 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/tunnel_name" android:layout_alignStart="@+id/tunnel_name"
android:layout_marginBottom="@dimen/listitem_text_bottom_margin_two_lines" android:layout_marginBottom="@dimen/listitem_text_bottom_margin_two_lines"
android:layout_toLeftOf="@id/tunnel_open"
android:layout_toStartOf="@id/tunnel_open"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:text="Tunnel description" android:text="Tunnel description"
......
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