Update UI for onion port

This commit is contained in:
Juan Ezquerro LLanes 2016-11-17 10:14:01 +01:00
parent b10387bb07
commit e776e12492
8 changed files with 45 additions and 18 deletions

View File

@ -573,15 +573,18 @@ public class OrbotMainActivity extends AppCompatActivity
HSContentProvider.HiddenService.NAME, HSContentProvider.HiddenService.NAME,
HSContentProvider.HiddenService.DOMAIN, HSContentProvider.HiddenService.DOMAIN,
HSContentProvider.HiddenService.PORT, HSContentProvider.HiddenService.PORT,
HSContentProvider.HiddenService.REMOTE_PORT}; HSContentProvider.HiddenService.ONION_PORT};
if(hsName == null) if(hsName == null)
hsName = "hs"+hsPort; hsName = "hs"+hsPort;
if(hsRemotePort == -1)
hsRemotePort = hsPort;
ContentValues fields = new ContentValues(); ContentValues fields = new ContentValues();
fields.put("name", hsName); fields.put("name", hsName);
fields.put("port", hsPort); fields.put("port", hsPort);
fields.put("remote_port", hsRemotePort); fields.put("onion_port", hsRemotePort);
ContentResolver cr = getContentResolver(); ContentResolver cr = getContentResolver();
Cursor row = cr.query(HSContentProvider.CONTENT_URI, mProjection, "port="+hsPort, null, null); 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)) if (action.equals(INTENT_ACTION_REQUEST_HIDDEN_SERVICE))
{ {
final int hiddenServicePort = getIntent().getIntExtra("hs_port", -1); 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 String hiddenServiceName = getIntent().getStringExtra("hs_name");
final boolean getHiddenServiceKey = getIntent().getBooleanExtra("hs_get_key",false); final boolean getHiddenServiceKey = getIntent().getBooleanExtra("hs_get_key",false);

View File

@ -24,6 +24,7 @@ public class HiddenServicesActivity extends AppCompatActivity {
HSContentProvider.HiddenService._ID, HSContentProvider.HiddenService._ID,
HSContentProvider.HiddenService.NAME, HSContentProvider.HiddenService.NAME,
HSContentProvider.HiddenService.DOMAIN, HSContentProvider.HiddenService.DOMAIN,
HSContentProvider.HiddenService.ONION_PORT,
HSContentProvider.HiddenService.PORT}; HSContentProvider.HiddenService.PORT};
@Override @Override

View File

@ -32,8 +32,9 @@ public class HSAdapter extends CursorRecyclerViewAdapter<HSAdapter.ViewHolder> {
String name_string = cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME)); String name_string = cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.NAME));
Integer port = cursor.getInt(cursor.getColumnIndex(HSContentProvider.HiddenService.PORT)); 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( viewHolder.domain.setText(
cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN)) cursor.getString(cursor.getColumnIndex(HSContentProvider.HiddenService.DOMAIN))

View File

@ -15,7 +15,7 @@ public class HSDatabase extends SQLiteOpenHelper {
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"name TEXT, " + "name TEXT, " +
"domain TEXT, " + "domain TEXT, " +
"remote_port INTEGER, " + "onion_port INTEGER, " +
"port INTEGER);"; "port INTEGER);";
public HSDatabase(Context context) { public HSDatabase(Context context) {

View File

@ -7,6 +7,7 @@ import android.content.ContentValues;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.ShareCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -35,12 +36,15 @@ public class HSDataDialog extends DialogFragment {
save.setOnClickListener(new View.OnClickListener() { save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
String serverName = ((EditText) dialog_view.findViewById(R.id.hsName)).getText().toString(); String serverName = ((EditText) dialog_view.findViewById(R.id.hsName)).getText().toString();
Integer serverPort = Integer.parseInt( Integer localPort = Integer.parseInt(
((EditText) dialog_view.findViewById(R.id.serverPort)).getText().toString() ((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)) { if (checkInput(localPort,onionPort)) {
saveData(serverName, serverPort); saveData(serverName, localPort,onionPort);
serverDataDialog.dismiss(); serverDataDialog.dismiss();
} }
} }
@ -56,11 +60,11 @@ public class HSDataDialog extends DialogFragment {
return serverDataDialog; return serverDataDialog;
} }
private boolean checkInput(Integer port) { private boolean checkInput(Integer local, Integer remote){
boolean is_ok = true; boolean is_ok = true;
Integer error_msg = 0; Integer error_msg = 0;
if (port <= 1 || port > 65535) { if ((local <= 1 || local > 65535) || (remote <= 1 || remote > 65535)) {
error_msg = R.string.invalid_port; error_msg = R.string.invalid_port;
is_ok = false; is_ok = false;
} }
@ -72,10 +76,11 @@ public class HSDataDialog extends DialogFragment {
return is_ok; return is_ok;
} }
private void saveData(String name, Integer port) { private void saveData(String name, Integer local, Integer remote) {
ContentValues fields = new ContentValues(); ContentValues fields = new ContentValues();
fields.put("name", name); fields.put("name", name);
fields.put("port", port); fields.put("port", local);
fields.put("onion_port", remote);
ContentResolver cr = getContext().getContentResolver(); ContentResolver cr = getContext().getContentResolver();

View File

@ -113,7 +113,7 @@ public class HSContentProvider extends ContentProvider {
//Nombres de columnas //Nombres de columnas
public static final String NAME = "name"; public static final String NAME = "name";
public static final String PORT = "port"; 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"; public static final String DOMAIN = "domain";
private HiddenService() { private HiddenService() {

View File

@ -24,10 +24,10 @@
android:id="@+id/hsName" /> android:id="@+id/hsName" />
<TextView <TextView
android:text="@string/port" android:text="@string/local_port"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/HSPortLabel" android:id="@+id/HSLocalPortLabel"
android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small" android:textAppearance="@style/TextAppearance.AppCompat.Widget.PopupMenu.Small"
android:paddingLeft="5dp" /> android:paddingLeft="5dp" />
@ -35,7 +35,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="10" 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" /> android:inputType="number" />
<LinearLayout <LinearLayout

View File

@ -334,7 +334,9 @@
<string name="save">Save</string> <string name="save">Save</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="hs_dialog_title">Hidden Service</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="name">Name</string>
<string name="invalid_port">Invalid Port</string> <string name="invalid_port">Invalid Port</string>
</resources> </resources>