finish ui for connect activity. display identity. 'new identity' functionality

This commit is contained in:
Dan Ballard 2017-09-04 20:37:16 -07:00
parent 767fccef40
commit c68a45f088
2 changed files with 81 additions and 30 deletions

View File

@ -24,6 +24,14 @@ public class ConnectActivity extends AppCompatActivity {
private static final String TAG = "InitActivity";
private static final String PRIVATE_KEY_KEY = "privateKey";
Button regenButton;
Button connectButton;
ProgressBar spinner;
TextView progressText;
TextView idetityText;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Load identity and connect to addr. Enable appropriate buttons
@ -32,15 +40,29 @@ public class ConnectActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(im.ricochet.androidod.R.layout.activity_connect);
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
//progressText.setText("Loading private key...");
progressText = (TextView)findViewById(R.id.progressTextView);
idetityText = (TextView)findViewById(R.id.identityTextView);
regenButton = (Button)findViewById(R.id.regenIdentButton);
connectButton = (Button)findViewById(R.id.connectButton);
spinner = (ProgressBar)findViewById(R.id.progressBar);
regenButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RegenIdentTask regenIdentTask = new RegenIdentTask();
regenIdentTask.execute();
}
});
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
String privateKey = prefs.getString(PRIVATE_KEY_KEY, "");
Log.i(TAG, "Private key loaded:\n"+privateKey);
if (privateKey.equals("")) {
// Kick of identity generateion
regenIdentity();
Log.i(TAG, "regenerating pricate key");
RegenIdentTask regenIdentTask = new RegenIdentTask();
regenIdentTask.execute();
} else {
Log.i(TAG, "setting identity, enabling regen");
setIdentity(privateKey);
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
regenButton.setEnabled(true);
}
@ -60,32 +82,57 @@ public class ConnectActivity extends AppCompatActivity {
*/
}
private void regenIdentity() {
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
regenButton.setEnabled(false);
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
progressText.setText("Generating new identity...");
ProgressBar spinner = (ProgressBar)findViewById(R.id.progressBar);
spinner.setVisibility(View.VISIBLE);
private void setIdentity(String privateKey) {
Log.i(TAG, "setIdentity(): " + privateKey);
String addr = GoRicochetMobile.getOnionAddress(privateKey);
Log.i(TAG, "setIdentity(): addr: '" + addr + "'");
idetityText.setText("ricochet:" + addr);
}
String privateKey;
try {
privateKey = GoRicochetMobile.generatePrivateKey();
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putString(PRIVATE_KEY_KEY, privateKey);
prefsEditor.commit();
progressText.setText("");
} catch (Exception e) {
Log.e(TAG, e.toString());
progressText.setText("ERROR: unable to generate new identity: " + e.toString());
private class RegenIdentTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
Log.i(TAG, "RegenIdentTask.onPreExecute()");
regenButton.setEnabled(false);
connectButton.setEnabled(false);
progressText.setText("Generating new identity...");
spinner.setVisibility(View.VISIBLE);
}
spinner.setVisibility(View.INVISIBLE);
regenButton.setEnabled(true);
@Override
public String doInBackground(Void... voids) {
Log.i(TAG, "RegenIdentTask.doInBackground()");
String privateKey;
try {
privateKey = GoRicochetMobile.generatePrivateKey();
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = prefs.edit();
prefsEditor.putString(PRIVATE_KEY_KEY, privateKey);
prefsEditor.commit();
return privateKey;
} catch (Exception e) {
Log.e(TAG, e.toString());
return null;
}
}
@Override
protected void onPostExecute(String privateKey) {
Log.i(TAG, "RegenIdentTask.onPostExecute(): " + privateKey);
spinner.setVisibility(View.INVISIBLE);
regenButton.setEnabled(true);
connectButton.setEnabled(true);
if (privateKey == null) {
progressText.setText("ERROR: unable to generate new identity");
} else {
progressText.setText("");
setIdentity(privateKey);
}
}
}
private class EchoBot extends AsyncTask<Void, Void, Void> {
String privateKey;

View File

@ -11,9 +11,10 @@
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/connect"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintLeft_toRightOf="@+id/connectButton"
app:layout_constraintTop_toBottomOf="@+id/addressText" />
<EditText
@ -42,7 +43,7 @@
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/connect"
android:id="@+id/connectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
@ -58,9 +59,12 @@
android:id="@+id/progressTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="195dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/connect" />
app:layout_constraintTop_toBottomOf="@+id/connectButton"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/textView2"
@ -135,7 +139,7 @@
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="Regenerate Identity"
android:text="New Identity"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6" />