mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
remove unused activities and fragments
// FREEBIE
This commit is contained in:
parent
9fed60628d
commit
3e6e28e688
@ -138,11 +138,6 @@
|
||||
android:windowSoftInputMode="stateAlwaysVisible"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".ContactSelectionActivity"
|
||||
android:label="@string/AndroidManifest__select_contacts"
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>
|
||||
|
||||
<activity android:name=".NewConversationActivity"
|
||||
android:label="@string/AndroidManifest__select_contacts"
|
||||
android:windowSoftInputMode="stateVisible"
|
||||
|
@ -1,203 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBar.Tab;
|
||||
import android.support.v7.app.ActionBar.TabListener;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class ContactSelectionActivity extends PassphraseRequiredActionBarActivity {
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
||||
|
||||
private ViewPager viewPager;
|
||||
private ContactSelectionListFragment contactsFragment;
|
||||
private ContactSelectionGroupsFragment groupsFragment;
|
||||
private ContactSelectionRecentFragment recentFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
dynamicTheme.onCreate(this);
|
||||
super.onCreate(icicle);
|
||||
|
||||
final ActionBar actionBar = this.getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
setContentView(R.layout.contact_selection_activity);
|
||||
|
||||
setupFragments();
|
||||
setupViewPager();
|
||||
setupTabs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
dynamicTheme.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
inflater.inflate(R.menu.contact_selection, menu);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_selection_finished:
|
||||
case android.R.id.home:
|
||||
handleSelectionFinished(); return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleSelectionFinished() {
|
||||
List<ContactData> contacts = contactsFragment.getSelectedContacts();
|
||||
contacts.addAll(recentFragment.getSelectedContacts());
|
||||
contacts.addAll(groupsFragment.getSelectedContacts(this));
|
||||
|
||||
Intent resultIntent = getIntent();
|
||||
resultIntent.putParcelableArrayListExtra("contacts", new ArrayList<ContactData>(contacts));
|
||||
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
private void setupViewPager() {
|
||||
viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
viewPager.setAdapter(new SelectionPagerAdapter());
|
||||
viewPager.setOnPageChangeListener(new TabSwitchingPageListener());
|
||||
}
|
||||
|
||||
private void setupTabs() {
|
||||
int[] icons = new int[] { R.drawable.ic_tab_contacts, R.drawable.ic_tab_groups, R.drawable.ic_tab_recent };
|
||||
|
||||
for (int i = 0; i < icons.length; i++) {
|
||||
ActionBar.Tab tab = getSupportActionBar().newTab();
|
||||
tab.setIcon(icons[i]);
|
||||
tab.setTabListener(new ViewPagerTabListener(i));
|
||||
getSupportActionBar().addTab(tab);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupFragments() {
|
||||
contactsFragment = new ContactSelectionListFragment();
|
||||
groupsFragment = new ContactSelectionGroupsFragment();
|
||||
recentFragment = new ContactSelectionRecentFragment();
|
||||
}
|
||||
|
||||
private class SelectionPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public SelectionPagerAdapter() {
|
||||
super(getSupportFragmentManager());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return contactsFragment;
|
||||
case 1:
|
||||
return groupsFragment;
|
||||
case 2:
|
||||
default:
|
||||
return recentFragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ViewPagerTabListener implements TabListener {
|
||||
|
||||
private int tabIndex;
|
||||
|
||||
public ViewPagerTabListener(int index) {
|
||||
tabIndex = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
viewPager.setCurrentItem(tabIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TabSwitchingPageListener implements ViewPager.OnPageChangeListener {
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int i, float v, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int i) {
|
||||
getSupportActionBar().setSelectedNavigationItem(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,224 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.GroupData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An activity for selecting a list of "contact groups." Displayed
|
||||
* by ContactSelectionActivity in a tabbed frame, and ultimately called
|
||||
* by ComposeMessageActivity for selecting a list of recipients.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class ContactSelectionGroupsFragment extends ListFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
{
|
||||
|
||||
private final HashMap<Long, GroupData> selectedGroups = new HashMap<Long, GroupData>();
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle icicle) {
|
||||
super.onActivityCreated(icicle);
|
||||
|
||||
initializeResources();
|
||||
initializeCursor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.contact_selection_group_activity, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((GroupItemView)v).selected();
|
||||
}
|
||||
|
||||
private void initializeCursor() {
|
||||
setListAdapter(new GroupSelectionListAdapter(getActivity(), null));
|
||||
this.getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.getListView().setFocusable(true);
|
||||
}
|
||||
|
||||
public List<ContactData> getSelectedContacts(Context context) {
|
||||
List<ContactData> contacts = new LinkedList<ContactData>();
|
||||
|
||||
for (GroupData groupData : selectedGroups.values()) {
|
||||
List<ContactData> contactDataList = ContactAccessor.getInstance()
|
||||
.getGroupMembership(context, groupData.id);
|
||||
|
||||
contacts.addAll(contactDataList);
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private void addGroup(GroupData groupData) {
|
||||
selectedGroups.put(groupData.id, groupData);
|
||||
}
|
||||
|
||||
private void removeGroup(GroupData groupData) {
|
||||
selectedGroups.remove(groupData.id);
|
||||
}
|
||||
|
||||
private class GroupSelectionListAdapter extends CursorAdapter {
|
||||
|
||||
public GroupSelectionListAdapter(Context context, Cursor cursor) {
|
||||
super(context, cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
GroupItemView view = new GroupItemView(context);
|
||||
bindView(view, context, cursor);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
GroupData groupData = ContactAccessor.getInstance().getGroupData(getActivity(), cursor);
|
||||
((GroupItemView)view).set(groupData);
|
||||
}
|
||||
}
|
||||
|
||||
private class GroupItemView extends LinearLayout {
|
||||
private GroupData groupData;
|
||||
private CheckedTextView name;
|
||||
|
||||
public GroupItemView(Context context) {
|
||||
super(context);
|
||||
|
||||
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
li.inflate(R.layout.contact_selection_group_item, this, true);
|
||||
|
||||
this.name = (CheckedTextView)findViewById(R.id.name);
|
||||
}
|
||||
|
||||
public void selected() {
|
||||
name.toggle();
|
||||
|
||||
if (name.isChecked()) {
|
||||
addGroup(groupData);
|
||||
} else {
|
||||
removeGroup(groupData);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(GroupData groupData) {
|
||||
this.groupData = groupData;
|
||||
|
||||
if (selectedGroups.containsKey(groupData.id))
|
||||
this.name.setChecked(true);
|
||||
else
|
||||
this.name.setChecked(false);
|
||||
|
||||
this.name.setText(groupData.name);
|
||||
}
|
||||
}
|
||||
|
||||
// private class GroupAggregationHandler extends Handler implements Runnable {
|
||||
// private List<Recipient> recipientList = new LinkedList<Recipient>();
|
||||
// private ProgressDialog progressDialog;
|
||||
// private final Context context;
|
||||
//
|
||||
// public GroupAggregationHandler(Context context) {
|
||||
// this.context = context;
|
||||
// }
|
||||
//
|
||||
// public void run() {
|
||||
// recipientList.clear();
|
||||
//
|
||||
// for (GroupData groupData : selectedGroups.values()) {
|
||||
// List<ContactData> contactDataList = ContactAccessor.getInstance()
|
||||
// .getGroupMembership(getActivity(), groupData.id);
|
||||
//
|
||||
// Log.w("GroupSelectionListActivity", "Got contacts in group: " + contactDataList.size());
|
||||
//
|
||||
// for (ContactData contactData : contactDataList) {
|
||||
// for (NumberData numberData : contactData.numbers) {
|
||||
// recipientList.add(new Recipient(contactData.name, numberData.number, null));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.obtainMessage().sendToTarget();
|
||||
// }
|
||||
//
|
||||
// public void aggregateContacts() {
|
||||
// progressDialog = new ProgressDialog(context);
|
||||
// progressDialog.setTitle("Aggregating Contacts");
|
||||
// progressDialog.setMessage("Aggregating group contacts...");
|
||||
// progressDialog.setCancelable(false);
|
||||
// progressDialog.setIndeterminate(true);
|
||||
// progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
// progressDialog.show();
|
||||
// Log.w("GroupSelectionListActivity", "Showing group spinner...");
|
||||
// new Thread(this).start();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(Message message) {
|
||||
// progressDialog.dismiss();
|
||||
//
|
||||
// listener.groupAggregationComplete(new Recipients(recipientList));
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return ContactAccessor.getInstance().getCursorLoaderForContactGroups(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
}
|
||||
}
|
@ -1,315 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Activity for selecting a list of contacts. Displayed inside
|
||||
* a ContactSelectionActivity tab frame, and ultimately called by
|
||||
* ComposeMessageActivity for selecting a list of destination contacts.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
|
||||
public class ContactSelectionListFragment extends ListFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
{
|
||||
|
||||
private final HashMap<Long, ContactData> selectedContacts = new HashMap<Long, ContactData>();
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
initializeResources();
|
||||
initializeCursor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.contact_selection_list_activity, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.contact_selection_list, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_select_all: handleSelectAll(); return true;
|
||||
case R.id.menu_unselect_all: handleUnselectAll(); return true;
|
||||
}
|
||||
|
||||
super.onOptionsItemSelected(item);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public List<ContactData> getSelectedContacts() {
|
||||
List<ContactData> contacts = new LinkedList<ContactData>();
|
||||
contacts.addAll(selectedContacts.values());
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
|
||||
private void handleUnselectAll() {
|
||||
selectedContacts.clear();
|
||||
((CursorAdapter)getListView().getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void handleSelectAll() {
|
||||
selectedContacts.clear();
|
||||
|
||||
Cursor cursor = null;
|
||||
|
||||
try {
|
||||
cursor = ContactAccessor.getInstance().getCursorForContactsWithNumbers(getActivity());
|
||||
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
ContactData contactData = ContactAccessor.getInstance().getContactData(getActivity(), cursor);
|
||||
|
||||
if (contactData.numbers.isEmpty()) continue;
|
||||
else if (contactData.numbers.size() == 1) addSingleNumberContact(contactData);
|
||||
else addMultipleNumberContact(contactData, null);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
((CursorAdapter)getListView().getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void addSingleNumberContact(ContactData contactData) {
|
||||
selectedContacts.put(contactData.id, contactData);
|
||||
}
|
||||
|
||||
private void removeContact(ContactData contactData) {
|
||||
selectedContacts.remove(contactData.id);
|
||||
}
|
||||
|
||||
private void addMultipleNumberContact(ContactData contactData, CheckedTextView textView) {
|
||||
String[] options = new String[contactData.numbers.size()];
|
||||
int i = 0;
|
||||
|
||||
for (NumberData option : contactData.numbers) {
|
||||
options[i++] = option.type + " " + option.number;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.ContactSelectionlistFragment_select_for + " " + contactData.name);
|
||||
builder.setMultiChoiceItems(options, null, new DiscriminatorClickedListener(contactData));
|
||||
builder.setPositiveButton(android.R.string.ok, new DiscriminatorFinishedListener(contactData, textView));
|
||||
builder.setOnCancelListener(new DiscriminatorFinishedListener(contactData, textView));
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void initializeCursor() {
|
||||
setListAdapter(new ContactSelectionListAdapter(getActivity(), null));
|
||||
this.getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.getListView().setFocusable(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((ContactItemView)v).selected();
|
||||
}
|
||||
|
||||
private class ContactSelectionListAdapter extends CursorAdapter {
|
||||
|
||||
public ContactSelectionListAdapter(Context context, Cursor c) {
|
||||
super(context, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
ContactItemView view = new ContactItemView(context);
|
||||
bindView(view, context, cursor);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
ContactData contactData = ContactAccessor.getInstance().getContactData(context, cursor);
|
||||
((ContactItemView)view).set(contactData);
|
||||
}
|
||||
}
|
||||
|
||||
private class ContactItemView extends RelativeLayout {
|
||||
private ContactData contactData;
|
||||
private CheckedTextView name;
|
||||
private TextView number;
|
||||
private TextView label;
|
||||
private long id;
|
||||
|
||||
public ContactItemView(Context context) {
|
||||
super(context);
|
||||
|
||||
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
li.inflate(R.layout.contact_selection_list_item, this, true);
|
||||
|
||||
this.name = (CheckedTextView)findViewById(R.id.name);
|
||||
this.number = (TextView)findViewById(R.id.number);
|
||||
this.label = (TextView)findViewById(R.id.label);
|
||||
}
|
||||
|
||||
public void selected() {
|
||||
name.toggle();
|
||||
|
||||
if (name.isChecked()) {
|
||||
if (contactData.numbers.size() == 1) addSingleNumberContact(contactData);
|
||||
else addMultipleNumberContact(contactData, name);
|
||||
} else {
|
||||
removeContact(contactData);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(ContactData contactData) {
|
||||
this.contactData = contactData;
|
||||
|
||||
if (selectedContacts.containsKey(contactData.id))
|
||||
this.name.setChecked(true);
|
||||
else
|
||||
this.name.setChecked(false);
|
||||
|
||||
this.name.setText(contactData.name);
|
||||
|
||||
if (contactData.numbers.isEmpty()) {
|
||||
this.name.setEnabled(false);
|
||||
this.number.setText("");
|
||||
this.label.setText("");
|
||||
} else {
|
||||
this.number.setText(contactData.numbers.get(0).number);
|
||||
this.label.setText(contactData.numbers.get(0).type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DiscriminatorFinishedListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
|
||||
private final ContactData contactData;
|
||||
private final CheckedTextView textView;
|
||||
|
||||
public DiscriminatorFinishedListener(ContactData contactData, CheckedTextView textView) {
|
||||
this.contactData = contactData;
|
||||
this.textView = textView;
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ContactData selected = selectedContacts.get(contactData.id);
|
||||
|
||||
if (selected == null && textView != null) {
|
||||
if (textView != null) textView.setChecked(false);
|
||||
} else if (selected.numbers.size() == 0) {
|
||||
selectedContacts.remove(selected.id);
|
||||
if (textView != null) textView.setChecked(false);
|
||||
}
|
||||
|
||||
if (textView == null)
|
||||
((CursorAdapter)getListView().getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
onClick(dialog, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private class DiscriminatorClickedListener implements DialogInterface.OnMultiChoiceClickListener {
|
||||
private final ContactData contactData;
|
||||
|
||||
public DiscriminatorClickedListener(ContactData contactData) {
|
||||
this.contactData = contactData;
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
Log.w("ContactSelectionListActivity", "Got checked: " + isChecked);
|
||||
|
||||
ContactData existing = selectedContacts.get(contactData.id);
|
||||
|
||||
if (existing == null) {
|
||||
Log.w("ContactSelectionListActivity", "No existing contact data, creating...");
|
||||
|
||||
if (!isChecked)
|
||||
throw new AssertionError("We shouldn't be unchecking data that doesn't exist.");
|
||||
|
||||
existing = new ContactData(contactData.id, contactData.name);
|
||||
selectedContacts.put(existing.id, existing);
|
||||
}
|
||||
|
||||
NumberData selectedData = contactData.numbers.get(which);
|
||||
|
||||
if (!isChecked) existing.numbers.remove(selectedData);
|
||||
else existing.numbers.add(selectedData);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return ContactAccessor.getInstance().getCursorLoaderForContactsWithNumbers(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
}
|
||||
}
|
@ -1,206 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.provider.CallLog.Calls;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckedTextView;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.NumberData;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.RedPhoneCallTypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Displays a list of recently used contacts for multi-select. Displayed
|
||||
* by the ContactSelectionActivity in a tab frame, and ultimately used by
|
||||
* ComposeMessageActivity for selecting destination message contacts.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*
|
||||
*/
|
||||
public class ContactSelectionRecentFragment extends ListFragment
|
||||
implements LoaderManager.LoaderCallbacks<Cursor>
|
||||
{
|
||||
|
||||
private final HashMap<Long, ContactData> selectedContacts = new HashMap<Long, ContactData>();
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle icicle) {
|
||||
super.onActivityCreated(icicle);
|
||||
|
||||
initializeResources();
|
||||
initializeCursor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.contact_selection_recent_activity, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
((CallItemView)v).selected();
|
||||
}
|
||||
|
||||
private void initializeCursor() {
|
||||
setListAdapter(new ContactSelectionListAdapter(getActivity(), null));
|
||||
this.getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
public List<ContactData> getSelectedContacts() {
|
||||
List<ContactData> contacts = new LinkedList<ContactData>();
|
||||
contacts.addAll(selectedContacts.values());
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private void addSingleNumberContact(ContactData contactData) {
|
||||
selectedContacts.put(contactData.id, contactData);
|
||||
}
|
||||
|
||||
private void removeContact(ContactData contactData) {
|
||||
selectedContacts.remove(contactData.id);
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.getListView().setFocusable(true);
|
||||
}
|
||||
|
||||
private class ContactSelectionListAdapter extends CursorAdapter {
|
||||
|
||||
public ContactSelectionListAdapter(Context context, Cursor c) {
|
||||
super(context, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
CallItemView view = new CallItemView(context);
|
||||
bindView(view, context, cursor);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
long id = cursor.getLong(cursor.getColumnIndexOrThrow(Calls._ID));
|
||||
String name = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NAME));
|
||||
String label = cursor.getString(cursor.getColumnIndexOrThrow(Calls.CACHED_NUMBER_LABEL));
|
||||
String number = cursor.getString(cursor.getColumnIndexOrThrow(Calls.NUMBER));
|
||||
int type = cursor.getInt(cursor.getColumnIndexOrThrow(Calls.TYPE));
|
||||
long date = cursor.getLong(cursor.getColumnIndexOrThrow(Calls.DATE));
|
||||
|
||||
((CallItemView)view).set(id, name, label, number, type, date);
|
||||
}
|
||||
}
|
||||
|
||||
private class CallItemView extends RelativeLayout {
|
||||
private ContactData contactData;
|
||||
private Context context;
|
||||
private ImageView callTypeIcon;
|
||||
private TextView date;
|
||||
private TextView label;
|
||||
private TextView number;
|
||||
private CheckedTextView line1;
|
||||
|
||||
public CallItemView(Context context) {
|
||||
super(context);
|
||||
|
||||
LayoutInflater li = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
li.inflate(R.layout.recent_call_item_selectable, this, true);
|
||||
|
||||
this.context = context;
|
||||
this.callTypeIcon = (ImageView) findViewById(R.id.call_type_icon);
|
||||
this.date = (TextView) findViewById(R.id.date);
|
||||
this.label = (TextView) findViewById(R.id.label);
|
||||
this.number = (TextView) findViewById(R.id.number);
|
||||
this.line1 = (CheckedTextView) findViewById(R.id.line1);
|
||||
}
|
||||
|
||||
public void selected() {
|
||||
line1.toggle();
|
||||
|
||||
if (line1.isChecked()) {
|
||||
addSingleNumberContact(contactData);
|
||||
} else {
|
||||
removeContact(contactData);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(long id, String name, String label, String number, int type, long date) {
|
||||
if( name == null ) {
|
||||
name = ContactAccessor.getInstance().getNameForNumber(getActivity(), number);
|
||||
}
|
||||
|
||||
this.line1.setText((name == null || name.equals("")) ? number : name);
|
||||
this.number.setText((name == null || name.equals("")) ? "" : number);
|
||||
this.label.setText(label);
|
||||
this.date.setText(DateUtils.getRelativeDateTimeString(context, date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
|
||||
if (type == Calls.INCOMING_TYPE || type == RedPhoneCallTypes.INCOMING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_incoming_call));
|
||||
else if (type == Calls.OUTGOING_TYPE || type == RedPhoneCallTypes.OUTGOING) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_outgoing_call));
|
||||
else if (type == Calls.MISSED_TYPE || type == RedPhoneCallTypes.MISSED) callTypeIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_call_log_list_missed_call));
|
||||
|
||||
this.contactData = new ContactData(id, name);
|
||||
this.contactData.numbers.add(new NumberData(null, number));
|
||||
|
||||
if (selectedContacts.containsKey(id))
|
||||
this.line1.setChecked(true);
|
||||
else
|
||||
this.line1.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return new CursorLoader(getActivity(), Calls.CONTENT_URI,
|
||||
null, null, null,
|
||||
Calls.DEFAULT_SORT_ORDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
||||
((CursorAdapter)getListAdapter()).changeCursor(null);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user