mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 16:33:39 +00:00
better intent sequence for single contact selection
This commit is contained in:
parent
725e943842
commit
4f87c1e52e
@ -208,24 +208,6 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
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;
|
||||
@ -598,11 +580,11 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -138,12 +138,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
||||
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;
|
||||
@ -160,6 +160,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
||||
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);
|
||||
|
@ -19,14 +19,19 @@ package org.thoughtcrime.securesms;
|
||||
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;
|
||||
|
||||
@ -41,9 +46,11 @@ import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
*
|
||||
*/
|
||||
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);
|
||||
@ -54,33 +61,51 @@ public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFr
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
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();
|
||||
recipientsPanel.setVisibility(View.INVISIBLE);
|
||||
recipientsPanel.addContacts(contactList);
|
||||
try {
|
||||
openNewConversation(recipientsPanel.getRecipients());
|
||||
} catch (RecipientFormattingException rfe) {
|
||||
recipientsPanel.clear();
|
||||
recipientsPanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
recipientsPanel.setPanelChangeListener(new SingleRecipientPanel.RecipientsPanelChangedListener() {
|
||||
@Override
|
||||
public void onRecipientsPanelUpdate(Recipients recipients) {
|
||||
Log.i(TAG, "onRecipientsPanelUpdate received.");
|
||||
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
|
||||
|
@ -103,10 +103,14 @@ public class SingleRecipientPanel extends RelativeLayout {
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
recipientsText.setText("");
|
||||
clear();
|
||||
panel.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
recipientsText.setText("");
|
||||
}
|
||||
|
||||
public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
|
||||
this.panelChangeListener = panelChangeListener;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user