2012-07-21 05:23:25 +00:00
|
|
|
/**
|
2011-12-20 18:20:44 +00:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-21 05:23:25 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* 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.
|
2012-07-21 05:23:25 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* 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;
|
2012-07-21 05:23:25 +00:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
|
|
2013-02-11 01:30:51 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2013-06-21 18:56:59 +00:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2013-02-11 01:30:51 +00:00
|
|
|
|
2012-07-21 05:23:25 +00:00
|
|
|
import com.actionbarsherlock.app.ActionBar;
|
|
|
|
import com.actionbarsherlock.app.ActionBar.Tab;
|
|
|
|
import com.actionbarsherlock.app.ActionBar.TabListener;
|
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
import com.actionbarsherlock.view.MenuInflater;
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2012-07-21 05:23:25 +00:00
|
|
|
*
|
2011-12-20 18:20:44 +00:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
2013-02-11 01:30:51 +00:00
|
|
|
public class ContactSelectionActivity extends PassphraseRequiredSherlockFragmentActivity {
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
|
2012-07-21 05:23:25 +00:00
|
|
|
private ContactSelectionListFragment contactsFragment;
|
|
|
|
private ContactSelectionGroupsFragment groupsFragment;
|
|
|
|
private ContactSelectionRecentFragment recentFragment;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-07-21 05:23:25 +00:00
|
|
|
private Recipients recipients;
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle) {
|
2013-06-21 18:56:59 +00:00
|
|
|
dynamicTheme.onCreate(this);
|
2011-12-20 18:20:44 +00:00
|
|
|
super.onCreate(icicle);
|
|
|
|
|
2012-07-21 05:23:25 +00:00
|
|
|
ActionBar actionBar = this.getSupportActionBar();
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
2011-12-20 18:20:44 +00:00
|
|
|
|
2012-07-21 05:23:25 +00:00
|
|
|
setContentView(R.layout.contact_selection_activity);
|
2011-12-20 18:20:44 +00:00
|
|
|
|
|
|
|
setupContactsTab();
|
|
|
|
setupGroupsTab();
|
|
|
|
setupRecentTab();
|
|
|
|
}
|
2012-07-21 05:23:25 +00:00
|
|
|
|
2013-06-21 18:56:59 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
@Override
|
2012-07-21 05:23:25 +00:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
MenuInflater inflater = this.getSupportMenuInflater();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-20 18:20:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-21 05:23:25 +00:00
|
|
|
|
|
|
|
private void handleSelectionFinished() {
|
|
|
|
recipients = contactsFragment.getSelectedContacts();
|
|
|
|
recipients.append(recentFragment.getSelectedContacts());
|
2013-05-31 03:35:56 +00:00
|
|
|
recipients.append(groupsFragment.getSelectedContacts(this));
|
2012-07-21 05:23:25 +00:00
|
|
|
|
|
|
|
Intent resultIntent = getIntent();
|
|
|
|
resultIntent.putExtra("recipients", this.recipients);
|
|
|
|
|
|
|
|
setResult(RESULT_OK, resultIntent);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ActionBar.Tab constructTab(final Fragment fragment) {
|
|
|
|
ActionBar actionBar = this.getSupportActionBar();
|
|
|
|
ActionBar.Tab tab = actionBar.newTab();
|
|
|
|
|
|
|
|
tab.setTabListener(new TabListener(){
|
|
|
|
@Override
|
|
|
|
public void onTabSelected(Tab tab, FragmentTransaction ignore) {
|
|
|
|
FragmentManager manager = ContactSelectionActivity.this.getSupportFragmentManager();
|
|
|
|
FragmentTransaction ft = manager.beginTransaction();
|
|
|
|
|
|
|
|
ft.add(R.id.fragment_container, fragment);
|
|
|
|
ft.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabUnselected(Tab tab, FragmentTransaction ignore) {
|
|
|
|
FragmentManager manager = ContactSelectionActivity.this.getSupportFragmentManager();
|
|
|
|
FragmentTransaction ft = manager.beginTransaction();
|
|
|
|
ft.remove(fragment);
|
|
|
|
ft.commit();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onTabReselected(Tab tab, FragmentTransaction ft) {}
|
|
|
|
});
|
|
|
|
|
|
|
|
return tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupContactsTab() {
|
|
|
|
contactsFragment = (ContactSelectionListFragment)Fragment.instantiate(this,
|
|
|
|
ContactSelectionListFragment.class.getName());
|
|
|
|
ActionBar.Tab contactsTab = constructTab(contactsFragment);
|
|
|
|
contactsTab.setIcon(R.drawable.ic_tab_contacts);
|
|
|
|
this.getSupportActionBar().addTab(contactsTab);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupGroupsTab() {
|
|
|
|
groupsFragment = (ContactSelectionGroupsFragment)Fragment.instantiate(this,
|
|
|
|
ContactSelectionGroupsFragment.class.getName());
|
|
|
|
ActionBar.Tab groupsTab = constructTab(groupsFragment);
|
|
|
|
groupsTab.setIcon(R.drawable.ic_tab_groups);
|
|
|
|
this.getSupportActionBar().addTab(groupsTab);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setupRecentTab() {
|
|
|
|
recentFragment = (ContactSelectionRecentFragment)Fragment.instantiate(this,
|
|
|
|
ContactSelectionRecentFragment.class.getName());
|
|
|
|
|
|
|
|
ActionBar.Tab recentTab = constructTab(recentFragment);
|
|
|
|
recentTab.setIcon(R.drawable.ic_tab_recent);
|
|
|
|
this.getSupportActionBar().addTab(recentTab);
|
|
|
|
}
|
2011-12-20 18:20:44 +00:00
|
|
|
}
|