mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-15 07:28:30 +00:00
Extract Media and TransformProperties to core/util/models.
This commit is contained in:
27
core/models-jvm/build.gradle.kts
Normal file
27
core/models-jvm/build.gradle.kts
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("ktlint")
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
|
||||
targetCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
languageVersion = JavaLanguageVersion.of(libs.versions.kotlinJvmTarget.get())
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.libsignal.client)
|
||||
implementation(libs.square.okio)
|
||||
implementation(project(":core:util-jvm"))
|
||||
}
|
||||
@@ -4,24 +4,16 @@
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("ktlint")
|
||||
id("signal-library")
|
||||
id("kotlin-parcelize")
|
||||
alias(libs.plugins.kotlinx.serialization)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
|
||||
targetCompatibility = JavaVersion.toVersion(libs.versions.javaVersion.get())
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
languageVersion = JavaLanguageVersion.of(libs.versions.kotlinJvmTarget.get())
|
||||
}
|
||||
android {
|
||||
namespace = "org.signal.core.models"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.libsignal.client)
|
||||
implementation(libs.square.okio)
|
||||
implementation(project(":core:util-jvm"))
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.jackson.core)
|
||||
}
|
||||
|
||||
5
core/models/src/main/AndroidManifest.xml
Normal file
5
core/models/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.models
|
||||
|
||||
import android.net.Uri
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* Kotlinx Serialization serializer for Android [Uri] objects.
|
||||
*/
|
||||
class UriSerializer : KSerializer<Uri> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Uri", PrimitiveKind.STRING)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: Uri) {
|
||||
encoder.encodeString(value.toString())
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): Uri {
|
||||
return Uri.parse(decoder.decodeString())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.models.media
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.signal.core.models.UriSerializer
|
||||
|
||||
/**
|
||||
* Represents a piece of media that the user has on their device.
|
||||
*/
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class Media(
|
||||
@Serializable(with = UriSerializer::class) val uri: Uri,
|
||||
val contentType: String?,
|
||||
val date: Long,
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
val size: Long,
|
||||
val duration: Long,
|
||||
@get:JvmName("isBorderless") val isBorderless: Boolean,
|
||||
@get:JvmName("isVideoGif") val isVideoGif: Boolean,
|
||||
val bucketId: String?,
|
||||
val caption: String?,
|
||||
val transformProperties: TransformProperties?,
|
||||
var fileName: String?
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
const val ALL_MEDIA_BUCKET_ID: String = "org.thoughtcrime.securesms.ALL_MEDIA"
|
||||
}
|
||||
|
||||
fun withMimeType(newMimeType: String) = copy(contentType = newMimeType)
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.models.media
|
||||
|
||||
import android.os.Parcelable
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Properties that describe transformations to be applied to media before sending.
|
||||
*/
|
||||
@Serializable
|
||||
@Parcelize
|
||||
data class TransformProperties(
|
||||
@JsonProperty("skipTransform")
|
||||
@JvmField
|
||||
val skipTransform: Boolean = false,
|
||||
|
||||
@JsonProperty("videoTrim")
|
||||
@JvmField
|
||||
val videoTrim: Boolean = false,
|
||||
|
||||
@JsonProperty("videoTrimStartTimeUs")
|
||||
@JvmField
|
||||
val videoTrimStartTimeUs: Long = 0,
|
||||
|
||||
@JsonProperty("videoTrimEndTimeUs")
|
||||
@JvmField
|
||||
val videoTrimEndTimeUs: Long = 0,
|
||||
|
||||
@JsonProperty("sentMediaQuality")
|
||||
@JvmField
|
||||
val sentMediaQuality: Int = DEFAULT_MEDIA_QUALITY,
|
||||
|
||||
@JsonProperty("mp4Faststart")
|
||||
@JvmField
|
||||
val mp4FastStart: Boolean = false
|
||||
) : Parcelable {
|
||||
fun shouldSkipTransform(): Boolean {
|
||||
return skipTransform
|
||||
}
|
||||
|
||||
@IgnoredOnParcel
|
||||
@JsonProperty("videoEdited")
|
||||
val videoEdited: Boolean = videoTrim
|
||||
|
||||
fun withSkipTransform(): TransformProperties {
|
||||
return this.copy(
|
||||
skipTransform = true
|
||||
)
|
||||
}
|
||||
|
||||
fun withMp4FastStart(): TransformProperties {
|
||||
return this.copy(mp4FastStart = true)
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Corresponds to SentMediaQuality.STANDARD.code */
|
||||
const val DEFAULT_MEDIA_QUALITY = 0
|
||||
|
||||
@JvmStatic
|
||||
fun empty(): TransformProperties {
|
||||
return TransformProperties(
|
||||
skipTransform = false,
|
||||
videoTrim = false,
|
||||
videoTrimStartTimeUs = 0,
|
||||
videoTrimEndTimeUs = 0,
|
||||
sentMediaQuality = DEFAULT_MEDIA_QUALITY,
|
||||
mp4FastStart = false
|
||||
)
|
||||
}
|
||||
|
||||
fun forSkipTransform(): TransformProperties {
|
||||
return TransformProperties(
|
||||
skipTransform = true,
|
||||
videoTrim = false,
|
||||
videoTrimStartTimeUs = 0,
|
||||
videoTrimEndTimeUs = 0,
|
||||
sentMediaQuality = DEFAULT_MEDIA_QUALITY,
|
||||
mp4FastStart = false
|
||||
)
|
||||
}
|
||||
|
||||
fun forVideoTrim(videoTrimStartTimeUs: Long, videoTrimEndTimeUs: Long): TransformProperties {
|
||||
return TransformProperties(
|
||||
skipTransform = false,
|
||||
videoTrim = true,
|
||||
videoTrimStartTimeUs = videoTrimStartTimeUs,
|
||||
videoTrimEndTimeUs = videoTrimEndTimeUs,
|
||||
sentMediaQuality = DEFAULT_MEDIA_QUALITY,
|
||||
mp4FastStart = false
|
||||
)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun forSentMediaQuality(sentMediaQuality: Int): TransformProperties {
|
||||
return TransformProperties(sentMediaQuality = sentMediaQuality)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
plugins {
|
||||
id("signal-library")
|
||||
id("com.squareup.wire")
|
||||
id("kotlin-parcelize")
|
||||
alias(libs.plugins.kotlinx.serialization)
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -12,6 +14,8 @@ dependencies {
|
||||
|
||||
implementation(libs.androidx.sqlite)
|
||||
implementation(libs.androidx.documentfile)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.jackson.core)
|
||||
testImplementation(libs.androidx.sqlite.framework)
|
||||
|
||||
testImplementation(testLibs.junit.junit)
|
||||
|
||||
Reference in New Issue
Block a user