mirror of https://github.com/tasks/tasks
Finish converting data module to kmp
parent
19de0e08a5
commit
4ddfe937b0
@ -0,0 +1,41 @@
|
|||||||
|
package org.tasks.data
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
import org.tasks.data.entity.UserActivity
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun UserActivity.setPicture(uri: Uri?) {
|
||||||
|
picture = uri?.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
val UserActivity.pictureUri: Uri?
|
||||||
|
get() = if (picture.isNullOrBlank()) null else Uri.parse(picture)
|
||||||
|
|
||||||
|
fun UserActivity.convertPictureUri() {
|
||||||
|
setPicture(getLegacyPictureUri(picture))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getLegacyPictureUri(value: String?): Uri? {
|
||||||
|
return try {
|
||||||
|
if (value.isNullOrBlank()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
if (value.contains("uri") || value.contains("path")) {
|
||||||
|
val json = JSONObject(value)
|
||||||
|
if (json.has("uri")) {
|
||||||
|
return Uri.parse(json.getString("uri"))
|
||||||
|
}
|
||||||
|
if (json.has("path")) {
|
||||||
|
val path = json.getString("path")
|
||||||
|
return Uri.fromFile(File(path))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
null
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
Timber.e(e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||||
|
|
||||||
|
package org.tasks
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.parcelize.RawValue
|
||||||
|
import org.tasks.data.BuildConfig
|
||||||
|
|
||||||
|
actual typealias CommonParcelable = Parcelable
|
||||||
|
|
||||||
|
actual typealias CommonRawValue = RawValue
|
||||||
|
|
||||||
|
actual val IS_DEBUG = BuildConfig.DEBUG
|
||||||
@ -1,7 +0,0 @@
|
|||||||
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
|
||||||
|
|
||||||
package org.tasks
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
|
|
||||||
actual typealias CommonParcelable = Parcelable
|
|
||||||
@ -1,112 +1,37 @@
|
|||||||
package org.tasks.data.entity
|
package org.tasks.data.entity
|
||||||
|
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Parcel
|
|
||||||
import android.os.Parcelable
|
|
||||||
import androidx.room.ColumnInfo
|
import androidx.room.ColumnInfo
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.Ignore
|
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import co.touchlab.kermit.Logger
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import org.json.JSONException
|
import org.tasks.CommonParcelable
|
||||||
import org.json.JSONObject
|
import org.tasks.CommonParcelize
|
||||||
import org.tasks.data.db.Table
|
import org.tasks.data.db.Table
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@CommonParcelize
|
||||||
@Entity(tableName = "userActivity")
|
@Entity(tableName = "userActivity")
|
||||||
class UserActivity : Parcelable {
|
data class UserActivity(
|
||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
@ColumnInfo(name = "_id")
|
@ColumnInfo(name = "_id")
|
||||||
@Transient
|
@Transient
|
||||||
var id: Long? = null
|
var id: Long? = null,
|
||||||
|
|
||||||
@ColumnInfo(name = "remoteId")
|
@ColumnInfo(name = "remoteId")
|
||||||
var remoteId: String? = Task.NO_UUID
|
var remoteId: String? = Task.NO_UUID,
|
||||||
|
|
||||||
@ColumnInfo(name = "message")
|
@ColumnInfo(name = "message")
|
||||||
var message: String? = ""
|
var message: String? = "",
|
||||||
|
|
||||||
@ColumnInfo(name = "picture")
|
@ColumnInfo(name = "picture")
|
||||||
var picture: String? = ""
|
var picture: String? = "",
|
||||||
|
|
||||||
@ColumnInfo(name = "target_id")
|
@ColumnInfo(name = "target_id")
|
||||||
@Transient
|
@Transient
|
||||||
var targetId: String? = Task.NO_UUID
|
var targetId: String? = Task.NO_UUID,
|
||||||
|
|
||||||
@ColumnInfo(name = "created_at")
|
@ColumnInfo(name = "created_at")
|
||||||
var created: Long? = 0L
|
var created: Long? = 0L,
|
||||||
|
) : CommonParcelable {
|
||||||
constructor()
|
|
||||||
|
|
||||||
@Ignore
|
|
||||||
private constructor(parcel: Parcel) {
|
|
||||||
with(parcel) {
|
|
||||||
id = readLong()
|
|
||||||
remoteId = readString()
|
|
||||||
message = readString()
|
|
||||||
picture = readString()
|
|
||||||
targetId = readString()
|
|
||||||
created = readLong()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setPicture(uri: Uri?) {
|
|
||||||
picture = uri?.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
val pictureUri: Uri?
|
|
||||||
get() = if (picture.isNullOrBlank()) null else Uri.parse(picture)
|
|
||||||
|
|
||||||
fun convertPictureUri() {
|
|
||||||
setPicture(getLegacyPictureUri(picture))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun describeContents() = 0
|
|
||||||
|
|
||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
|
||||||
with(dest) {
|
|
||||||
writeLong(id!!)
|
|
||||||
writeString(remoteId)
|
|
||||||
writeString(message)
|
|
||||||
writeString(picture)
|
|
||||||
writeString(targetId)
|
|
||||||
writeLong(created!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmField val TABLE = Table("userActivity")
|
@JvmField val TABLE = Table("userActivity")
|
||||||
@JvmField val TASK = TABLE.column("target_id")
|
@JvmField val TASK = TABLE.column("target_id")
|
||||||
@JvmField val MESSAGE = TABLE.column("message")
|
@JvmField val MESSAGE = TABLE.column("message")
|
||||||
@JvmField val CREATOR: Parcelable.Creator<UserActivity> = object : Parcelable.Creator<UserActivity> {
|
|
||||||
override fun createFromParcel(source: Parcel): UserActivity = UserActivity(source)
|
|
||||||
|
|
||||||
override fun newArray(size: Int): Array<UserActivity?> = arrayOfNulls(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getLegacyPictureUri(value: String?): Uri? {
|
|
||||||
return try {
|
|
||||||
if (value.isNullOrBlank()) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
if (value.contains("uri") || value.contains("path")) {
|
|
||||||
val json = JSONObject(value)
|
|
||||||
if (json.has("uri")) {
|
|
||||||
return Uri.parse(json.getString("uri"))
|
|
||||||
}
|
|
||||||
if (json.has("path")) {
|
|
||||||
val path = json.getString("path")
|
|
||||||
return Uri.fromFile(File(path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
null
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
Logger.e("Failed to parse picture uri", e, tag = "UserActivity")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
@file:Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
|
||||||
|
|
||||||
|
package org.tasks
|
||||||
|
|
||||||
|
actual interface CommonParcelable
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.TYPE)
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
annotation class RawValue
|
||||||
|
|
||||||
|
actual typealias CommonRawValue = RawValue
|
||||||
|
|
||||||
|
actual val IS_DEBUG = false
|
||||||
Loading…
Reference in New Issue