2017-10-16 20:11:42 +00:00
|
|
|
/*
|
2015-11-05 16:47:29 +00: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/>.
|
|
|
|
*/
|
2019-02-01 03:28:40 +00:00
|
|
|
package org.thoughtcrime.securesms.conversation;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2017-11-16 00:29:00 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2012-08-04 00:34:09 +00:00
|
|
|
import android.app.Activity;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.database.Cursor;
|
2018-11-20 17:59:23 +00:00
|
|
|
import android.net.Uri;
|
2014-11-08 19:35:58 +00:00
|
|
|
import android.os.AsyncTask;
|
2015-07-07 21:46:21 +00:00
|
|
|
import android.os.Build;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.os.Bundle;
|
2020-08-19 00:06:26 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.core.app.ActivityOptionsCompat;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.loader.app.LoaderManager;
|
|
|
|
import androidx.loader.content.Loader;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.view.ActionMode;
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.text.ClipboardManager;
|
2015-07-26 00:35:28 +00:00
|
|
|
import android.text.TextUtils;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-06-29 03:40:57 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-07-19 21:22:03 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2020-01-16 00:37:52 +00:00
|
|
|
import android.view.ViewParent;
|
2015-07-07 21:46:21 +00:00
|
|
|
import android.view.Window;
|
2017-01-24 19:04:32 +00:00
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.AnimationUtils;
|
2017-01-26 00:38:36 +00:00
|
|
|
import android.widget.TextView;
|
2014-06-12 01:03:01 +00:00
|
|
|
import android.widget.Toast;
|
2018-04-07 01:15:24 +00:00
|
|
|
import android.widget.ViewSwitcher;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2019-01-15 22:56:25 +00:00
|
|
|
import com.annimon.stream.Stream;
|
|
|
|
|
2019-06-28 02:32:23 +00:00
|
|
|
import org.thoughtcrime.securesms.ApplicationContext;
|
|
|
|
import org.thoughtcrime.securesms.MessageDetailsActivity;
|
|
|
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
|
|
|
|
import org.thoughtcrime.securesms.ShareActivity;
|
|
|
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
|
|
|
import org.thoughtcrime.securesms.components.ConversationTypingView;
|
|
|
|
import org.thoughtcrime.securesms.components.recyclerview.SmoothScrollingLinearLayoutManager;
|
|
|
|
import org.thoughtcrime.securesms.contactshare.Contact;
|
2018-04-27 00:03:54 +00:00
|
|
|
import org.thoughtcrime.securesms.contactshare.ContactUtil;
|
|
|
|
import org.thoughtcrime.securesms.contactshare.SharedContactDetailsActivity;
|
2019-06-28 02:32:23 +00:00
|
|
|
import org.thoughtcrime.securesms.conversation.ConversationAdapter.HeaderViewHolder;
|
|
|
|
import org.thoughtcrime.securesms.conversation.ConversationAdapter.ItemClickListener;
|
|
|
|
import org.thoughtcrime.securesms.database.Address;
|
2012-07-19 21:22:03 +00:00
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
2015-01-15 21:35:35 +00:00
|
|
|
import org.thoughtcrime.securesms.database.MmsSmsDatabase;
|
2017-08-22 18:51:01 +00:00
|
|
|
import org.thoughtcrime.securesms.database.RecipientDatabase;
|
2012-07-19 21:22:03 +00:00
|
|
|
import org.thoughtcrime.securesms.database.loaders.ConversationLoader;
|
2014-06-12 01:03:01 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
2012-10-28 23:04:24 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
2018-04-02 23:17:32 +00:00
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
2019-06-28 02:32:23 +00:00
|
|
|
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
|
|
|
import org.thoughtcrime.securesms.logging.Log;
|
2019-02-27 03:29:52 +00:00
|
|
|
import org.thoughtcrime.securesms.longmessage.LongMessageActivity;
|
2018-11-20 17:59:23 +00:00
|
|
|
import org.thoughtcrime.securesms.mediasend.Media;
|
2017-10-16 20:11:42 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
2017-04-22 23:29:26 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
2019-02-27 03:29:52 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
2014-06-12 01:03:01 +00:00
|
|
|
import org.thoughtcrime.securesms.mms.Slide;
|
2017-08-19 00:28:56 +00:00
|
|
|
import org.thoughtcrime.securesms.profiles.UnknownSenderView;
|
2017-08-01 15:56:00 +00:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2013-10-13 10:53:41 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.MessageSender;
|
2017-04-22 23:29:26 +00:00
|
|
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
2019-04-17 14:21:30 +00:00
|
|
|
import org.thoughtcrime.securesms.stickers.StickerLocator;
|
|
|
|
import org.thoughtcrime.securesms.stickers.StickerPackPreviewActivity;
|
2018-04-27 00:03:54 +00:00
|
|
|
import org.thoughtcrime.securesms.util.CommunicationActions;
|
2014-08-12 19:11:23 +00:00
|
|
|
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
2017-01-24 00:44:38 +00:00
|
|
|
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
2018-10-29 22:14:31 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
2019-01-15 22:56:25 +00:00
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
2015-09-15 22:28:27 +00:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
2019-02-01 17:06:59 +00:00
|
|
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
2016-08-16 03:23:56 +00:00
|
|
|
import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask;
|
2018-11-20 17:59:23 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2020-07-15 02:24:43 +00:00
|
|
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChat;
|
|
|
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChatAPI;
|
2014-11-03 23:16:04 +00:00
|
|
|
|
2019-02-27 03:29:52 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-11-20 17:59:23 +00:00
|
|
|
import java.util.ArrayList;
|
2015-07-26 00:35:28 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
2014-12-14 02:10:59 +00:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2015-03-19 20:08:48 +00:00
|
|
|
import java.util.Locale;
|
2015-09-15 22:28:27 +00:00
|
|
|
import java.util.Set;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2019-08-08 04:25:09 +00:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2017-11-16 00:29:00 +00:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2015-09-15 22:28:27 +00:00
|
|
|
public class ConversationFragment extends Fragment
|
2012-07-19 21:22:03 +00:00
|
|
|
implements LoaderManager.LoaderCallbacks<Cursor>
|
|
|
|
{
|
2018-04-07 01:15:24 +00:00
|
|
|
private static final String TAG = ConversationFragment.class.getSimpleName();
|
|
|
|
private static final String KEY_LIMIT = "limit";
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
private static final int PARTIAL_CONVERSATION_LIMIT = 500;
|
|
|
|
private static final int SCROLL_ANIMATION_THRESHOLD = 50;
|
|
|
|
private static final int CODE_ADD_EDIT_CONTACT = 77;
|
2015-08-04 19:29:26 +00:00
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private final ActionModeCallback actionModeCallback = new ActionModeCallback();
|
|
|
|
private final ItemClickListener selectionClickListener = new ConversationFragmentItemClickListener();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2012-08-04 00:34:09 +00:00
|
|
|
private ConversationFragmentListener listener;
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
private Recipient recipient;
|
2017-02-14 06:35:47 +00:00
|
|
|
private long threadId;
|
|
|
|
private long lastSeen;
|
2018-04-07 01:15:24 +00:00
|
|
|
private int startingPosition;
|
|
|
|
private int previousOffset;
|
2019-02-01 17:06:59 +00:00
|
|
|
private int activeOffset;
|
2017-02-14 06:35:47 +00:00
|
|
|
private boolean firstLoad;
|
2018-04-07 01:15:24 +00:00
|
|
|
private long loaderStartTime;
|
2017-02-14 06:35:47 +00:00
|
|
|
private ActionMode actionMode;
|
|
|
|
private Locale locale;
|
|
|
|
private RecyclerView list;
|
|
|
|
private RecyclerView.ItemDecoration lastSeenDecoration;
|
2018-04-07 01:15:24 +00:00
|
|
|
private ViewSwitcher topLoadMoreView;
|
|
|
|
private ViewSwitcher bottomLoadMoreView;
|
2018-10-29 22:14:31 +00:00
|
|
|
private ConversationTypingView typingView;
|
2017-08-19 00:28:56 +00:00
|
|
|
private UnknownSenderView unknownSenderView;
|
2017-02-14 06:35:47 +00:00
|
|
|
private View composeDivider;
|
|
|
|
private View scrollToBottomButton;
|
|
|
|
private TextView scrollDateHeader;
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2014-12-15 20:25:55 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
2018-01-25 03:17:44 +00:00
|
|
|
this.locale = (Locale) getArguments().getSerializable(PassphraseRequiredActionBarActivity.LOCALE_EXTRA);
|
2014-12-15 20:25:55 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
2018-01-25 03:17:44 +00:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
2015-09-15 22:28:27 +00:00
|
|
|
final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
|
2017-01-23 08:34:10 +00:00
|
|
|
list = ViewUtil.findById(view, android.R.id.list);
|
|
|
|
composeDivider = ViewUtil.findById(view, R.id.compose_divider);
|
|
|
|
scrollToBottomButton = ViewUtil.findById(view, R.id.scroll_to_bottom_button);
|
2017-01-26 00:38:36 +00:00
|
|
|
scrollDateHeader = ViewUtil.findById(view, R.id.scroll_date_header);
|
2017-01-23 08:34:10 +00:00
|
|
|
|
2017-10-16 20:11:42 +00:00
|
|
|
scrollToBottomButton.setOnClickListener(v -> scrollToBottom());
|
2016-10-20 03:08:00 +00:00
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
final LinearLayoutManager layoutManager = new SmoothScrollingLinearLayoutManager(getActivity(), true);
|
2015-08-04 19:29:26 +00:00
|
|
|
list.setHasFixedSize(false);
|
|
|
|
list.setLayoutManager(layoutManager);
|
2017-01-08 18:16:23 +00:00
|
|
|
list.setItemAnimator(null);
|
2015-08-04 19:29:26 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
topLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
|
|
|
|
bottomLoadMoreView = (ViewSwitcher) inflater.inflate(R.layout.load_more_header, container, false);
|
|
|
|
initializeLoadMoreView(topLoadMoreView);
|
|
|
|
initializeLoadMoreView(bottomLoadMoreView);
|
2017-08-19 00:28:56 +00:00
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
typingView = (ConversationTypingView) inflater.inflate(R.layout.conversation_typing_view, container, false);
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
return view;
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle bundle) {
|
|
|
|
super.onActivityCreated(bundle);
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-12 17:22:57 +00:00
|
|
|
public void onAttach(Activity activity) {
|
|
|
|
super.onAttach(activity);
|
|
|
|
this.listener = (ConversationFragmentListener)activity;
|
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2018-12-01 18:38:57 +00:00
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
initializeTypingObserver();
|
|
|
|
}
|
|
|
|
|
2015-03-05 23:51:23 +00:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
if (list.getAdapter() != null) {
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2015-03-05 23:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 18:38:57 +00:00
|
|
|
@Override
|
|
|
|
public void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
ApplicationContext.getInstance(requireContext()).getTypingStatusRepository().getTypists(threadId).removeObservers(this);
|
|
|
|
}
|
|
|
|
|
2014-12-25 02:32:51 +00:00
|
|
|
public void onNewIntent() {
|
|
|
|
if (actionMode != null) {
|
|
|
|
actionMode.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeResources();
|
|
|
|
initializeListAdapter();
|
2015-04-03 21:54:47 +00:00
|
|
|
|
|
|
|
if (threadId == -1) {
|
2015-08-04 19:29:26 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2015-04-03 21:54:47 +00:00
|
|
|
}
|
2014-12-25 02:32:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 13:39:27 +00:00
|
|
|
public void reloadList() {
|
2015-12-13 01:37:16 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2015-10-16 13:39:27 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 15:30:48 +00:00
|
|
|
public void moveToLastSeen() {
|
2018-08-02 15:57:10 +00:00
|
|
|
if (lastSeen <= 0) {
|
|
|
|
Log.i(TAG, "No need to move to last seen.");
|
|
|
|
return;
|
2018-07-25 15:30:48 +00:00
|
|
|
}
|
2018-08-02 15:57:10 +00:00
|
|
|
|
|
|
|
if (list == null || getListAdapter() == null) {
|
|
|
|
Log.w(TAG, "Tried to move to last seen position, but we hadn't initialized the view yet.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int position = getListAdapter().findLastSeenPosition(lastSeen);
|
|
|
|
scrollToLastSeenPosition(position);
|
2018-07-25 15:30:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
private void initializeResources() {
|
2018-08-06 18:42:22 +00:00
|
|
|
this.recipient = Recipient.from(getActivity(), getActivity().getIntent().getParcelableExtra(ConversationActivity.ADDRESS_EXTRA), true);
|
2017-08-19 00:28:56 +00:00
|
|
|
this.threadId = this.getActivity().getIntent().getLongExtra(ConversationActivity.THREAD_ID_EXTRA, -1);
|
|
|
|
this.lastSeen = this.getActivity().getIntent().getLongExtra(ConversationActivity.LAST_SEEN_EXTRA, -1);
|
2018-04-07 01:15:24 +00:00
|
|
|
this.startingPosition = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
|
2017-08-19 00:28:56 +00:00
|
|
|
this.firstLoad = true;
|
|
|
|
this.unknownSenderView = new UnknownSenderView(getActivity(), recipient, threadId);
|
2017-01-24 19:04:32 +00:00
|
|
|
|
|
|
|
OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
|
|
|
|
list.addOnScrollListener(scrollListener);
|
2014-06-12 17:22:57 +00:00
|
|
|
}
|
2014-06-12 01:03:01 +00:00
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
private void initializeListAdapter() {
|
2017-08-01 15:56:00 +00:00
|
|
|
if (this.recipient != null && this.threadId != -1) {
|
2018-01-25 03:17:44 +00:00
|
|
|
ConversationAdapter adapter = new ConversationAdapter(getActivity(), GlideApp.with(this), locale, selectionClickListener, null, this.recipient);
|
2017-01-24 00:44:38 +00:00
|
|
|
list.setAdapter(adapter);
|
2017-01-26 00:38:36 +00:00
|
|
|
list.addItemDecoration(new StickyHeaderDecoration(adapter, false, false));
|
2017-01-24 00:44:38 +00:00
|
|
|
|
2017-02-14 06:35:47 +00:00
|
|
|
setLastSeen(lastSeen);
|
2015-08-04 19:29:26 +00:00
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, this);
|
2013-10-13 10:53:41 +00:00
|
|
|
}
|
2014-06-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
private void initializeLoadMoreView(ViewSwitcher loadMoreView) {
|
|
|
|
loadMoreView.setOnClickListener(v -> {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt(KEY_LIMIT, 0);
|
|
|
|
getLoaderManager().restartLoader(0, args, ConversationFragment.this);
|
|
|
|
loadMoreView.showNext();
|
|
|
|
loadMoreView.setOnClickListener(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
private void initializeTypingObserver() {
|
|
|
|
if (!TextSecurePreferences.isTypingIndicatorsEnabled(requireContext())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ApplicationContext.getInstance(requireContext()).getTypingStatusRepository().getTypists(threadId).observe(this, typingState -> {
|
|
|
|
List<Recipient> recipients;
|
|
|
|
boolean replacedByIncomingMessage;
|
|
|
|
|
|
|
|
if (typingState != null) {
|
|
|
|
recipients = typingState.getTypists();
|
|
|
|
replacedByIncomingMessage = typingState.isReplacedByIncomingMessage();
|
|
|
|
} else {
|
|
|
|
recipients = Collections.emptyList();
|
|
|
|
replacedByIncomingMessage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
typingView.setTypists(GlideApp.with(ConversationFragment.this), recipients, recipient.isGroupRecipient());
|
|
|
|
|
|
|
|
ConversationAdapter adapter = getListAdapter();
|
|
|
|
|
|
|
|
if (adapter.getHeaderView() != null && adapter.getHeaderView() != typingView) {
|
|
|
|
Log.i(TAG, "Skipping typing indicator -- the header slot is occupied.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recipients.size() > 0) {
|
2019-01-24 11:06:39 +00:00
|
|
|
if (adapter.getHeaderView() == null && isAtBottom()) {
|
2018-10-29 22:14:31 +00:00
|
|
|
list.setVerticalScrollBarEnabled(false);
|
|
|
|
list.post(() -> getListLayoutManager().smoothScrollToPosition(requireContext(), 0, 250));
|
|
|
|
list.postDelayed(() -> list.setVerticalScrollBarEnabled(true), 300);
|
|
|
|
adapter.setHeaderView(typingView);
|
|
|
|
adapter.notifyItemInserted(0);
|
|
|
|
} else {
|
|
|
|
if (adapter.getHeaderView() == null) {
|
|
|
|
adapter.setHeaderView(typingView);
|
|
|
|
adapter.notifyItemInserted(0);
|
|
|
|
} else {
|
|
|
|
adapter.setHeaderView(typingView);
|
|
|
|
adapter.notifyItemChanged(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (getListLayoutManager().findFirstCompletelyVisibleItemPosition() == 0 && getListLayoutManager().getItemCount() > 1 && !replacedByIncomingMessage) {
|
|
|
|
getListLayoutManager().smoothScrollToPosition(requireContext(), 1, 250);
|
|
|
|
list.setVerticalScrollBarEnabled(false);
|
|
|
|
list.postDelayed(() -> {
|
|
|
|
adapter.setHeaderView(null);
|
|
|
|
adapter.notifyItemRemoved(0);
|
|
|
|
list.post(() -> list.setVerticalScrollBarEnabled(true));
|
|
|
|
}, 200);
|
|
|
|
} else if (!replacedByIncomingMessage) {
|
|
|
|
adapter.setHeaderView(null);
|
|
|
|
adapter.notifyItemRemoved(0);
|
|
|
|
} else {
|
|
|
|
adapter.setHeaderView(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
private void setCorrectMenuVisibility(Menu menu) {
|
2015-09-15 22:28:27 +00:00
|
|
|
Set<MessageRecord> messageRecords = getListAdapter().getSelectedItems();
|
2016-08-16 03:23:56 +00:00
|
|
|
boolean actionMessage = false;
|
2018-04-03 16:58:06 +00:00
|
|
|
boolean hasText = false;
|
2018-09-17 05:48:57 +00:00
|
|
|
boolean sharedContact = false;
|
2014-06-12 17:22:57 +00:00
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
if (actionMode != null && messageRecords.size() == 0) {
|
|
|
|
actionMode.finish();
|
|
|
|
return;
|
|
|
|
}
|
2014-06-12 01:03:01 +00:00
|
|
|
|
2016-08-16 03:23:56 +00:00
|
|
|
for (MessageRecord messageRecord : messageRecords) {
|
|
|
|
if (messageRecord.isGroupAction() || messageRecord.isCallLog() ||
|
2016-09-12 15:26:46 +00:00
|
|
|
messageRecord.isJoined() || messageRecord.isExpirationTimerUpdate() ||
|
2017-06-07 01:03:09 +00:00
|
|
|
messageRecord.isEndSession() || messageRecord.isIdentityUpdate() ||
|
2019-12-06 02:00:08 +00:00
|
|
|
messageRecord.isIdentityVerified() || messageRecord.isIdentityDefault() || messageRecord.isLokiSessionRestoreSent())
|
2016-08-16 03:23:56 +00:00
|
|
|
{
|
|
|
|
actionMessage = true;
|
2018-04-03 16:58:06 +00:00
|
|
|
}
|
2018-09-17 05:48:57 +00:00
|
|
|
|
2018-04-03 16:58:06 +00:00
|
|
|
if (messageRecord.getBody().length() > 0) {
|
|
|
|
hasText = true;
|
|
|
|
}
|
2018-09-17 05:48:57 +00:00
|
|
|
|
|
|
|
if (messageRecord.isMms() && !((MmsMessageRecord) messageRecord).getSharedContacts().isEmpty()) {
|
|
|
|
sharedContact = true;
|
2016-08-16 03:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
if (messageRecords.size() > 1) {
|
2018-04-02 23:17:32 +00:00
|
|
|
menu.findItem(R.id.menu_context_reply).setVisible(false);
|
2014-12-14 02:10:59 +00:00
|
|
|
menu.findItem(R.id.menu_context_save_attachment).setVisible(false);
|
|
|
|
menu.findItem(R.id.menu_context_resend).setVisible(false);
|
2014-06-12 17:22:57 +00:00
|
|
|
} else {
|
2015-09-15 22:28:27 +00:00
|
|
|
MessageRecord messageRecord = messageRecords.iterator().next();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
|
|
|
menu.findItem(R.id.menu_context_resend).setVisible(messageRecord.isFailed());
|
2019-04-17 14:21:30 +00:00
|
|
|
menu.findItem(R.id.menu_context_save_attachment).setVisible(!actionMessage &&
|
|
|
|
messageRecord.isMms() &&
|
|
|
|
!messageRecord.isMmsNotification() &&
|
|
|
|
((MediaMmsMessageRecord)messageRecord).containsMediaSlide() &&
|
|
|
|
((MediaMmsMessageRecord)messageRecord).getSlideDeck().getStickerSlide() == null);
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2018-05-23 19:16:42 +00:00
|
|
|
menu.findItem(R.id.menu_context_reply).setVisible(!actionMessage &&
|
|
|
|
!messageRecord.isPending() &&
|
2018-04-02 23:17:32 +00:00
|
|
|
!messageRecord.isFailed() &&
|
|
|
|
messageRecord.isSecure());
|
2014-06-12 01:03:01 +00:00
|
|
|
}
|
2020-06-23 01:59:51 +00:00
|
|
|
|
2018-04-03 16:58:06 +00:00
|
|
|
menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage && hasText);
|
2019-08-08 04:25:09 +00:00
|
|
|
|
2019-09-04 00:02:42 +00:00
|
|
|
boolean isGroupChat = recipient.isGroupRecipient();
|
2019-08-08 04:25:09 +00:00
|
|
|
|
2019-09-03 05:17:14 +00:00
|
|
|
if (isGroupChat) {
|
2020-07-15 02:24:43 +00:00
|
|
|
PublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
2020-06-23 01:59:51 +00:00
|
|
|
boolean isPublicChat = (publicChat != null);
|
2019-09-04 00:02:42 +00:00
|
|
|
int selectedMessageCount = messageRecords.size();
|
2019-11-18 04:00:55 +00:00
|
|
|
boolean areAllSentByUser = true;
|
|
|
|
for (MessageRecord message : messageRecords) {
|
|
|
|
if (!message.isOutgoing()) { areAllSentByUser = false; }
|
|
|
|
}
|
|
|
|
menu.findItem(R.id.menu_context_copy_public_key).setVisible(isPublicChat && selectedMessageCount == 1 && !areAllSentByUser);
|
2020-06-23 01:59:51 +00:00
|
|
|
menu.findItem(R.id.menu_context_reply).setVisible(selectedMessageCount == 1);
|
2019-09-12 06:42:52 +00:00
|
|
|
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(getContext());
|
2020-07-15 02:24:43 +00:00
|
|
|
boolean userCanModerate = isPublicChat && PublicChatAPI.Companion.isUserModerator(userHexEncodedPublicKey, publicChat.getChannel(), publicChat.getServer());
|
2020-06-23 01:59:51 +00:00
|
|
|
boolean isDeleteOptionVisible = !isPublicChat || (areAllSentByUser || userCanModerate);
|
2019-09-03 05:17:14 +00:00
|
|
|
menu.findItem(R.id.menu_context_delete_message).setVisible(isDeleteOptionVisible);
|
|
|
|
} else {
|
2019-09-12 04:10:04 +00:00
|
|
|
menu.findItem(R.id.menu_context_copy_public_key).setVisible(false);
|
2019-09-03 05:17:14 +00:00
|
|
|
menu.findItem(R.id.menu_context_delete_message).setVisible(true);
|
2019-08-08 04:25:09 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private ConversationAdapter getListAdapter() {
|
|
|
|
return (ConversationAdapter) list.getAdapter();
|
|
|
|
}
|
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
private SmoothScrollingLinearLayoutManager getListLayoutManager() {
|
|
|
|
return (SmoothScrollingLinearLayoutManager) list.getLayoutManager();
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
private MessageRecord getSelectedMessageRecord() {
|
2015-09-15 22:28:27 +00:00
|
|
|
Set<MessageRecord> messageRecords = getListAdapter().getSelectedItems();
|
2020-06-23 02:13:27 +00:00
|
|
|
return messageRecords.iterator().next();
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 15:56:00 +00:00
|
|
|
public void reload(Recipient recipient, long threadId) {
|
|
|
|
this.recipient = recipient;
|
2012-07-31 23:27:58 +00:00
|
|
|
|
2015-03-06 00:06:11 +00:00
|
|
|
if (this.threadId != threadId) {
|
|
|
|
this.threadId = threadId;
|
|
|
|
initializeListAdapter();
|
|
|
|
}
|
2012-07-31 23:27:58 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 22:11:56 +00:00
|
|
|
public void scrollToBottom() {
|
2019-01-24 11:06:39 +00:00
|
|
|
if (getListLayoutManager().findFirstVisibleItemPosition() < SCROLL_ANIMATION_THRESHOLD) {
|
2018-04-07 01:15:24 +00:00
|
|
|
list.smoothScrollToPosition(0);
|
|
|
|
} else {
|
|
|
|
list.scrollToPosition(0);
|
|
|
|
}
|
2014-03-26 22:11:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 06:35:47 +00:00
|
|
|
public void setLastSeen(long lastSeen) {
|
|
|
|
this.lastSeen = lastSeen;
|
|
|
|
if (lastSeenDecoration != null) {
|
|
|
|
list.removeItemDecoration(lastSeenDecoration);
|
|
|
|
}
|
|
|
|
|
|
|
|
lastSeenDecoration = new ConversationAdapter.LastSeenHeader(getListAdapter(), lastSeen);
|
|
|
|
list.addItemDecoration(lastSeenDecoration);
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private void handleCopyMessage(final Set<MessageRecord> messageRecords) {
|
|
|
|
List<MessageRecord> messageList = new LinkedList<>(messageRecords);
|
|
|
|
Collections.sort(messageList, new Comparator<MessageRecord>() {
|
2015-07-26 00:35:28 +00:00
|
|
|
@Override
|
|
|
|
public int compare(MessageRecord lhs, MessageRecord rhs) {
|
|
|
|
if (lhs.getDateReceived() < rhs.getDateReceived()) return -1;
|
|
|
|
else if (lhs.getDateReceived() == rhs.getDateReceived()) return 0;
|
|
|
|
else return 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
StringBuilder bodyBuilder = new StringBuilder();
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
for (MessageRecord messageRecord : messageList) {
|
2019-03-13 21:28:16 +00:00
|
|
|
String body = messageRecord.getDisplayBody(requireContext()).toString();
|
2018-04-03 16:58:06 +00:00
|
|
|
if (!TextUtils.isEmpty(body)) {
|
|
|
|
bodyBuilder.append(body).append('\n');
|
2015-07-26 00:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-03 16:58:06 +00:00
|
|
|
if (bodyBuilder.length() > 0 && bodyBuilder.charAt(bodyBuilder.length() - 1) == '\n') {
|
|
|
|
bodyBuilder.deleteCharAt(bodyBuilder.length() - 1);
|
|
|
|
}
|
2015-07-26 00:35:28 +00:00
|
|
|
|
|
|
|
String result = bodyBuilder.toString();
|
2012-07-19 21:22:03 +00:00
|
|
|
|
2015-07-26 00:35:28 +00:00
|
|
|
if (!TextUtils.isEmpty(result))
|
|
|
|
clipboard.setText(result);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2019-09-12 04:10:04 +00:00
|
|
|
private void handleCopyPublicKey(MessageRecord messageRecord) {
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
clipboard.setText(messageRecord.getRecipient().getAddress().toString());
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
|
2015-05-20 21:36:30 +00:00
|
|
|
int messagesCount = messageRecords.size();
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2015-11-04 20:29:14 +00:00
|
|
|
|
2015-03-24 12:44:22 +00:00
|
|
|
builder.setIconAttribute(R.attr.dialog_alert_icon);
|
2015-11-04 20:29:14 +00:00
|
|
|
builder.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
|
|
|
|
builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.setCancelable(true);
|
2015-10-23 21:01:53 +00:00
|
|
|
|
2020-07-15 02:24:43 +00:00
|
|
|
PublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(getContext()).getPublicChat(threadId);
|
2019-09-03 04:48:07 +00:00
|
|
|
|
2015-11-24 06:55:32 +00:00
|
|
|
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2014-12-14 02:10:59 +00:00
|
|
|
new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(),
|
|
|
|
R.string.ConversationFragment_deleting,
|
|
|
|
R.string.ConversationFragment_deleting_messages)
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(MessageRecord... messageRecords) {
|
2020-01-16 23:06:32 +00:00
|
|
|
if (publicChat != null) {
|
|
|
|
ArrayList<Long> serverIDs = new ArrayList<>();
|
|
|
|
ArrayList<Long> ignoredMessages = new ArrayList<>();
|
|
|
|
ArrayList<Long> failedMessages = new ArrayList<>();
|
|
|
|
boolean isSentByUser = true;
|
2020-07-15 02:24:43 +00:00
|
|
|
PublicChatAPI publicChatAPI = ApplicationContext.getInstance(getContext()).getPublicChatAPI();
|
2020-01-16 23:06:32 +00:00
|
|
|
for (MessageRecord messageRecord : messageRecords) {
|
|
|
|
isSentByUser = isSentByUser && messageRecord.isOutgoing();
|
|
|
|
Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id);
|
|
|
|
if (serverID != null) {
|
|
|
|
serverIDs.add(serverID);
|
|
|
|
} else {
|
|
|
|
ignoredMessages.add(messageRecord.getId());
|
|
|
|
}
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
2020-01-16 23:06:32 +00:00
|
|
|
if (publicChat != null && publicChatAPI != null) {
|
|
|
|
publicChatAPI
|
|
|
|
.deleteMessages(serverIDs, publicChat.getChannel(), publicChat.getServer(), isSentByUser)
|
|
|
|
.success(l -> {
|
|
|
|
for (MessageRecord messageRecord : messageRecords) {
|
|
|
|
Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id);
|
|
|
|
if (l.contains(serverID)) {
|
|
|
|
if (messageRecord.isMms()) {
|
|
|
|
DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
|
|
|
|
} else {
|
|
|
|
DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
|
|
|
|
}
|
|
|
|
} else if (!ignoredMessages.contains(serverID)) {
|
|
|
|
failedMessages.add(messageRecord.getId());
|
|
|
|
Log.d("Loki", "Failed to delete message: " + messageRecord.getId() + ".");
|
2019-11-14 02:14:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 23:06:32 +00:00
|
|
|
return null;
|
|
|
|
}). fail(e -> {
|
|
|
|
Log.d("Loki", "Couldn't delete message due to error: " + e.toString() + ".");
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (MessageRecord messageRecord : messageRecords) {
|
|
|
|
if (messageRecord.isMms()) {
|
|
|
|
DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
|
|
|
|
} else {
|
|
|
|
DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
|
2019-11-14 02:14:09 +00:00
|
|
|
}
|
2020-01-16 23:06:32 +00:00
|
|
|
}
|
2019-11-14 02:14:09 +00:00
|
|
|
}
|
2014-12-14 02:10:59 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, messageRecords.toArray(new MessageRecord[messageRecords.size()]));
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-11-24 06:55:32 +00:00
|
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
2012-07-19 21:22:03 +00:00
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDisplayDetails(MessageRecord message) {
|
2015-01-15 21:35:35 +00:00
|
|
|
Intent intent = new Intent(getActivity(), MessageDetailsActivity.class);
|
|
|
|
intent.putExtra(MessageDetailsActivity.MESSAGE_ID_EXTRA, message.getId());
|
2015-08-15 12:00:08 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.THREAD_ID_EXTRA, threadId);
|
2015-01-15 21:35:35 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.TYPE_EXTRA, message.isMms() ? MmsSmsDatabase.MMS_TRANSPORT : MmsSmsDatabase.SMS_TRANSPORT);
|
2017-08-01 15:56:00 +00:00
|
|
|
intent.putExtra(MessageDetailsActivity.ADDRESS_EXTRA, recipient.getAddress());
|
|
|
|
intent.putExtra(MessageDetailsActivity.IS_PUSH_GROUP_EXTRA, recipient.isGroupRecipient() && message.isPush());
|
2015-01-15 21:35:35 +00:00
|
|
|
startActivity(intent);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleForwardMessage(MessageRecord message) {
|
2019-04-09 13:35:47 +00:00
|
|
|
listener.onForwardClicked();
|
|
|
|
|
2019-02-27 03:29:52 +00:00
|
|
|
SimpleTask.run(getLifecycle(), () -> {
|
|
|
|
Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
|
2019-03-13 21:28:16 +00:00
|
|
|
composeIntent.putExtra(Intent.EXTRA_TEXT, message.getDisplayBody(requireContext()).toString());
|
2019-02-27 03:29:52 +00:00
|
|
|
|
|
|
|
if (message.isMms()) {
|
|
|
|
MmsMessageRecord mediaMessage = (MmsMessageRecord) message;
|
2019-04-17 14:21:30 +00:00
|
|
|
boolean isAlbum = mediaMessage.containsMediaSlide() &&
|
|
|
|
mediaMessage.getSlideDeck().getSlides().size() > 1 &&
|
|
|
|
mediaMessage.getSlideDeck().getAudioSlide() == null &&
|
|
|
|
mediaMessage.getSlideDeck().getDocumentSlide() == null &&
|
|
|
|
mediaMessage.getSlideDeck().getStickerSlide() == null;
|
2019-02-27 03:29:52 +00:00
|
|
|
|
|
|
|
if (isAlbum) {
|
|
|
|
ArrayList<Media> mediaList = new ArrayList<>(mediaMessage.getSlideDeck().getSlides().size());
|
|
|
|
List<Attachment> attachments = Stream.of(mediaMessage.getSlideDeck().getSlides())
|
|
|
|
.filter(s -> s.hasImage() || s.hasVideo())
|
|
|
|
.map(Slide::asAttachment)
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
for (Attachment attachment : attachments) {
|
|
|
|
Uri uri = attachment.getDataUri() != null ? attachment.getDataUri() : attachment.getThumbnailUri();
|
|
|
|
|
|
|
|
if (uri != null) {
|
|
|
|
mediaList.add(new Media(uri,
|
|
|
|
attachment.getContentType(),
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
attachment.getWidth(),
|
|
|
|
attachment.getHeight(),
|
|
|
|
attachment.getSize(),
|
|
|
|
Optional.absent(),
|
|
|
|
Optional.fromNullable(attachment.getCaption())));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!mediaList.isEmpty()) {
|
|
|
|
composeIntent.putExtra(ConversationActivity.MEDIA_EXTRA, mediaList);
|
2018-11-20 17:59:23 +00:00
|
|
|
}
|
2019-02-27 03:29:52 +00:00
|
|
|
} else if (mediaMessage.containsMediaSlide()) {
|
|
|
|
Slide slide = mediaMessage.getSlideDeck().getSlides().get(0);
|
|
|
|
composeIntent.putExtra(Intent.EXTRA_STREAM, slide.getUri());
|
|
|
|
composeIntent.setType(slide.getContentType());
|
2019-04-17 14:21:30 +00:00
|
|
|
|
|
|
|
if (slide.hasSticker()) {
|
|
|
|
composeIntent.putExtra(ConversationActivity.STICKER_EXTRA, slide.asAttachment().getSticker());
|
|
|
|
}
|
2018-11-20 17:59:23 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 03:29:52 +00:00
|
|
|
if (mediaMessage.getSlideDeck().getTextSlide() != null && mediaMessage.getSlideDeck().getTextSlide().getUri() != null) {
|
|
|
|
try (InputStream stream = PartAuthority.getAttachmentStream(requireContext(), mediaMessage.getSlideDeck().getTextSlide().getUri())) {
|
2019-03-02 02:14:47 +00:00
|
|
|
String fullBody = Util.readFullyAsString(stream);
|
|
|
|
composeIntent.putExtra(Intent.EXTRA_TEXT, fullBody);
|
2019-02-27 03:29:52 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.w(TAG, "Failed to read long message text when forwarding.");
|
|
|
|
}
|
2018-11-20 17:59:23 +00:00
|
|
|
}
|
2015-11-18 20:54:40 +00:00
|
|
|
}
|
2019-02-27 03:29:52 +00:00
|
|
|
|
|
|
|
return composeIntent;
|
|
|
|
}, this::startActivity);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 19:35:58 +00:00
|
|
|
private void handleResendMessage(final MessageRecord message) {
|
|
|
|
final Context context = getActivity().getApplicationContext();
|
|
|
|
new AsyncTask<MessageRecord, Void, Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void doInBackground(MessageRecord... messageRecords) {
|
2018-01-25 03:17:44 +00:00
|
|
|
MessageSender.resend(context, messageRecords[0]);
|
2014-11-08 19:35:58 +00:00
|
|
|
return null;
|
|
|
|
}
|
2017-10-23 20:03:32 +00:00
|
|
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, message);
|
2013-10-13 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 22:01:37 +00:00
|
|
|
private void handleReplyMessage(final MessageRecord message) {
|
|
|
|
listener.handleReplyMessage(message);
|
|
|
|
}
|
|
|
|
|
2014-08-12 19:11:23 +00:00
|
|
|
private void handleSaveAttachment(final MediaMmsMessageRecord message) {
|
|
|
|
SaveAttachmentTask.showWarningDialog(getActivity(), new DialogInterface.OnClickListener() {
|
2014-06-12 01:03:01 +00:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2019-01-15 22:56:25 +00:00
|
|
|
List<SaveAttachmentTask.Attachment> attachments = Stream.of(message.getSlideDeck().getSlides())
|
|
|
|
.filter(s -> s.getUri() != null && (s.hasImage() || s.hasVideo() || s.hasAudio() || s.hasDocument()))
|
|
|
|
.map(s -> new SaveAttachmentTask.Attachment(s.getUri(), s.getContentType(), message.getDateReceived(), s.getFileName().orNull()))
|
|
|
|
.toList();
|
|
|
|
if (!Util.isEmpty(attachments)) {
|
|
|
|
SaveAttachmentTask saveTask = new SaveAttachmentTask(getActivity());
|
|
|
|
saveTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, attachments.toArray(new SaveAttachmentTask.Attachment[0]));
|
|
|
|
return;
|
2015-10-21 22:32:19 +00:00
|
|
|
}
|
2014-10-28 07:23:00 +00:00
|
|
|
|
2015-10-21 22:32:19 +00:00
|
|
|
Log.w(TAG, "No slide with attachable media found, failing nicely.");
|
2015-08-22 11:03:07 +00:00
|
|
|
Toast.makeText(getActivity(),
|
|
|
|
getResources().getQuantityString(R.plurals.ConversationFragment_error_while_saving_attachments_to_sd_card, 1),
|
|
|
|
Toast.LENGTH_LONG).show();
|
2014-06-12 01:03:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public @NonNull Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
2018-08-02 13:25:33 +00:00
|
|
|
Log.i(TAG, "onCreateLoader");
|
2018-04-07 01:15:24 +00:00
|
|
|
loaderStartTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
int limit = args.getInt(KEY_LIMIT, PARTIAL_CONVERSATION_LIMIT);
|
|
|
|
int offset = 0;
|
2018-08-28 18:52:26 +00:00
|
|
|
if (limit != 0 && startingPosition >= limit) {
|
2018-04-07 01:15:24 +00:00
|
|
|
offset = Math.max(startingPosition - (limit / 2) + 1, 0);
|
|
|
|
startingPosition -= offset - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ConversationLoader(getActivity(), threadId, offset, limit, lastSeen);
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public void onLoadFinished(@NonNull Loader<Cursor> cursorLoader, Cursor cursor) {
|
2018-04-07 01:15:24 +00:00
|
|
|
long loadTime = System.currentTimeMillis() - loaderStartTime;
|
|
|
|
int count = cursor.getCount();
|
2018-08-02 13:25:33 +00:00
|
|
|
Log.i(TAG, "onLoadFinished - took " + loadTime + " ms to load a cursor of size " + count);
|
2017-02-14 06:35:47 +00:00
|
|
|
ConversationLoader loader = (ConversationLoader)cursorLoader;
|
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
ConversationAdapter adapter = getListAdapter();
|
|
|
|
if (adapter == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-14 06:35:47 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
if (cursor.getCount() >= PARTIAL_CONVERSATION_LIMIT && loader.hasLimit()) {
|
|
|
|
adapter.setFooterView(topLoadMoreView);
|
|
|
|
} else {
|
|
|
|
adapter.setFooterView(null);
|
|
|
|
}
|
2017-02-14 06:35:47 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
if (lastSeen == -1) {
|
|
|
|
setLastSeen(loader.getLastSeen());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!loader.hasSent() && !recipient.isSystemContact() && !recipient.isGroupRecipient() && recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
|
2020-05-14 00:44:13 +00:00
|
|
|
// adapter.setHeaderView(unknownSenderView);
|
2018-04-07 01:15:24 +00:00
|
|
|
} else {
|
2018-10-29 22:14:31 +00:00
|
|
|
clearHeaderIfNotTyping(adapter);
|
2018-04-07 01:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loader.hasOffset()) {
|
|
|
|
adapter.setHeaderView(bottomLoadMoreView);
|
2019-02-01 17:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (firstLoad || loader.hasOffset()) {
|
2018-04-07 01:15:24 +00:00
|
|
|
previousOffset = loader.getOffset();
|
|
|
|
}
|
2017-08-19 00:28:56 +00:00
|
|
|
|
2019-02-01 17:06:59 +00:00
|
|
|
activeOffset = loader.getOffset();
|
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
adapter.changeCursor(cursor);
|
2017-02-14 06:35:47 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
int lastSeenPosition = adapter.findLastSeenPosition(lastSeen);
|
2017-02-26 18:49:48 +00:00
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
if (adapter.getHeaderView() == typingView) {
|
|
|
|
lastSeenPosition = Math.max(lastSeenPosition - 1, 0);
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
if (firstLoad) {
|
|
|
|
if (startingPosition >= 0) {
|
|
|
|
scrollToStartingPosition(startingPosition);
|
|
|
|
} else {
|
2017-02-26 18:49:48 +00:00
|
|
|
scrollToLastSeenPosition(lastSeenPosition);
|
2017-02-14 06:35:47 +00:00
|
|
|
}
|
2018-04-07 01:15:24 +00:00
|
|
|
firstLoad = false;
|
|
|
|
} else if (previousOffset > 0) {
|
2019-01-24 11:06:39 +00:00
|
|
|
int scrollPosition = previousOffset + getListLayoutManager().findFirstVisibleItemPosition();
|
2018-04-07 01:15:24 +00:00
|
|
|
scrollPosition = Math.min(scrollPosition, count - 1);
|
2017-02-26 18:49:48 +00:00
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
View firstView = list.getLayoutManager().getChildAt(scrollPosition);
|
|
|
|
int pixelOffset = (firstView == null) ? 0 : (firstView.getBottom() - list.getPaddingBottom());
|
|
|
|
|
2019-01-24 11:06:39 +00:00
|
|
|
getListLayoutManager().scrollToPositionWithOffset(scrollPosition, pixelOffset);
|
2018-04-07 01:15:24 +00:00
|
|
|
previousOffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastSeenPosition <= 0) {
|
|
|
|
setLastSeen(0);
|
2015-04-13 18:49:08 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 22:14:31 +00:00
|
|
|
private void clearHeaderIfNotTyping(ConversationAdapter adapter) {
|
|
|
|
if (adapter.getHeaderView() != typingView) {
|
|
|
|
adapter.setHeaderView(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 21:22:03 +00:00
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public void onLoaderReset(@NonNull Loader<Cursor> arg0) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (list.getAdapter() != null) {
|
|
|
|
getListAdapter().changeCursor(null);
|
2015-04-13 18:49:08 +00:00
|
|
|
}
|
2012-07-19 21:22:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 23:29:26 +00:00
|
|
|
public long stageOutgoingMessage(OutgoingMediaMessage message) {
|
|
|
|
MessageRecord messageRecord = DatabaseFactory.getMmsDatabase(getContext()).readerFor(message, threadId).getCurrent();
|
|
|
|
|
|
|
|
if (getListAdapter() != null) {
|
2018-10-29 22:14:31 +00:00
|
|
|
clearHeaderIfNotTyping(getListAdapter());
|
2017-08-19 00:28:56 +00:00
|
|
|
setLastSeen(0);
|
2017-04-22 23:29:26 +00:00
|
|
|
getListAdapter().addFastRecord(messageRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
return messageRecord.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
public long stageOutgoingMessage(OutgoingTextMessage message) {
|
|
|
|
MessageRecord messageRecord = DatabaseFactory.getSmsDatabase(getContext()).readerFor(message, threadId).getCurrent();
|
|
|
|
|
|
|
|
if (getListAdapter() != null) {
|
2018-10-29 22:14:31 +00:00
|
|
|
clearHeaderIfNotTyping(getListAdapter());
|
2017-08-19 00:28:56 +00:00
|
|
|
setLastSeen(0);
|
2017-04-22 23:29:26 +00:00
|
|
|
getListAdapter().addFastRecord(messageRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
return messageRecord.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void releaseOutgoingMessage(long id) {
|
|
|
|
if (getListAdapter() != null) {
|
|
|
|
getListAdapter().releaseFastRecord(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 01:15:24 +00:00
|
|
|
private void scrollToStartingPosition(final int startingPosition) {
|
|
|
|
list.post(() -> {
|
|
|
|
list.getLayoutManager().scrollToPosition(startingPosition);
|
|
|
|
getListAdapter().pulseHighlightItem(startingPosition);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-26 18:49:48 +00:00
|
|
|
private void scrollToLastSeenPosition(final int lastSeenPosition) {
|
2017-02-14 06:35:47 +00:00
|
|
|
if (lastSeenPosition > 0) {
|
2019-01-24 11:06:39 +00:00
|
|
|
list.post(() -> getListLayoutManager().scrollToPositionWithOffset(lastSeenPosition, list.getHeight()));
|
2017-02-14 06:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 11:06:39 +00:00
|
|
|
private boolean isAtBottom() {
|
|
|
|
if (list.getChildCount() == 0) return true;
|
|
|
|
|
|
|
|
int firstVisiblePosition = getListLayoutManager().findFirstVisibleItemPosition();
|
|
|
|
|
|
|
|
if (getListAdapter().getHeaderView() == typingView) {
|
|
|
|
RecyclerView.ViewHolder item1 = list.findViewHolderForAdapterPosition(1);
|
|
|
|
return firstVisiblePosition <= 1 && item1 != null && item1.itemView.getBottom() <= list.getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
return firstVisiblePosition == 0 && list.getChildAt(0).getBottom() <= list.getHeight();
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:06:59 +00:00
|
|
|
public void onSearchQueryUpdated(@Nullable String query) {
|
2019-02-21 01:20:12 +00:00
|
|
|
if (getListAdapter() != null) {
|
|
|
|
getListAdapter().onSearchQueryUpdated(query);
|
|
|
|
}
|
2019-02-01 17:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void jumpToMessage(@NonNull Address author, long timestamp, @Nullable Runnable onMessageNotFound) {
|
|
|
|
SimpleTask.run(getLifecycle(), () -> {
|
|
|
|
return DatabaseFactory.getMmsSmsDatabase(getContext())
|
|
|
|
.getMessagePositionInConversation(threadId, timestamp, author);
|
|
|
|
}, p -> moveToMessagePosition(p, onMessageNotFound));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void moveToMessagePosition(int position, @Nullable Runnable onMessageNotFound) {
|
|
|
|
Log.d(TAG, "Moving to message position: " + position + " activeOffset: " + activeOffset + " cursorCount: " + getListAdapter().getCursorCount());
|
|
|
|
|
|
|
|
if (position >= activeOffset && position >= 0 && position < getListAdapter().getCursorCount()) {
|
|
|
|
int offset = activeOffset > 0 ? activeOffset - 1 : 0;
|
|
|
|
list.scrollToPosition(position - offset);
|
|
|
|
getListAdapter().pulseHighlightItem(position - offset);
|
|
|
|
} else if (position < 0) {
|
|
|
|
Log.w(TAG, "Tried to navigate to message, but it wasn't found.");
|
|
|
|
if (onMessageNotFound != null) {
|
|
|
|
onMessageNotFound.run();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Log.i(TAG, "Message was outside of the loaded range. Need to restart the loader.");
|
|
|
|
|
|
|
|
firstLoad = true;
|
|
|
|
startingPosition = position;
|
|
|
|
getLoaderManager().restartLoader(0, Bundle.EMPTY, ConversationFragment.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-04 00:34:09 +00:00
|
|
|
public interface ConversationFragmentListener {
|
2015-09-15 22:28:27 +00:00
|
|
|
void setThreadId(long threadId);
|
2018-02-07 22:01:37 +00:00
|
|
|
void handleReplyMessage(MessageRecord messageRecord);
|
2019-02-01 17:06:59 +00:00
|
|
|
void onMessageActionToolbarOpened();
|
2019-04-09 13:35:47 +00:00
|
|
|
void onForwardClicked();
|
2012-08-04 00:34:09 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 03:08:00 +00:00
|
|
|
private class ConversationScrollListener extends OnScrollListener {
|
2017-01-24 19:04:32 +00:00
|
|
|
|
2017-01-26 00:38:36 +00:00
|
|
|
private final Animation scrollButtonInAnimation;
|
|
|
|
private final Animation scrollButtonOutAnimation;
|
|
|
|
private final ConversationDateHeader conversationDateHeader;
|
2017-01-24 19:04:32 +00:00
|
|
|
|
|
|
|
private boolean wasAtBottom = true;
|
|
|
|
private boolean wasAtZoomScrollHeight = false;
|
2017-01-26 00:38:36 +00:00
|
|
|
private long lastPositionId = -1;
|
2017-01-24 19:04:32 +00:00
|
|
|
|
|
|
|
ConversationScrollListener(@NonNull Context context) {
|
|
|
|
this.scrollButtonInAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_in);
|
|
|
|
this.scrollButtonOutAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_out);
|
2017-01-26 00:38:36 +00:00
|
|
|
this.conversationDateHeader = new ConversationDateHeader(context, scrollDateHeader);
|
2017-01-24 19:04:32 +00:00
|
|
|
|
|
|
|
this.scrollButtonInAnimation.setDuration(100);
|
|
|
|
this.scrollButtonOutAnimation.setDuration(50);
|
|
|
|
}
|
2016-10-20 03:08:00 +00:00
|
|
|
|
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public void onScrolled(@NonNull final RecyclerView rv, final int dx, final int dy) {
|
2017-01-24 19:04:32 +00:00
|
|
|
boolean currentlyAtBottom = isAtBottom();
|
|
|
|
boolean currentlyAtZoomScrollHeight = isAtZoomScrollHeight();
|
2017-01-26 00:38:36 +00:00
|
|
|
int positionId = getHeaderPositionId();
|
2017-01-24 19:04:32 +00:00
|
|
|
|
|
|
|
if (currentlyAtBottom && !wasAtBottom) {
|
|
|
|
ViewUtil.fadeOut(composeDivider, 50, View.INVISIBLE);
|
|
|
|
ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
|
|
|
|
} else if (!currentlyAtBottom && wasAtBottom) {
|
|
|
|
ViewUtil.fadeIn(composeDivider, 500);
|
|
|
|
}
|
2016-10-20 03:08:00 +00:00
|
|
|
|
2017-01-24 19:04:32 +00:00
|
|
|
if (currentlyAtZoomScrollHeight && !wasAtZoomScrollHeight) {
|
|
|
|
ViewUtil.animateIn(scrollToBottomButton, scrollButtonInAnimation);
|
2016-10-20 03:08:00 +00:00
|
|
|
}
|
2017-01-24 19:04:32 +00:00
|
|
|
|
2017-01-26 00:38:36 +00:00
|
|
|
if (positionId != lastPositionId) {
|
|
|
|
bindScrollHeader(conversationDateHeader, positionId);
|
|
|
|
}
|
|
|
|
|
2017-01-24 19:04:32 +00:00
|
|
|
wasAtBottom = currentlyAtBottom;
|
|
|
|
wasAtZoomScrollHeight = currentlyAtZoomScrollHeight;
|
2017-01-26 00:38:36 +00:00
|
|
|
lastPositionId = positionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-22 16:51:56 +00:00
|
|
|
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
2017-01-26 00:38:36 +00:00
|
|
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
|
|
conversationDateHeader.show();
|
|
|
|
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
|
|
|
conversationDateHeader.hide();
|
|
|
|
}
|
2016-10-20 03:08:00 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 19:04:32 +00:00
|
|
|
private boolean isAtZoomScrollHeight() {
|
2019-01-24 11:06:39 +00:00
|
|
|
return getListLayoutManager().findFirstCompletelyVisibleItemPosition() > 4;
|
2017-01-24 19:04:32 +00:00
|
|
|
}
|
2017-01-26 00:38:36 +00:00
|
|
|
|
|
|
|
private int getHeaderPositionId() {
|
2019-01-24 11:06:39 +00:00
|
|
|
return getListLayoutManager().findLastVisibleItemPosition();
|
2017-01-26 00:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void bindScrollHeader(HeaderViewHolder headerViewHolder, int positionId) {
|
2017-01-26 02:00:26 +00:00
|
|
|
if (((ConversationAdapter)list.getAdapter()).getHeaderId(positionId) != -1) {
|
|
|
|
((ConversationAdapter) list.getAdapter()).onBindHeaderViewHolder(headerViewHolder, positionId);
|
|
|
|
}
|
2017-01-26 00:38:36 +00:00
|
|
|
}
|
2016-10-20 03:08:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 22:28:27 +00:00
|
|
|
private class ConversationFragmentItemClickListener implements ItemClickListener {
|
2015-03-08 18:37:18 +00:00
|
|
|
|
2015-11-04 20:29:14 +00:00
|
|
|
@Override
|
2016-08-16 03:23:56 +00:00
|
|
|
public void onItemClick(MessageRecord messageRecord) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (actionMode != null) {
|
|
|
|
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2018-02-13 20:55:59 +00:00
|
|
|
if (getListAdapter().getSelectedItems().size() == 0) {
|
|
|
|
actionMode.finish();
|
|
|
|
} else {
|
|
|
|
setCorrectMenuVisibility(actionMode.getMenu());
|
|
|
|
actionMode.setTitle(String.valueOf(getListAdapter().getSelectedItems().size()));
|
|
|
|
}
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 20:29:14 +00:00
|
|
|
@Override
|
2016-08-16 03:23:56 +00:00
|
|
|
public void onItemLongClick(MessageRecord messageRecord) {
|
2015-09-15 22:28:27 +00:00
|
|
|
if (actionMode == null) {
|
2016-08-16 03:23:56 +00:00
|
|
|
((ConversationAdapter) list.getAdapter()).toggleSelection(messageRecord);
|
2015-09-15 22:28:27 +00:00
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2015-06-09 14:37:20 +00:00
|
|
|
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback);
|
2020-01-16 00:37:52 +00:00
|
|
|
|
|
|
|
View titleTextView = (getActivity().findViewById(R.id.action_bar_title));
|
|
|
|
if (titleTextView != null) {
|
|
|
|
titleTextView.setBackgroundColor(getResources().getColor(R.color.transparent));
|
|
|
|
ViewParent titleTextViewContainerView = titleTextView.getParent();
|
|
|
|
if (titleTextViewContainerView != null) {
|
|
|
|
((View)titleTextViewContainerView).setBackgroundColor(getResources().getColor(R.color.transparent));
|
|
|
|
}
|
|
|
|
}
|
2014-12-14 02:10:59 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-02 23:17:32 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onQuoteClicked(MmsMessageRecord messageRecord) {
|
|
|
|
if (messageRecord.getQuote() == null) {
|
|
|
|
Log.w(TAG, "Received a 'quote clicked' event, but there's no quote...");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-11 13:55:52 +00:00
|
|
|
if (messageRecord.getQuote().isOriginalMissing()) {
|
|
|
|
Log.i(TAG, "Clicked on a quote whose original message we never had.");
|
|
|
|
Toast.makeText(getContext(), R.string.ConversationFragment_quoted_message_not_found, Toast.LENGTH_SHORT).show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:06:59 +00:00
|
|
|
SimpleTask.run(getLifecycle(), () -> {
|
|
|
|
return DatabaseFactory.getMmsSmsDatabase(getContext())
|
|
|
|
.getQuotedMessagePosition(threadId,
|
|
|
|
messageRecord.getQuote().getId(),
|
|
|
|
messageRecord.getQuote().getAuthor());
|
|
|
|
}, p -> moveToMessagePosition(p, () -> {
|
|
|
|
Toast.makeText(getContext(), R.string.ConversationFragment_quoted_message_no_longer_available, Toast.LENGTH_SHORT).show();
|
|
|
|
}));
|
2018-04-02 23:17:32 +00:00
|
|
|
}
|
2018-04-27 00:03:54 +00:00
|
|
|
|
2019-01-15 08:41:05 +00:00
|
|
|
@Override
|
|
|
|
public void onLinkPreviewClicked(@NonNull LinkPreview linkPreview) {
|
|
|
|
if (getContext() != null && getActivity() != null) {
|
|
|
|
CommunicationActions.openBrowserLink(getActivity(), linkPreview.getUrl());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 03:29:52 +00:00
|
|
|
@Override
|
|
|
|
public void onMoreTextClicked(@NonNull Address conversationAddress, long messageId, boolean isMms) {
|
|
|
|
if (getContext() != null && getActivity() != null) {
|
|
|
|
startActivity(LongMessageActivity.getIntent(getContext(), conversationAddress, messageId, isMms));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 14:21:30 +00:00
|
|
|
@Override
|
|
|
|
public void onStickerClicked(@NonNull StickerLocator sticker) {
|
|
|
|
if (getContext() != null && getActivity() != null) {
|
|
|
|
startActivity(StickerPackPreviewActivity.getIntent(sticker.getPackId(), sticker.getPackKey()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 00:03:54 +00:00
|
|
|
@Override
|
|
|
|
public void onSharedContactDetailsClicked(@NonNull Contact contact, @NonNull View avatarTransitionView) {
|
|
|
|
if (getContext() != null && getActivity() != null) {
|
|
|
|
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), avatarTransitionView, "avatar").toBundle();
|
|
|
|
ActivityCompat.startActivity(getActivity(), SharedContactDetailsActivity.getIntent(getContext(), contact), bundle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAddToContactsClicked(@NonNull Contact contactWithAvatar) {
|
|
|
|
if (getContext() != null) {
|
|
|
|
new AsyncTask<Void, Void, Intent>() {
|
|
|
|
@Override
|
|
|
|
protected Intent doInBackground(Void... voids) {
|
|
|
|
return ContactUtil.buildAddToContactsIntent(getContext(), contactWithAvatar);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Intent intent) {
|
|
|
|
startActivityForResult(intent, CODE_ADD_EDIT_CONTACT);
|
|
|
|
}
|
|
|
|
}.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMessageSharedContactClicked(@NonNull List<Recipient> choices) {
|
|
|
|
if (getContext() == null) return;
|
|
|
|
|
|
|
|
ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
|
|
|
CommunicationActions.startConversation(getContext(), recipient, null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInviteSharedContactClicked(@NonNull List<Recipient> choices) {
|
|
|
|
if (getContext() == null) return;
|
|
|
|
|
|
|
|
ContactUtil.selectRecipientThroughDialog(getContext(), choices, locale, recipient -> {
|
2019-05-23 11:02:15 +00:00
|
|
|
CommunicationActions.composeSmsThroughDefaultApp(getContext(), recipient.getAddress(), getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url)));
|
2018-04-27 00:03:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
private class ActionModeCallback implements ActionMode.Callback {
|
2014-06-12 17:22:57 +00:00
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
private int statusBarColor;
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
MenuInflater inflater = mode.getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.conversation_context, menu);
|
|
|
|
|
2018-02-13 20:55:59 +00:00
|
|
|
mode.setTitle("1");
|
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
Window window = getActivity().getWindow();
|
|
|
|
statusBarColor = window.getStatusBarColor();
|
|
|
|
}
|
|
|
|
|
2014-12-14 02:10:59 +00:00
|
|
|
setCorrectMenuVisibility(menu);
|
2019-02-01 17:06:59 +00:00
|
|
|
listener.onMessageActionToolbarOpened();
|
2014-06-12 17:22:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
2015-09-15 22:28:27 +00:00
|
|
|
((ConversationAdapter)list.getAdapter()).clearSelection();
|
|
|
|
list.getAdapter().notifyDataSetChanged();
|
2014-12-14 02:10:59 +00:00
|
|
|
|
2015-07-07 21:46:21 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
getActivity().getWindow().setStatusBarColor(statusBarColor);
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
switch(item.getItemId()) {
|
|
|
|
case R.id.menu_context_copy:
|
2015-09-15 22:28:27 +00:00
|
|
|
handleCopyMessage(getListAdapter().getSelectedItems());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2019-09-12 04:10:04 +00:00
|
|
|
case R.id.menu_context_copy_public_key:
|
|
|
|
handleCopyPublicKey((MessageRecord) getListAdapter().getSelectedItems().toArray()[0]);
|
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2014-06-12 17:22:57 +00:00
|
|
|
case R.id.menu_context_delete_message:
|
2015-09-15 22:28:27 +00:00
|
|
|
handleDeleteMessages(getListAdapter().getSelectedItems());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2019-07-22 03:08:56 +00:00
|
|
|
/*
|
2014-06-12 17:22:57 +00:00
|
|
|
case R.id.menu_context_details:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleDisplayDetails(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_forward:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleForwardMessage(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2019-07-22 03:08:56 +00:00
|
|
|
*/
|
2014-06-12 17:22:57 +00:00
|
|
|
case R.id.menu_context_resend:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleResendMessage(getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
|
|
|
case R.id.menu_context_save_attachment:
|
2014-12-14 02:10:59 +00:00
|
|
|
handleSaveAttachment((MediaMmsMessageRecord)getSelectedMessageRecord());
|
2014-06-12 17:22:57 +00:00
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2018-02-07 22:01:37 +00:00
|
|
|
case R.id.menu_context_reply:
|
|
|
|
handleReplyMessage(getSelectedMessageRecord());
|
|
|
|
actionMode.finish();
|
|
|
|
return true;
|
2014-06-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 22:28:27 +00:00
|
|
|
}
|
2017-01-26 00:38:36 +00:00
|
|
|
|
|
|
|
private static class ConversationDateHeader extends HeaderViewHolder {
|
|
|
|
|
|
|
|
private final Animation animateIn;
|
|
|
|
private final Animation animateOut;
|
|
|
|
|
|
|
|
private boolean pendingHide = false;
|
|
|
|
|
|
|
|
private ConversationDateHeader(Context context, TextView textView) {
|
|
|
|
super(textView);
|
|
|
|
this.animateIn = AnimationUtils.loadAnimation(context, R.anim.slide_from_top);
|
|
|
|
this.animateOut = AnimationUtils.loadAnimation(context, R.anim.slide_to_top);
|
|
|
|
|
|
|
|
this.animateIn.setDuration(100);
|
|
|
|
this.animateOut.setDuration(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void show() {
|
|
|
|
if (pendingHide) {
|
|
|
|
pendingHide = false;
|
|
|
|
} else {
|
|
|
|
ViewUtil.animateIn(textView, animateIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
|
|
|
pendingHide = true;
|
|
|
|
|
|
|
|
textView.postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (pendingHide) {
|
|
|
|
pendingHide = false;
|
|
|
|
ViewUtil.animateOut(textView, animateOut, View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 400);
|
|
|
|
}
|
|
|
|
}
|
2014-03-06 04:11:36 +00:00
|
|
|
}
|