diff --git a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java index 580bd688f5..c425f39d8b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/audio/AudioRecorder.java @@ -6,6 +6,8 @@ import android.net.Uri; import android.os.Build; import android.os.ParcelFileDescriptor; import androidx.annotation.NonNull; + +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.logging.Log; import android.util.Pair; @@ -50,7 +52,7 @@ public class AudioRecorder { captureUri = BlobProvider.getInstance() .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)); audioCodec = new AudioCodec(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java index ba2965f6a8..6ef9adab37 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -85,6 +85,7 @@ import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; +import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.guava.Optional; 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); Uri textUri = BlobProvider.getInstance() .forData(textData) - .withMimeType(MediaUtil.LONG_TEXT) + .withMimeType(MediaTypes.LONG_TEXT) .withFileName(filename) .createForSingleSessionInMemory(); @@ -2186,7 +2187,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity int subscriptionId = -1; long expiresIn = recipient.getExpireMessages() * 1000L; 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.addSlide(audioSlide); diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java index 522e52996d..c7284f9256 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/AttachmentDatabase.java @@ -38,6 +38,7 @@ import net.sqlcipher.database.SQLiteDatabase; import org.json.JSONArray; import org.json.JSONException; +import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.libsignal.logging.Log; import org.thoughtcrime.securesms.crypto.AttachmentSecret; @@ -797,7 +798,7 @@ public class AttachmentDatabase extends Database { if (thumbnailUri != null) { try (InputStream attachmentStream = PartAuthority.getAttachmentStream(context, thumbnailUri)) { Pair dimens; - if (attachment.getContentType().equals(MediaUtil.IMAGE_GIF)) { + if (attachment.getContentType().equals(MediaTypes.IMAGE_GIF)) { dimens = new Pair<>(attachment.getWidth(), attachment.getHeight()); } else { dimens = BitmapUtil.getDimensions(attachmentStream); diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java index 868ed11202..4e904fa0d8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/ui/GiphyActivity.java @@ -18,10 +18,10 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.providers.BlobProvider; -import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsession.utilities.ViewUtil; import java.io.IOException; @@ -110,7 +110,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity return BlobProvider.getInstance() .forData(data) - .withMimeType(MediaUtil.IMAGE_GIF) + .withMimeType(MediaTypes.IMAGE_GIF) .createForSingleSessionOnDisk(GiphyActivity.this, e -> Log.w(TAG, "Failed to write to disk.", e)); } catch (InterruptedException | ExecutionException | IOException e) { Log.w(TAG, e); diff --git a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java index cae7cbf180..6d9ac5e29a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/groups/GroupManager.java @@ -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.recipients.Recipient; import org.session.libsession.utilities.GroupUtil; +import org.session.libsession.utilities.MediaTypes; import org.session.libsession.utilities.TextSecurePreferences; 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.sms.MessageSender; 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.internal.push.SignalServiceProtos.GroupContext; -import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -192,7 +191,7 @@ public class GroupManager { if (avatar != null) { 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()); diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index fb3304f4bb..0515638e23 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -15,6 +15,7 @@ import com.annimon.stream.Collectors; import com.annimon.stream.Stream; import org.session.libsession.messaging.jobs.Data; +import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.metadata.InvalidMetadataMessageException; import org.session.libsignal.metadata.InvalidMetadataVersionException; 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.OutgoingTextMessage; import org.session.libsignal.utilities.Hex; -import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.loki.SessionResetProtocol; import org.session.libsignal.libsignal.state.SignalProtocolStore; @@ -1170,7 +1170,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { if (stickerRecord != null) { return Optional.of(new UriAttachment(stickerRecord.getUri(), stickerRecord.getUri(), - MediaUtil.IMAGE_WEBP, + MediaTypes.IMAGE_WEBP, AttachmentDatabase.TRANSFER_PROGRESS_DONE, stickerRecord.getSize(), StickerSlide.WIDTH, diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java index e42133d047..2263dd948e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/PushSendJob.java @@ -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.contacts.Contact; +import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.utilities.Base64; import org.session.libsession.utilities.TextSecurePreferences; import org.session.libsession.utilities.Util; @@ -191,7 +192,7 @@ public abstract class PushSendJob extends SendJob { for (Attachment attachment : message.getOutgoingQuote().getAttachments()) { BitmapUtil.ScaleResult thumbnailData = null; SignalServiceAttachment thumbnail = null; - String thumbnailType = MediaUtil.IMAGE_JPEG; + String thumbnailType = MediaTypes.IMAGE_JPEG; try { if (MediaUtil.isImageType(attachment.getContentType()) && attachment.getDataUri() != null) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java index 50beebb9c5..e38928ccc4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/UpdateApkJob.java @@ -18,7 +18,7 @@ import org.thoughtcrime.securesms.jobmanager.Job; import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint; import org.thoughtcrime.securesms.logging.Log; 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.JsonUtil; import org.session.libsession.utilities.TextSecurePreferences; diff --git a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java index 006a79a412..219d5c8d41 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/linkpreview/LinkPreviewRepository.java @@ -11,6 +11,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.google.android.gms.common.util.IOUtils; +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.ApplicationContext; import org.thoughtcrime.securesms.database.AttachmentDatabase; 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.StickerUrl; import org.session.libsignal.utilities.Hex; -import org.thoughtcrime.securesms.util.MediaUtil; import org.session.libsignal.libsignal.InvalidMessageException; import org.session.libsignal.libsignal.util.Pair; import org.session.libsignal.libsignal.util.guava.Optional; @@ -175,7 +175,7 @@ public class LinkPreviewRepository implements InjectableType { byte[] data = IOUtils.readInputStreamFully(bodyStream); Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); - Optional thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.JPEG, MediaUtil.IMAGE_JPEG); + Optional thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.JPEG, MediaTypes.IMAGE_JPEG); if (bitmap != null) bitmap.recycle(); @@ -225,7 +225,7 @@ public class LinkPreviewRepository implements InjectableType { Uri uri = BlobProvider.getInstance().forData(bytes).createForSingleSessionInMemory(); Optional thumbnail = Optional.of(new UriAttachment(uri, uri, - MediaUtil.IMAGE_WEBP, + MediaTypes.IMAGE_WEBP, AttachmentDatabase.TRANSFER_PROGRESS_STARTED, bytes.length, bitmap.getWidth(), diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java index ad0aadab24..c4911cd839 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendActivity.java @@ -20,13 +20,13 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.lifecycle.ViewModelProvider; +import org.session.libsession.utilities.MediaTypes; import org.session.libsignal.libsignal.util.guava.Optional; import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.providers.BlobProvider; 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.recipients.Recipient; @@ -266,10 +266,10 @@ public class MediaSendActivity extends PassphraseRequiredActionBarActivity imple try { Uri uri = BlobProvider.getInstance() .forData(data) - .withMimeType(MediaUtil.IMAGE_JPEG) + .withMimeType(MediaTypes.IMAGE_JPEG) .createForSingleSessionOnDisk(this, e -> Log.w(TAG, "Failed to write to disk.", e)); return new Media(uri, - MediaUtil.IMAGE_JPEG, + MediaTypes.IMAGE_JPEG, System.currentTimeMillis(), width, height, diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java index 8300f0866d..89b61cfc0b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediasend/MediaSendFragment.java @@ -28,6 +28,7 @@ import android.view.inputmethod.EditorInfo; import android.widget.ImageButton; import android.widget.TextView; +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.components.ComposeText; import org.thoughtcrime.securesms.components.ControllableViewPager; 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.thoughtcrime.securesms.scribbles.ImageEditorFragment; import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState; -import org.thoughtcrime.securesms.util.MediaUtil; import org.thoughtcrime.securesms.util.PushCharacterCalculator; import org.thoughtcrime.securesms.util.Stopwatch; import org.session.libsignal.libsignal.util.guava.Optional; @@ -453,10 +453,10 @@ public class MediaSendFragment extends Fragment implements ViewTreeObserver.OnGl Uri uri = BlobProvider.getInstance() .forData(baos.toByteArray()) - .withMimeType(MediaUtil.IMAGE_JPEG) + .withMimeType(MediaTypes.IMAGE_JPEG) .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); renderTimer.split("item"); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java index 7fc01e672c..5c78ecda4b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AttachmentManager.java @@ -39,7 +39,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; - +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.MediaPreviewActivity; import org.thoughtcrime.securesms.loki.views.MessageAudioView; import org.thoughtcrime.securesms.components.DocumentView; @@ -213,7 +213,7 @@ public class AttachmentManager { byte[] blob = BitmapUtil.toByteArray(result); Uri uri = BlobProvider.getInstance() .forData(blob) - .withMimeType(MediaUtil.IMAGE_JPEG) + .withMimeType(MediaTypes.IMAGE_JPEG) .createForSingleSessionInMemory(); LocationSlide locationSlide = new LocationSlide(context, uri, blob.length, place); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java index f1bd08afa5..1041b5c72e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/AudioSlide.java @@ -26,15 +26,15 @@ import androidx.annotation.Nullable; import network.loki.messenger.R; import org.session.libsession.messaging.sending_receiving.attachments.Attachment; 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.util.MediaUtil; import org.thoughtcrime.securesms.util.ResUtil; public class AudioSlide extends Slide { 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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java index 9ee38cca0b..7cfe7ddf69 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/GifSlide.java @@ -5,7 +5,7 @@ import android.net.Uri; import androidx.annotation.Nullable; 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 { @@ -19,7 +19,7 @@ public class GifSlide extends ImageSlide { } 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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java index 1e8755ff11..e60708845b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/ImageSlide.java @@ -25,7 +25,7 @@ import androidx.annotation.Nullable; import network.loki.messenger.R; 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 { @@ -41,7 +41,7 @@ public class ImageSlide extends Slide { } 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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java b/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java index f65c51c844..d9e866c8f3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java @@ -4,6 +4,8 @@ import android.content.Context; import android.net.Uri; import androidx.annotation.NonNull; import androidx.annotation.Nullable; + +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.logging.Log; import android.util.Pair; @@ -75,7 +77,7 @@ public abstract class MediaConstraints { try { // 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); - 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) { throw new IOException(e); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java index bbb9fbf049..7f8341f4fc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/StickerSlide.java @@ -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.StickerLocator; -import org.thoughtcrime.securesms.util.MediaUtil; +import org.session.libsession.utilities.MediaTypes; 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) { - 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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java index 38a3374a17..530749830b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/TextSlide.java @@ -7,7 +7,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; 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 { @@ -16,6 +16,6 @@ public class TextSlide extends Slide { } 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)); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java index 4b9c72abb3..3993ff730e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mms/VideoSlide.java @@ -25,6 +25,7 @@ import androidx.annotation.Nullable; import network.loki.messenger.R; 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.ResUtil; @@ -35,7 +36,7 @@ public class VideoSlide extends Slide { } 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) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java index 6207b873b8..73bb184ef8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/UpdateApkReadyListener.java @@ -17,7 +17,7 @@ import org.thoughtcrime.securesms.logging.Log; import network.loki.messenger.R; import org.thoughtcrime.securesms.notifications.NotificationChannels; 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.libsession.utilities.ServiceUtil; import org.session.libsession.utilities.TextSecurePreferences; diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java index dc2e7c9153..5fe323357f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/BitmapUtil.java @@ -18,6 +18,7 @@ import android.util.Pair; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import org.session.libsession.utilities.MediaTypes; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.MediaConstraints; @@ -203,9 +204,9 @@ public class BitmapUtil { if (contentType == null) return CompressFormat.JPEG; switch (contentType) { - case MediaUtil.IMAGE_JPEG: return CompressFormat.JPEG; - case MediaUtil.IMAGE_PNG: return CompressFormat.PNG; - case MediaUtil.IMAGE_WEBP: return CompressFormat.WEBP; + case MediaTypes.IMAGE_JPEG: return CompressFormat.JPEG; + case MediaTypes.IMAGE_PNG: return CompressFormat.PNG; + case MediaTypes.IMAGE_WEBP: return CompressFormat.WEBP; default: return CompressFormat.JPEG; } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java b/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java index e201e683a0..586da50de6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/CommunicationActions.java @@ -1,7 +1,5 @@ package org.thoughtcrime.securesms.util; -import android.Manifest; -import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -18,7 +16,6 @@ import network.loki.messenger.R; import org.session.libsession.messaging.threads.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; -import org.thoughtcrime.securesms.permissions.Permissions; import org.session.libsession.messaging.threads.recipients.Recipient; public class CommunicationActions { diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/Dialogs.java b/app/src/main/java/org/thoughtcrime/securesms/util/Dialogs.java deleted file mode 100644 index 4d92621465..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/util/Dialogs.java +++ /dev/null @@ -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 . - */ -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(); - } -} diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/MathUtils.java b/app/src/main/java/org/thoughtcrime/securesms/util/MathUtils.java deleted file mode 100644 index 93842ea03c..0000000000 --- a/app/src/main/java/org/thoughtcrime/securesms/util/MathUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.thoughtcrime.securesms.util; - -import android.graphics.PointF; -import androidx.annotation.NonNull; - -public class MathUtils { - - /** - * For more info: - * StackOverflow: How to check point is in rectangle - * - * @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); - } -} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java index 1dcdc54a90..d2a621bda9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/MediaUtil.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.gif.GifDrawable; 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.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri; @@ -39,17 +40,6 @@ public class MediaUtil { 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) { Slide slide = null; if (attachment.isSticker()) { @@ -94,8 +84,8 @@ public class MediaUtil { switch(mimeType) { case "image/jpg": - return MimeTypeMap.getSingleton().hasMimeType(IMAGE_JPEG) - ? IMAGE_JPEG + return MimeTypeMap.getSingleton().hasMimeType(MediaTypes.IMAGE_JPEG) + ? MediaTypes.IMAGE_JPEG : mimeType; default: return mimeType; @@ -206,7 +196,7 @@ public class MediaUtil { } 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) { @@ -214,7 +204,7 @@ public class MediaUtil { } 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) { @@ -240,7 +230,7 @@ public class MediaUtil { } 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) { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/Attachment.java b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/Attachment.java index 0bb0248ea7..e87c519191 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/Attachment.java +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/Attachment.java @@ -79,8 +79,8 @@ public abstract class Attachment { } public boolean isInProgress() { - return transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE.getValue() && - transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED.getValue(); + return transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_DONE && + transferState != AttachmentTransferProgress.TRANSFER_PROGRESS_FAILED; } public long getSize() { diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/AttachmentTransferProgress.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/AttachmentTransferProgress.kt index 60d6b95cbe..76b1e57bbb 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/AttachmentTransferProgress.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/AttachmentTransferProgress.kt @@ -1,8 +1,8 @@ package org.session.libsession.messaging.sending_receiving.attachments -enum class AttachmentTransferProgress(val value: Int) { - TRANSFER_PROGRESS_DONE(0), - TRANSFER_PROGRESS_STARTED(1), - TRANSFER_PROGRESS_PENDING(2), - TRANSFER_PROGRESS_FAILED(3) +object AttachmentTransferProgress { + const val TRANSFER_PROGRESS_DONE = 0 + const val TRANSFER_PROGRESS_STARTED = 1 + const val TRANSFER_PROGRESS_PENDING = 2 + const val TRANSFER_PROGRESS_FAILED = 3 } \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/PointerAttachment.java b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/PointerAttachment.java index 78746b0364..b391815250 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/PointerAttachment.java +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/attachments/PointerAttachment.java @@ -104,7 +104,7 @@ public class PointerAttachment extends Attachment { } 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().getFileName().orNull(), String.valueOf(pointer.get().asPointer().getId()), @@ -122,7 +122,7 @@ public class PointerAttachment extends Attachment { public static Optional forPointer(SignalServiceProtos.AttachmentPointer pointer) { return Optional.of(new PointerAttachment(pointer.getContentType(), - AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), + AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING, (long)pointer.getSize(), pointer.getFileName(), String.valueOf(pointer != null ? pointer.getId() : 0), @@ -142,7 +142,7 @@ public class PointerAttachment extends Attachment { SignalServiceProtos.AttachmentPointer thumbnail = pointer.getThumbnail(); return Optional.of(new PointerAttachment(pointer.getContentType(), - AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), + AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING, thumbnail != null ? (long)thumbnail.getSize() : 0, thumbnail.getFileName(), String.valueOf(thumbnail != null ? thumbnail.getId() : 0), @@ -162,7 +162,7 @@ public class PointerAttachment extends Attachment { SignalServiceAttachment thumbnail = pointer.getThumbnail(); return Optional.of(new PointerAttachment(pointer.getContentType(), - AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING.getValue(), + AttachmentTransferProgress.TRANSFER_PROGRESS_PENDING, thumbnail != null ? thumbnail.asPointer().getSize().or(0) : 0, pointer.getFileName(), String.valueOf(thumbnail != null ? thumbnail.asPointer().getId() : 0), diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/contacts/Contact.java b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/contacts/Contact.java index 8bcde1ad8b..37307cd79b 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/contacts/Contact.java +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/contacts/Contact.java @@ -643,7 +643,7 @@ public class Contact implements Parcelable { private static Attachment attachmentFromUri(@Nullable Uri uri) { 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 diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/FileUtils.java b/libsession/src/main/java/org/session/libsession/utilities/FileUtils.java similarity index 94% rename from app/src/main/java/org/thoughtcrime/securesms/util/FileUtils.java rename to libsession/src/main/java/org/session/libsession/utilities/FileUtils.java index 52202fd9cf..5eaed1a3f7 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/FileUtils.java +++ b/libsession/src/main/java/org/session/libsession/utilities/FileUtils.java @@ -1,7 +1,6 @@ -package org.thoughtcrime.securesms.util; +package org.session.libsession.utilities; import java.io.File; -import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; import java.security.MessageDigest; diff --git a/libsession/src/main/java/org/session/libsession/utilities/MediaTypes.kt b/libsession/src/main/java/org/session/libsession/utilities/MediaTypes.kt index 893f742e66..4ef7c10c11 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/MediaTypes.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/MediaTypes.kt @@ -1,13 +1,13 @@ package org.session.libsession.utilities -enum class MediaTypes(val value: String) { - IMAGE_PNG("image/png"), - IMAGE_JPEG("image/jpeg"), - IMAGE_WEBP("image/webp"), - IMAGE_GIF("image/gif"), - AUDIO_AAC("audio/aac"), - AUDIO_UNSPECIFIED("audio/*"), - VIDEO_UNSPECIFIED("video/*"), - VCARD("text/x-vcard"), - LONG_TEXT("text/x-signal-plain") +object MediaTypes { + const val IMAGE_PNG = "image/png" + const val IMAGE_JPEG = "image/jpeg" + const val IMAGE_WEBP = "image/webp" + const val IMAGE_GIF = "image/gif" + const val AUDIO_AAC = "audio/aac" + const val AUDIO_UNSPECIFIED = "audio/*" + const val VIDEO_UNSPECIFIED = "video/*" + const val VCARD = "text/x-vcard" + const val LONG_TEXT = "text/x-signal-plain" } \ No newline at end of file diff --git a/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java index cde571d5e1..070abb556e 100644 --- a/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java +++ b/libsignal/src/main/java/org/session/libsignal/utilities/concurrent/SettableFuture.java @@ -98,7 +98,7 @@ public class SettableFuture implements ListenableFuture { { long startTime = System.currentTimeMillis(); - while (!completed && System.currentTimeMillis() - startTime > unit.toMillis(timeout)) { + while (!completed && System.currentTimeMillis() - startTime < unit.toMillis(timeout)) { wait(unit.toMillis(timeout)); }