Skip to content

Commit

Permalink
better intent sequence for single contact selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mcginty committed Feb 17, 2014
1 parent 725e943 commit 4f87c1e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
20 changes: 1 addition & 19 deletions src/org/thoughtcrime/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,6 @@ public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);

switch (reqCode) {
case PICK_CONTACT:
if (resultCode == RESULT_OK) {
Recipients recipients = data.getParcelableExtra("recipients");
if (recipients != null) {
recipientsPanel.addRecipients(recipients);
this.recipients = getRecipients();
} else {
ArrayList<ContactData> contacts = data.getParcelableArrayListExtra("contacts");
if (contacts != null) {
recipientsPanel.addContacts(contacts);
this.recipients = getRecipients();
}
}
} else {
Log.w("ConversationActivity", "gonna have a bad time.");
finish();
}
break;
case PICK_IMAGE:
if (data != null && resultCode == RESULT_OK) addAttachmentImage(data.getData());
break;
Expand Down Expand Up @@ -598,11 +580,11 @@ private void initializeIme() {
}

private void initializeResources() {
recipientsPanel = (RecipientsPanel)findViewById(R.id.recipients);
recipients = getIntent().getParcelableExtra(RECIPIENTS_EXTRA);
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
ThreadDatabase.DistributionTypes.DEFAULT);
recipientsPanel = (RecipientsPanel)findViewById(R.id.recipients);
addContactButton = (ImageButton)findViewById(R.id.contacts_button);
sendButton = (ImageButton)findViewById(R.id.send_button);
composeText = (EditText)findViewById(R.id.embedded_text_editor);
Expand Down
18 changes: 12 additions & 6 deletions src/org/thoughtcrime/securesms/ConversationListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
int defaultType = ThreadDatabase.DistributionTypes.DEFAULT;

switch (item.getItemId()) {
case R.id.menu_new_message: createConversation(-1, null, defaultType); return true;
case R.id.menu_new_group: createGroup(); return true;
case R.id.menu_settings: handleDisplaySettings(); return true;
case R.id.menu_clear_passphrase: handleClearPassphrase(); return true;
case R.id.menu_mark_all_read: handleMarkAllRead(); return true;
case android.R.id.home: handleNavigationDrawerToggle(); return true;
case R.id.menu_new_message: openSingleContactSelection(); return true;
case R.id.menu_new_group: createGroup(); return true;
case R.id.menu_settings: handleDisplaySettings(); return true;
case R.id.menu_clear_passphrase: handleClearPassphrase(); return true;
case R.id.menu_mark_all_read: handleMarkAllRead(); return true;
case android.R.id.home: handleNavigationDrawerToggle(); return true;
}

return false;
Expand All @@ -160,6 +160,12 @@ private void createGroup() {
startActivity(intent);
}

private void openSingleContactSelection() {
Intent intent = new Intent(this, SingleContactSelectionActivity.class);
intent.putExtra(SingleContactSelectionActivity.MASTER_SECRET_EXTRA, masterSecret);
startActivity(intent);
}

private void createConversation(long threadId, Recipients recipients, int distributionType) {
Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients);
Expand Down
51 changes: 38 additions & 13 deletions src/org/thoughtcrime/securesms/SingleContactSelectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.MenuItem;

import org.thoughtcrime.securesms.components.SingleRecipientPanel;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.ActionBarUtil;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.whispersystems.textsecure.crypto.MasterSecret;

import java.util.ArrayList;

Expand All @@ -41,9 +46,11 @@
*
*/
public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
private final String TAG = "SingleContactSelectionActivity";
private final DynamicTheme dynamicTheme = new DynamicTheme();
private final static String TAG = "SingleContactSelectionActivity";
public final static String MASTER_SECRET_EXTRA = "master_secret";

private final DynamicTheme dynamicTheme = new DynamicTheme();
private MasterSecret masterSecret;
@Override
protected void onCreate(Bundle icicle) {
dynamicTheme.onCreate(this);
Expand All @@ -54,33 +61,51 @@ protected void onCreate(Bundle icicle) {
actionBar.setDisplayHomeAsUpEnabled(true);

setContentView(R.layout.single_contact_selection_activity);
initializeResources();
}

private void initializeResources() {
masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA);
final SingleRecipientPanel recipientsPanel = (SingleRecipientPanel) findViewById(R.id.recipients);

final SingleContactSelectionListFragment listFragment = (SingleContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
listFragment.setOnContactSelectedListener(new SingleContactSelectionListFragment.OnContactSelectedListener() {
@Override
public void onContactSelected(ContactData contactData) {
Intent resultIntent = getIntent();
ArrayList<ContactData> contactList = new ArrayList<ContactData>();
contactList.add(contactData);
resultIntent.putParcelableArrayListExtra("contacts", contactList);
setResult(RESULT_OK, resultIntent);
finish();

recipientsPanel.setVisibility(View.INVISIBLE);
recipientsPanel.addContacts(contactList);
try {
openNewConversation(recipientsPanel.getRecipients());
} catch (RecipientFormattingException rfe) {
recipientsPanel.clear();
recipientsPanel.setVisibility(View.VISIBLE);
}
}
});

SingleRecipientPanel recipientsPanel = (SingleRecipientPanel) findViewById(R.id.recipients);
recipientsPanel.setPanelChangeListener(new SingleRecipientPanel.RecipientsPanelChangedListener() {
@Override
public void onRecipientsPanelUpdate(Recipients recipients) {
Log.i(TAG, "onRecipientsPanelUpdate received.");
if (recipients != null) {
Intent resultIntent = getIntent();
resultIntent.putExtra("recipients", recipients);
setResult(RESULT_OK, resultIntent);
finish();
}
openNewConversation(recipients);
}
});
}

private void openNewConversation(Recipients recipients) {
if (recipients != null) {
Intent intent = new Intent(SingleContactSelectionActivity.this, ConversationActivity.class);
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients);
intent.putExtra(ConversationActivity.MASTER_SECRET_EXTRA, masterSecret);
long existingThread = DatabaseFactory.getThreadDatabase(SingleContactSelectionActivity.this).getThreadIdIfExistsFor(recipients);
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, existingThread);
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT);
startActivity(intent);
finish();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ public Recipients getRecipients() throws RecipientFormattingException {
}

public void disable() {
recipientsText.setText("");
clear();
panel.setVisibility(View.GONE);
}

public void clear() {
recipientsText.setText("");
}

public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
this.panelChangeListener = panelChangeListener;
}
Expand Down

0 comments on commit 4f87c1e

Please sign in to comment.