Skip to content
Open

Patch 1 #1254

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ import org.greenstand.android.TreeTracker.BuildConfig
import timber.log.Timber
import java.io.ByteArrayInputStream
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
import java.util.UUID
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

@Suppress("ImplicitDefaultLocale")
class ObjectStorageClient private constructor(
Expand Down Expand Up @@ -100,7 +102,6 @@ class ObjectStorageClient private constructor(
}
}

@SuppressLint("SimpleDateFormat")
@Throws(AmazonClientException::class)
fun put(
path: String,
Expand All @@ -111,7 +112,13 @@ class ObjectStorageClient private constructor(
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read)

val image = File(path)
val timeStamp = SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(Date())
val now = Clock.System.now()
.toLocalDateTime(TimeZone.currentSystemDefault())

val timeStamp = "%04d.%02d.%02d.%02d.%02d.%02d".format(
now.year, now.monthNumber, now.dayOfMonth,
now.hour, now.minute, now.second
)

val dosKey = timeStamp + '_' + lat + '_' + long + '_' + UUID.randomUUID() + '_' + image.name
val poRequest = PutObjectRequest(BuildConfig.OBJECT_STORAGE_BUCKET_IMAGES, dosKey, image)
Expand Down Expand Up @@ -145,7 +152,13 @@ class ObjectStorageClient private constructor(
val acl = AccessControlList()
acl.grantPermission(GroupGrantee.AllUsers, Permission.Read)

val timeStamp = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(Date())
val now = Clock.System.now()
.toLocalDateTime(TimeZone.currentSystemDefault())

val timeStamp = "%04d-%02d-%02d-%02d-%02d-%02d".format(
now.year, now.monthNumber, now.dayOfMonth,
now.hour, now.minute, now.second
)

val dosKey = timeStamp + '_'.toString() + UUID.randomUUID() + '_'.toString() + bundleId + ".json"

Expand Down Expand Up @@ -176,4 +189,4 @@ class ObjectStorageClient private constructor(

fun instance(): ObjectStorageClient = INSTANCE!!
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.round
Expand All @@ -50,11 +52,16 @@ object ImageUtils {
return f
}

@SuppressLint("SimpleDateFormat")
@Throws(IOException::class)
fun createImageFile(context: Context): File {
val now = Clock.System.now()
.toLocalDateTime(TimeZone.currentSystemDefault())

val timeStamp = "%04d%02d%02d_%02d%02d%02d".format(
now.year, now.monthNumber, now.dayOfMonth,
now.hour, now.minute, now.second
)
// Create an image file name
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val imageFileName = JPEG_FILE_PREFIX + timeStamp + "_"
val directory = context.getDir("treeImages", Context.MODE_PRIVATE)

Expand Down Expand Up @@ -603,4 +610,4 @@ object ImageUtils {

return encodedImage
}
}
}
Loading