clean & minor fix

This commit is contained in:
Ryan ZHAO 2021-02-01 17:00:32 +11:00
parent 2db567144d
commit c8149209a1
32 changed files with 78 additions and 180 deletions

View File

@ -6,6 +6,8 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import android.util.Pair; import android.util.Pair;
@ -50,7 +52,7 @@ public class AudioRecorder {
captureUri = BlobProvider.getInstance() captureUri = BlobProvider.getInstance()
.forData(new ParcelFileDescriptor.AutoCloseInputStream(fds[0]), 0) .forData(new ParcelFileDescriptor.AutoCloseInputStream(fds[0]), 0)
.withMimeType(MediaUtil.AUDIO_AAC) .withMimeType(MediaTypes.AUDIO_AAC)
.createForSingleSessionOnDisk(context, e -> Log.w(TAG, "Error during recording", e)); .createForSingleSessionOnDisk(context, e -> Log.w(TAG, "Error during recording", e));
audioCodec = new AudioCodec(); audioCodec = new AudioCodec();

View File

@ -85,6 +85,7 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.libsignal.util.guava.Optional;
import org.session.libsignal.service.loki.api.opengroups.PublicChat; import org.session.libsignal.service.loki.api.opengroups.PublicChat;
@ -1900,7 +1901,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
String filename = String.format("signal-%s.txt", timestamp); String filename = String.format("signal-%s.txt", timestamp);
Uri textUri = BlobProvider.getInstance() Uri textUri = BlobProvider.getInstance()
.forData(textData) .forData(textData)
.withMimeType(MediaUtil.LONG_TEXT) .withMimeType(MediaTypes.LONG_TEXT)
.withFileName(filename) .withFileName(filename)
.createForSingleSessionInMemory(); .createForSingleSessionInMemory();
@ -2186,7 +2187,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
int subscriptionId = -1; int subscriptionId = -1;
long expiresIn = recipient.getExpireMessages() * 1000L; long expiresIn = recipient.getExpireMessages() * 1000L;
boolean initiating = threadId == -1; boolean initiating = threadId == -1;
AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true); AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaTypes.AUDIO_AAC, true);
SlideDeck slideDeck = new SlideDeck(); SlideDeck slideDeck = new SlideDeck();
slideDeck.addSlide(audioSlide); slideDeck.addSlide(audioSlide);

View File

@ -38,6 +38,7 @@ import net.sqlcipher.database.SQLiteDatabase;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsignal.libsignal.logging.Log; import org.session.libsignal.libsignal.logging.Log;
import org.thoughtcrime.securesms.crypto.AttachmentSecret; import org.thoughtcrime.securesms.crypto.AttachmentSecret;
@ -797,7 +798,7 @@ public class AttachmentDatabase extends Database {
if (thumbnailUri != null) { if (thumbnailUri != null) {
try (InputStream attachmentStream = PartAuthority.getAttachmentStream(context, thumbnailUri)) { try (InputStream attachmentStream = PartAuthority.getAttachmentStream(context, thumbnailUri)) {
Pair<Integer, Integer> dimens; Pair<Integer, Integer> dimens;
if (attachment.getContentType().equals(MediaUtil.IMAGE_GIF)) { if (attachment.getContentType().equals(MediaTypes.IMAGE_GIF)) {
dimens = new Pair<>(attachment.getWidth(), attachment.getHeight()); dimens = new Pair<>(attachment.getWidth(), attachment.getHeight());
} else { } else {
dimens = BitmapUtil.getDimensions(attachmentStream); dimens = BitmapUtil.getDimensions(attachmentStream);

View File

@ -18,10 +18,10 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsession.utilities.ViewUtil; import org.session.libsession.utilities.ViewUtil;
import java.io.IOException; import java.io.IOException;
@ -110,7 +110,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
return BlobProvider.getInstance() return BlobProvider.getInstance()
.forData(data) .forData(data)
.withMimeType(MediaUtil.IMAGE_GIF) .withMimeType(MediaTypes.IMAGE_GIF)
.createForSingleSessionOnDisk(GiphyActivity.this, e -> Log.w(TAG, "Failed to write to disk.", e)); .createForSingleSessionOnDisk(GiphyActivity.this, e -> Log.w(TAG, "Failed to write to disk.", e));
} catch (InterruptedException | ExecutionException | IOException e) { } catch (InterruptedException | ExecutionException | IOException e) {
Log.w(TAG, e); Log.w(TAG, e);

View File

@ -14,6 +14,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.UriAttachm
import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.Address;
import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.Recipient;
import org.session.libsession.utilities.GroupUtil; import org.session.libsession.utilities.GroupUtil;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.TextSecurePreferences;
import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.AttachmentDatabase;
@ -24,11 +25,9 @@ import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.sms.MessageSender; import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.util.BitmapUtil; import org.thoughtcrime.securesms.util.BitmapUtil;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.service.api.util.InvalidNumberException; import org.session.libsignal.service.api.util.InvalidNumberException;
import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext; import org.session.libsignal.service.internal.push.SignalServiceProtos.GroupContext;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -192,7 +191,7 @@ public class GroupManager {
if (avatar != null) { if (avatar != null) {
Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory(); Uri avatarUri = BlobProvider.getInstance().forData(avatar).createForSingleUseInMemory();
avatarAttachment = new UriAttachment(avatarUri, MediaUtil.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null, null); avatarAttachment = new UriAttachment(avatarUri, MediaTypes.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length, null, false, false, null, null);
} }
OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0, null, Collections.emptyList(), Collections.emptyList()); OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0, null, Collections.emptyList(), Collections.emptyList());

View File

@ -15,6 +15,7 @@ import com.annimon.stream.Collectors;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
import org.session.libsession.messaging.jobs.Data; import org.session.libsession.messaging.jobs.Data;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsignal.metadata.InvalidMetadataMessageException; import org.session.libsignal.metadata.InvalidMetadataMessageException;
import org.session.libsignal.metadata.InvalidMetadataVersionException; import org.session.libsignal.metadata.InvalidMetadataVersionException;
import org.session.libsignal.metadata.ProtocolDuplicateMessageException; import org.session.libsignal.metadata.ProtocolDuplicateMessageException;
@ -98,7 +99,6 @@ import org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage;
import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage; import org.thoughtcrime.securesms.sms.OutgoingEndSessionMessage;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage; import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.session.libsignal.utilities.Hex; import org.session.libsignal.utilities.Hex;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.loki.SessionResetProtocol; import org.session.libsignal.libsignal.loki.SessionResetProtocol;
import org.session.libsignal.libsignal.state.SignalProtocolStore; import org.session.libsignal.libsignal.state.SignalProtocolStore;
@ -1170,7 +1170,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
if (stickerRecord != null) { if (stickerRecord != null) {
return Optional.of(new UriAttachment(stickerRecord.getUri(), return Optional.of(new UriAttachment(stickerRecord.getUri(),
stickerRecord.getUri(), stickerRecord.getUri(),
MediaUtil.IMAGE_WEBP, MediaTypes.IMAGE_WEBP,
AttachmentDatabase.TRANSFER_PROGRESS_DONE, AttachmentDatabase.TRANSFER_PROGRESS_DONE,
stickerRecord.getSize(), stickerRecord.getSize(),
StickerSlide.WIDTH, StickerSlide.WIDTH,

View File

@ -10,6 +10,7 @@ import com.annimon.stream.Stream;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.session.libsession.messaging.sending_receiving.contacts.Contact; import org.session.libsession.messaging.sending_receiving.contacts.Contact;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsignal.utilities.Base64; import org.session.libsignal.utilities.Base64;
import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsession.utilities.Util; import org.session.libsession.utilities.Util;
@ -191,7 +192,7 @@ public abstract class PushSendJob extends SendJob {
for (Attachment attachment : message.getOutgoingQuote().getAttachments()) { for (Attachment attachment : message.getOutgoingQuote().getAttachments()) {
BitmapUtil.ScaleResult thumbnailData = null; BitmapUtil.ScaleResult thumbnailData = null;
SignalServiceAttachment thumbnail = null; SignalServiceAttachment thumbnail = null;
String thumbnailType = MediaUtil.IMAGE_JPEG; String thumbnailType = MediaTypes.IMAGE_JPEG;
try { try {
if (MediaUtil.isImageType(attachment.getContentType()) && attachment.getDataUri() != null) { if (MediaUtil.isImageType(attachment.getContentType()) && attachment.getDataUri() != null) {

View File

@ -18,7 +18,7 @@ import org.thoughtcrime.securesms.jobmanager.Job;
import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.service.UpdateApkReadyListener; import org.thoughtcrime.securesms.service.UpdateApkReadyListener;
import org.thoughtcrime.securesms.util.FileUtils; import org.session.libsession.utilities.FileUtils;
import org.session.libsignal.utilities.Hex; import org.session.libsignal.utilities.Hex;
import org.session.libsignal.utilities.JsonUtil; import org.session.libsignal.utilities.JsonUtil;
import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.TextSecurePreferences;

View File

@ -11,6 +11,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.google.android.gms.common.util.IOUtils; import com.google.android.gms.common.util.IOUtils;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.ApplicationContext;
import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.dependencies.InjectableType; import org.thoughtcrime.securesms.dependencies.InjectableType;
@ -24,7 +25,6 @@ import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.stickers.StickerRemoteUri; import org.thoughtcrime.securesms.stickers.StickerRemoteUri;
import org.thoughtcrime.securesms.stickers.StickerUrl; import org.thoughtcrime.securesms.stickers.StickerUrl;
import org.session.libsignal.utilities.Hex; import org.session.libsignal.utilities.Hex;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.InvalidMessageException;
import org.session.libsignal.libsignal.util.Pair; import org.session.libsignal.libsignal.util.Pair;
import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.libsignal.util.guava.Optional;
@ -175,7 +175,7 @@ public class LinkPreviewRepository implements InjectableType {
byte[] data = IOUtils.readInputStreamFully(bodyStream); byte[] data = IOUtils.readInputStreamFully(bodyStream);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Optional<Attachment> thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.JPEG, MediaUtil.IMAGE_JPEG); Optional<Attachment> thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.JPEG, MediaTypes.IMAGE_JPEG);
if (bitmap != null) bitmap.recycle(); if (bitmap != null) bitmap.recycle();
@ -225,7 +225,7 @@ public class LinkPreviewRepository implements InjectableType {
Uri uri = BlobProvider.getInstance().forData(bytes).createForSingleSessionInMemory(); Uri uri = BlobProvider.getInstance().forData(bytes).createForSingleSessionInMemory();
Optional<Attachment> thumbnail = Optional.of(new UriAttachment(uri, Optional<Attachment> thumbnail = Optional.of(new UriAttachment(uri,
uri, uri,
MediaUtil.IMAGE_WEBP, MediaTypes.IMAGE_WEBP,
AttachmentDatabase.TRANSFER_PROGRESS_STARTED, AttachmentDatabase.TRANSFER_PROGRESS_STARTED,
bytes.length, bytes.length,
bitmap.getWidth(), bitmap.getWidth(),

View File

@ -20,13 +20,13 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import org.session.libsession.utilities.MediaTypes;
import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.libsignal.util.guava.Optional;
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.providers.BlobProvider; import org.thoughtcrime.securesms.providers.BlobProvider;
import org.thoughtcrime.securesms.scribbles.ImageEditorFragment; import org.thoughtcrime.securesms.scribbles.ImageEditorFragment;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.Address;
import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.Recipient;
@ -266,10 +266,10 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple
try { try {
Uri uri = BlobProvider.getInstance() Uri uri = BlobProvider.getInstance()
.forData(data) .forData(data)
.withMimeType(MediaUtil.IMAGE_JPEG) .withMimeType(MediaTypes.IMAGE_JPEG)
.createForSingleSessionOnDisk(this, e -> Log.w(TAG, "Failed to write to disk.", e)); .createForSingleSessionOnDisk(this, e -> Log.w(TAG, "Failed to write to disk.", e));
return new Media(uri, return new Media(uri,
MediaUtil.IMAGE_JPEG, MediaTypes.IMAGE_JPEG,
System.currentTimeMillis(), System.currentTimeMillis(),
width, width,
height, height,

View File

@ -28,6 +28,7 @@ import android.view.inputmethod.EditorInfo;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.components.ComposeText; import org.thoughtcrime.securesms.components.ComposeText;
import org.thoughtcrime.securesms.components.ControllableViewPager; import org.thoughtcrime.securesms.components.ControllableViewPager;
import org.thoughtcrime.securesms.components.InputAwareLayout; import org.thoughtcrime.securesms.components.InputAwareLayout;
@ -44,7 +45,6 @@ import org.thoughtcrime.securesms.providers.BlobProvider;
import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.Recipient;
import org.thoughtcrime.securesms.scribbles.ImageEditorFragment; import org.thoughtcrime.securesms.scribbles.ImageEditorFragment;
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState; import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.PushCharacterCalculator; import org.thoughtcrime.securesms.util.PushCharacterCalculator;
import org.thoughtcrime.securesms.util.Stopwatch; import org.thoughtcrime.securesms.util.Stopwatch;
import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.libsignal.util.guava.Optional;
@ -453,10 +453,10 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl
Uri uri = BlobProvider.getInstance() Uri uri = BlobProvider.getInstance()
.forData(baos.toByteArray()) .forData(baos.toByteArray())
.withMimeType(MediaUtil.IMAGE_JPEG) .withMimeType(MediaTypes.IMAGE_JPEG)
.createForSingleSessionOnDisk(context, e -> Log.w(TAG, "Failed to write to disk.", e)); .createForSingleSessionOnDisk(context, e -> Log.w(TAG, "Failed to write to disk.", e));
Media updated = new Media(uri, MediaUtil.IMAGE_JPEG, media.getDate(), bitmap.getWidth(), bitmap.getHeight(), baos.size(), media.getBucketId(), media.getCaption()); Media updated = new Media(uri, MediaTypes.IMAGE_JPEG, media.getDate(), bitmap.getWidth(), bitmap.getHeight(), baos.size(), media.getBucketId(), media.getCaption());
updatedMedia.add(updated); updatedMedia.add(updated);
renderTimer.split("item"); renderTimer.split("item");

View File

@ -39,7 +39,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.MediaPreviewActivity; import org.thoughtcrime.securesms.MediaPreviewActivity;
import org.thoughtcrime.securesms.loki.views.MessageAudioView; import org.thoughtcrime.securesms.loki.views.MessageAudioView;
import org.thoughtcrime.securesms.components.DocumentView; import org.thoughtcrime.securesms.components.DocumentView;
@ -213,7 +213,7 @@ public class AttachmentManager {
byte[] blob = BitmapUtil.toByteArray(result); byte[] blob = BitmapUtil.toByteArray(result);
Uri uri = BlobProvider.getInstance() Uri uri = BlobProvider.getInstance()
.forData(blob) .forData(blob)
.withMimeType(MediaUtil.IMAGE_JPEG) .withMimeType(MediaTypes.IMAGE_JPEG)
.createForSingleSessionInMemory(); .createForSingleSessionInMemory();
LocationSlide locationSlide = new LocationSlide(context, uri, blob.length, place); LocationSlide locationSlide = new LocationSlide(context, uri, blob.length, place);

View File

@ -26,15 +26,15 @@ import androidx.annotation.Nullable;
import network.loki.messenger.R; import network.loki.messenger.R;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment; import org.session.libsession.messaging.sending_receiving.attachments.UriAttachment;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.database.AttachmentDatabase; import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.ResUtil; import org.thoughtcrime.securesms.util.ResUtil;
public class AudioSlide extends Slide { public class AudioSlide extends Slide {
public AudioSlide(Context context, Uri uri, long dataSize, boolean voiceNote) { public AudioSlide(Context context, Uri uri, long dataSize, boolean voiceNote) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.AUDIO_UNSPECIFIED, dataSize, 0, 0, false, null, null, null, voiceNote, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.AUDIO_UNSPECIFIED, dataSize, 0, 0, false, null, null, null, voiceNote, false));
} }
public AudioSlide(Context context, Uri uri, long dataSize, String contentType, boolean voiceNote) { public AudioSlide(Context context, Uri uri, long dataSize, String contentType, boolean voiceNote) {

View File

@ -5,7 +5,7 @@ import android.net.Uri;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsession.utilities.MediaTypes;
public class GifSlide extends ImageSlide { public class GifSlide extends ImageSlide {
@ -19,7 +19,7 @@ public class GifSlide extends ImageSlide {
} }
public GifSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) { public GifSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.IMAGE_GIF, size, width, height, true, null, caption, null, false, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_GIF, size, width, height, true, null, caption, null, false, false));
} }
@Override @Override

View File

@ -25,7 +25,7 @@ import androidx.annotation.Nullable;
import network.loki.messenger.R; import network.loki.messenger.R;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsession.utilities.MediaTypes;
public class ImageSlide extends Slide { public class ImageSlide extends Slide {
@ -41,7 +41,7 @@ public class ImageSlide extends Slide {
} }
public ImageSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) { public ImageSlide(Context context, Uri uri, long size, int width, int height, @Nullable String caption) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.IMAGE_JPEG, size, width, height, true, null, caption, null, false, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_JPEG, size, width, height, true, null, caption, null, false, false));
} }
@Override @Override

View File

@ -4,6 +4,8 @@ import android.content.Context;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import android.util.Pair; import android.util.Pair;
@ -75,7 +77,7 @@ public abstract class MediaConstraints {
try { try {
// XXX - This is loading everything into memory! We want the send path to be stream-like. // XXX - This is loading everything into memory! We want the send path to be stream-like.
BitmapUtil.ScaleResult scaleResult = BitmapUtil.createScaledBytes(context, new DecryptableUri(attachment.getDataUri()), this); BitmapUtil.ScaleResult scaleResult = BitmapUtil.createScaledBytes(context, new DecryptableUri(attachment.getDataUri()), this);
return new MediaStream(new ByteArrayInputStream(scaleResult.getBitmap()), MediaUtil.IMAGE_JPEG, scaleResult.getWidth(), scaleResult.getHeight()); return new MediaStream(new ByteArrayInputStream(scaleResult.getBitmap()), MediaTypes.IMAGE_JPEG, scaleResult.getWidth(), scaleResult.getHeight());
} catch (BitmapDecodingException e) { } catch (BitmapDecodingException e) {
throw new IOException(e); throw new IOException(e);
} }

View File

@ -9,7 +9,7 @@ import androidx.annotation.Nullable;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator; import org.session.libsession.messaging.sending_receiving.attachments.StickerLocator;
import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsession.utilities.MediaTypes;
import network.loki.messenger.R; import network.loki.messenger.R;
@ -23,7 +23,7 @@ public class StickerSlide extends Slide {
} }
public StickerSlide(Context context, Uri uri, long size, @NonNull StickerLocator stickerLocator) { public StickerSlide(Context context, Uri uri, long size, @NonNull StickerLocator stickerLocator) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.IMAGE_WEBP, size, WIDTH, HEIGHT, true, null, null, stickerLocator, false, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.IMAGE_WEBP, size, WIDTH, HEIGHT, true, null, null, stickerLocator, false, false));
} }
@Override @Override

View File

@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsession.utilities.MediaTypes;
public class TextSlide extends Slide { public class TextSlide extends Slide {
@ -16,6 +16,6 @@ public class TextSlide extends Slide {
} }
public TextSlide(@NonNull Context context, @NonNull Uri uri, @Nullable String filename, long size) { public TextSlide(@NonNull Context context, @NonNull Uri uri, @Nullable String filename, long size) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.LONG_TEXT, size, 0, 0, true, filename, null, null, false, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.LONG_TEXT, size, 0, 0, true, filename, null, null, false, false));
} }
} }

View File

@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
import network.loki.messenger.R; import network.loki.messenger.R;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.MediaUtil;
import org.thoughtcrime.securesms.util.ResUtil; import org.thoughtcrime.securesms.util.ResUtil;
@ -35,7 +36,7 @@ public class VideoSlide extends Slide {
} }
public VideoSlide(Context context, Uri uri, long dataSize, @Nullable String caption) { public VideoSlide(Context context, Uri uri, long dataSize, @Nullable String caption) {
super(context, constructAttachmentFromUri(context, uri, MediaUtil.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(uri), null, caption, null, false, false)); super(context, constructAttachmentFromUri(context, uri, MediaTypes.VIDEO_UNSPECIFIED, dataSize, 0, 0, MediaUtil.hasVideoThumbnail(uri), null, caption, null, false, false));
} }
public VideoSlide(Context context, Attachment attachment) { public VideoSlide(Context context, Attachment attachment) {

View File

@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.logging.Log;
import network.loki.messenger.R; import network.loki.messenger.R;
import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.notifications.NotificationChannels;
import org.thoughtcrime.securesms.util.FileProviderUtil; import org.thoughtcrime.securesms.util.FileProviderUtil;
import org.thoughtcrime.securesms.util.FileUtils; import org.session.libsession.utilities.FileUtils;
import org.session.libsignal.utilities.Hex; import org.session.libsignal.utilities.Hex;
import org.session.libsession.utilities.ServiceUtil; import org.session.libsession.utilities.ServiceUtil;
import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.TextSecurePreferences;

View File

@ -18,6 +18,7 @@ import android.util.Pair;
import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.mms.MediaConstraints; import org.thoughtcrime.securesms.mms.MediaConstraints;
@ -203,9 +204,9 @@ public class BitmapUtil {
if (contentType == null) return CompressFormat.JPEG; if (contentType == null) return CompressFormat.JPEG;
switch (contentType) { switch (contentType) {
case MediaUtil.IMAGE_JPEG: return CompressFormat.JPEG; case MediaTypes.IMAGE_JPEG: return CompressFormat.JPEG;
case MediaUtil.IMAGE_PNG: return CompressFormat.PNG; case MediaTypes.IMAGE_PNG: return CompressFormat.PNG;
case MediaUtil.IMAGE_WEBP: return CompressFormat.WEBP; case MediaTypes.IMAGE_WEBP: return CompressFormat.WEBP;
default: return CompressFormat.JPEG; default: return CompressFormat.JPEG;
} }
} }

View File

@ -1,7 +1,5 @@
package org.thoughtcrime.securesms.util; package org.thoughtcrime.securesms.util;
import android.Manifest;
import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -18,7 +16,6 @@ import network.loki.messenger.R;
import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.Recipient;
public class CommunicationActions { public class CommunicationActions {

View File

@ -1,42 +0,0 @@
/**
* Copyright (C) 2011 Whisper Systems
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.thoughtcrime.securesms.util;
import android.content.Context;
import androidx.appcompat.app.AlertDialog;
import network.loki.messenger.R;
public class Dialogs {
public static void showAlertDialog(Context context, String title, String message) {
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIconAttribute(R.attr.dialog_alert_icon);
dialog.setPositiveButton(android.R.string.ok, null);
dialog.show();
}
public static void showInfoDialog(Context context, String title, String message) {
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setIconAttribute(R.attr.dialog_info_icon);
dialog.setPositiveButton(android.R.string.ok, null);
dialog.show();
}
}

View File

@ -1,54 +0,0 @@
package org.thoughtcrime.securesms.util;
import android.graphics.PointF;
import androidx.annotation.NonNull;
public class MathUtils {
/**
* For more info:
* <a href="http://math.stackexchange.com/questions/190111/how-to-check-if-a-point-is-inside-a-rectangle">StackOverflow: How to check point is in rectangle</a>
*
* @param pt point to check
* @param v1 vertex 1 of the triangle
* @param v2 vertex 2 of the triangle
* @param v3 vertex 3 of the triangle
* @return true if point (x, y) is inside the triangle
*/
public static boolean pointInTriangle(@NonNull PointF pt, @NonNull PointF v1,
@NonNull PointF v2, @NonNull PointF v3) {
boolean b1 = crossProduct(pt, v1, v2) < 0.0f;
boolean b2 = crossProduct(pt, v2, v3) < 0.0f;
boolean b3 = crossProduct(pt, v3, v1) < 0.0f;
return (b1 == b2) && (b2 == b3);
}
/**
* calculates cross product of vectors AB and AC
*
* @param a beginning of 2 vectors
* @param b end of vector 1
* @param c enf of vector 2
* @return cross product AB * AC
*/
private static float crossProduct(@NonNull PointF a, @NonNull PointF b, @NonNull PointF c) {
return crossProduct(a.x, a.y, b.x, b.y, c.x, c.y);
}
/**
* calculates cross product of vectors AB and AC
*
* @param ax X coordinate of point A
* @param ay Y coordinate of point A
* @param bx X coordinate of point B
* @param by Y coordinate of point B
* @param cx X coordinate of point C
* @param cy Y coordinate of point C
* @return cross product AB * AC
*/
private static float crossProduct(float ax, float ay, float bx, float by, float cx, float cy) {
return (ax - cx) * (by - cy) - (bx - cx) * (ay - cy);
}
}

View File

@ -16,6 +16,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.gif.GifDrawable; import com.bumptech.glide.load.resource.gif.GifDrawable;
import org.session.libsession.messaging.sending_receiving.attachments.Attachment; import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
import org.session.libsession.utilities.MediaTypes;
import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.AudioSlide;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
@ -39,17 +40,6 @@ public class MediaUtil {
private static final String TAG = MediaUtil.class.getSimpleName(); private static final String TAG = MediaUtil.class.getSimpleName();
public static final String IMAGE_PNG = "image/png";
public static final String IMAGE_JPEG = "image/jpeg";
public static final String IMAGE_WEBP = "image/webp";
public static final String IMAGE_GIF = "image/gif";
public static final String AUDIO_AAC = "audio/aac";
public static final String AUDIO_UNSPECIFIED = "audio/*";
public static final String VIDEO_UNSPECIFIED = "video/*";
public static final String VCARD = "text/x-vcard";
public static final String LONG_TEXT = "text/x-signal-plain";
public static Slide getSlideForAttachment(Context context, Attachment attachment) { public static Slide getSlideForAttachment(Context context, Attachment attachment) {
Slide slide = null; Slide slide = null;
if (attachment.isSticker()) { if (attachment.isSticker()) {
@ -94,8 +84,8 @@ public class MediaUtil {
switch(mimeType) { switch(mimeType) {
case "image/jpg": case "image/jpg":
return MimeTypeMap.getSingleton().hasMimeType(IMAGE_JPEG) return MimeTypeMap.getSingleton().hasMimeType(MediaTypes.IMAGE_JPEG)
? IMAGE_JPEG ? MediaTypes.IMAGE_JPEG
: mimeType; : mimeType;
default: default:
return mimeType; return mimeType;
@ -206,7 +196,7 @@ public class MediaUtil {
} }
public static boolean isVcard(String contentType) { public static boolean isVcard(String contentType) {
return !TextUtils.isEmpty(contentType) && contentType.trim().equals(VCARD); return !TextUtils.isEmpty(contentType) && contentType.trim().equals(MediaTypes.VCARD);
} }
public static boolean isGif(String contentType) { public static boolean isGif(String contentType) {
@ -214,7 +204,7 @@ public class MediaUtil {
} }
public static boolean isJpegType(String contentType) { public static boolean isJpegType(String contentType) {
return !TextUtils.isEmpty(contentType) && contentType.trim().equals(IMAGE_JPEG); return !TextUtils.isEmpty(contentType) && contentType.trim().equals(MediaTypes.IMAGE_JPEG);
} }
public static boolean isFile(Attachment attachment) { public static boolean isFile(Attachment attachment) {
@ -240,7 +230,7 @@ public class MediaUtil {
} }
public static boolean isLongTextType(String contentType) { public static boolean isLongTextType(String contentType) {
return (null != contentType) && contentType.equals(LONG_TEXT); return (null != contentType) && contentType.equals(MediaTypes.LONG_TEXT);
} }
public static boolean hasVideoThumbnail(Uri uri) { public static boolean hasVideoThumbnail(Uri uri) {

View File

@ -79,8 +79,8 @@ public abstract class Attachment {
} }
public boolean isInProgress() { public boolean isInProgress() {
return transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE.getValue() && return transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE &&
transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED.getValue(); transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED;
} }
public long getSize() { public long getSize() {

View File

@ -1,8 +1,8 @@
package org.session.libsession.messaging.sending_receiving.attachments package org.session.libsession.messaging.sending_receiving.attachments
enum class AttachmentTransferProgress(val value: Int) { object AttachmentTransferProgress {
TRANSFER_PROGRESS_DONE(0), const val TRANSFER_PROGRESS_DONE = 0
TRANSFER_PROGRESS_STARTED(1), const val TRANSFER_PROGRESS_STARTED = 1
TRANSFER_PROGRESS_PENDING(2), const val TRANSFER_PROGRESS_PENDING = 2
TRANSFER_PROGRESS_FAILED(3) const val TRANSFER_PROGRESS_FAILED = 3
} }

View File

@ -104,7 +104,7 @@ public class PointerAttachment extends Attachment {
} }
return Optional.of(new PointerAttachment(pointer.get().getContentType(), return Optional.of(new PointerAttachment(pointer.get().getContentType(),
AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING,
pointer.get().asPointer().getSize().or(0), pointer.get().asPointer().getSize().or(0),
pointer.get().asPointer().getFileName().orNull(), pointer.get().asPointer().getFileName().orNull(),
String.valueOf(pointer.get().asPointer().getId()), String.valueOf(pointer.get().asPointer().getId()),
@ -122,7 +122,7 @@ public class PointerAttachment extends Attachment {
public static Optional<Attachment> forPointer(SignalServiceProtos.AttachmentPointer pointer) { public static Optional<Attachment> forPointer(SignalServiceProtos.AttachmentPointer pointer) {
return Optional.of(new PointerAttachment(pointer.getContentType(), return Optional.of(new PointerAttachment(pointer.getContentType(),
AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING,
(long)pointer.getSize(), (long)pointer.getSize(),
pointer.getFileName(), pointer.getFileName(),
String.valueOf(pointer != null ? pointer.getId() : 0), String.valueOf(pointer != null ? pointer.getId() : 0),
@ -142,7 +142,7 @@ public class PointerAttachment extends Attachment {
SignalServiceProtos.AttachmentPointer thumbnail = pointer.getThumbnail(); SignalServiceProtos.AttachmentPointer thumbnail = pointer.getThumbnail();
return Optional.of(new PointerAttachment(pointer.getContentType(), return Optional.of(new PointerAttachment(pointer.getContentType(),
AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING,
thumbnail != null ? (long)thumbnail.getSize() : 0, thumbnail != null ? (long)thumbnail.getSize() : 0,
thumbnail.getFileName(), thumbnail.getFileName(),
String.valueOf(thumbnail != null ? thumbnail.getId() : 0), String.valueOf(thumbnail != null ? thumbnail.getId() : 0),
@ -162,7 +162,7 @@ public class PointerAttachment extends Attachment {
SignalServiceAttachment thumbnail = pointer.getThumbnail(); SignalServiceAttachment thumbnail = pointer.getThumbnail();
return Optional.of(new PointerAttachment(pointer.getContentType(), return Optional.of(new PointerAttachment(pointer.getContentType(),
AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING,
thumbnail != null ? thumbnail.asPointer().getSize().or(0) : 0, thumbnail != null ? thumbnail.asPointer().getSize().or(0) : 0,
pointer.getFileName(), pointer.getFileName(),
String.valueOf(thumbnail != null ? thumbnail.asPointer().getId() : 0), String.valueOf(thumbnail != null ? thumbnail.asPointer().getId() : 0),

View File

@ -643,7 +643,7 @@ public class Contact implements Parcelable {
private static Attachment attachmentFromUri(@Nullable Uri uri) { private static Attachment attachmentFromUri(@Nullable Uri uri) {
if (uri == null) return null; if (uri == null) return null;
return new UriAttachment(uri, MediaTypes.IMAGE_JPEG.getValue(), AttachmentTransferProgress.TRANSFER_PROGRESS_DONE.getValue(), 0, null, false, false, null, null); return new UriAttachment(uri, MediaTypes.IMAGE_JPEG, AttachmentTransferProgress.TRANSFER_PROGRESS_DONE, 0, null, false, false, null, null);
} }
@Override @Override

View File

@ -1,7 +1,6 @@
package org.thoughtcrime.securesms.util; package org.session.libsession.utilities;
import java.io.File; import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.security.MessageDigest; import java.security.MessageDigest;

View File

@ -1,13 +1,13 @@
package org.session.libsession.utilities package org.session.libsession.utilities
enum class MediaTypes(val value: String) { object MediaTypes {
IMAGE_PNG("image/png"), const val IMAGE_PNG = "image/png"
IMAGE_JPEG("image/jpeg"), const val IMAGE_JPEG = "image/jpeg"
IMAGE_WEBP("image/webp"), const val IMAGE_WEBP = "image/webp"
IMAGE_GIF("image/gif"), const val IMAGE_GIF = "image/gif"
AUDIO_AAC("audio/aac"), const val AUDIO_AAC = "audio/aac"
AUDIO_UNSPECIFIED("audio/*"), const val AUDIO_UNSPECIFIED = "audio/*"
VIDEO_UNSPECIFIED("video/*"), const val VIDEO_UNSPECIFIED = "video/*"
VCARD("text/x-vcard"), const val VCARD = "text/x-vcard"
LONG_TEXT("text/x-signal-plain") const val LONG_TEXT = "text/x-signal-plain"
} }

View File

@ -98,7 +98,7 @@ public class SettableFuture<T> implements ListenableFuture<T> {
{ {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
while (!completed && System.currentTimeMillis() - startTime > unit.toMillis(timeout)) { while (!completed && System.currentTimeMillis() - startTime < unit.toMillis(timeout)) {
wait(unit.toMillis(timeout)); wait(unit.toMillis(timeout));
} }