That fuck shit the fascists are using
1/*
2 * Copyright (C) 2015 Open Whisper Systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17package org.tm.archive;
18
19import android.content.Context;
20import android.os.AsyncTask;
21import android.os.Bundle;
22
23import androidx.annotation.NonNull;
24import androidx.appcompat.widget.Toolbar;
25import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
26
27import org.signal.core.util.DimensionUnit;
28import org.signal.core.util.logging.Log;
29import org.tm.archive.components.ContactFilterView;
30import org.tm.archive.contacts.ContactSelectionDisplayMode;
31import org.tm.archive.contacts.sync.ContactDiscovery;
32import org.tm.archive.keyvalue.SignalStore;
33import org.tm.archive.recipients.RecipientId;
34import org.tm.archive.util.DisplayMetricsUtil;
35import org.tm.archive.util.DynamicNoActionBarTheme;
36import org.tm.archive.util.DynamicTheme;
37import org.tm.archive.util.FeatureFlags;
38import org.tm.archive.util.ServiceUtil;
39import org.tm.archive.util.Util;
40
41import java.io.IOException;
42import java.lang.ref.WeakReference;
43import java.util.Optional;
44import java.util.function.Consumer;
45
46/**
47 * Base activity container for selecting a list of contacts.
48 *
49 * @author Moxie Marlinspike
50 *
51 */
52public abstract class ContactSelectionActivity extends PassphraseRequiredActivity
53 implements SwipeRefreshLayout.OnRefreshListener,
54 ContactSelectionListFragment.OnContactSelectedListener,
55 ContactSelectionListFragment.ScrollCallback
56{
57 private static final String TAG = Log.tag(ContactSelectionActivity.class);
58
59 public static final String EXTRA_LAYOUT_RES_ID = "layout_res_id";
60
61 private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
62
63 protected ContactSelectionListFragment contactsFragment;
64
65 private Toolbar toolbar;
66 private ContactFilterView contactFilterView;
67
68 @Override
69 protected void onPreCreate() {
70 dynamicTheme.onCreate(this);
71 }
72
73 @Override
74 protected void onCreate(Bundle icicle, boolean ready) {
75 if (!getIntent().hasExtra(ContactSelectionListFragment.DISPLAY_MODE)) {
76 int displayMode = ContactSelectionDisplayMode.FLAG_PUSH | ContactSelectionDisplayMode.FLAG_ACTIVE_GROUPS | ContactSelectionDisplayMode.FLAG_INACTIVE_GROUPS | ContactSelectionDisplayMode.FLAG_SELF;
77 getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, displayMode);
78 }
79
80 setContentView(getIntent().getIntExtra(EXTRA_LAYOUT_RES_ID, R.layout.contact_selection_activity));
81
82 initializeContactFilterView();
83 initializeToolbar();
84 initializeResources();
85 initializeSearch();
86 }
87
88 @Override
89 public void onResume() {
90 super.onResume();
91 dynamicTheme.onResume(this);
92 }
93
94 protected Toolbar getToolbar() {
95 return toolbar;
96 }
97
98 protected ContactFilterView getContactFilterView() {
99 return contactFilterView;
100 }
101
102 private void initializeContactFilterView() {
103 this.contactFilterView = findViewById(R.id.contact_filter_edit_text);
104
105 if (getResources().getDisplayMetrics().heightPixels >= DimensionUnit.DP.toPixels(600)) {
106 this.contactFilterView.focusAndShowKeyboard();
107 }
108 }
109
110 private void initializeToolbar() {
111 this.toolbar = findViewById(R.id.toolbar);
112 setSupportActionBar(toolbar);
113
114 getSupportActionBar().setDisplayHomeAsUpEnabled(false);
115 getSupportActionBar().setIcon(null);
116 getSupportActionBar().setLogo(null);
117 }
118
119 private void initializeResources() {
120 contactsFragment = (ContactSelectionListFragment) getSupportFragmentManager().findFragmentById(R.id.contact_selection_list_fragment);
121 contactsFragment.setOnRefreshListener(this);
122 }
123
124 private void initializeSearch() {
125 contactFilterView.setOnFilterChangedListener(filter -> contactsFragment.setQueryFilter(filter));
126 }
127
128 @Override
129 public void onRefresh() {
130 new RefreshDirectoryTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getApplicationContext());
131 }
132
133 @Override
134 public void onBeforeContactSelected(boolean isFromUnknownSearchKey, @NonNull Optional<RecipientId> recipientId, String number, @NonNull Consumer<Boolean> callback) {
135 callback.accept(true);
136 }
137
138 @Override
139 public void onContactDeselected(@NonNull Optional<RecipientId> recipientId, String number) {}
140
141 @Override
142 public void onBeginScroll() {
143 hideKeyboard();
144 }
145
146 private void hideKeyboard() {
147 ServiceUtil.getInputMethodManager(this)
148 .hideSoftInputFromWindow(toolbar.getWindowToken(), 0);
149 toolbar.clearFocus();
150 }
151
152 private static class RefreshDirectoryTask extends AsyncTask<Context, Void, Void> {
153
154 private final WeakReference<ContactSelectionActivity> activity;
155
156 private RefreshDirectoryTask(ContactSelectionActivity activity) {
157 this.activity = new WeakReference<>(activity);
158 }
159
160 @Override
161 protected Void doInBackground(Context... params) {
162 try {
163 ContactDiscovery.refreshAll(params[0], true);
164 } catch (IOException e) {
165 Log.w(TAG, e);
166 }
167
168 return null;
169 }
170
171 @Override
172 protected void onPostExecute(Void result) {
173 ContactSelectionActivity activity = this.activity.get();
174
175 if (activity != null && !activity.isFinishing()) {
176 activity.contactFilterView.clear();
177 activity.contactsFragment.resetQueryFilter();
178 }
179 }
180 }
181}