mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #895 from deltachat/forward_and_share
search during forwarding, forward to archives, forward to new contacts
This commit is contained in:
+3
-3
@@ -35,7 +35,7 @@
|
||||
|
||||
<application android:name=".ApplicationContext"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="Delta Chat"
|
||||
android:label="@string/dc_app_name"
|
||||
android:supportsRtl="true"
|
||||
tools:replace="android:allowBackup"
|
||||
android:allowBackup="false"
|
||||
@@ -62,7 +62,7 @@
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ShareActivity"
|
||||
android:theme="@style/TextSecure.LightNoActionBar"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleTask"
|
||||
android:taskAffinity=""
|
||||
@@ -100,7 +100,7 @@
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ConversationListActivity"
|
||||
android:label="Delta Chat"
|
||||
android:label="@string/dc_app_name"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/TextSecure.LightNoActionBar"
|
||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Delta Chat"
|
||||
android:text="@string/dc_app_name"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:wheel="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -29,34 +28,15 @@
|
||||
android:textSize="20sp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toLeftOf="@+id/search_action"
|
||||
android:layout_toStartOf="@+id/search_action"/>
|
||||
android:layout_centerVertical="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
|
||||
<fragment android:id="@+id/share_fragment"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="org.thoughtcrime.securesms.ShareActivity$ShareFragment" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SearchToolbar
|
||||
android:id="@+id/search_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:elevation="4dp"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="invisible"/>
|
||||
|
||||
<com.pnikosis.materialishprogress.ProgressWheel android:id="@+id/progress_wheel"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_centerInParent="true"
|
||||
wheel:matProg_progressIndeterminate="true" />
|
||||
|
||||
wheel:matProg_progressIndeterminate="true"
|
||||
android:visibility="visible" />
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="dc_app_name" translatable="false">Delta Chat</string>
|
||||
</resources>
|
||||
@@ -66,6 +66,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
|
||||
/**
|
||||
* Fragment for selecting a one or more contacts from a list.
|
||||
*
|
||||
@@ -287,7 +289,7 @@ public class ContactSelectionListFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public Loader<DcContactsLoader.Ret> onCreateLoader(int id, Bundle args) {
|
||||
boolean addCreateGroupLinks = isFromShareActivity() ? false : !isMulti();
|
||||
boolean addCreateGroupLinks = isFromShareActivity() || isRelayingMessageContent(getActivity()) ? false : !isMulti();
|
||||
int listflags = DcContext.DC_GCL_ADD_SELF;
|
||||
if(isSelectVerfied()) {
|
||||
listflags = DcContext.DC_GCL_VERIFIED_ONLY;
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.thoughtcrime.securesms;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
@@ -101,6 +101,7 @@ import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
@@ -113,12 +114,18 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.thoughtcrime.securesms.TransportOption.Type;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.getForwardedMessageIDs;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.getSharedUris;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isForwarding;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isSharing;
|
||||
|
||||
/**
|
||||
* Activity for displaying a message thread, as well as
|
||||
@@ -139,8 +146,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
{
|
||||
private static final String TAG = ConversationActivity.class.getSimpleName();
|
||||
|
||||
// TODO: rename to CHAT_ID_EXTRA
|
||||
public static final String THREAD_ID_EXTRA = "thread_id";
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
public static final String IS_ARCHIVED_EXTRA = "is_archived";
|
||||
public static final String TEXT_EXTRA = "draft_text";
|
||||
public static final String LAST_SEEN_EXTRA = "last_seen";
|
||||
@@ -179,7 +185,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private DcChat dcChat = new DcChat(0);
|
||||
private int chatId;
|
||||
private boolean archived;
|
||||
private final boolean isSecureText = true;
|
||||
private final boolean isSecureText = true;
|
||||
private boolean isDefaultSms = true;
|
||||
private boolean isSecurityInitialized = false;
|
||||
|
||||
@@ -236,6 +242,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
|
||||
if (isForwarding(this)) {
|
||||
handleForwarding();
|
||||
} else if (isSharing(this)) {
|
||||
handleSharing();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -402,7 +414,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
menu.clear();
|
||||
|
||||
if(chatId ==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -498,7 +510,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void handleConversationSettings() {
|
||||
if(chatId !=DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId != DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
Intent intent = new Intent(ConversationActivity.this, RecipientPreferenceActivity.class);
|
||||
intent.putExtra(RecipientPreferenceActivity.ADDRESS_EXTRA, recipient.getAddress());
|
||||
startActivitySceneTransition(intent, titleView.findViewById(R.id.contact_photo_image), "avatar");
|
||||
@@ -528,7 +540,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void handleArchiveChat() {
|
||||
int doArchive = dcContext.getChat(chatId).getArchived()==0? 1: 0;
|
||||
int doArchive = dcContext.getChat(chatId).getArchived() == 0 ? 1: 0;
|
||||
dcContext.archiveChat(chatId, doArchive);
|
||||
Toast.makeText(this, getString(R.string.done), Toast.LENGTH_SHORT).show();
|
||||
if( doArchive == 1 ) {
|
||||
@@ -579,6 +591,30 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void handleForwarding() {
|
||||
String name = dcContext.getChat(chatId).getName();
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.ask_forward, name))
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i) -> new RelayingTask(this, chatId).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR))
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> finish())
|
||||
.show();
|
||||
}
|
||||
|
||||
private void handleSharing() {
|
||||
ArrayList uriList = RelayUtil.getSharedUris(this);
|
||||
if (uriList != null && uriList.size() > 0) {
|
||||
String message = String.format(getString(R.string.share_multiple_attachments), uriList.size());
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(android.R.string.cancel, ((dialog, which) -> {
|
||||
finish();
|
||||
}))
|
||||
.setPositiveButton(R.string.menu_send, (dialog, which) -> new RelayingTask(this, chatId).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
///// Initializers
|
||||
|
||||
private ListenableFuture<Boolean> initializeDraft() {
|
||||
@@ -771,7 +807,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
chatId = getIntent().getIntExtra(THREAD_ID_EXTRA, -1);
|
||||
chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, -1);
|
||||
if(chatId == DcChat.DC_CHAT_NO_CHAT)
|
||||
throw new IllegalStateException("can't display a conversation for no chat.");
|
||||
dcChat = dcContext.getChat(chatId);
|
||||
@@ -786,7 +822,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
conversationContainer.setClipToPadding(true);
|
||||
}
|
||||
|
||||
if(chatId ==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
composePanel.setVisibility(View.GONE);
|
||||
titleView.hideAvatar();
|
||||
}
|
||||
@@ -989,6 +1025,119 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
return future;
|
||||
}
|
||||
|
||||
private static class RelayingTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
WeakReference<Activity> activityRef;
|
||||
int chatId;
|
||||
|
||||
RelayingTask(Activity activity, int chatId) {
|
||||
activityRef = new WeakReference<>(activity);
|
||||
this.chatId = chatId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Activity activity = activityRef.get();
|
||||
if (isForwarding(activity)) {
|
||||
handleForwarding(activity);
|
||||
} else if (isSharing(activity)) {
|
||||
handleSharing(activity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
Activity activity = activityRef.get();
|
||||
if (activity != null) {
|
||||
activity.setResult(RESULT_OK);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleForwarding(Activity activity) {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
dcContext.forwardMsgs(getForwardedMessageIDs(activity), chatId);
|
||||
}
|
||||
|
||||
private void handleSharing(Activity activity) {
|
||||
DcContext dcContext = DcHelper.getContext(activity);
|
||||
ArrayList<Uri> uris = getSharedUris(activity);
|
||||
try {
|
||||
for(Uri uri : uris) {
|
||||
DcMsg message = createMessage(uri);
|
||||
dcContext.sendMsg(chatId, message);
|
||||
}
|
||||
|
||||
for(Uri uri : uris) {
|
||||
cleanup(activity, uri);
|
||||
}
|
||||
} catch (NullPointerException npe) {
|
||||
Log.w(TAG, "Activity destroyed before background task finished. " +
|
||||
"Cancelling message relaying. " +
|
||||
npe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup(Context context, final @Nullable Uri uri) {
|
||||
if (uri != null && PersistentBlobProvider.isAuthority(context, uri)) {
|
||||
Log.w(TAG, "cleaning up " + uri);
|
||||
PersistentBlobProvider.getInstance(context).delete(context, uri);
|
||||
}
|
||||
}
|
||||
|
||||
private DcMsg createMessage(Uri uri) throws NullPointerException {
|
||||
Context context = activityRef.get();
|
||||
DcContext dcContext = DcHelper.getContext(context);
|
||||
DcMsg message;
|
||||
String mimeType = MediaUtil.getMimeType(context, uri);
|
||||
if (MediaUtil.isImageType(mimeType)) {
|
||||
message = new DcMsg(dcContext, DcMsg.DC_MSG_IMAGE);
|
||||
}
|
||||
else if (MediaUtil.isAudioType(mimeType)) {
|
||||
message = new DcMsg(dcContext,DcMsg.DC_MSG_AUDIO);
|
||||
}
|
||||
else if (MediaUtil.isVideoType(mimeType)) {
|
||||
message = new DcMsg(dcContext, DcMsg.DC_MSG_VIDEO);
|
||||
}
|
||||
else {
|
||||
message = new DcMsg(dcContext, DcMsg.DC_MSG_FILE);
|
||||
}
|
||||
message.setFile(getRealPathFromUri(uri), mimeType);
|
||||
return message;
|
||||
}
|
||||
|
||||
private String getRealPathFromUri(Uri uri) throws NullPointerException {
|
||||
Context context = activityRef.get();
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(context);
|
||||
try {
|
||||
String filename = uri.getPathSegments().get(2); // Get real file name from Uri
|
||||
String ext = "";
|
||||
int i = filename.lastIndexOf(".");
|
||||
if(i>=0) {
|
||||
ext = filename.substring(i);
|
||||
filename = filename.substring(0, i);
|
||||
}
|
||||
String path = dcContext.getBlobdirFile(filename, ext);
|
||||
|
||||
// copy content to this file
|
||||
if(path != null) {
|
||||
InputStream inputStream = PartAuthority.getAttachmentStream(context, uri);
|
||||
OutputStream outputStream = new FileOutputStream(path);
|
||||
Util.copy(inputStream, outputStream);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void sendComplete(int threadId) {
|
||||
boolean refreshFragment = (threadId != this.chatId);
|
||||
this.chatId = threadId;
|
||||
|
||||
@@ -69,6 +69,7 @@ import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.Debouncer;
|
||||
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
|
||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
@@ -82,8 +83,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.b44t.messenger.DcContact.DC_CONTACT_ID_SELF;
|
||||
import static org.thoughtcrime.securesms.ShareActivity.EXTRA_FORWARD;
|
||||
import static org.thoughtcrime.securesms.ShareActivity.EXTRA_MSG_IDS;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.setForwardingMessageIds;
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class ConversationFragment extends Fragment
|
||||
@@ -102,7 +102,7 @@ public class ConversationFragment extends Fragment
|
||||
private ConversationFragmentListener listener;
|
||||
|
||||
private Recipient recipient;
|
||||
private long threadId;
|
||||
private long chatId;
|
||||
private long lastSeen;
|
||||
private int startingPosition;
|
||||
private int previousOffset;
|
||||
@@ -153,10 +153,8 @@ public class ConversationFragment extends Fragment
|
||||
|
||||
// setLayerType() is needed to allow larger items (long texts in our case)
|
||||
// with hardware layers, drawing may result in errors as "OpenGLRenderer: Path too large to be rendered into a texture"
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11)
|
||||
{
|
||||
list.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
list.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -169,7 +167,7 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
|
||||
private void setNoMessageText() {
|
||||
if(threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(DcHelper.getInt(getActivity(), "show_emails")!= DcContext.DC_SHOW_EMAILS_ALL) {
|
||||
noMessageTextView.setText(R.string.chat_no_contact_requests);
|
||||
}
|
||||
@@ -178,7 +176,7 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
}
|
||||
else if(getListAdapter().isGroupChat()){
|
||||
if( dcContext.getChat((int)threadId).isUnpromoted() ) {
|
||||
if(dcContext.getChat((int) chatId).isUnpromoted()) {
|
||||
noMessageTextView.setText(R.string.chat_new_group_hint);
|
||||
}
|
||||
else {
|
||||
@@ -186,7 +184,7 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
}else{
|
||||
String name = getListAdapter().getChatName();
|
||||
if(dcContext.getChat((int)threadId).isSelfTalk()) {
|
||||
if(dcContext.getChat((int) chatId).isSelfTalk()) {
|
||||
noMessageTextView.setText(R.string.chat_no_messages);
|
||||
}
|
||||
else {
|
||||
@@ -225,7 +223,7 @@ public class ConversationFragment extends Fragment
|
||||
initializeResources();
|
||||
initializeListAdapter();
|
||||
|
||||
if (threadId == -1) {
|
||||
if (chatId == -1) {
|
||||
reloadList();
|
||||
updateLocationButton();
|
||||
}
|
||||
@@ -246,8 +244,8 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
this.threadId = this.getActivity().getIntent().getIntExtra(ConversationActivity.THREAD_ID_EXTRA, -1);
|
||||
this.recipient = Recipient.from(getActivity(), Address.fromChat((int)this.threadId));
|
||||
this.chatId = this.getActivity().getIntent().getIntExtra(ConversationActivity.CHAT_ID_EXTRA, -1);
|
||||
this.recipient = Recipient.from(getActivity(), Address.fromChat((int)this.chatId));
|
||||
this.lastSeen = this.getActivity().getIntent().getLongExtra(ConversationActivity.LAST_SEEN_EXTRA, -1);
|
||||
this.startingPosition = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
|
||||
this.firstLoad = true;
|
||||
@@ -257,7 +255,7 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
|
||||
private void initializeListAdapter() {
|
||||
if (this.recipient != null && this.threadId != -1) {
|
||||
if (this.recipient != null && this.chatId != -1) {
|
||||
ConversationAdapter adapter = new ConversationAdapter(getActivity(), this.recipient.getChat(), GlideApp.with(this), locale, selectionClickListener, this.recipient);
|
||||
list.setAdapter(adapter);
|
||||
list.addItemDecoration(new StickyHeaderDecoration(adapter, false, false));
|
||||
@@ -297,11 +295,11 @@ public class ConversationFragment extends Fragment
|
||||
else throw new AssertionError();
|
||||
}
|
||||
|
||||
public void reload(Recipient recipient, long threadId) {
|
||||
public void reload(Recipient recipient, long chatId) {
|
||||
this.recipient = recipient;
|
||||
|
||||
if (this.threadId != threadId) {
|
||||
this.threadId = threadId;
|
||||
if (this.chatId != chatId) {
|
||||
this.chatId = chatId;
|
||||
initializeListAdapter();
|
||||
}
|
||||
}
|
||||
@@ -333,7 +331,7 @@ public class ConversationFragment extends Fragment
|
||||
ret += contact.getDisplayName() + ":\n";
|
||||
}
|
||||
|
||||
if( msg.getType()==DcMsg.DC_MSG_TEXT ) {
|
||||
if(msg.getType() == DcMsg.DC_MSG_TEXT) {
|
||||
ret += msg.getText();
|
||||
}
|
||||
else {
|
||||
@@ -401,10 +399,9 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
|
||||
private void handleForwardMessage(final Set<DcMsg> messageRecords) {
|
||||
Intent composeIntent = new Intent(getActivity(), ShareActivity.class);
|
||||
Intent composeIntent = new Intent(getActivity(), ConversationListActivity.class);
|
||||
int[] msgIds = DcMsg.msgSetToIds(messageRecords);
|
||||
composeIntent.putExtra(EXTRA_MSG_IDS, msgIds);
|
||||
composeIntent.putExtra(EXTRA_FORWARD, true);
|
||||
setForwardingMessageIds(composeIntent, msgIds);
|
||||
startActivity(composeIntent);
|
||||
Objects.requireNonNull(getActivity()).overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
||||
}
|
||||
@@ -456,9 +453,10 @@ public class ConversationFragment extends Fragment
|
||||
if (loadSynchronous) {
|
||||
// this typically takes <1 ms ...
|
||||
loaderStartTime = System.currentTimeMillis();
|
||||
int[] msgs = DcHelper.getContext(getContext()).getChatMsgs((int)threadId, 0, 0);
|
||||
int[] msgs = DcHelper.getContext(getContext()).getChatMsgs((int) chatId, 0, 0);
|
||||
onLoadFinished(null, msgs);
|
||||
}
|
||||
//FIXME: remove dead code
|
||||
else {
|
||||
// ... while this takes >100 ms
|
||||
LoaderManager loaderManager = getLoaderManager();
|
||||
@@ -469,7 +467,7 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
|
||||
private void updateLocationButton() {
|
||||
floatingLocationButton.setVisibility(dcContext.isSendingLocationsToChat((int)threadId)? View.VISIBLE : View.GONE);
|
||||
floatingLocationButton.setVisibility(dcContext.isSendingLocationsToChat((int) chatId)? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -477,7 +475,7 @@ public class ConversationFragment extends Fragment
|
||||
Log.w(TAG, "onCreateLoader");
|
||||
loaderStartTime = System.currentTimeMillis();
|
||||
|
||||
return new DcMsgListLoader(getActivity(), (int)threadId, 0, 0);
|
||||
return new DcMsgListLoader(getActivity(), (int) chatId, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -858,7 +856,7 @@ public class ConversationFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if (eventId==DcContext.DC_EVENT_CHAT_MODIFIED) {
|
||||
if (eventId == DcContext.DC_EVENT_CHAT_MODIFIED) {
|
||||
updateLocationButton();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.LongClickCopySpan;
|
||||
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
|
||||
@@ -627,7 +626,7 @@ public class ConversationItem extends LinearLayout
|
||||
int chatId = dcContext.createChatByMsgId(messageRecord.getId());
|
||||
if( chatId != 0 ) {
|
||||
Intent intent = new Intent(context, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.google.zxing.integration.android.IntentIntegrator;
|
||||
@@ -39,7 +40,15 @@ import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.LAST_SEEN_EXTRA;
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.STARTING_POSITION_EXTRA;
|
||||
import static org.thoughtcrime.securesms.map.MapDataManager.ALL_CHATS_GLOBAL_MAP;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isForwarding;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.resetRelayingMessageContent;
|
||||
|
||||
public class ConversationListActivity extends PassphraseRequiredActionBarActivity
|
||||
implements ConversationListFragment.ConversationSelectedListener
|
||||
@@ -51,6 +60,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private ConversationListFragment conversationListFragment;
|
||||
private TextView title;
|
||||
private SearchFragment searchFragment;
|
||||
private SearchToolbar searchToolbar;
|
||||
private ImageView searchAction;
|
||||
@@ -69,6 +79,7 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
title = findViewById(R.id.toolbar_title);
|
||||
searchToolbar = findViewById(R.id.search_toolbar);
|
||||
searchAction = findViewById(R.id.search_action);
|
||||
fragmentContainer = findViewById(R.id.fragment_container);
|
||||
@@ -77,6 +88,24 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
initializeSearchListener();
|
||||
|
||||
TooltipCompat.setTooltipText(searchAction, getText(R.string.search_explain));
|
||||
if (isRelayingMessageContent(this)) {
|
||||
title.setText(isForwarding(this) ? R.string.forward_to : R.string.chat_share_with_title);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
title.setText(isForwarding(this) ? R.string.forward_to : R.string.chat_share_with_title);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
conversationListFragment.onNewIntent();
|
||||
} else {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
}
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,14 +120,16 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
MenuInflater inflater = this.getMenuInflater();
|
||||
menu.clear();
|
||||
|
||||
inflater.inflate(R.menu.text_secure_normal, menu);
|
||||
MenuItem item = menu.findItem(R.id.menu_global_map);
|
||||
if (Prefs.isLocationStreamingEnabled(this)) {
|
||||
item.setVisible(true);
|
||||
}
|
||||
if (!isRelayingMessageContent(this)) {
|
||||
inflater.inflate(R.menu.text_secure_normal, menu);
|
||||
MenuItem item = menu.findItem(R.id.menu_global_map);
|
||||
if (Prefs.isLocationStreamingEnabled(this)) {
|
||||
item.setVisible(true);
|
||||
}
|
||||
|
||||
if (!Prefs.isLocationStreamingEnabled(this)) {
|
||||
menu.findItem(R.id.menu_global_map).setVisible(false);
|
||||
if (!Prefs.isLocationStreamingEnabled(this)) {
|
||||
menu.findItem(R.id.menu_global_map).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
@@ -155,11 +186,20 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
case R.id.menu_qr_show: handleQrShow(); return true;
|
||||
case R.id.menu_deaddrop: handleDeaddrop(); return true;
|
||||
case R.id.menu_global_map: handleShowMap(); return true;
|
||||
case android.R.id.home: handleResetRelaying(); return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleResetRelaying() {
|
||||
resetRelayingMessageContent(this);
|
||||
title.setText(R.string.dc_app_name);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
conversationListFragment.onNewIntent();
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void handleShowMap() {
|
||||
Intent intent = new Intent(this, MapActivity.class);
|
||||
intent.putExtra(MapActivity.CHAT_IDS, ALL_CHATS_GLOBAL_MAP);
|
||||
@@ -176,42 +216,59 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateConversation(int threadId, long lastSeen) {
|
||||
openConversation(threadId, lastSeen, -1);
|
||||
public void onCreateConversation(int chatId, long lastSeen) {
|
||||
openConversation(chatId, lastSeen, -1);
|
||||
}
|
||||
|
||||
public void openConversation(int threadId, long lastSeen, int startingPosition) {
|
||||
public void openConversation(int chatId, long lastSeen, int startingPosition) {
|
||||
searchToolbar.clearFocus();
|
||||
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, lastSeen);
|
||||
intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition);
|
||||
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
||||
intent.putExtra(LAST_SEEN_EXTRA, lastSeen);
|
||||
intent.putExtra(STARTING_POSITION_EXTRA, startingPosition);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
acquireRelayMessageContent(this, intent);
|
||||
startActivityForResult(intent, REQUEST_RELAY);
|
||||
} else {
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
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);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
acquireRelayMessageContent(this, intent);
|
||||
startActivityForResult(intent, REQUEST_RELAY);
|
||||
} else {
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (searchToolbar.isVisible()) searchToolbar.collapse();
|
||||
else super.onBackPressed();
|
||||
else if (isRelayingMessageContent(this)) {
|
||||
handleResetRelaying();
|
||||
} else super.onBackPressed();
|
||||
}
|
||||
|
||||
private void createChat() {
|
||||
Intent intent = new Intent(this, NewConversationActivity.class);
|
||||
startActivity(intent);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
acquireRelayMessageContent(this, intent);
|
||||
startActivityForResult(intent, REQUEST_RELAY);
|
||||
} else {
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeaddrop() {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, DcChat.DC_CHAT_ID_DEADDROP);
|
||||
intent.putExtra(CHAT_ID_EXTRA, DcChat.DC_CHAT_ID_DEADDROP);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@@ -223,10 +280,19 @@ public class ConversationListActivity extends PassphraseRequiredActionBarActivit
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == IntentIntegrator.REQUEST_CODE) {
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
QrScanHandler qrScanHandler = new QrScanHandler(this);
|
||||
qrScanHandler.onScanPerformed(scanResult);
|
||||
switch (requestCode) {
|
||||
case IntentIntegrator.REQUEST_CODE:
|
||||
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
||||
QrScanHandler qrScanHandler = new QrScanHandler(this);
|
||||
qrScanHandler.onScanPerformed(scanResult);
|
||||
break;
|
||||
case REQUEST_RELAY:
|
||||
if (resultCode == RESULT_OK) {
|
||||
handleResetRelaying();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,13 @@ import android.view.MenuItem;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.IS_ARCHIVED_EXTRA;
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.LAST_SEEN_EXTRA;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
|
||||
public class ConversationListArchiveActivity extends PassphraseRequiredActionBarActivity
|
||||
implements ConversationListFragment.ConversationSelectedListener
|
||||
{
|
||||
@@ -23,7 +30,12 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle, boolean ready) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setTitle(R.string.chat_archived_chats_title);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
getSupportActionBar().setTitle(R.string.forward_to);
|
||||
getSupportActionBar().setSubtitle(R.string.chat_archived_chats_title);
|
||||
} else {
|
||||
getSupportActionBar().setTitle(R.string.chat_archived_chats_title);
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(ConversationListFragment.ARCHIVE, true);
|
||||
@@ -50,13 +62,18 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateConversation(int threadId, long lastSeenTime) {
|
||||
public void onCreateConversation(int chatId, long lastSeenTime) {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||
intent.putExtra(ConversationActivity.IS_ARCHIVED_EXTRA, true);
|
||||
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, lastSeenTime);
|
||||
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
||||
intent.putExtra(IS_ARCHIVED_EXTRA, true);
|
||||
intent.putExtra(LAST_SEEN_EXTRA, lastSeenTime);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
acquireRelayMessageContent(this, intent);
|
||||
startActivityForResult(intent, REQUEST_RELAY);
|
||||
} else {
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
startActivity(intent);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
||||
}
|
||||
|
||||
@@ -65,4 +82,12 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_RELAY && resultCode == RESULT_OK) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
|
||||
|
||||
public class ConversationListFragment extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<DcChatlist>, ActionMode.Callback, ItemClickListener, DcEventCenter.DcEventDelegate
|
||||
@@ -101,12 +105,12 @@ public class ConversationListFragment extends Fragment
|
||||
archive = getArguments().getBoolean(ARCHIVE, false);
|
||||
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(getActivity());
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_CHAT_MODIFIED);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_INCOMING_MSG);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_MSGS_CHANGED);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_MSG_DELIVERED);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_MSG_FAILED);
|
||||
dcContext.eventCenter.addObserver(this, DcContext.DC_EVENT_MSG_READ);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSG_DELIVERED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSG_FAILED, this);
|
||||
dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSG_READ, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +132,7 @@ public class ConversationListFragment extends Fragment
|
||||
if (archive) fab.setVisibility(View.GONE);
|
||||
else fab.setVisibility(View.VISIBLE);
|
||||
|
||||
reminderView.setOnDismissListener(() -> updateReminders(true));
|
||||
reminderView.setOnDismissListener(this::updateReminders);
|
||||
|
||||
list.setHasFixedSize(true);
|
||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
@@ -144,7 +148,7 @@ public class ConversationListFragment extends Fragment
|
||||
super.onActivityCreated(bundle);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewConversationActivity.class)));
|
||||
initializeFabClickListener();
|
||||
initializeListAdapter();
|
||||
}
|
||||
|
||||
@@ -152,17 +156,20 @@ public class ConversationListFragment extends Fragment
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
updateReminders(true);
|
||||
updateReminders();
|
||||
list.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
fab.stopPulse();
|
||||
}
|
||||
|
||||
public void onNewIntent() {
|
||||
initializeFabClickListener();
|
||||
}
|
||||
|
||||
public ConversationListAdapter getListAdapter() {
|
||||
return (ConversationListAdapter) list.getAdapter();
|
||||
}
|
||||
@@ -178,8 +185,18 @@ public class ConversationListFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void updateReminders(boolean hide) {
|
||||
private void initializeFabClickListener() {
|
||||
Intent intent = new Intent(getActivity(), NewConversationActivity.class);
|
||||
if (isRelayingMessageContent(getActivity())) {
|
||||
acquireRelayMessageContent(getActivity(), intent);
|
||||
fab.setOnClickListener(v -> getActivity().startActivityForResult(intent, REQUEST_RELAY));
|
||||
} else {
|
||||
fab.setOnClickListener(v -> startActivity(intent));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint({"StaticFieldLeak", "NewApi"})
|
||||
private void updateReminders() {
|
||||
new AsyncTask<Context, Void, Optional<? extends Reminder>>() {
|
||||
@Override
|
||||
protected Optional<? extends Reminder> doInBackground(Context... params) {
|
||||
@@ -244,12 +261,12 @@ public class ConversationListFragment extends Fragment
|
||||
|
||||
@Override
|
||||
protected void executeAction(@Nullable Void parameter) {
|
||||
for (long threadId : selectedConversations) {
|
||||
if (threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
for (long chatId : selectedConversations) {
|
||||
if (chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
dcContext.marknoticedContact(getListAdapter().getDeaddropContactId());
|
||||
}
|
||||
else {
|
||||
dcContext.archiveChat((int)threadId, !archive? 1 : 0);
|
||||
dcContext.archiveChat((int)chatId, !archive? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,12 +307,12 @@ public class ConversationListFragment extends Fragment
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
for (long threadId : selectedConversations) {
|
||||
if (threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
for (long chatId : selectedConversations) {
|
||||
if (chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
dcContext.marknoticedContact(getListAdapter().getDeaddropContactId());
|
||||
}
|
||||
else {
|
||||
dcContext.deleteChat((int) threadId);
|
||||
dcContext.deleteChat((int) chatId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -381,13 +398,14 @@ public class ConversationListFragment extends Fragment
|
||||
@Override
|
||||
public void onItemClick(ConversationListItem item) {
|
||||
if (actionMode == null) {
|
||||
int threadId = (int)item.getThreadId();
|
||||
int chatId = (int)item.getChatId();
|
||||
|
||||
if (threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if (chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
DcContext dcContext = DcHelper.getContext(getActivity());
|
||||
int msgId = item.getMsgId();
|
||||
int contactId = item.getContactId();
|
||||
DcContact contact = dcContext.getContact(contactId);
|
||||
//TODO: check if forward messages
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setMessage(getActivity().getString(R.string.ask_start_chat_with, contact.getNameNAddr()))
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
@@ -404,10 +422,10 @@ public class ConversationListFragment extends Fragment
|
||||
return;
|
||||
}
|
||||
|
||||
handleCreateConversation(threadId, 0);
|
||||
handleCreateConversation(chatId, 0);
|
||||
} else {
|
||||
ConversationListAdapter adapter = (ConversationListAdapter)list.getAdapter();
|
||||
adapter.toggleThreadInBatchSet(item.getThreadId());
|
||||
adapter.toggleThreadInBatchSet(item.getChatId());
|
||||
|
||||
if (adapter.getBatchSelections().size() == 0) {
|
||||
actionMode.finish();
|
||||
@@ -424,7 +442,7 @@ public class ConversationListFragment extends Fragment
|
||||
actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(ConversationListFragment.this);
|
||||
|
||||
getListAdapter().initializeBatchMode(true);
|
||||
getListAdapter().toggleThreadInBatchSet(item.getThreadId());
|
||||
getListAdapter().toggleThreadInBatchSet(item.getChatId());
|
||||
getListAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -440,6 +458,10 @@ public class ConversationListFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
if (isRelayingMessageContent(getActivity())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MenuInflater inflater = getActivity().getMenuInflater();
|
||||
|
||||
if (archive) inflater.inflate(R.menu.conversation_list_batch_unarchive, menu);
|
||||
@@ -516,7 +538,7 @@ public class ConversationListFragment extends Fragment
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
if (viewHolder.itemView instanceof ConversationListItemInboxZero) return;
|
||||
final long threadId = ((ConversationListItem)viewHolder.itemView).getThreadId();
|
||||
final long chatId = ((ConversationListItem)viewHolder.itemView).getChatId();
|
||||
final DcContext dcContext = DcHelper.getContext(getActivity());
|
||||
|
||||
if (archive) {
|
||||
@@ -527,16 +549,16 @@ public class ConversationListFragment extends Fragment
|
||||
{
|
||||
@Override
|
||||
protected void executeAction(@Nullable Long parameter) {
|
||||
dcContext.archiveChat((int)threadId, 0);
|
||||
dcContext.archiveChat((int) chatId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reverseAction(@Nullable Long parameter) {
|
||||
dcContext.archiveChat((int)threadId, 1);
|
||||
dcContext.archiveChat((int) chatId, 1);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, chatId);
|
||||
} else {
|
||||
if (threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if (chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
int contactId = ((ConversationListItem)viewHolder.itemView).getContactId();
|
||||
dcContext.marknoticedContact(contactId);
|
||||
forceListRedraw = true;
|
||||
@@ -550,14 +572,14 @@ public class ConversationListFragment extends Fragment
|
||||
{
|
||||
@Override
|
||||
protected void executeAction(@Nullable Long parameter) {
|
||||
dcContext.archiveChat((int)threadId, 1);
|
||||
dcContext.archiveChat((int) chatId, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reverseAction(@Nullable Long parameter) {
|
||||
dcContext.archiveChat((int)threadId, 0);
|
||||
dcContext.archiveChat((int) chatId, 0);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, threadId);
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, chatId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
|
||||
private DcLot dcSummary;
|
||||
private Set<Long> selectedThreads;
|
||||
private long threadId;
|
||||
private long chatId;
|
||||
private int msgId;
|
||||
private GlideRequests glideRequests;
|
||||
private TextView subjectView;
|
||||
@@ -133,7 +133,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
this.dcSummary = dcSummary;
|
||||
this.selectedThreads = selectedThreads;
|
||||
Recipient recipient = thread.getRecipient();
|
||||
this.threadId = thread.getThreadId();
|
||||
this.chatId = thread.getThreadId();
|
||||
this.msgId = msgId;
|
||||
this.glideRequests = glideRequests;
|
||||
this.unreadCount = thread.getUnreadCount();
|
||||
@@ -165,7 +165,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
setBgColor();
|
||||
|
||||
ApplicationDcContext dcContext = DcHelper.getContext(getContext());
|
||||
if(threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
DcContact dcContact = dcContext.getContact(dcContext.getMsg(msgId).getFromId());
|
||||
this.contactPhotoImage.setAvatar(glideRequests, dcContext.getRecipient(dcContact), false);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
}
|
||||
|
||||
fromView.setCompoundDrawablesWithIntrinsicBounds(
|
||||
Prefs.isChatMuted(getContext(), (int)threadId)? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
Prefs.isChatMuted(getContext(), (int) chatId)? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
0,
|
||||
thread.isVerified()? R.drawable.ic_verified : 0,
|
||||
0);
|
||||
@@ -247,11 +247,11 @@ public class ConversationListItem extends RelativeLayout
|
||||
}
|
||||
|
||||
private void setBatchState(boolean batch) {
|
||||
setSelected(batch && selectedThreads.contains(threadId));
|
||||
setSelected(batch && selectedThreads.contains(chatId));
|
||||
}
|
||||
|
||||
public long getThreadId() {
|
||||
return threadId;
|
||||
public long getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public int getMsgId() {
|
||||
@@ -315,7 +315,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
}
|
||||
|
||||
private void setBgColor() {
|
||||
if(threadId==DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
if(chatId == DcChat.DC_CHAT_ID_DEADDROP) {
|
||||
TypedArray ta = getContext().obtainStyledAttributes(new int[] { R.attr.conversation_list_deaddrop_bg_color});
|
||||
setBackgroundColor(ta.getColor(0, 0xffffffff));
|
||||
ta.recycle();
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ConversationPopupActivity extends ConversationActivity {
|
||||
public void onSuccess(Integer result) {
|
||||
ActivityOptionsCompat transition = ActivityOptionsCompat.makeScaleUpAnimation(getWindow().getDecorView(), 0, 0, getWindow().getAttributes().width, getWindow().getAttributes().height);
|
||||
Intent intent = new Intent(ConversationPopupActivity.this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, result);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, result);
|
||||
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
|
||||
startActivity(intent, transition.toBundle());
|
||||
|
||||
@@ -318,7 +318,7 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
private void groupCreateDone() {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, groupChatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, groupChatId);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ import org.thoughtcrime.securesms.util.Util;
|
||||
import java.io.IOException;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import static org.thoughtcrime.securesms.ShareActivity.EXTRA_FORWARD;
|
||||
import static org.thoughtcrime.securesms.ShareActivity.EXTRA_MSG_IDS;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.setForwardingMessageIds;
|
||||
|
||||
/**
|
||||
* Activity for displaying media attachments in-app
|
||||
@@ -257,10 +256,9 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity
|
||||
MediaItem mediaItem = getCurrentMediaItem();
|
||||
|
||||
if (mediaItem != null) {
|
||||
Intent composeIntent = new Intent(this, ShareActivity.class);
|
||||
Intent composeIntent = new Intent(this, ConversationListActivity.class);
|
||||
int[] msgIds = new int[]{mediaItem.msgId};
|
||||
composeIntent.putExtra(EXTRA_MSG_IDS, msgIds);
|
||||
composeIntent.putExtra(EXTRA_FORWARD, true);
|
||||
setForwardingMessageIds(composeIntent, msgIds);
|
||||
startActivity(composeIntent);
|
||||
overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,12 @@ import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.CHAT_ID_EXTRA;
|
||||
import static org.thoughtcrime.securesms.ConversationActivity.TEXT_EXTRA;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.REQUEST_RELAY;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.acquireRelayMessageContent;
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
|
||||
/**
|
||||
* Activity container for starting a new conversation.
|
||||
*
|
||||
@@ -76,7 +82,7 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
if (recipientsArray.length >= 1) {
|
||||
String recipient = recipientsArray[0];
|
||||
if (textToShare != null && !textToShare.isEmpty()) {
|
||||
getIntent().putExtra(ConversationActivity.TEXT_EXTRA, textToShare);
|
||||
getIntent().putExtra(TEXT_EXTRA, textToShare);
|
||||
}
|
||||
onContactSelected(DcContact.DC_CONTACT_ID_NEW_CONTACT, recipient);
|
||||
}
|
||||
@@ -121,9 +127,9 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
@Override
|
||||
public void onContactSelected(int specialId, String addr) {
|
||||
final DcContext dcContext = DcHelper.getContext(this);
|
||||
if(specialId==DcContact.DC_CONTACT_ID_NEW_GROUP || specialId==DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP) {
|
||||
if(specialId == DcContact.DC_CONTACT_ID_NEW_GROUP || specialId == DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP) {
|
||||
Intent intent = new Intent(this, GroupCreateActivity.class);
|
||||
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, specialId==DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP);
|
||||
intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, specialId == DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
@@ -136,14 +142,14 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
int contactId = dcContext.lookupContactIdByAddr(addr);
|
||||
int chatId = dcContext.getChatIdByContactId(contactId);
|
||||
if (chatId == 0) {
|
||||
String nameNAddr = contactId==0? addr : dcContext.getContact(contactId).getNameNAddr();
|
||||
String nameNAddr = contactId == 0 ? addr : dcContext.getContact(contactId).getNameNAddr();
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.ask_start_chat_with, nameNAddr))
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
int contactId1 = dcContext.createContact(null, addr);
|
||||
if(contactId1 ==0) {
|
||||
if(contactId1 == 0) {
|
||||
Toast.makeText(NewConversationActivity.this, R.string.bad_email_address, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
@@ -157,12 +163,17 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
|
||||
private void openConversation(int chatId) {
|
||||
Intent intent = new Intent(this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA));
|
||||
intent.putExtra(TEXT_EXTRA, getIntent().getStringExtra(TEXT_EXTRA));
|
||||
intent.setDataAndType(getIntent().getData(), getIntent().getType());
|
||||
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
intent.putExtra(CHAT_ID_EXTRA, chatId);
|
||||
if (isRelayingMessageContent(this)) {
|
||||
acquireRelayMessageContent(this, intent);
|
||||
startActivityForResult(intent, REQUEST_RELAY);
|
||||
} else {
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,4 +197,14 @@ public class NewConversationActivity extends ContactSelectionActivity {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_RELAY && resultCode == RESULT_OK) {
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
int chatId = dcContext.createChatByContactId(contact.getId());
|
||||
if (chatId != 0) {
|
||||
Intent intent = new Intent(getActivity(), ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
getActivity().startActivity(intent);
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.util.FileUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ResolveMediaTask extends AsyncTask<Uri, Void, Uri> {
|
||||
|
||||
private static final String TAG = ResolveMediaTask.class.getSimpleName();
|
||||
|
||||
interface OnMediaResolvedListener {
|
||||
void onMediaResolved(Uri uri);
|
||||
}
|
||||
|
||||
private WeakReference<Activity> contextRef;
|
||||
private WeakReference<OnMediaResolvedListener> listenerWeakReference;
|
||||
|
||||
private static HashSet<ResolveMediaTask> instances = new HashSet<>();
|
||||
|
||||
ResolveMediaTask(Activity activityContext, ResolveMediaTask.OnMediaResolvedListener listener) {
|
||||
this.contextRef = new WeakReference<>(activityContext);
|
||||
this.listenerWeakReference = new WeakReference<>(listener);
|
||||
instances.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Uri doInBackground(Uri... uris) {
|
||||
try {
|
||||
Uri uri = uris[0];
|
||||
if (uris.length != 1 || uri == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream;
|
||||
String fileName = null;
|
||||
Long fileSize = null;
|
||||
|
||||
if (hasFileScheme(uri)) {
|
||||
inputStream = this.openFileUri(uri);
|
||||
if (uri.getPath() != null) {
|
||||
File file = new File(uri.getPath());
|
||||
fileName = file.getName();
|
||||
fileSize = file.length();
|
||||
}
|
||||
} else {
|
||||
inputStream = contextRef.get().getContentResolver().openInputStream(uri);
|
||||
}
|
||||
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Cursor cursor = contextRef.get().getContentResolver().query(uri, new String[]{OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE}, null, null, null);
|
||||
|
||||
try {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
try {
|
||||
fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
|
||||
fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
String mimeType = getMimeType(contextRef.get(), uri);
|
||||
return PersistentBlobProvider.getInstance(contextRef.get()).create(contextRef.get(), inputStream, mimeType, fileName, fileSize);
|
||||
} catch (NullPointerException | IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Uri uri) {
|
||||
instances.remove(this);
|
||||
if (!this.isCancelled()) {
|
||||
listenerWeakReference.get().onMediaResolved(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
instances.remove(this);
|
||||
super.onCancelled();
|
||||
listenerWeakReference.get().onMediaResolved(null);
|
||||
|
||||
}
|
||||
|
||||
public static boolean isExecuting() {
|
||||
return !instances.isEmpty();
|
||||
}
|
||||
|
||||
public static void cancelTasks() {
|
||||
for (ResolveMediaTask task : instances) {
|
||||
task.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream openFileUri(Uri uri) throws IOException {
|
||||
FileInputStream fin = new FileInputStream(uri.getPath());
|
||||
int owner = FileUtils.getFileDescriptorOwner(fin.getFD());
|
||||
|
||||
|
||||
if (owner == -1 || owner == Process.myUid()) {
|
||||
fin.close();
|
||||
throw new IOException("File owned by application");
|
||||
}
|
||||
|
||||
return fin;
|
||||
}
|
||||
|
||||
|
||||
private boolean hasFileScheme(Uri uri) {
|
||||
if (uri == null) {
|
||||
return false;
|
||||
}
|
||||
return "file".equals(uri.getScheme());
|
||||
}
|
||||
|
||||
private String getMimeType(Activity activityContext, @Nullable Uri uri) {
|
||||
if (uri != null) {
|
||||
final String mimeType = MediaUtil.getMimeType(activityContext.getApplicationContext(), uri);
|
||||
if (mimeType != null) return mimeType;
|
||||
}
|
||||
return MediaUtil.getCorrectedMimeType(activityContext.getIntent().getType());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,97 +18,61 @@
|
||||
package org.thoughtcrime.securesms;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Process;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.b44t.messenger.DcChatlist;
|
||||
import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcEventCenter;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.ApplicationDcContext;
|
||||
import org.thoughtcrime.securesms.connect.DcChatlistLoader;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.providers.PersistentBlobProvider;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.FileUtils;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.RelayUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* An activity to quickly share content with chats
|
||||
*
|
||||
* @author Jake McGinty
|
||||
*/
|
||||
public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
public class ShareActivity extends PassphraseRequiredActionBarActivity implements ResolveMediaTask.OnMediaResolvedListener
|
||||
{
|
||||
|
||||
interface ConversationClickedListener {
|
||||
|
||||
void onConversationClicked(int chatId);
|
||||
|
||||
}
|
||||
|
||||
private static final String TAG = ShareActivity.class.getSimpleName();
|
||||
|
||||
public static final String EXTRA_THREAD_ID = "thread_id";
|
||||
public static final String EXTRA_CHAT_ID = "chat_id";
|
||||
public static final String EXTRA_ADDRESS_MARSHALLED = "address_marshalled";
|
||||
public static final String EXTRA_DISTRIBUTION_TYPE = "distribution_type";
|
||||
public static final String EXTRA_MSG_IDS = "message_ids";
|
||||
public static final String EXTRA_FORWARD = "forward";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private ShareFragment shareFragment;
|
||||
private View progressWheel;
|
||||
private List<Uri> resolvedExtras;
|
||||
private boolean isPassingAlongMedia;
|
||||
private ArrayList<Uri> resolvedExtras;
|
||||
private ApplicationDcContext dcContext;
|
||||
private boolean isForward;
|
||||
private boolean isResolvingUrisOnMainThread;
|
||||
|
||||
@Override
|
||||
protected void onPreCreate() {
|
||||
@@ -122,16 +86,10 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
setContentView(R.layout.share_activity);
|
||||
|
||||
initializeActivityContext();
|
||||
initializeToolbar();
|
||||
initializeResources();
|
||||
initializeMedia();
|
||||
}
|
||||
|
||||
private void initializeActivityContext() {
|
||||
isForward = getIntent().getBooleanExtra(EXTRA_FORWARD, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
Log.w(TAG, "onNewIntent()");
|
||||
@@ -151,29 +109,12 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (!isPassingAlongMedia && resolvedExtras.size() != 0) {
|
||||
for(Uri uri : resolvedExtras) {
|
||||
if (uri != null) {
|
||||
PersistentBlobProvider.getInstance(this).delete(this, uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
||||
ResolveMediaTask.cancelTasks();
|
||||
}
|
||||
|
||||
private void initializeToolbar() {
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
if(isForward) {
|
||||
TextView title = toolbar.findViewById(R.id.title);
|
||||
title.setText(R.string.forward_to);
|
||||
}
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
@@ -181,34 +122,7 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeResources() {
|
||||
progressWheel = findViewById(R.id.progress_wheel);
|
||||
shareFragment = (ShareFragment) getSupportFragmentManager().findFragmentById(R.id.share_fragment);
|
||||
shareFragment.setConversationClickedListener(this::onConversationClick);
|
||||
shareFragment.setLocale(dynamicLanguage.getCurrentLocale());
|
||||
}
|
||||
|
||||
private void onConversationClick(int chatId) {
|
||||
String name = dcContext.getChat(chatId).getName();
|
||||
if (isForward) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.ask_forward, name))
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i) -> delegateMessage(chatId))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
} else {
|
||||
delegateMessage(chatId);
|
||||
}
|
||||
}
|
||||
|
||||
private void delegateMessage(int chatId) {
|
||||
int[] value = getIntent().getIntArrayExtra(EXTRA_MSG_IDS);
|
||||
dcContext.forwardMsgs(value, chatId);
|
||||
createConversation(chatId);
|
||||
}
|
||||
|
||||
private void initializeMedia() {
|
||||
isPassingAlongMedia = false;
|
||||
resolvedExtras = new ArrayList<>();
|
||||
|
||||
List<Uri> streamExtras = new ArrayList<>();
|
||||
@@ -264,17 +178,19 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void resolveUris(List<Uri> streamExtras) {
|
||||
isResolvingUrisOnMainThread = true;
|
||||
for (Uri streamExtra : streamExtras) {
|
||||
if (streamExtra != null && PartAuthority.isLocalUri(streamExtra)) {
|
||||
isPassingAlongMedia = true;
|
||||
resolvedExtras.add(streamExtra);
|
||||
handleResolvedMedia(getIntent(), false);
|
||||
} else {
|
||||
shareFragment.getView().setVisibility(View.GONE);
|
||||
progressWheel.setVisibility(View.VISIBLE);
|
||||
new ResolveMediaTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, streamExtra);
|
||||
new ResolveMediaTask(this, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, streamExtra);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ResolveMediaTask.isExecuting()) {
|
||||
handleResolvedMedia(getIntent());
|
||||
}
|
||||
isResolvingUrisOnMainThread = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -286,8 +202,19 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleResolvedMedia(Intent intent, boolean animate) {
|
||||
int threadId = intent.getIntExtra(EXTRA_THREAD_ID, -1);
|
||||
@Override
|
||||
public void onMediaResolved(Uri uri) {
|
||||
if (uri != null) {
|
||||
resolvedExtras.add(uri);
|
||||
}
|
||||
|
||||
if (!ResolveMediaTask.isExecuting() && !isResolvingUrisOnMainThread) {
|
||||
handleResolvedMedia(getIntent());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleResolvedMedia(Intent intent) {
|
||||
int chatId = intent.getIntExtra(EXTRA_CHAT_ID, -1);
|
||||
int distributionType = intent.getIntExtra(EXTRA_DISTRIBUTION_TYPE, -1);
|
||||
Address address = null;
|
||||
|
||||
@@ -300,44 +227,45 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
parcel.recycle();
|
||||
}
|
||||
|
||||
boolean hasResolvedDestination = threadId != -1 && address != null && distributionType != -1;
|
||||
boolean hasResolvedDestination = chatId != -1 && address != null && distributionType != -1;
|
||||
|
||||
if (!hasResolvedDestination && animate) {
|
||||
ViewUtil.fadeIn(shareFragment.getView(), 300);
|
||||
ViewUtil.fadeOut(progressWheel, 300);
|
||||
} else if (!hasResolvedDestination) {
|
||||
shareFragment.getView().setVisibility(View.VISIBLE);
|
||||
progressWheel.setVisibility(View.GONE);
|
||||
if (hasResolvedDestination) {
|
||||
createConversation(chatId);
|
||||
} else {
|
||||
createConversation(threadId);
|
||||
Intent composeIntent = new Intent(this, ConversationListActivity.class);
|
||||
RelayUtil.setSharedUris(composeIntent, resolvedExtras);
|
||||
startActivity(composeIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
private void createConversation(int threadId) {
|
||||
private void createConversation(int chatId) {
|
||||
if (resolvedExtras.size() > 1) {
|
||||
String message = String.format(getString(R.string.share_multiple_attachments), resolvedExtras.size());
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setCancelable(true)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.menu_send, (dialog, which) -> sendMultipleAttachmentsAndCreateConversation(threadId)).show();
|
||||
.setCancelable(false)
|
||||
.setNegativeButton(android.R.string.cancel, ((dialog, which) -> {
|
||||
finish();
|
||||
}))
|
||||
.setPositiveButton(R.string.menu_send, (dialog, which) -> sendMultipleAttachmentsAndCreateConversation(chatId))
|
||||
.show();
|
||||
} else {
|
||||
openConversation(threadId);
|
||||
openConversation(chatId);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMultipleAttachmentsAndCreateConversation(int threadId) {
|
||||
private void sendMultipleAttachmentsAndCreateConversation(int chatId) {
|
||||
for(Uri uri : resolvedExtras) {
|
||||
DcMsg message = createMessage(uri);
|
||||
dcContext.sendMsg(threadId, message);
|
||||
dcContext.sendMsg(chatId, message);
|
||||
}
|
||||
openConversation(threadId);
|
||||
openConversation(chatId);
|
||||
}
|
||||
|
||||
private void openConversation(int threadId) {
|
||||
private void openConversation(int chatId) {
|
||||
final Intent intent = getBaseShareIntent(ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, threadId);
|
||||
isPassingAlongMedia = true;
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
@@ -410,84 +338,6 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
return MediaUtil.getCorrectedMimeType(getIntent().getType());
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class ResolveMediaTask extends AsyncTask<Uri, Void, Uri> {
|
||||
private final Context context;
|
||||
|
||||
ResolveMediaTask(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Uri doInBackground(Uri... uris) {
|
||||
try {
|
||||
Uri uri = uris[0];
|
||||
if (uris.length != 1 || uri == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream inputStream;
|
||||
String fileName = null;
|
||||
Long fileSize = null;
|
||||
|
||||
if (hasFileScheme(uri)) {
|
||||
inputStream = openFileUri(uri);
|
||||
if (uri.getPath() != null) {
|
||||
File file = new File(uri.getPath());
|
||||
fileName = file.getName();
|
||||
fileSize = file.length();
|
||||
}
|
||||
} else {
|
||||
inputStream = context.getContentResolver().openInputStream(uri);
|
||||
}
|
||||
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Cursor cursor = getContentResolver().query(uri, new String[] {OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE}, null, null, null);
|
||||
|
||||
try {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
try {
|
||||
fileName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
|
||||
fileSize = cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
String mimeType = getMimeType(uri);
|
||||
return PersistentBlobProvider.getInstance(context).create(context, inputStream, mimeType, fileName, fileSize);
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Uri uri) {
|
||||
resolvedExtras.add(uri);
|
||||
handleResolvedMedia(getIntent(), true);
|
||||
}
|
||||
|
||||
private InputStream openFileUri(Uri uri) throws IOException {
|
||||
FileInputStream fin = new FileInputStream(uri.getPath());
|
||||
int owner = FileUtils.getFileDescriptorOwner(fin.getFD());
|
||||
|
||||
|
||||
if (owner == -1 || owner == Process.myUid()) {
|
||||
fin.close();
|
||||
throw new IOException("File owned by application");
|
||||
}
|
||||
|
||||
return fin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean hasFileScheme(Uri uri) {
|
||||
if (uri==null) {
|
||||
return false;
|
||||
@@ -495,103 +345,4 @@ public class ShareActivity extends PassphraseRequiredActionBarActivity
|
||||
return "file".equals(uri.getScheme());
|
||||
}
|
||||
|
||||
public static class ShareFragment
|
||||
extends Fragment
|
||||
implements LoaderManager.LoaderCallbacks<DcChatlist>, ConversationListAdapter.ItemClickListener, DcEventCenter.DcEventDelegate {
|
||||
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private ConversationClickedListener conversationClickedListener;
|
||||
private Locale locale;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||
View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);
|
||||
recyclerView = ViewUtil.findById(view, R.id.recycler_view);
|
||||
swipeRefreshLayout = ViewUtil.findById(view, R.id.swipe_refresh);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle bundle) {
|
||||
super.onActivityCreated(bundle);
|
||||
initializeAdapter();
|
||||
}
|
||||
|
||||
private void initializeAdapter() {
|
||||
recyclerView.setAdapter(new ConversationListAdapter(getActivity(), GlideApp.with(this),
|
||||
locale, null, this));
|
||||
getLoaderManager().restartLoader(0, null, this);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
swipeRefreshLayout.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<DcChatlist> onCreateLoader(int arg0, Bundle arg1) {
|
||||
return new DcChatlistLoader(getActivity(), 0, null , 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<DcChatlist> arg0, DcChatlist chatlist) {
|
||||
ConversationListAdapter adapter = getConversationListAdapter();
|
||||
adapter.changeData(chatlist);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private ConversationListAdapter getConversationListAdapter() {
|
||||
return (ConversationListAdapter) recyclerView.getAdapter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<DcChatlist> loader) {
|
||||
ConversationListAdapter adapter = getConversationListAdapter();
|
||||
adapter.changeData(null);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEvent(int eventId, Object data1, Object data2) {
|
||||
if (eventId==DcContext.DC_EVENT_CONTACTS_CHANGED) {
|
||||
restartLoader();
|
||||
}
|
||||
}
|
||||
|
||||
private void restartLoader() {
|
||||
getLoaderManager().restartLoader(0, null, ShareFragment.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(ConversationListItem item) {
|
||||
if (conversationClickedListener != null) {
|
||||
conversationClickedListener.onConversationClicked((int) item.getThreadId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemLongClick(ConversationListItem item) {
|
||||
// Not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchToArchive() {
|
||||
// Not needed
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public void setConversationClickedListener(ConversationClickedListener listener) {
|
||||
conversationClickedListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -296,7 +296,7 @@ public class MapActivity extends BaseActivity implements Observer, TimeRangeSlid
|
||||
}
|
||||
|
||||
Intent intent = new Intent(MapActivity.this, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, dcMsgChatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, dcMsgChatId);
|
||||
intent.putExtra(ConversationActivity.LAST_SEEN_EXTRA, 0);
|
||||
intent.putExtra(ConversationActivity.STARTING_POSITION_EXTRA, startingPosition);
|
||||
startActivity(intent);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class NotificationItem {
|
||||
public @NonNull PendingIntent getPendingIntent(Context context) {
|
||||
Intent intent = new Intent(context, ConversationActivity.class);
|
||||
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||
|
||||
return TaskStackBuilder.create(context)
|
||||
|
||||
@@ -165,7 +165,7 @@ public class NotificationState {
|
||||
if (chats.size() != 1) throw new AssertionError("We only support replies to single chat notifications! " + chats.size());
|
||||
|
||||
Intent intent = new Intent(context, ConversationPopupActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, (chats.toArray(new Integer[chats.size()]))[0]);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, (chats.toArray(new Integer[chats.size()]))[0]);
|
||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||
|
||||
return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class QrScanHandler implements DcEventCenter.DcEventDelegate {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
|
||||
int chatId = dcContext.createChatByContactId(qrParsed.getId());
|
||||
Intent intent = new Intent(activity, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
activity.startActivity(intent);
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, null);
|
||||
@@ -181,7 +181,7 @@ public class QrScanHandler implements DcEventCenter.DcEventDelegate {
|
||||
dcContext.endCaptureNextError();
|
||||
if (newChatId != 0) {
|
||||
Intent intent = new Intent(activity, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, newChatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, newChatId);
|
||||
activity.startActivity(intent);
|
||||
} else if (!errorString.isEmpty()) {
|
||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(activity);
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.RelayUtil.isRelayingMessageContent;
|
||||
|
||||
/**
|
||||
* A fragment that is displayed to do full-text search of messages, groups, and contacts.
|
||||
*/
|
||||
@@ -96,6 +98,7 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
viewModel.includeMessageQueries(!isRelayingMessageContent(getActivity()));
|
||||
viewModel.getSearchResult().observe(this, result -> {
|
||||
result = result != null ? result : SearchResult.EMPTY;
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class SearchRepository {
|
||||
private final Context context;
|
||||
private final ApplicationDcContext dcContext;
|
||||
private final Executor executor;
|
||||
private boolean queryMessages = true;
|
||||
|
||||
SearchRepository(@NonNull Context context,
|
||||
@NonNull Executor executor)
|
||||
@@ -62,12 +63,19 @@ class SearchRepository {
|
||||
|
||||
int[] contacts = dcContext.getContacts(DcContext.DC_GCL_ADD_SELF, cleanQuery);
|
||||
DcChatlist conversations = dcContext.getChatlist(DcContext.DC_GCL_NO_SPECIALS, cleanQuery, 0);
|
||||
int[] messages = dcContext.searchMsgs(0, cleanQuery);
|
||||
int[] messages = new int[0];
|
||||
if (queryMessages) {
|
||||
messages = dcContext.searchMsgs(0, cleanQuery);
|
||||
}
|
||||
|
||||
callback.onResult(new SearchResult(cleanQuery, contacts, conversations, messages));
|
||||
});
|
||||
}
|
||||
|
||||
public void setQueryMessages(boolean includeMessageQueries) {
|
||||
this.queryMessages = includeMessageQueries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unfortunately {@link DatabaseUtils#sqlEscapeString(String)} is not sufficient for our purposes.
|
||||
* MATCH queries have a separate format of their own that disallow most "special" characters.
|
||||
|
||||
@@ -44,6 +44,10 @@ class SearchViewModel extends ViewModel {
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
public void includeMessageQueries(boolean include) {
|
||||
this.searchRepository.setQueryMessages(include);
|
||||
}
|
||||
|
||||
void updateQuery(String query) {
|
||||
lastQuery = query;
|
||||
debouncer.publish(() -> searchRepository.query(query, searchResult::postValue));
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DirectShareService extends ChooserTargetService {
|
||||
// parcel.writeParcelable(recipient.getAddress(), 0);
|
||||
//
|
||||
// Bundle bundle = new Bundle();
|
||||
// bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getChatId());
|
||||
// bundle.putLong(ShareActivity.EXTRA_CHAT_ID, record.getChatId());
|
||||
// bundle.putByteArray(ShareActivity.EXTRA_ADDRESS_MARSHALLED, parcel.marshall());
|
||||
// bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
|
||||
// bundle.setClassLoader(getClassLoader());
|
||||
|
||||
@@ -46,7 +46,7 @@ public class LongClickCopySpan extends URLSpan {
|
||||
int chatId = dcContext.createChatByContactId(contact.getId());
|
||||
if (chatId != 0) {
|
||||
Intent intent = new Intent(activity, ConversationActivity.class);
|
||||
intent.putExtra(ConversationActivity.THREAD_ID_EXTRA, chatId);
|
||||
intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RelayUtil {
|
||||
private static final String FORWARDED_MESSAGE_IDS = "forwarded_message_ids";
|
||||
private static final String SHARED_URIS = "shared_uris";
|
||||
public static final int REQUEST_RELAY = 100;
|
||||
|
||||
public static boolean isRelayingMessageContent(Activity activity) {
|
||||
try {
|
||||
return activity.getIntent().getIntArrayExtra(FORWARDED_MESSAGE_IDS) != null ||
|
||||
activity.getIntent().getParcelableArrayListExtra(SHARED_URIS) != null;
|
||||
} catch (NullPointerException npe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isForwarding(Activity activity) {
|
||||
try {
|
||||
return activity.getIntent().getIntArrayExtra(FORWARDED_MESSAGE_IDS) != null;
|
||||
} catch (NullPointerException npe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSharing(Activity activity) {
|
||||
try {
|
||||
return activity.getIntent().getParcelableArrayListExtra(SHARED_URIS) != null;
|
||||
} catch (NullPointerException npe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] getForwardedMessageIDs(Activity activity) {
|
||||
try {
|
||||
return activity.getIntent().getIntArrayExtra(FORWARDED_MESSAGE_IDS);
|
||||
} catch (NullPointerException npe) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<Uri> getSharedUris(Activity activity) {
|
||||
try {
|
||||
return activity.getIntent().getParcelableArrayListExtra(SHARED_URIS);
|
||||
} catch (NullPointerException npe) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetRelayingMessageContent(Activity activity) {
|
||||
try {
|
||||
activity.getIntent().removeExtra(FORWARDED_MESSAGE_IDS);
|
||||
activity.getIntent().removeExtra(SHARED_URIS);
|
||||
} catch (NullPointerException npe) {
|
||||
npe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void acquireRelayMessageContent(Activity currentActivity, @NonNull Intent newActivityIntent) {
|
||||
if (isForwarding(currentActivity)) {
|
||||
newActivityIntent.putExtra(FORWARDED_MESSAGE_IDS, getForwardedMessageIDs(currentActivity));
|
||||
} else if (isSharing(currentActivity)) {
|
||||
newActivityIntent.putParcelableArrayListExtra(SHARED_URIS, getSharedUris(currentActivity));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setForwardingMessageIds(Intent composeIntent, int[] messageIds) {
|
||||
composeIntent.putExtra(FORWARDED_MESSAGE_IDS, messageIds);
|
||||
}
|
||||
|
||||
public static void setSharedUris(Intent composeIntent, ArrayList<Uri> uris) {
|
||||
composeIntent.putParcelableArrayListExtra(SHARED_URIS, uris);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user