diff --git a/app/src/main/java/im/ricochet/androidod/ConnectActivity.java b/app/src/main/java/im/ricochet/androidod/ConnectActivity.java index 93753c3..6fcf110 100644 --- a/app/src/main/java/im/ricochet/androidod/ConnectActivity.java +++ b/app/src/main/java/im/ricochet/androidod/ConnectActivity.java @@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; @@ -25,30 +26,26 @@ public class ConnectActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + // Load identity and connect to addr. Enable appropriate buttons + // If no identity, generate. + 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.setText("Loading private key..."); - Log.i(TAG, "Loading private key..."); SharedPreferences prefs = getSharedPreferences(PREFERNCE_FILE, MODE_PRIVATE); String privateKey = prefs.getString(PRIVATE_KEY_KEY, ""); - Log.i(TAG, "Loaded! '" + privateKey + "'"); if (privateKey.equals("")) { - Log.i(TAG, "Failed to load private key from preferences, generating new"); - progressText.setText("Generating private key..."); - try { - privateKey = GoRicochetMobile.generatePrivateKey(); - } catch (Exception e) { - Log.e(TAG, e.toString()); - } - Log.i(TAG, "Generated!: '" + privateKey + "'"); - SharedPreferences.Editor prefsEditor = prefs.edit(); - prefsEditor.putString(PRIVATE_KEY_KEY, privateKey); - prefsEditor.commit(); + // Kick of identity generateion + regenIdentity(); + } else { + Button regenButton = (Button)findViewById(R.id.regenIdentButton); + regenButton.setEnabled(true); } - Log.i(TAG, "Ready!"); + + /*Log.i(TAG, "Ready!"); progressText.setText("Ready!"); ProgressBar progressBar = (ProgressBar)findViewById(im.ricochet.androidod.R.id.progressBar); progressBar.setVisibility(View.GONE); @@ -60,7 +57,33 @@ public class ConnectActivity extends AppCompatActivity { Log.i(TAG, "Starting Echo Bot"); //GoRicochetMobile.echoBot(privateKey); new EchoBot(privateKey).execute(); + */ + } + 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); + + 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()); + } + + spinner.setVisibility(View.INVISIBLE); + regenButton.setEnabled(true); } private class EchoBot extends AsyncTask { diff --git a/app/src/main/res/layout/activity_connect.xml b/app/src/main/res/layout/activity_connect.xml index a0706c2..ddc5ef8 100644 --- a/app/src/main/res/layout/activity_connect.xml +++ b/app/src/main/res/layout/activity_connect.xml @@ -11,12 +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_marginRight="8dp" - android:layout_marginTop="32dp" - app:layout_constraintLeft_toLeftOf="parent" - app:layout_constraintRight_toRightOf="parent" - app:layout_constraintTop_toBottomOf="@+id/connect" /> + android:layout_marginTop="8dp" + app:layout_constraintTop_toBottomOf="@+id/addressText" /> + android:layout_marginTop="8dp" + android:text="Connect to Onion address:" + app:layout_constraintLeft_toLeftOf="@+id/addressText" + app:layout_constraintTop_toTopOf="parent" />