wire in connect button

This commit is contained in:
Dan Ballard 2017-09-07 08:11:44 -07:00
parent 1e48f69691
commit fc279e8062
1 changed files with 48 additions and 1 deletions

View File

@ -62,6 +62,15 @@ public class ConnectActivity extends AppCompatActivity {
} }
}); });
connectButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ConnectTask connectTask = new ConnectTask();
String connectToAddr = addressText.getText().toString().replaceFirst(RICOCHET_ADDRESS_PREFIX, "");
String privateKey = prefs.getString(PRIVATE_KEY_KEY, "");
connectTask.execute(privateKey, connectToAddr);
}
});
addressText.addTextChangedListener(new TextWatcher(){ addressText.addTextChangedListener(new TextWatcher(){
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -93,7 +102,45 @@ public class ConnectActivity extends AppCompatActivity {
String connectToAddress = prefs.getString(CONNECT_TO_ADDRESS_KEY, RICOCHET_ADDRESS_PREFIX); String connectToAddress = prefs.getString(CONNECT_TO_ADDRESS_KEY, RICOCHET_ADDRESS_PREFIX);
addressText.setText(connectToAddress); addressText.setText(connectToAddress);
validateOnionAddress(); validateOnionAddress();
}
private class ConnectTask extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
Log.i(TAG, "ConnectTask.onPreExecute()");
regenButton.setEnabled(false);
connectButton.setEnabled(false);
connectStatusText.setText("Connecting to Onion server...");
connectSpinner.setVisibility(View.VISIBLE);
}
@Override
// execute(privateKey, connectToAddr)
// return string of exception if failed
public String doInBackground(String... params) {
Log.i(TAG, "ConntectTask.doInBackground()");
String privateKey = params[0];
String connectToAddr = params[1];
try {
GoRicochetMobile.odClientConnect(privateKey, connectToAddr);
return "";
} catch (Exception e) {
Log.e(TAG, e.toString());
return e.toString();
}
}
@Override
protected void onPostExecute(String exception) {
Log.i(TAG, "ConnectTask.onPostExecute(): " );
connectSpinner.setVisibility(View.INVISIBLE);
if (exception != "") {
connectStatusText.setText("ERROR connecting: " + exception);
} else {
connectStatusText.setText("");
// TODO: Open OD control activity
}
}
} }
private void setIdentity(String privateKey) { private void setIdentity(String privateKey) {
@ -157,7 +204,7 @@ public class ConnectActivity extends AppCompatActivity {
} }
} }
/********** TESTING by standing up an echobot **********88/ /********** TESTING by standing up an echobot ************/
private void echoBot(String privateKey) { private void echoBot(String privateKey) {
// Test echobot // Test echobot