mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Distinguish request and result codes of different activities.
This commit is contained in:
@@ -20,7 +20,7 @@ public class BriarActivity extends RoboFragmentActivity {
|
||||
|
||||
// This build expires on 7 February 2014
|
||||
private static final long EXPIRY_DATE = 1391731200 * 1000L;
|
||||
private static final int PASSWORD_REQUEST_CODE = 1;
|
||||
private static final int REQUEST_PASSWORD = 1;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(BriarActivity.class.getName());
|
||||
@@ -45,7 +45,7 @@ public class BriarActivity extends RoboFragmentActivity {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("No password");
|
||||
Intent i = new Intent(this, PasswordActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_NO_ANIMATION);
|
||||
startActivityForResult(i, PASSWORD_REQUEST_CODE);
|
||||
startActivityForResult(i, REQUEST_PASSWORD);
|
||||
} else {
|
||||
startAndBindService();
|
||||
}
|
||||
@@ -53,7 +53,8 @@ public class BriarActivity extends RoboFragmentActivity {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if(request == PASSWORD_REQUEST_CODE) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_PASSWORD) {
|
||||
if(result == RESULT_OK) startAndBindService();
|
||||
else finish();
|
||||
}
|
||||
|
||||
@@ -53,9 +53,7 @@ public class HomeScreenActivity extends BriarActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Created");
|
||||
Intent i = getIntent();
|
||||
long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
|
||||
long handle = getIntent().getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
|
||||
if(handle == -1) {
|
||||
// The activity has been launched before
|
||||
showButtons();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PasswordActivity extends RoboActivity {
|
||||
tryAgain();
|
||||
} else {
|
||||
databaseConfig.setEncryptionKey(key);
|
||||
returnOk();
|
||||
setResultAndFinish();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -143,7 +143,7 @@ public class PasswordActivity extends RoboActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void returnOk() {
|
||||
private void setResultAndFinish() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
setResult(RESULT_OK);
|
||||
|
||||
@@ -6,6 +6,7 @@ import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.contact.ReadPrivateMessageActivity.RESULT_PREV_NEXT;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
@@ -47,6 +48,7 @@ import android.widget.ListView;
|
||||
public class ConversationActivity extends RoboActivity
|
||||
implements EventListener, OnClickListener, OnItemClickListener {
|
||||
|
||||
private static final int REQUEST_READ_MESSAGE = 2;
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ConversationActivity.class.getName());
|
||||
|
||||
@@ -180,12 +182,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if(result == ReadPrivateMessageActivity.RESULT_PREV) {
|
||||
int position = request - 1;
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
} else if(result == ReadPrivateMessageActivity.RESULT_NEXT) {
|
||||
int position = request + 1;
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_READ_MESSAGE && result == RESULT_PREV_NEXT) {
|
||||
int position = data.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
}
|
||||
@@ -244,6 +244,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
i.putExtra("briar.MESSAGE_ID", header.getId().getBytes());
|
||||
i.putExtra("briar.CONTENT_TYPE", header.getContentType());
|
||||
i.putExtra("briar.TIMESTAMP", header.getTimestamp());
|
||||
startActivityForResult(i, position);
|
||||
i.putExtra("briar.POSITION", position);
|
||||
startActivityForResult(i, REQUEST_READ_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ public class ReadPrivateMessageActivity extends RoboActivity
|
||||
implements OnClickListener {
|
||||
|
||||
static final int RESULT_REPLY = RESULT_FIRST_USER;
|
||||
static final int RESULT_PREV = RESULT_FIRST_USER + 1;
|
||||
static final int RESULT_NEXT = RESULT_FIRST_USER + 2;
|
||||
static final int RESULT_PREV_NEXT = RESULT_FIRST_USER + 1;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ReadPrivateMessageActivity.class.getName());
|
||||
@@ -60,6 +59,7 @@ implements OnClickListener {
|
||||
private ImageButton readButton = null, prevButton = null, nextButton = null;
|
||||
private ImageButton replyButton = null;
|
||||
private TextView content = null;
|
||||
private int position = -1;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile DatabaseComponent db;
|
||||
@@ -92,6 +92,8 @@ implements OnClickListener {
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
position = i.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
|
||||
if(state == null) {
|
||||
read = false;
|
||||
@@ -262,10 +264,14 @@ implements OnClickListener {
|
||||
if(view == readButton) {
|
||||
setReadInDatabase(!read);
|
||||
} else if(view == prevButton) {
|
||||
setResult(RESULT_PREV);
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position - 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == nextButton) {
|
||||
setResult(RESULT_NEXT);
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position + 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == replyButton) {
|
||||
Intent i = new Intent(this, WritePrivateMessageActivity.class);
|
||||
|
||||
@@ -6,8 +6,7 @@ import static android.view.View.VISIBLE;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_NEXT;
|
||||
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_PREV;
|
||||
import static org.briarproject.android.groups.ReadGroupPostActivity.RESULT_PREV_NEXT;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
|
||||
|
||||
@@ -49,6 +48,7 @@ import android.widget.ListView;
|
||||
public class GroupActivity extends RoboActivity implements EventListener,
|
||||
OnClickListener, OnItemClickListener {
|
||||
|
||||
private static final int REQUEST_READ_POST = 2;
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(GroupActivity.class.getName());
|
||||
|
||||
@@ -170,12 +170,10 @@ OnClickListener, OnItemClickListener {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if(result == RESULT_PREV) {
|
||||
int position = request - 1;
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
} else if(result == RESULT_NEXT) {
|
||||
int position = request + 1;
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_READ_POST && result == RESULT_PREV_NEXT) {
|
||||
int position = data.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
}
|
||||
@@ -227,13 +225,11 @@ OnClickListener, OnItemClickListener {
|
||||
i.putExtra("briar.GROUP_NAME", groupName);
|
||||
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
|
||||
Author author = item.getAuthor();
|
||||
if(author != null) {
|
||||
i.putExtra("briar.AUTHOR_ID", author.getId().getBytes());
|
||||
i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||
}
|
||||
if(author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||
i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name());
|
||||
i.putExtra("briar.CONTENT_TYPE", item.getContentType());
|
||||
i.putExtra("briar.TIMESTAMP", item.getTimestamp());
|
||||
startActivityForResult(i, position);
|
||||
i.putExtra("briar.POSITION", position);
|
||||
startActivityForResult(i, REQUEST_READ_POST);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,8 +47,7 @@ public class ReadGroupPostActivity extends RoboActivity
|
||||
implements OnClickListener {
|
||||
|
||||
static final int RESULT_REPLY = RESULT_FIRST_USER;
|
||||
static final int RESULT_PREV = RESULT_FIRST_USER + 1;
|
||||
static final int RESULT_NEXT = RESULT_FIRST_USER + 2;
|
||||
static final int RESULT_PREV_NEXT = RESULT_FIRST_USER + 1;
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ReadGroupPostActivity.class.getName());
|
||||
@@ -58,6 +57,7 @@ implements OnClickListener {
|
||||
private ImageButton readButton = null, prevButton = null, nextButton = null;
|
||||
private ImageButton replyButton = null;
|
||||
private TextView content = null;
|
||||
private int position = -1;
|
||||
|
||||
// Fields that are accessed from background threads must be volatile
|
||||
@Inject private volatile DatabaseComponent db;
|
||||
@@ -84,6 +84,8 @@ implements OnClickListener {
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
position = i.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
String authorName = i.getStringExtra("briar.AUTHOR_NAME");
|
||||
String s = i.getStringExtra("briar.AUTHOR_STATUS");
|
||||
if(s == null) throw new IllegalStateException();
|
||||
@@ -258,10 +260,14 @@ implements OnClickListener {
|
||||
if(view == readButton) {
|
||||
setReadInDatabase(!read);
|
||||
} else if(view == prevButton) {
|
||||
setResult(RESULT_PREV);
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position - 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == nextButton) {
|
||||
setResult(RESULT_NEXT);
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position + 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == replyButton) {
|
||||
Intent i = new Intent(this, WriteGroupPostActivity.class);
|
||||
|
||||
@@ -61,6 +61,7 @@ import android.widget.Toast;
|
||||
public class WriteGroupPostActivity extends RoboActivity
|
||||
implements OnItemSelectedListener, OnClickListener {
|
||||
|
||||
private static final int REQUEST_CREATE_IDENTITY = 2;
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(WriteGroupPostActivity.class.getName());
|
||||
|
||||
@@ -219,12 +220,13 @@ 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();
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
|
||||
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,
|
||||
@@ -237,7 +239,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
localAuthor = null;
|
||||
localAuthorId = null;
|
||||
Intent i = new Intent(this, CreateIdentityActivity.class);
|
||||
startActivityForResult(i, 0);
|
||||
startActivityForResult(i, REQUEST_CREATE_IDENTITY);
|
||||
} else {
|
||||
localAuthor = item.getLocalAuthor();
|
||||
localAuthorId = localAuthor.getId();
|
||||
|
||||
Reference in New Issue
Block a user