Skip to content

Commit

Permalink
Support sharing multiple photos/videos into Signal.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 14, 2020
1 parent 7ab2406 commit 9bac886
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 214 deletions.
14 changes: 10 additions & 4 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -148,15 +148,14 @@
<activity android:name=".preferences.MmsPreferencesActivity"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".ShareActivity"
<activity android:name=".sharing.ShareActivity"
android:theme="@style/TextSecure.LightNoActionBar"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:taskAffinity=""
android:noHistory="true"
android:windowSoftInputMode="stateHidden"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT"/>
Expand All @@ -169,8 +168,15 @@
<data android:mimeType="*/*"/>
</intent-filter>

<meta-data
android:name="android.service.chooser.chooser_target_service"
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>

<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value=".service.DirectShareService" />

</activity>
Expand Down
Expand Up @@ -64,6 +64,7 @@
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.sharing.ShareActivity;
import org.thoughtcrime.securesms.util.AttachmentUtil;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.SaveAttachmentTask;
Expand Down
Expand Up @@ -1322,11 +1322,13 @@ private ListenableFuture<Boolean> initializeDraft() {
final StickerLocator stickerLocator = getIntent().getParcelableExtra(STICKER_EXTRA);

if (stickerLocator != null && draftMedia != null) {
Log.d(TAG, "Handling shared sticker.");
sendSticker(stickerLocator, draftMedia, 0, true);
return new SettableFuture<>(false);
}

if (!Util.isEmpty(mediaList)) {
Log.d(TAG, "Handling shared Media.");
Intent sendIntent = MediaSendActivity.buildEditorIntent(this, mediaList, recipient.get(), draftText, sendButton.getSelectedTransport());
startActivityForResult(sendIntent, MEDIA_SENDER);
return new SettableFuture<>(false);
Expand All @@ -1339,6 +1341,7 @@ private ListenableFuture<Boolean> initializeDraft() {
}

if (draftMedia != null && draftMediaType != null) {
Log.d(TAG, "Handling shared Data.");
return setMedia(draftMedia, draftMediaType);
}

Expand Down Expand Up @@ -2633,7 +2636,6 @@ private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull Uri ur
slideDeck.addSlide(stickerSlide);

sendMediaMessage(transport.isSms(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, clearCompose);

}

private void silentlySetComposeText(String text) {
Expand Down
Expand Up @@ -63,7 +63,7 @@
import org.thoughtcrime.securesms.MessageDetailsActivity;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.ShareActivity;
import org.thoughtcrime.securesms.sharing.ShareActivity;
import org.thoughtcrime.securesms.attachments.Attachment;
import org.thoughtcrime.securesms.components.ConversationTypingView;
import org.thoughtcrime.securesms.components.TooltipPopup;
Expand Down
Expand Up @@ -142,11 +142,11 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
/**
* Get an intent to launch the media send flow starting with the picker.
*/
public static Intent buildGalleryIntent(@NonNull Context context, @NonNull Recipient recipient, @NonNull String body, @NonNull TransportOption transport) {
public static Intent buildGalleryIntent(@NonNull Context context, @NonNull Recipient recipient, @Nullable String body, @NonNull TransportOption transport) {
Intent intent = new Intent(context, MediaSendActivity.class);
intent.putExtra(KEY_RECIPIENT, recipient.getId());
intent.putExtra(KEY_TRANSPORT, transport);
intent.putExtra(KEY_BODY, body);
intent.putExtra(KEY_BODY, body == null ? "" : body);
return intent;
}

Expand Down
@@ -0,0 +1,6 @@
package org.thoughtcrime.securesms.mediasend;

public class MediaSendConstants {
public static final int MAX_PUSH = 32;
public static final int MAX_SMS = 1;
}
Expand Up @@ -51,9 +51,6 @@ class MediaSendViewModel extends ViewModel {

private static final String TAG = MediaSendViewModel.class.getSimpleName();

private static final int MAX_PUSH = 32;
private static final int MAX_SMS = 1;

private final Application application;
private final MediaRepository repository;
private final MediaUploadRepository uploadRepository;
Expand Down Expand Up @@ -122,11 +119,11 @@ void setTransport(@NonNull TransportOption transport) {

if (transport.isSms()) {
isSms = true;
maxSelection = MAX_SMS;
maxSelection = MediaSendConstants.MAX_SMS;
mediaConstraints = MediaConstraints.getMmsMediaConstraints(transport.getSimSubscriptionId().or(-1));
} else {
isSms = false;
maxSelection = MAX_PUSH;
maxSelection = MediaSendConstants.MAX_PUSH;
mediaConstraints = MediaConstraints.getPushMediaConstraints();
}

Expand All @@ -151,7 +148,9 @@ void onSelectedMediaChanged(@NonNull Context context, @NonNull List<Media> newMe

if (filteredMedia.size() != newMedia.size()) {
error.setValue(Error.ITEM_TOO_LARGE);
} else if (filteredMedia.size() > maxSelection) {
}

if (filteredMedia.size() > maxSelection) {
filteredMedia = filteredMedia.subList(0, maxSelection);
error.setValue(Error.TOO_MANY_ITEMS);
}
Expand Down
Expand Up @@ -9,15 +9,14 @@
import android.graphics.drawable.Icon;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.service.chooser.ChooserTarget;
import android.service.chooser.ChooserTargetService;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.view.ContextThemeWrapper;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.ShareActivity;
import org.thoughtcrime.securesms.sharing.ShareActivity;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.database.model.ThreadRecord;
Expand Down

0 comments on commit 9bac886

Please sign in to comment.