mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
261 lines
8.9 KiB
Java
261 lines
8.9 KiB
Java
/**
|
|
* 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.annotation.SuppressLint;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.database.ContentObserver;
|
|
import android.net.Uri;
|
|
import android.os.AsyncTask;
|
|
import android.os.Bundle;
|
|
import android.provider.ContactsContract;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.v4.view.MenuItemCompat;
|
|
import android.support.v7.app.ActionBar;
|
|
import android.support.v7.widget.SearchView;
|
|
import android.support.v7.widget.Toolbar;
|
|
import android.util.Log;
|
|
import android.view.Menu;
|
|
import android.view.MenuInflater;
|
|
import android.view.MenuItem;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.Toast;
|
|
|
|
import org.thoughtcrime.securesms.components.RatingManager;
|
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase;
|
|
import org.thoughtcrime.securesms.database.MessagingDatabase.MarkedMessageInfo;
|
|
import org.thoughtcrime.securesms.notifications.MarkReadReceiver;
|
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
|
import org.thoughtcrime.securesms.service.KeyCachingService;
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import java.util.List;
|
|
|
|
public class ConversationListActivity extends PassphraseRequiredActionBarActivity
|
|
implements ConversationListFragment.ConversationSelectedListener
|
|
{
|
|
private static final String TAG = ConversationListActivity.class.getSimpleName();
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
private ConversationListFragment fragment;
|
|
private ContentObserver observer;
|
|
private MasterSecret masterSecret;
|
|
|
|
@Override
|
|
protected void onPreCreate() {
|
|
dynamicTheme.onCreate(this);
|
|
dynamicLanguage.onCreate(this);
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle icicle, @NonNull MasterSecret masterSecret) {
|
|
this.masterSecret = masterSecret;
|
|
|
|
setContentView(R.layout.conversation_list_activity);
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
setSupportActionBar(toolbar);
|
|
|
|
fragment = initFragment(R.id.fragment_container, new ConversationListFragment(), masterSecret, dynamicLanguage.getCurrentLocale());
|
|
|
|
initializeContactUpdatesReceiver();
|
|
|
|
RatingManager.showRatingDialogIfNecessary(this);
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
dynamicTheme.onResume(this);
|
|
dynamicLanguage.onResume(this);
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
if (observer != null) getContentResolver().unregisterContentObserver(observer);
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
MenuInflater inflater = this.getMenuInflater();
|
|
menu.clear();
|
|
|
|
inflater.inflate(R.menu.text_secure_normal, menu);
|
|
|
|
menu.findItem(R.id.menu_clear_passphrase).setVisible(!TextSecurePreferences.isPasswordDisabled(this));
|
|
|
|
inflater.inflate(R.menu.conversation_list, menu);
|
|
MenuItem menuItem = menu.findItem(R.id.menu_search);
|
|
initializeSearch(menuItem);
|
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
return true;
|
|
}
|
|
|
|
private void initializeSearch(MenuItem searchViewItem) {
|
|
SearchView searchView = (SearchView)MenuItemCompat.getActionView(searchViewItem);
|
|
searchView.setQueryHint(getString(R.string.ConversationListActivity_search));
|
|
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
@Override
|
|
public boolean onQueryTextSubmit(String query) {
|
|
if (fragment != null) {
|
|
fragment.setQueryFilter(query);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean onQueryTextChange(String newText) {
|
|
return onQueryTextSubmit(newText);
|
|
}
|
|
});
|
|
|
|
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;
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
super.onOptionsItemSelected(item);
|
|
|
|
switch (item.getItemId()) {
|
|
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;
|
|
case R.id.menu_help: handleHelp(); return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void onCreateConversation(long threadId, Recipient recipient, int distributionType, long lastSeen) {
|
|
Intent intent = new Intent(this, ConversationActivity.class);
|
|
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, recipient.getAddress());
|
|
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
|
intent.putExtra(ConversationActivity.DISTRIBUTION_TYPE_EXTRA, distributionType);
|
|
intent.putExtra(ConversationActivity.TIMING_EXTRA, System.currentTimeMillis());
|
|
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, lastSeen);
|
|
|
|
startActivity(intent);
|
|
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
private void handleDisplaySettings() {
|
|
Intent preferencesIntent = new Intent(this, ApplicationPreferencesActivity.class);
|
|
startActivity(preferencesIntent);
|
|
}
|
|
|
|
private void handleClearPassphrase() {
|
|
Intent intent = new Intent(this, KeyCachingService.class);
|
|
intent.setAction(KeyCachingService.CLEAR_KEY_ACTION);
|
|
startService(intent);
|
|
}
|
|
|
|
private void handleImportExport() {
|
|
startActivity(new Intent(this, ImportExportActivity.class));
|
|
}
|
|
|
|
@SuppressLint("StaticFieldLeak")
|
|
private void handleMarkAllRead() {
|
|
new AsyncTask<Void, Void, Void>() {
|
|
@Override
|
|
protected Void doInBackground(Void... params) {
|
|
Context context = ConversationListActivity.this;
|
|
List<MarkedMessageInfo> messageIds = DatabaseFactory.getThreadDatabase(context).setAllThreadsRead();
|
|
|
|
MessageNotifier.updateNotification(context, masterSecret);
|
|
MarkReadReceiver.process(context, messageIds);
|
|
|
|
return null;
|
|
}
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
}
|
|
|
|
private void handleInvite() {
|
|
startActivity(new Intent(this, InviteActivity.class));
|
|
}
|
|
|
|
private void handleHelp() {
|
|
try {
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://support.whispersystems.org")));
|
|
} catch (ActivityNotFoundException e) {
|
|
Toast.makeText(this, R.string.ConversationListActivity_there_is_no_browser_installed_on_your_device, Toast.LENGTH_LONG).show();
|
|
}
|
|
}
|
|
|
|
private void initializeContactUpdatesReceiver() {
|
|
observer = new ContentObserver(null) {
|
|
@Override
|
|
public void onChange(boolean selfChange) {
|
|
super.onChange(selfChange);
|
|
Log.w(TAG, "Detected android contact data changed, refreshing cache");
|
|
Recipient.clearCache(ConversationListActivity.this);
|
|
ConversationListActivity.this.runOnUiThread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
fragment.getListAdapter().notifyDataSetChanged();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI,
|
|
true, observer);
|
|
}
|
|
}
|