mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 20:07:51 +00:00
clean & minor fix
This commit is contained in:
@@ -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() {
|
||||
|
@@ -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
|
||||
}
|
@@ -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<Attachment> 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),
|
||||
|
@@ -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
|
||||
|
@@ -0,0 +1,50 @@
|
||||
package org.session.libsession.utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static byte[] getFileDigest(FileInputStream fin) throws IOException {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA256");
|
||||
|
||||
byte[] buffer = new byte[4096];
|
||||
int read = 0;
|
||||
|
||||
while ((read = fin.read(buffer, 0, buffer.length)) != -1) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
|
||||
return digest.digest();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectoryContents(File directory) throws IOException {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory()) return;
|
||||
|
||||
File[] files = directory.listFiles();
|
||||
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) deleteDirectory(file);
|
||||
else file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteDirectory(File directory) throws IOException {
|
||||
if (directory == null || !directory.exists() || !directory.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteDirectoryContents(directory);
|
||||
|
||||
directory.delete();
|
||||
}
|
||||
}
|
@@ -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"
|
||||
}
|
Reference in New Issue
Block a user