Select newly created identity on return from CreateIdentityActivity.

This partially fixes dev task #40. CreateIdentityActivity is also called
from AddContactActivity, but that's likely to change soon so I'm not
going to fix it now.
This commit is contained in:
akwizgran
2014-01-30 11:06:26 +00:00
parent 0bc479d4f2
commit 85b02eccc7
2 changed files with 31 additions and 13 deletions

View File

@@ -92,7 +92,6 @@ implements OnItemSelectedListener, OnClickListener {
byte[] b = i.getByteArrayExtra("briar.GROUP_ID"); byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
if(b == null) throw new IllegalStateException(); if(b == null) throw new IllegalStateException();
groupId = new GroupId(b); groupId = new GroupId(b);
b = i.getByteArrayExtra("briar.PARENT_ID"); b = i.getByteArrayExtra("briar.PARENT_ID");
if(b != null) parentId = new MessageId(b); if(b != null) parentId = new MessageId(b);
timestamp = i.getLongExtra("briar.TIMESTAMP", -1); timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
@@ -218,6 +217,16 @@ implements OnItemSelectedListener, OnClickListener {
} }
} }
@Override
protected void onActivityResult(int request, int result, Intent data) {
// This is the result of CreateIdentityActivity
if(result == RESULT_CANCELED) return;
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
if(b == null) throw new IllegalStateException();
localAuthorId = new AuthorId(b);
loadAuthorsAndGroup();
}
public void onItemSelected(AdapterView<?> parent, View view, int position, public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) { long id) {
LocalAuthorItem item = adapter.getItem(position); LocalAuthorItem item = adapter.getItem(position);
@@ -227,7 +236,8 @@ implements OnItemSelectedListener, OnClickListener {
} else if(item == LocalAuthorItem.NEW) { } else if(item == LocalAuthorItem.NEW) {
localAuthor = null; localAuthor = null;
localAuthorId = null; localAuthorId = null;
startActivity(new Intent(this, CreateIdentityActivity.class)); Intent i = new Intent(this, CreateIdentityActivity.class);
startActivityForResult(i, 0);
} else { } else {
localAuthor = item.getLocalAuthor(); localAuthor = item.getLocalAuthor();
localAuthorId = localAuthor.getId(); localAuthorId = localAuthor.getId();

View File

@@ -31,6 +31,7 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.lifecycle.LifecycleManager; import org.briarproject.api.lifecycle.LifecycleManager;
import roboguice.activity.RoboActivity; import roboguice.activity.RoboActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
@@ -133,6 +134,14 @@ implements OnEditorActionListener, OnClickListener {
}); });
} }
private boolean validateNickname() {
if(nicknameEntry.getText().toString().equals("")) return false;
// Hide the soft keyboard
Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
return true;
}
private void storeLocalAuthor(final LocalAuthor a) { private void storeLocalAuthor(final LocalAuthor a) {
dbUiExecutor.execute(new Runnable() { dbUiExecutor.execute(new Runnable() {
public void run() { public void run() {
@@ -151,20 +160,19 @@ implements OnEditorActionListener, OnClickListener {
LOG.info("Interrupted while waiting for database"); LOG.info("Interrupted while waiting for database");
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
runOnUiThread(new Runnable() { setResultAndFinish(a);
public void run() {
finish();
}
});
} }
}); });
} }
private boolean validateNickname() { private void setResultAndFinish(final LocalAuthor a) {
if(nicknameEntry.getText().toString().equals("")) return false; runOnUiThread(new Runnable() {
// Hide the soft keyboard public void run() {
Object o = getSystemService(INPUT_METHOD_SERVICE); Intent i = new Intent();
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0); i.putExtra("briar.LOCAL_AUTHOR_ID", a.getId().getBytes());
return true; setResult(RESULT_OK, i);
finish();
}
});
} }
} }