mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-10 06:41:47 +00:00
refactor and improve contact selection
* unify single and multi contact selection activities * follow android listview design recommendations more closely * add contact photos to selection * change indicator for push to be more obvious * cache circle-cropped bitmaps * dedupe numbers when contact has multiple of same phone number // FREEBIE
This commit is contained in:
@@ -19,11 +19,24 @@ package org.thoughtcrime.securesms;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.components.SingleRecipientPanel;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.ActionBarUtil;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.NumberUtil;
|
||||
import org.thoughtcrime.securesms.util.ProgressDialogAsyncTask;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
@@ -31,22 +44,24 @@ import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
|
||||
/**
|
||||
* Activity container for selecting a list of contacts. Provides a tab frame for
|
||||
* contact, group, and "recent contact" activity tabs. Used by ComposeMessageActivity
|
||||
* when selecting a list of contacts to address a message to.
|
||||
* Activity container for selecting a list of contacts.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class PushContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
|
||||
private final static String TAG = "ContactSelectActivity";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
|
||||
private PushContactSelectionListFragment contactsFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
dynamicTheme.onCreate(this);
|
||||
@@ -57,6 +72,7 @@ public class PushContactSelectionActivity extends PassphraseRequiredSherlockFrag
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
setContentView(R.layout.push_contact_selection_activity);
|
||||
initializeResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,34 +82,55 @@ public class PushContactSelectionActivity extends PassphraseRequiredSherlockFrag
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = this.getSupportMenuInflater();
|
||||
inflater.inflate(R.menu.contact_selection, menu);
|
||||
menu.clear();
|
||||
|
||||
if (TextSecurePreferences.isPushRegistered(this)) inflater.inflate(R.menu.push_directory, menu);
|
||||
|
||||
inflater.inflate(R.menu.contact_selection, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_selection_finished:
|
||||
case android.R.id.home:
|
||||
handleSelectionFinished(); return true;
|
||||
case R.id.menu_refresh_directory: handleDirectoryRefresh(); return true;
|
||||
case R.id.menu_selection_finished: handleSelectionFinished(); return true;
|
||||
case android.R.id.home: finish(); return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
contactsFragment = (PushContactSelectionListFragment) getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
|
||||
contactsFragment.setMultiSelect(true);
|
||||
contactsFragment.setOnContactSelectedListener(new PushContactSelectionListFragment.OnContactSelectedListener() {
|
||||
@Override
|
||||
public void onContactSelected(ContactData contactData) {
|
||||
Log.i(TAG, "Choosing contact from list.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSelectionFinished() {
|
||||
PushContactSelectionListFragment contactsFragment = (PushContactSelectionListFragment) getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
|
||||
List<ContactData> contacts = contactsFragment.getSelectedContacts();
|
||||
|
||||
Intent resultIntent = getIntent();
|
||||
resultIntent.putParcelableArrayListExtra("contacts", new ArrayList<ContactData>(contacts));
|
||||
|
||||
final Intent resultIntent = getIntent();
|
||||
final List<ContactData> selectedContacts = contactsFragment.getSelectedContacts();
|
||||
if (selectedContacts != null) {
|
||||
resultIntent.putParcelableArrayListExtra("contacts", new ArrayList<ContactData>(contactsFragment.getSelectedContacts()));
|
||||
}
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleDirectoryRefresh() {
|
||||
DirectoryHelper.refreshDirectoryWithProgressDialog(this, new DirectoryHelper.DirectoryUpdateFinishedListener() {
|
||||
@Override
|
||||
public void onUpdateFinished() {
|
||||
contactsFragment.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user