finish ui for connect activity. display identity. 'new identity' functionality
This commit is contained in:
parent
767fccef40
commit
c68a45f088
|
@ -24,6 +24,14 @@ public class ConnectActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "InitActivity";
|
private static final String TAG = "InitActivity";
|
||||||
private static final String PRIVATE_KEY_KEY = "privateKey";
|
private static final String PRIVATE_KEY_KEY = "privateKey";
|
||||||
|
|
||||||
|
Button regenButton;
|
||||||
|
Button connectButton;
|
||||||
|
ProgressBar spinner;
|
||||||
|
TextView progressText;
|
||||||
|
TextView idetityText;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
// Load identity and connect to addr. Enable appropriate buttons
|
// Load identity and connect to addr. Enable appropriate buttons
|
||||||
|
@ -32,15 +40,29 @@ public class ConnectActivity extends AppCompatActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(im.ricochet.androidod.R.layout.activity_connect);
|
setContentView(im.ricochet.androidod.R.layout.activity_connect);
|
||||||
|
|
||||||
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
|
progressText = (TextView)findViewById(R.id.progressTextView);
|
||||||
//progressText.setText("Loading private key...");
|
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);
|
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
|
||||||
String privateKey = prefs.getString(PRIVATE_KEY_KEY, "");
|
String privateKey = prefs.getString(PRIVATE_KEY_KEY, "");
|
||||||
|
Log.i(TAG, "Private key loaded:\n"+privateKey);
|
||||||
if (privateKey.equals("")) {
|
if (privateKey.equals("")) {
|
||||||
// Kick of identity generateion
|
Log.i(TAG, "regenerating pricate key");
|
||||||
regenIdentity();
|
RegenIdentTask regenIdentTask = new RegenIdentTask();
|
||||||
|
regenIdentTask.execute();
|
||||||
} else {
|
} else {
|
||||||
|
Log.i(TAG, "setting identity, enabling regen");
|
||||||
|
setIdentity(privateKey);
|
||||||
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
|
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
|
||||||
regenButton.setEnabled(true);
|
regenButton.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
@ -60,32 +82,57 @@ public class ConnectActivity extends AppCompatActivity {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void regenIdentity() {
|
private void setIdentity(String privateKey) {
|
||||||
Button regenButton = (Button)findViewById(R.id.regenIdentButton);
|
Log.i(TAG, "setIdentity(): " + privateKey);
|
||||||
regenButton.setEnabled(false);
|
String addr = GoRicochetMobile.getOnionAddress(privateKey);
|
||||||
TextView progressText = (TextView)findViewById(im.ricochet.androidod.R.id.progressTextView);
|
Log.i(TAG, "setIdentity(): addr: '" + addr + "'");
|
||||||
progressText.setText("Generating new identity...");
|
idetityText.setText("ricochet:" + addr);
|
||||||
ProgressBar spinner = (ProgressBar)findViewById(R.id.progressBar);
|
}
|
||||||
spinner.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
String privateKey;
|
private class RegenIdentTask extends AsyncTask<Void, Void, String> {
|
||||||
try {
|
@Override
|
||||||
privateKey = GoRicochetMobile.generatePrivateKey();
|
protected void onPreExecute() {
|
||||||
|
Log.i(TAG, "RegenIdentTask.onPreExecute()");
|
||||||
SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE);
|
regenButton.setEnabled(false);
|
||||||
SharedPreferences.Editor prefsEditor = prefs.edit();
|
connectButton.setEnabled(false);
|
||||||
prefsEditor.putString(PRIVATE_KEY_KEY, privateKey);
|
progressText.setText("Generating new identity...");
|
||||||
prefsEditor.commit();
|
spinner.setVisibility(View.VISIBLE);
|
||||||
progressText.setText("");
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, e.toString());
|
|
||||||
progressText.setText("ERROR: unable to generate new identity: " + e.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spinner.setVisibility(View.INVISIBLE);
|
@Override
|
||||||
regenButton.setEnabled(true);
|
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> {
|
private class EchoBot extends AsyncTask<Void, Void, Void> {
|
||||||
String privateKey;
|
String privateKey;
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,10 @@
|
||||||
style="@style/Widget.AppCompat.ProgressBar"
|
style="@style/Widget.AppCompat.ProgressBar"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintLeft_toRightOf="@+id/connect"
|
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintLeft_toRightOf="@+id/connectButton"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/addressText" />
|
app:layout_constraintTop_toBottomOf="@+id/addressText" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
@ -42,7 +43,7 @@
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/connect"
|
android:id="@+id/connectButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
|
@ -58,9 +59,12 @@
|
||||||
android:id="@+id/progressTextView"
|
android:id="@+id/progressTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:layout_editor_absoluteX="195dp"
|
|
||||||
android:layout_marginTop="8dp"
|
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
|
<TextView
|
||||||
android:id="@+id/textView2"
|
android:id="@+id/textView2"
|
||||||
|
@ -135,7 +139,7 @@
|
||||||
android:layout_marginRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:text="Regenerate Identity"
|
android:text="New Identity"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView6" />
|
app:layout_constraintTop_toBottomOf="@+id/textView6" />
|
||||||
|
|
Loading…
Reference in New Issue