2018-01-24 19:17:44 -08:00
|
|
|
/*
|
2015-07-14 14:31:03 -07:00
|
|
|
* Copyright (C) 2015 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;
|
|
|
|
|
2015-07-15 14:27:37 -07:00
|
|
|
import android.content.Context;
|
2015-07-14 14:31:03 -07:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
|
|
2015-10-19 11:23:12 -07:00
|
|
|
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
|
2018-03-27 22:13:27 -07:00
|
|
|
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode;
|
2019-07-24 12:30:23 +10:00
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2015-07-14 14:31:03 -07:00
|
|
|
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
2015-10-19 11:23:12 -07:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2015-07-14 14:31:03 -07:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2015-07-15 14:27:37 -07:00
|
|
|
import java.lang.ref.WeakReference;
|
2015-07-14 14:31:03 -07:00
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-07-14 14:31:03 -07:00
|
|
|
/**
|
|
|
|
* Base activity container for selecting a list of contacts.
|
|
|
|
*
|
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public abstract class ContactSelectionActivity extends PassphraseRequiredActionBarActivity
|
|
|
|
implements SwipeRefreshLayout.OnRefreshListener,
|
|
|
|
ContactSelectionListFragment.OnContactSelectedListener
|
|
|
|
{
|
2015-10-19 11:23:12 -07:00
|
|
|
private static final String TAG = ContactSelectionActivity.class.getSimpleName();
|
2015-07-14 14:31:03 -07:00
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
protected ContactSelectionListFragment contactsFragment;
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
private ContactFilterToolbar toolbar;
|
2015-07-14 14:31:03 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPreCreate() {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-02-01 19:22:48 -08:00
|
|
|
protected void onCreate(Bundle icicle, boolean ready) {
|
2015-10-19 11:23:12 -07:00
|
|
|
if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
|
2018-03-27 22:13:27 -07:00
|
|
|
int displayMode = TextSecurePreferences.isSmsEnabled(this) ? DisplayMode.FLAG_ALL
|
|
|
|
: DisplayMode.FLAG_PUSH | DisplayMode.FLAG_GROUPS;
|
|
|
|
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode);
|
2015-10-19 11:23:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
setContentView(R.layout.contact_selection_activity);
|
2015-07-14 14:31:03 -07:00
|
|
|
|
|
|
|
initializeToolbar();
|
|
|
|
initializeResources();
|
|
|
|
initializeSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
2015-10-19 11:23:12 -07:00
|
|
|
protected ContactFilterToolbar getToolbar() {
|
|
|
|
return toolbar;
|
|
|
|
}
|
|
|
|
|
2015-07-14 14:31:03 -07:00
|
|
|
private void initializeToolbar() {
|
2015-10-19 11:23:12 -07:00
|
|
|
this.toolbar = ViewUtil.findById(this, R.id.toolbar);
|
2015-07-14 14:31:03 -07:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2018-01-24 19:17:44 -08:00
|
|
|
assert getSupportActionBar() != null;
|
2015-07-14 14:31:03 -07:00
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
|
|
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
2016-12-17 15:52:27 -08:00
|
|
|
getSupportActionBar().setIcon(null);
|
|
|
|
getSupportActionBar().setLogo(null);
|
2015-07-14 14:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeResources() {
|
|
|
|
contactsFragment = (ContactSelectionListFragment) getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
|
|
|
|
contactsFragment.setOnContactSelectedListener(this);
|
|
|
|
contactsFragment.setOnRefreshListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeSearch() {
|
2018-01-24 19:17:44 -08:00
|
|
|
toolbar.setOnFilterChangedListener(filter -> contactsFragment.setQueryFilter(filter));
|
2015-07-14 14:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRefresh() {
|
2017-10-23 13:03:32 -07:00
|
|
|
new RefreshDirectoryTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getApplicationContext());
|
2015-07-14 14:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContactSelected(String number) {}
|
|
|
|
|
2015-10-19 11:23:12 -07:00
|
|
|
@Override
|
|
|
|
public void onContactDeselected(String number) {}
|
2015-07-15 14:27:37 -07:00
|
|
|
|
|
|
|
private static class RefreshDirectoryTask extends AsyncTask<Context, Void, Void> {
|
|
|
|
|
|
|
|
private final WeakReference<ContactSelectionActivity> activity;
|
|
|
|
|
|
|
|
private RefreshDirectoryTask(ContactSelectionActivity activity) {
|
2018-01-24 19:17:44 -08:00
|
|
|
this.activity = new WeakReference<>(activity);
|
2015-07-15 14:27:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(Context... params) {
|
2015-10-27 12:18:02 -07:00
|
|
|
|
2015-07-15 14:27:37 -07:00
|
|
|
try {
|
2018-01-24 19:17:44 -08:00
|
|
|
DirectoryHelper.refreshDirectory(params[0], true);
|
2015-07-15 14:27:37 -07:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Void result) {
|
|
|
|
ContactSelectionActivity activity = this.activity.get();
|
|
|
|
|
|
|
|
if (activity != null && !activity.isFinishing()) {
|
2015-10-19 11:23:12 -07:00
|
|
|
activity.toolbar.clear();
|
2015-07-15 14:27:37 -07:00
|
|
|
activity.contactsFragment.resetQueryFilter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-14 14:31:03 -07:00
|
|
|
}
|