2014-08-15 08:11:06 +02:00
|
|
|
/**
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2012-07-19 00:35:13 +02:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2016-08-14 12:23:51 +02:00
|
|
|
import android.content.ActivityNotFoundException;
|
2012-07-19 00:35:13 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.ContentObserver;
|
2015-11-24 01:02:05 +01:00
|
|
|
import android.net.Uri;
|
2013-05-06 22:59:40 +02:00
|
|
|
import android.os.AsyncTask;
|
2012-07-19 00:35:13 +02:00
|
|
|
import android.os.Bundle;
|
2012-10-23 04:17:08 +02:00
|
|
|
import android.provider.ContactsContract;
|
2014-12-15 21:25:55 +01:00
|
|
|
import android.support.annotation.NonNull;
|
2015-01-21 08:26:58 +01:00
|
|
|
import android.support.v7.app.ActionBar;
|
2012-07-19 00:35:13 +02:00
|
|
|
import android.util.Log;
|
2014-06-29 05:40:57 +02:00
|
|
|
import android.support.v4.view.MenuItemCompat;
|
|
|
|
import android.support.v7.widget.SearchView;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2016-08-14 12:23:51 +02:00
|
|
|
import android.widget.Toast;
|
2013-12-02 21:31:59 +01:00
|
|
|
|
2015-03-31 21:34:49 +02:00
|
|
|
import org.thoughtcrime.securesms.components.RatingManager;
|
2014-11-08 20:35:58 +01:00
|
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
2013-05-06 22:59:40 +02:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
2012-07-19 00:35:13 +02:00
|
|
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
2014-11-08 20:35:58 +01:00
|
|
|
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
2012-07-19 00:35:13 +02:00
|
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
2013-06-30 03:03:55 +02:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
2013-06-21 20:56:59 +02:00
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2013-12-19 05:15:21 +01:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2012-07-19 00:35:13 +02:00
|
|
|
|
2014-06-29 05:40:57 +02:00
|
|
|
public class ConversationListActivity extends PassphraseRequiredActionBarActivity
|
2014-08-15 08:11:06 +02:00
|
|
|
implements ConversationListFragment.ConversationSelectedListener
|
2014-12-15 21:25:55 +01:00
|
|
|
{
|
2015-04-04 10:38:44 +02:00
|
|
|
private static final String TAG = ConversationListActivity.class.getSimpleName();
|
|
|
|
|
2013-06-30 03:03:55 +02:00
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme ();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
2012-07-19 00:35:13 +02:00
|
|
|
|
|
|
|
private ConversationListFragment fragment;
|
2014-04-25 01:40:54 +02:00
|
|
|
private ContentObserver observer;
|
2014-12-15 21:25:55 +01:00
|
|
|
private MasterSecret masterSecret;
|
2012-07-19 00:35:13 +02:00
|
|
|
|
|
|
|
@Override
|
2014-12-15 21:25:55 +01:00
|
|
|
protected void onPreCreate() {
|
2013-06-21 20:56:59 +02:00
|
|
|
dynamicTheme.onCreate(this);
|
2013-06-30 03:03:55 +02:00
|
|
|
dynamicLanguage.onCreate(this);
|
2014-12-15 21:25:55 +01:00
|
|
|
}
|
2015-01-21 08:26:58 +01:00
|
|
|
|
2014-12-15 21:25:55 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
|
|
|
|
this.masterSecret = masterSecret;
|
2014-01-08 23:29:05 +01:00
|
|
|
|
2014-12-15 21:25:55 +01:00
|
|
|
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
|
2014-04-08 22:14:40 +02:00
|
|
|
getSupportActionBar().setTitle(R.string.app_name);
|
2015-03-19 21:08:48 +01:00
|
|
|
fragment = initFragment(android.R.id.content, new ConversationListFragment(), masterSecret, dynamicLanguage.getCurrentLocale());
|
2012-07-19 00:35:13 +02:00
|
|
|
|
|
|
|
initializeContactUpdatesReceiver();
|
2013-10-13 13:38:26 +02:00
|
|
|
|
2015-03-31 21:34:49 +02:00
|
|
|
RatingManager.showRatingDialogIfNecessary(this);
|
2012-07-19 00:35:13 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 20:56:59 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
2013-06-30 03:03:55 +02:00
|
|
|
dynamicLanguage.onResume(this);
|
2013-06-21 20:56:59 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
2014-04-25 01:40:54 +02:00
|
|
|
if (observer != null) getContentResolver().unregisterContentObserver(observer);
|
2012-07-19 00:35:13 +02:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
2014-06-29 05:40:57 +02:00
|
|
|
MenuInflater inflater = this.getMenuInflater();
|
2012-07-19 00:35:13 +02:00
|
|
|
menu.clear();
|
|
|
|
|
2013-02-17 20:42:30 +01:00
|
|
|
inflater.inflate(R.menu.text_secure_normal, menu);
|
2012-07-19 00:35:13 +02:00
|
|
|
|
2013-12-19 05:15:21 +01:00
|
|
|
menu.findItem(R.id.menu_clear_passphrase).setVisible(!TextSecurePreferences.isPasswordDisabled(this));
|
|
|
|
|
2014-12-15 21:25:55 +01:00
|
|
|
inflater.inflate(R.menu.conversation_list, menu);
|
|
|
|
MenuItem menuItem = menu.findItem(R.id.menu_search);
|
|
|
|
initializeSearch(menuItem);
|
2014-06-29 05:40:57 +02:00
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-26 23:24:55 +01:00
|
|
|
private void initializeSearch(MenuItem searchViewItem) {
|
|
|
|
SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchViewItem);
|
2015-05-27 12:19:11 +02:00
|
|
|
searchView.setQueryHint(getString(R.string.ConversationListActivity_search));
|
2014-06-29 05:40:57 +02:00
|
|
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String query) {
|
|
|
|
if (fragment != null) {
|
|
|
|
fragment.setQueryFilter(query);
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-26 23:24:55 +01:00
|
|
|
|
2014-06-29 05:40:57 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-26 23:24:55 +01:00
|
|
|
|
2014-06-29 05:40:57 +02:00
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String newText) {
|
|
|
|
return onQueryTextSubmit(newText);
|
|
|
|
}
|
|
|
|
});
|
2014-10-26 23:24:55 +01:00
|
|
|
|
|
|
|
MenuItemCompat.setOnActionExpandListener(searchViewItem, new MenuItemCompat.OnActionExpandListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionExpand(MenuItem menuItem) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
|
|
|
|
if (fragment != null) {
|
|
|
|
fragment.resetQueryFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-06-29 05:40:57 +02:00
|
|
|
}
|
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
super.onOptionsItemSelected(item);
|
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
2015-10-19 20:23:12 +02:00
|
|
|
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 R.id.menu_import_export: handleImportExport(); return true;
|
|
|
|
case R.id.menu_invite: handleInvite(); return true;
|
2015-11-24 01:02:05 +01:00
|
|
|
case R.id.menu_help: handleHelp(); return true;
|
2012-07-19 00:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-14 07:35:47 +01:00
|
|
|
public void onCreateConversation(long threadId, Recipients recipients, int distributionType, long lastSeen) {
|
2012-07-19 23:22:03 +02:00
|
|
|
Intent intent = new Intent(this, ConversationActivity.class);
|
2014-12-18 03:14:19 +01:00
|
|
|
intent.putExtra(ConversationActivity.RECIPIENTS_EXTRA, recipients.getIds());
|
2013-02-03 05:37:40 +01:00
|
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
2013-04-26 03:59:49 +02:00
|
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);
|
2017-01-19 20:37:19 +01:00
|
|
|
intent.putExtra(ConversationActivity.TIMING_EXTRA, System.currentTimeMillis());
|
2017-02-14 07:35:47 +01:00
|
|
|
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, lastSeen);
|
2013-02-03 05:37:40 +01:00
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
startActivity(intent);
|
2015-06-22 17:46:43 +02:00
|
|
|
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
2012-07-19 00:35:13 +02:00
|
|
|
}
|
|
|
|
|
2015-11-24 00:07:41 +01:00
|
|
|
@Override
|
|
|
|
public void onSwitchToArchive() {
|
|
|
|
Intent intent = new Intent(this, ConversationListArchiveActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createGroup() {
|
|
|
|
Intent intent = new Intent(this, GroupCreateActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
private void handleDisplaySettings() {
|
|
|
|
Intent preferencesIntent = new Intent(this, ApplicationPreferencesActivity.class);
|
|
|
|
startActivity(preferencesIntent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleClearPassphrase() {
|
2013-02-08 20:57:54 +01:00
|
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
|
|
intent.setAction(KeyCachingService.CLEAR_KEY_ACTION);
|
|
|
|
startService(intent);
|
2012-07-19 00:35:13 +02:00
|
|
|
}
|
|
|
|
|
2014-08-15 08:11:06 +02:00
|
|
|
private void handleImportExport() {
|
2014-12-15 21:25:55 +01:00
|
|
|
startActivity(new Intent(this, ImportExportActivity.class));
|
2014-08-15 08:11:06 +02:00
|
|
|
}
|
|
|
|
|
2013-05-06 22:59:40 +02:00
|
|
|
private void handleMarkAllRead() {
|
|
|
|
new AsyncTask<Void, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Void... params) {
|
|
|
|
DatabaseFactory.getThreadDatabase(ConversationListActivity.this).setAllThreadsRead();
|
|
|
|
MessageNotifier.updateNotification(ConversationListActivity.this, masterSecret);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
|
2015-10-19 20:23:12 +02:00
|
|
|
private void handleInvite() {
|
|
|
|
startActivity(new Intent(this, InviteActivity.class));
|
|
|
|
}
|
|
|
|
|
2015-11-24 01:02:05 +01:00
|
|
|
private void handleHelp() {
|
2016-08-14 12:23:51 +02:00
|
|
|
try {
|
2017-01-16 01:52:58 +01:00
|
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://support.whispersystems.org")));
|
2016-08-14 12:23:51 +02:00
|
|
|
} catch (ActivityNotFoundException e) {
|
|
|
|
Toast.makeText(this, R.string.ConversationListActivity_there_is_no_browser_installed_on_your_device, Toast.LENGTH_LONG).show();
|
|
|
|
}
|
2015-11-24 01:02:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-19 00:35:13 +02:00
|
|
|
private void initializeContactUpdatesReceiver() {
|
2014-04-25 01:40:54 +02:00
|
|
|
observer = new ContentObserver(null) {
|
2012-07-19 00:35:13 +02:00
|
|
|
@Override
|
|
|
|
public void onChange(boolean selfChange) {
|
|
|
|
super.onChange(selfChange);
|
2015-07-17 19:16:14 +02:00
|
|
|
Log.w(TAG, "Detected android contact data changed, refreshing cache");
|
2016-08-16 05:23:56 +02:00
|
|
|
RecipientFactory.clearCache(ConversationListActivity.this);
|
2014-04-25 01:40:54 +02:00
|
|
|
ConversationListActivity.this.runOnUiThread(new Runnable() {
|
2015-04-04 10:38:44 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
fragment.getListAdapter().notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
2012-07-19 00:35:13 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
|
2012-07-19 00:35:13 +02:00
|
|
|
true, observer);
|
|
|
|
}
|
2013-12-02 21:31:59 +01:00
|
|
|
}
|