mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 21:43:38 +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);
|
super.onActivityResult(reqCode, resultCode, data);
|
||||||
|
|
||||||
switch (reqCode) {
|
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:
|
case PICK_IMAGE:
|
||||||
if (data != null && resultCode == RESULT_OK) addAttachmentImage(data.getData());
|
if (data != null && resultCode == RESULT_OK) addAttachmentImage(data.getData());
|
||||||
break;
|
break;
|
||||||
@ -598,11 +580,11 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeResources() {
|
private void initializeResources() {
|
||||||
recipientsPanel = (RecipientsPanel)findViewById(R.id.recipients);
|
|
||||||
recipients = getIntent().getParcelableExtra(RECIPIENTS_EXTRA);
|
recipients = getIntent().getParcelableExtra(RECIPIENTS_EXTRA);
|
||||||
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
threadId = getIntent().getLongExtra(THREAD_ID_EXTRA, -1);
|
||||||
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
|
distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA,
|
||||||
ThreadDatabase.DistributionTypes.DEFAULT);
|
ThreadDatabase.DistributionTypes.DEFAULT);
|
||||||
|
recipientsPanel = (RecipientsPanel)findViewById(R.id.recipients);
|
||||||
addContactButton = (ImageButton)findViewById(R.id.contacts_button);
|
addContactButton = (ImageButton)findViewById(R.id.contacts_button);
|
||||||
sendButton = (ImageButton)findViewById(R.id.send_button);
|
sendButton = (ImageButton)findViewById(R.id.send_button);
|
||||||
composeText = (EditText)findViewById(R.id.embedded_text_editor);
|
composeText = (EditText)findViewById(R.id.embedded_text_editor);
|
||||||
|
@ -138,12 +138,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|||||||
int defaultType = ThreadDatabase.DistributionTypes.DEFAULT;
|
int defaultType = ThreadDatabase.DistributionTypes.DEFAULT;
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_new_message: createConversation(-1, null, defaultType); return true;
|
case R.id.menu_new_message: openSingleContactSelection(); return true;
|
||||||
case R.id.menu_new_group: createGroup(); return true;
|
case R.id.menu_new_group: createGroup(); return true;
|
||||||
case R.id.menu_settings: handleDisplaySettings(); return true;
|
case R.id.menu_settings: handleDisplaySettings(); return true;
|
||||||
case R.id.menu_clear_passphrase: handleClearPassphrase(); return true;
|
case R.id.menu_clear_passphrase: handleClearPassphrase(); return true;
|
||||||
case R.id.menu_mark_all_read: handleMarkAllRead(); return true;
|
case R.id.menu_mark_all_read: handleMarkAllRead(); return true;
|
||||||
case android.R.id.home: handleNavigationDrawerToggle(); return true;
|
case android.R.id.home: handleNavigationDrawerToggle(); return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -160,6 +160,12 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|||||||
startActivity(intent);
|
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) {
|
private void createConversation(long threadId, Recipients recipients, int distributionType) {
|
||||||
Intent intent = new Intent(this, ConversationActivity.class);
|
Intent intent = new Intent(this, ConversationActivity.class);
|
||||||
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients);
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients);
|
||||||
|
@ -19,14 +19,19 @@ package org.thoughtcrime.securesms;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.ActionBar;
|
import com.actionbarsherlock.app.ActionBar;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.components.SingleRecipientPanel;
|
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.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -41,9 +46,11 @@ import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
|
public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
|
||||||
private final String TAG = "SingleContactSelectionActivity";
|
private final static String TAG = "SingleContactSelectionActivity";
|
||||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
public final static String MASTER_SECRET_EXTRA = "master_secret";
|
||||||
|
|
||||||
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||||
|
private MasterSecret masterSecret;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
dynamicTheme.onCreate(this);
|
dynamicTheme.onCreate(this);
|
||||||
@ -54,33 +61,51 @@ public class SingleContactSelectionActivity extends PassphraseRequiredSherlockFr
|
|||||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
setContentView(R.layout.single_contact_selection_activity);
|
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);
|
final SingleContactSelectionListFragment listFragment = (SingleContactSelectionListFragment)getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
|
||||||
listFragment.setOnContactSelectedListener(new SingleContactSelectionListFragment.OnContactSelectedListener() {
|
listFragment.setOnContactSelectedListener(new SingleContactSelectionListFragment.OnContactSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onContactSelected(ContactData contactData) {
|
public void onContactSelected(ContactData contactData) {
|
||||||
Intent resultIntent = getIntent();
|
|
||||||
ArrayList<ContactData> contactList = new ArrayList<ContactData>();
|
ArrayList<ContactData> contactList = new ArrayList<ContactData>();
|
||||||
contactList.add(contactData);
|
contactList.add(contactData);
|
||||||
resultIntent.putParcelableArrayListExtra("contacts", contactList);
|
|
||||||
setResult(RESULT_OK, resultIntent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SingleRecipientPanel recipientsPanel = (SingleRecipientPanel) findViewById(R.id.recipients);
|
recipientsPanel.setVisibility(View.INVISIBLE);
|
||||||
recipientsPanel.setPanelChangeListener(new SingleRecipientPanel.RecipientsPanelChangedListener() {
|
recipientsPanel.addContacts(contactList);
|
||||||
@Override
|
try {
|
||||||
public void onRecipientsPanelUpdate(Recipients recipients) {
|
openNewConversation(recipientsPanel.getRecipients());
|
||||||
Log.i(TAG, "onRecipientsPanelUpdate received.");
|
} catch (RecipientFormattingException rfe) {
|
||||||
if (recipients != null) {
|
recipientsPanel.clear();
|
||||||
Intent resultIntent = getIntent();
|
recipientsPanel.setVisibility(View.VISIBLE);
|
||||||
resultIntent.putExtra("recipients", recipients);
|
|
||||||
setResult(RESULT_OK, resultIntent);
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
|
@ -103,10 +103,14 @@ public class SingleRecipientPanel extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
recipientsText.setText("");
|
clear();
|
||||||
panel.setVisibility(View.GONE);
|
panel.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
recipientsText.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
|
public void setPanelChangeListener(RecipientsPanelChangedListener panelChangeListener) {
|
||||||
this.panelChangeListener = panelChangeListener;
|
this.panelChangeListener = panelChangeListener;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user