commit e776e12492c4433f5a9bf1cb6884c4c39251cc63 Author: Juan Ezquerro LLanes juan@paynopain.com Date: Thu Nov 17 10:14:01 2016 +0100
Update UI for onion port --- .../org/torproject/android/OrbotMainActivity.java | 9 ++++++--- .../android/ui/hs/HiddenServicesActivity.java | 1 + .../android/ui/hs/adapters/HSAdapter.java | 3 ++- .../android/ui/hs/database/HSDatabase.java | 2 +- .../android/ui/hs/dialogs/HSDataDialog.java | 21 +++++++++++++-------- .../android/ui/hs/providers/HSContentProvider.java | 2 +- app/src/main/res/layout/dialog_hs_data.xml | 21 ++++++++++++++++++--- app/src/main/res/values/strings.xml | 4 +++- 8 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/app/src/main/java/org/torproject/android/OrbotMainActivity.java b/app/src/main/java/org/torproject/android/OrbotMainActivity.java index 7374455..3a9e356 100644 --- a/app/src/main/java/org/torproject/android/OrbotMainActivity.java +++ b/app/src/main/java/org/torproject/android/OrbotMainActivity.java @@ -573,15 +573,18 @@ public class OrbotMainActivity extends AppCompatActivity HSContentProvider.HiddenService.NAME, HSContentProvider.HiddenService.DOMAIN, HSContentProvider.HiddenService.PORT, - HSContentProvider.HiddenService.REMOTE_PORT}; + HSContentProvider.HiddenService.ONION_PORT};
if(hsName == null) hsName = "hs"+hsPort;
+ if(hsRemotePort == -1) + hsRemotePort = hsPort; + ContentValues fields = new ContentValues(); fields.put("name", hsName); fields.put("port", hsPort); - fields.put("remote_port", hsRemotePort); + fields.put("onion_port", hsRemotePort);
ContentResolver cr = getContentResolver(); Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port="+hsPort, null, null); @@ -623,7 +626,7 @@ public class OrbotMainActivity extends AppCompatActivity if (action.equals(INTENT_ACTION_REQUEST_HIDDEN_SERVICE)) { final int hiddenServicePort = getIntent().getIntExtra("hs_port", -1); - final int hiddenServiceRemotePort = getIntent().getIntExtra("hs_remote_port", -1); + final int hiddenServiceRemotePort = getIntent().getIntExtra("hs_onion_port", -1); final String hiddenServiceName = getIntent().getStringExtra("hs_name"); final boolean getHiddenServiceKey = getIntent().getBooleanExtra("hs_get_key",false);
diff --git a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java index ebf1ec3..da556da 100644 --- a/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java +++ b/app/src/main/java/org/torproject/android/ui/hs/HiddenServicesActivity.java @@ -24,6 +24,7 @@ public class HiddenServicesActivity extends AppCompatActivity { HSContentProvider.HiddenService._ID, HSContentProvider.HiddenService.NAME, HSContentProvider.HiddenService.DOMAIN, + HSContentProvider.HiddenService.ONION_PORT, HSContentProvider.HiddenService.PORT};
@Override diff --git a/app/src/main/java/org/torproject/android/ui/hs/adapters/HSAdapter.java b/app/src/main/java/org/torproject/android/ui/hs/adapters/HSAdapter.java index 66ecb22..92189ad 100644 --- a/app/src/main/java/org/torproject/android/ui/hs/adapters/HSAdapter.java +++ b/app/src/main/java/org/torproject/android/ui/hs/adapters/HSAdapter.java @@ -32,8 +32,9 @@ public class HSAdapter extends CursorRecyclerViewAdapter<HSAdapter.ViewHolder> {
String name_string = cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)); Integer port = cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)); + Integer onion_port = cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService.ONION_PORT));
- viewHolder.name.setText(name_string + ": " + port.toString()); + viewHolder.name.setText(name_string + ": " + port.toString()+ " -> " +onion_port.toString());
viewHolder.domain.setText( cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN)) diff --git a/app/src/main/java/org/torproject/android/ui/hs/database/HSDatabase.java b/app/src/main/java/org/torproject/android/ui/hs/database/HSDatabase.java index 0cfb6e5..cafa7ed 100644 --- a/app/src/main/java/org/torproject/android/ui/hs/database/HSDatabase.java +++ b/app/src/main/java/org/torproject/android/ui/hs/database/HSDatabase.java @@ -15,7 +15,7 @@ public class HSDatabase extends SQLiteOpenHelper { "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " + "domain TEXT, " + - "remote_port INTEGER, " + + "onion_port INTEGER, " + "port INTEGER);";
public HSDatabase(Context context) { diff --git a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java index e62d2cb..0dc0a30 100644 --- a/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java +++ b/app/src/main/java/org/torproject/android/ui/hs/dialogs/HSDataDialog.java @@ -7,6 +7,7 @@ import android.content.ContentValues; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; +import android.support.v4.app.ShareCompat; import android.support.v7.app.AlertDialog; import android.view.View; import android.widget.Button; @@ -35,12 +36,15 @@ public class HSDataDialog extends DialogFragment { save.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String serverName = ((EditText) dialog_view.findViewById(R.id.hsName)).getText().toString(); - Integer serverPort = Integer.parseInt( - ((EditText) dialog_view.findViewById(R.id.serverPort)).getText().toString() + Integer localPort = Integer.parseInt( + ((EditText) dialog_view.findViewById(R.id.hsLocalPort)).getText().toString() + ); + Integer onionPort = Integer.parseInt( + ((EditText) dialog_view.findViewById(R.id.hsOnionPort)).getText().toString() );
- if (checkInput(serverPort)) { - saveData(serverName, serverPort); + if (checkInput(localPort,onionPort)) { + saveData(serverName, localPort,onionPort); serverDataDialog.dismiss(); } } @@ -56,11 +60,11 @@ public class HSDataDialog extends DialogFragment { return serverDataDialog; }
- private boolean checkInput(Integer port) { + private boolean checkInput(Integer local, Integer remote){ boolean is_ok = true; Integer error_msg = 0;
- if (port <= 1 || port > 65535) { + if ((local <= 1 || local > 65535) || (remote <= 1 || remote > 65535)) { error_msg = R.string.invalid_port; is_ok = false; } @@ -72,10 +76,11 @@ public class HSDataDialog extends DialogFragment { return is_ok; }
- private void saveData(String name, Integer port) { + private void saveData(String name, Integer local, Integer remote) { ContentValues fields = new ContentValues(); fields.put("name", name); - fields.put("port", port); + fields.put("port", local); + fields.put("onion_port", remote);
ContentResolver cr = getContext().getContentResolver();
diff --git a/app/src/main/java/org/torproject/android/ui/hs/providers/HSContentProvider.java b/app/src/main/java/org/torproject/android/ui/hs/providers/HSContentProvider.java index 6fec6b0..9b52a37 100644 --- a/app/src/main/java/org/torproject/android/ui/hs/providers/HSContentProvider.java +++ b/app/src/main/java/org/torproject/android/ui/hs/providers/HSContentProvider.java @@ -113,7 +113,7 @@ public class HSContentProvider extends ContentProvider { //Nombres de columnas public static final String NAME = "name"; public static final String PORT = "port"; - public static final String REMOTE_PORT = "remote_port"; + public static final String ONION_PORT = "onion_port"; public static final String DOMAIN = "domain";
private HiddenService() { diff --git a/app/src/main/res/layout/dialog_hs_data.xml b/app/src/main/res/layout/dialog_hs_data.xml index 2f4daa6..05d52fe 100644 --- a/app/src/main/res/layout/dialog_hs_data.xml +++ b/app/src/main/res/layout/dialog_hs_data.xml @@ -24,10 +24,10 @@ android:id="@+id/hsName" />
<TextView - android:text="@string/port" + android:text="@string/local_port" android:layout_width="match_parent" android:layout_height="wrap_content" - android:id="@+id/HSPortLabel" + android:id="@+id/HSLocalPortLabel" android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" android:paddingLeft="5dp" />
@@ -35,7 +35,22 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" - android:id="@+id/serverPort" + android:id="@+id/hsLocalPort" + android:inputType="number" /> + + <TextView + android:text="@string/onion_port" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/HSOnionPortLabel" + android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" + android:paddingLeft="5dp" /> + + <EditText + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:ems="10" + android:id="@+id/hsOnionPort" android:inputType="number" />
<LinearLayout diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 333ac58..ea01787 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -334,7 +334,9 @@ <string name="save">Save</string> <string name="cancel">Cancel</string> <string name="hs_dialog_title">Hidden Service</string> - <string name="port">Port</string> + <string name="ports">Ports</string> + <string name="local_port">Local Port</string> + <string name="onion_port">Onion Port</string> <string name="name">Name</string> <string name="invalid_port">Invalid Port</string> </resources>
tor-commits@lists.torproject.org