|
|
|
@ -1,23 +1,27 @@
|
|
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2014 Open 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.Activity;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.database.ContentObserver;
|
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
|
import android.provider.Telephony;
|
|
|
|
|
import android.support.v4.app.ActionBarDrawerToggle;
|
|
|
|
|
import android.support.v4.view.GravityCompat;
|
|
|
|
|
import android.support.v4.widget.DrawerLayout;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
import android.widget.SimpleAdapter;
|
|
|
|
|
|
|
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
|
import com.actionbarsherlock.view.MenuInflater;
|
|
|
|
@ -25,7 +29,6 @@ import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
|
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
|
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
|
|
|
@ -34,26 +37,18 @@ import org.thoughtcrime.securesms.service.SendReceiveService;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class ConversationListActivity extends PassphraseRequiredSherlockFragmentActivity
|
|
|
|
|
implements ConversationListFragment.ConversationSelectedListener,
|
|
|
|
|
ListView.OnItemClickListener
|
|
|
|
|
implements ConversationListFragment.ConversationSelectedListener
|
|
|
|
|
{
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme ();
|
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
|
|
private ConversationListFragment fragment;
|
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
|
private DrawerLayout drawerLayout;
|
|
|
|
|
private DrawerToggle drawerToggle;
|
|
|
|
|
private ListView drawerList;
|
|
|
|
|
private ContentObserver observer;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -66,7 +61,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
|
|
|
|
|
getSupportActionBar().setTitle(R.string.app_name);
|
|
|
|
|
|
|
|
|
|
initializeNavigationDrawer();
|
|
|
|
|
initializeSenderReceiverService();
|
|
|
|
|
initializeResources();
|
|
|
|
|
initializeContactUpdatesReceiver();
|
|
|
|
@ -77,7 +71,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
@Override
|
|
|
|
|
public void onPostCreate(Bundle bundle) {
|
|
|
|
|
super.onPostCreate(bundle);
|
|
|
|
|
drawerToggle.syncState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -115,40 +108,18 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(AdapterView parent, View view, int position, long id) {
|
|
|
|
|
String[] values = getResources().getStringArray(R.array.navigation_drawer_values);
|
|
|
|
|
String selected = values[position];
|
|
|
|
|
|
|
|
|
|
Intent intent;
|
|
|
|
|
|
|
|
|
|
if (selected.equals("import_export")) {
|
|
|
|
|
intent = new Intent(this, ImportExportActivity.class);
|
|
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
|
} else if (selected.equals("my_identity_key")) {
|
|
|
|
|
intent = new Intent(this, ViewLocalIdentityActivity.class);
|
|
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
|
} else {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drawerLayout.closeDrawers();
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
|
|
|
|
|
|
int defaultType = ThreadDatabase.DistributionTypes.DEFAULT;
|
|
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
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;
|
|
|
|
|
case R.id.menu_import_export: handleImportExport(); return true;
|
|
|
|
|
case R.id.menu_my_identity: handleMyIdentity(); return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
@ -181,14 +152,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleNavigationDrawerToggle() {
|
|
|
|
|
if (drawerLayout.isDrawerOpen(drawerList)) {
|
|
|
|
|
drawerLayout.closeDrawer(drawerList);
|
|
|
|
|
} else {
|
|
|
|
|
drawerLayout.openDrawer(drawerList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleDisplaySettings() {
|
|
|
|
|
Intent preferencesIntent = new Intent(this, ApplicationPreferencesActivity.class);
|
|
|
|
|
preferencesIntent.putExtra("master_secret", masterSecret);
|
|
|
|
@ -201,6 +164,18 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
startService(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleImportExport() {
|
|
|
|
|
final Intent intent = new Intent(this, ImportExportActivity.class);
|
|
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleMyIdentity() {
|
|
|
|
|
final Intent intent = new Intent(this, ViewLocalIdentityActivity.class);
|
|
|
|
|
intent.putExtra("master_secret", masterSecret);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleMarkAllRead() {
|
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
|
@Override
|
|
|
|
@ -212,47 +187,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
}.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeNavigationDrawer() {
|
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
getSupportActionBar().setHomeButtonEnabled(true);
|
|
|
|
|
|
|
|
|
|
int[] attributes = new int[] {R.attr.navigation_drawer_icons, R.attr.navigation_drawer_shadow};
|
|
|
|
|
String[] from = new String[]{"navigation_icon", "navigation_text" };
|
|
|
|
|
int[] to = new int[] {R.id.navigation_icon, R.id.navigation_text};
|
|
|
|
|
|
|
|
|
|
TypedArray iconArray = obtainStyledAttributes(attributes);
|
|
|
|
|
int iconArrayResource = iconArray.getResourceId(0, -1);
|
|
|
|
|
TypedArray icons = getResources().obtainTypedArray(iconArrayResource);
|
|
|
|
|
String[] text = getResources().getStringArray(R.array.navigation_drawer_text);
|
|
|
|
|
|
|
|
|
|
List<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < text.length; i++){
|
|
|
|
|
HashMap<String, String> item = new HashMap<String, String>();
|
|
|
|
|
item.put("navigation_icon", Integer.toString(icons.getResourceId(i, -1)));
|
|
|
|
|
item.put("navigation_text", text[i]);
|
|
|
|
|
items.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawerLayout drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
|
|
|
|
|
drawerToggle = new DrawerToggle(this, drawerLayout,
|
|
|
|
|
R.drawable.ic_drawer,
|
|
|
|
|
R.string.conversation_list__drawer_open,
|
|
|
|
|
R.string.conversation_list__drawer_close);
|
|
|
|
|
|
|
|
|
|
drawerLayout.setDrawerListener(drawerToggle);
|
|
|
|
|
|
|
|
|
|
ListView drawer = (ListView)findViewById(R.id.left_drawer);
|
|
|
|
|
SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.navigation_drawer_item, from, to);
|
|
|
|
|
|
|
|
|
|
drawerLayout.setDrawerShadow(iconArray.getDrawable(1), GravityCompat.START);
|
|
|
|
|
drawer.setAdapter(adapter);
|
|
|
|
|
drawer.setOnItemClickListener(this);
|
|
|
|
|
|
|
|
|
|
iconArray.recycle();
|
|
|
|
|
icons.recycle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeContactUpdatesReceiver() {
|
|
|
|
|
observer = new ContentObserver(null) {
|
|
|
|
|
@Override
|
|
|
|
@ -284,8 +218,6 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initializeResources() {
|
|
|
|
|
this.drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
|
|
|
|
|
this.drawerList = (ListView)findViewById(R.id.left_drawer);
|
|
|
|
|
this.masterSecret = getIntent().getParcelableExtra("master_secret");
|
|
|
|
|
|
|
|
|
|
this.fragment = (ConversationListFragment)this.getSupportFragmentManager()
|
|
|
|
@ -293,32 +225,4 @@ public class ConversationListActivity extends PassphraseRequiredSherlockFragment
|
|
|
|
|
|
|
|
|
|
this.fragment.setMasterSecret(masterSecret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DrawerToggle extends ActionBarDrawerToggle {
|
|
|
|
|
|
|
|
|
|
public DrawerToggle(Activity activity, DrawerLayout drawerLayout,
|
|
|
|
|
int drawerImageRes, int openDrawerContentDescRes,
|
|
|
|
|
int closeDrawerContentDescRes) {
|
|
|
|
|
|
|
|
|
|
super(activity, drawerLayout, drawerImageRes,
|
|
|
|
|
openDrawerContentDescRes, closeDrawerContentDescRes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDrawerClosed(View drawerView) {
|
|
|
|
|
|
|
|
|
|
super.onDrawerClosed(drawerView);
|
|
|
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDrawerOpened(View drawerView) {
|
|
|
|
|
|
|
|
|
|
super.onDrawerOpened(drawerView);
|
|
|
|
|
fragment.resetQueryFilter();
|
|
|
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|