diff --git a/aws-common/src/commonMain/kotlin/com/estivensh4/aws_kmp/AwsException.kt b/aws-common/src/commonMain/kotlin/com/estivensh4/aws_kmp/AwsException.kt index bd6a78d..d8837d6 100644 --- a/aws-common/src/commonMain/kotlin/com/estivensh4/aws_kmp/AwsException.kt +++ b/aws-common/src/commonMain/kotlin/com/estivensh4/aws_kmp/AwsException.kt @@ -5,12 +5,7 @@ package com.estivensh4.aws_kmp class AwsException : Exception { - @Throws(Exception::class) constructor(message: String?) : super(message) - - @Throws(Exception::class) constructor(cause: Throwable?) : super(cause) - - @Throws(Exception::class) constructor(message: String?, cause: Throwable?) : super(message, cause) } \ No newline at end of file diff --git a/aws-s3/src/commonMain/kotlin/com/estivensh4/aws_s3/ImageFile.kt b/aws-s3/src/commonMain/kotlin/com/estivensh4/aws_s3/ImageFile.kt index 2419662..0adbe67 100644 --- a/aws-s3/src/commonMain/kotlin/com/estivensh4/aws_s3/ImageFile.kt +++ b/aws-s3/src/commonMain/kotlin/com/estivensh4/aws_s3/ImageFile.kt @@ -4,5 +4,5 @@ package com.estivensh4.aws_s3 -expect class ImageFile +expect open class ImageFile expect fun ImageFile.toByteArray(): ByteArray \ No newline at end of file diff --git a/aws-s3/src/iosMain/kotlin/com/estivensh4/aws_s3/AWSS3.kt b/aws-s3/src/iosMain/kotlin/com/estivensh4/aws_s3/AWSS3.kt index dc7fd87..b455ce8 100644 --- a/aws-s3/src/iosMain/kotlin/com/estivensh4/aws_s3/AWSS3.kt +++ b/aws-s3/src/iosMain/kotlin/com/estivensh4/aws_s3/AWSS3.kt @@ -11,6 +11,7 @@ import cocoapods.AWSS3.AWSS3CreateBucketRequest import cocoapods.AWSS3.AWSS3DeleteBucketRequest import cocoapods.AWSS3.AWSS3DeleteObjectsRequest import cocoapods.AWSS3.AWSS3DeletedObject +import cocoapods.AWSS3.AWSS3GetObjectRequest import cocoapods.AWSS3.AWSS3GetPreSignedURLRequest import cocoapods.AWSS3.AWSS3ListObjectsV2Output import cocoapods.AWSS3.AWSS3ListObjectsV2Request @@ -97,9 +98,9 @@ actual class AWSS3 actual constructor( return try { val preSignedURLRequest = AWSS3GetPreSignedURLRequest() preSignedURLRequest.apply { - bucket = bucketName + this.bucket = bucketName this.key = key - expires = NSDate().dateByAddingTimeInterval(expirationInSeconds.toDouble()) + this.expires = NSDate().dateByAddingTimeInterval(expirationInSeconds.toDouble()) } val request = AWSS3PreSignedURLBuilder.defaultS3PreSignedURLBuilder() @@ -107,7 +108,7 @@ actual class AWSS3 actual constructor( val url = request.result() as NSURL url.absoluteString } catch (exception: Exception) { - throw AwsException("Exception is ${exception.message}", exception) + throw Exception("Exception is ${exception.message}", exception) } } @@ -323,14 +324,16 @@ actual class AWSS3 actual constructor( * @throws AwsException If any errors are encountered in the client * while making the request or handling the response. */ - @Suppress("CAST_NEVER_SUCCEEDS") actual suspend fun createBucket(bucketName: String): Bucket { val request = AWSS3CreateBucketRequest() request.bucket = bucketName - val result = awaitResult { client.createBucket(request, it) } as AWSS3Bucket + val result = awaitResult { client.createBucket(request, it) } - return result.toBucket() + return Bucket( + name = result.location, + creationDate = null + ) } /** diff --git a/example/androidapp/build.gradle.kts b/example/androidapp/build.gradle.kts index 6c1a941..7237547 100644 --- a/example/androidapp/build.gradle.kts +++ b/example/androidapp/build.gradle.kts @@ -31,11 +31,11 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "11" } buildFeatures { compose = true diff --git a/example/androidapp/src/main/java/com/estivensh4/androidapp/MainActivity.kt b/example/androidapp/src/main/java/com/estivensh4/androidapp/MainActivity.kt index 64f6538..4ea014c 100644 --- a/example/androidapp/src/main/java/com/estivensh4/androidapp/MainActivity.kt +++ b/example/androidapp/src/main/java/com/estivensh4/androidapp/MainActivity.kt @@ -72,10 +72,10 @@ fun Greeting() { Column { CButton(text = "GeneratePresignedURL") { - text = sampleViewModel.generatePresignedUrl( + sampleViewModel.generatePresignedUrl( bucketName = bucketName, key = key - ) ?: "" + ) Log.d("ResultGeneratePresignedUrl", text) } CButton(text = "Create bucket") { diff --git a/example/desktopApp/src/main/kotlin/Main.kt b/example/desktopApp/src/main/kotlin/Main.kt index 9763d4a..5edcdbb 100644 --- a/example/desktopApp/src/main/kotlin/Main.kt +++ b/example/desktopApp/src/main/kotlin/Main.kt @@ -1,11 +1,16 @@ import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.material.Button +import androidx.compose.material.Divider import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -26,11 +31,13 @@ import java.io.File @Composable @Preview fun App() { - var generatePresignerUrlResult by remember { mutableStateOf("") } val sampleViewModel = SampleViewModel() val bucketName = "test-bucket-desktop-app" val key = "test.jpg" val scope = rememberCoroutineScope() + val bucketList by sampleViewModel.bucketList.collectAsState() + val bucket by sampleViewModel.bucket.collectAsState() + val generatePresignedUrl by sampleViewModel.generatePresignedUrl.collectAsState() MaterialTheme { Column( @@ -56,11 +63,22 @@ fun App() { } ) } + LazyColumn { + items(bucketList) { item -> + Text("${item.name}") + } + } + + Divider() + Text("Status bucket: $bucket") + Divider() + Text("Status generate presigned url: $generatePresignedUrl") + CButton(text = "generatePresignedUrl") { - generatePresignerUrlResult = sampleViewModel.generatePresignedUrl( + sampleViewModel.generatePresignedUrl( bucketName = bucketName, key = key - ) ?: "" + ) } CButton(text = "Create bucket") { scope.launch { diff --git a/example/gradle/libs.versions.toml b/example/gradle/libs.versions.toml index cb20b34..0b5a565 100644 --- a/example/gradle/libs.versions.toml +++ b/example/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] agp = "8.1.3" -awsS3 = "0.4.4" +awsS3 = "0.5.0" kotlin = "1.9.20" compose = "1.5.4" compose-compiler = "1.5.4" diff --git a/example/gradle/wrapper/gradle-wrapper.properties b/example/gradle/wrapper/gradle-wrapper.properties index c109e9b..2d426ca 100644 --- a/example/gradle/wrapper/gradle-wrapper.properties +++ b/example/gradle/wrapper/gradle-wrapper.properties @@ -5,6 +5,6 @@ #Thu Nov 09 01:52:10 COT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/example/iosApp/iosApp.xcodeproj/project.pbxproj b/example/iosApp/iosApp.xcodeproj/project.pbxproj index 7f4eee8..2e2cc41 100644 --- a/example/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/example/iosApp/iosApp.xcodeproj/project.pbxproj @@ -10,6 +10,9 @@ 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; }; 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; }; 14B556C42B02FCD900F83F55 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14B556C32B02FCD900F83F55 /* AppDelegate.swift */; }; + 14D2717A2B069C5E008E0210 /* KMMViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D271792B069C5E008E0210 /* KMMViewModel.swift */; }; + 14D2717D2B069CFA008E0210 /* KMMViewModelCore in Frameworks */ = {isa = PBXBuildFile; productRef = 14D2717C2B069CFA008E0210 /* KMMViewModelCore */; }; + 14D2717F2B069CFA008E0210 /* KMMViewModelSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 14D2717E2B069CFA008E0210 /* KMMViewModelSwiftUI */; }; 2080562A60F485076008115A /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5A9C2A9FE107A1EB6B1A594 /* Pods_iosApp.framework */; }; 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; }; @@ -19,6 +22,7 @@ 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 14B556C32B02FCD900F83F55 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 14D271792B069C5E008E0210 /* KMMViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMMViewModel.swift; sourceTree = ""; }; 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; }; 6BCC0A48C5FCF9A097A71478 /* Pods-iosApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.debug.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.debug.xcconfig"; sourceTree = ""; }; 7555FF7B242A565900829871 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -33,6 +37,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 14D2717D2B069CFA008E0210 /* KMMViewModelCore in Frameworks */, + 14D2717F2B069CFA008E0210 /* KMMViewModelSwiftUI in Frameworks */, 2080562A60F485076008115A /* Pods_iosApp.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -75,6 +81,7 @@ 2152FB032600AC8F00CF470E /* iOSApp.swift */, 058557D7273AAEEB004C7B11 /* Preview Content */, 14B556C32B02FCD900F83F55 /* AppDelegate.swift */, + 14D271792B069C5E008E0210 /* KMMViewModel.swift */, ); path = iosApp; sourceTree = ""; @@ -114,6 +121,10 @@ dependencies = ( ); name = iosApp; + packageProductDependencies = ( + 14D2717C2B069CFA008E0210 /* KMMViewModelCore */, + 14D2717E2B069CFA008E0210 /* KMMViewModelSwiftUI */, + ); productName = iosApp; productReference = 7555FF7B242A565900829871 /* iosApp.app */; productType = "com.apple.product-type.application"; @@ -142,6 +153,9 @@ Base, ); mainGroup = 7555FF72242A565900829871; + packageReferences = ( + 14D2717B2B069CFA008E0210 /* XCRemoteSwiftPackageReference "KMM-ViewModel" */, + ); productRefGroup = 7555FF7C242A565900829871 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -212,6 +226,7 @@ files = ( 14B556C42B02FCD900F83F55 /* AppDelegate.swift in Sources */, 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */, + 14D2717A2B069C5E008E0210 /* KMMViewModel.swift in Sources */, 7555FF83242A565900829871 /* ContentView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -399,6 +414,30 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 14D2717B2B069CFA008E0210 /* XCRemoteSwiftPackageReference "KMM-ViewModel" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/rickclephas/KMM-ViewModel.git"; + requirement = { + branch = master; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 14D2717C2B069CFA008E0210 /* KMMViewModelCore */ = { + isa = XCSwiftPackageProductDependency; + package = 14D2717B2B069CFA008E0210 /* XCRemoteSwiftPackageReference "KMM-ViewModel" */; + productName = KMMViewModelCore; + }; + 14D2717E2B069CFA008E0210 /* KMMViewModelSwiftUI */ = { + isa = XCSwiftPackageProductDependency; + package = 14D2717B2B069CFA008E0210 /* XCRemoteSwiftPackageReference "KMM-ViewModel" */; + productName = KMMViewModelSwiftUI; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 7555FF73242A565900829871 /* Project object */; } diff --git a/example/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved b/example/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..5436087 --- /dev/null +++ b/example/iosApp/iosApp.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "kmm-viewmodel", + "kind" : "remoteSourceControl", + "location" : "https://github.com/rickclephas/KMM-ViewModel.git", + "state" : { + "branch" : "master", + "revision" : "5122024085c468d006c66afc3ae37f233f88ec1f" + } + } + ], + "version" : 2 +} diff --git a/example/iosApp/iosApp/AppDelegate.swift b/example/iosApp/iosApp/AppDelegate.swift index 5370b09..a059d59 100644 --- a/example/iosApp/iosApp/AppDelegate.swift +++ b/example/iosApp/iosApp/AppDelegate.swift @@ -26,7 +26,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func initializeS3(){ - let credentialsProvider = AWSStaticCredentialsProvider(accessKey: "1", secretKey: "1") + let credentialsProvider = AWSStaticCredentialsProvider(accessKey: BuildPublicConfig().accessKey, secretKey: BuildPublicConfig().secretKey) let configuration = AWSServiceConfiguration.init(region: .USEast1, credentialsProvider: credentialsProvider) AWSServiceManager.default().defaultServiceConfiguration = configuration diff --git a/example/iosApp/iosApp/ContentView.swift b/example/iosApp/iosApp/ContentView.swift index d37ccc0..cd992b1 100644 --- a/example/iosApp/iosApp/ContentView.swift +++ b/example/iosApp/iosApp/ContentView.swift @@ -1,15 +1,83 @@ import SwiftUI import shared +import KMMViewModelSwiftUI +import PhotosUI +@available(iOS 16.0, *) struct ContentView: View { - var greet = "Hi" + + @StateViewModel var sampleViewModel = SampleViewModel() + let bucketName = "test-bucket-desktop-app" + let key = "test.jpg" + @State private var selectedItem: PhotosPickerItem? = nil + @State private var selectedImageData: Data? = nil + var body: some View { - Text(greet) + PhotosPicker( + selection: $selectedItem, + matching: .images, + photoLibrary: .shared()) { + Text("Select a photo") + } + .onChange(of: selectedItem) { newItem in + Task { + // Retrieve selected asset in the form of Data + if let data = try? await newItem?.loadTransferable(type: Data.self) { + selectedImageData = data + } + } + } + + if let selectedImageData, + let uiImage = UIImage(data: selectedImageData) { + Image(uiImage: uiImage) + .resizable() + .scaledToFit() + .frame(width: 250, height: 250) + } + + + VStack { + List { + ForEach(sampleViewModel.bucketList, id: \.name){ data in + Text(data.name ?? "Default value") + } + } + Text("Status bucket: \(sampleViewModel.bucket)") + Text("Status generate presigned url: \(sampleViewModel.generatePresignedUrl)") + Button(action: { + sampleViewModel.createBucket(bucketName: bucketName) + }, label: { + Text("Create bucket") + }) + Button(action: { + sampleViewModel.listBuckets() + }, label: { + Text("List bucket") + }) + Button(action: { + sampleViewModel.deleteBucket(bucketName: bucketName) + }, label: { + Text("Delete bucket") + }) + Button(action: { + sampleViewModel.generatePresignedUrl(bucketName: bucketName, key: key) + }, label: { + Text("Generate presigned URL") + }) + + Button(action: { + + if let selectedImageData, + let uiImage = UIImage(data: selectedImageData) { + sampleViewModel.putObject(bucketName: bucketName, key: key, imageFile: uiImage) + } + + + }, label: { + Text("Put object") + }) + } } } -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -} diff --git a/example/iosApp/iosApp/KMMViewModel.swift b/example/iosApp/iosApp/KMMViewModel.swift new file mode 100644 index 0000000..43a9ec1 --- /dev/null +++ b/example/iosApp/iosApp/KMMViewModel.swift @@ -0,0 +1,12 @@ +// +// KMMViewModel.swift +// iosApp +// +// Created by Estiven on 16/11/23. +// Copyright © 2023 orgName. All rights reserved. +// + +import KMMViewModelCore +import shared + +extension Kmm_viewmodel_coreKMMViewModel: KMMViewModel { } diff --git a/example/iosApp/iosApp/iOSApp.swift b/example/iosApp/iosApp/iOSApp.swift index 667fa87..ee6901c 100644 --- a/example/iosApp/iosApp/iOSApp.swift +++ b/example/iosApp/iosApp/iOSApp.swift @@ -1,5 +1,6 @@ import SwiftUI +@available(iOS 16.0, *) @main struct iOSApp: App { diff --git a/example/shared/build.gradle.kts b/example/shared/build.gradle.kts index 0a3420a..da4cc5b 100644 --- a/example/shared/build.gradle.kts +++ b/example/shared/build.gradle.kts @@ -11,12 +11,14 @@ plugins { } kotlin { - applyDefaultHierarchyTemplate() + //applyDefaultHierarchyTemplate() + + jvmToolchain(11) androidTarget { compilations.all { kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "11" } } } @@ -25,10 +27,6 @@ kotlin { iosSimulatorArm64() jvm() - kotlin.sourceSets.all { - languageSettings.optIn("kotlin.experimental.ExperimentalObjCName") - } - cocoapods { summary = "Some description for the Shared Module" homepage = "Link to the Shared Module homepage" @@ -37,12 +35,16 @@ kotlin { framework { baseName = "shared" export(libs.kotlinx.datetime) + //export(libs.aws.s3) linkerOpts.add("-lsqlite3") } pod("AWSS3", "~> 2.33.4") } sourceSets { + all { + languageSettings.optIn("kotlin.experimental.ExperimentalObjCName") + } commonMain { dependencies { api(libs.kotlinx.datetime) @@ -55,6 +57,11 @@ kotlin { implementation(libs.kotlin.test) } } + jvmMain { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.7.3") + } + } } } @@ -77,4 +84,11 @@ buildkonfig { buildConfigField(STRING, "accessKey", localProperties.getProperty("AWS_ACCESS_KEY")) buildConfigField(STRING, "secretKey", localProperties.getProperty("AWS_SECRET_KEY")) } +} + +tasks.withType().configureEach { + compilerOptions.freeCompilerArgs.addAll( + "-opt-in=kotlinx.cinterop.ExperimentalForeignApi", + "-opt-in=kotlin.experimental.ExperimentalNativeApi" + ) } \ No newline at end of file diff --git a/example/shared/src/commonMain/kotlin/com/estivensh4/shared/SampleViewModel.kt b/example/shared/src/commonMain/kotlin/com/estivensh4/shared/SampleViewModel.kt index 80232d7..c8ac1a3 100644 --- a/example/shared/src/commonMain/kotlin/com/estivensh4/shared/SampleViewModel.kt +++ b/example/shared/src/commonMain/kotlin/com/estivensh4/shared/SampleViewModel.kt @@ -1,57 +1,67 @@ package com.estivensh4.shared -import com.estivensh4.aws_s3.AwsS3 +import com.estivensh4.aws_s3.AWSS3 import com.estivensh4.aws_s3.Bucket import com.estivensh4.aws_s3.ImageFile import com.rickclephas.kmm.viewmodel.KMMViewModel +import com.rickclephas.kmm.viewmodel.MutableStateFlow import com.rickclephas.kmp.nativecoroutines.NativeCoroutinesState import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import kotlinx.datetime.Clock @OptIn(DelicateCoroutinesApi::class) open class SampleViewModel : KMMViewModel() { - private var _bucket = Bucket("", Clock.System.now()) - private val client: AwsS3 - get() { - return AwsS3.Builder() - .accessKey(BuildPublicConfig.accessKey) - .secretKey(BuildPublicConfig.secretKey) - .setEndpoint("s3.amazonaws.com") - .build() - } + private var _bucketList = MutableStateFlow>(viewModelScope, emptyList()) + private var _bucket = MutableStateFlow(viewModelScope, Bucket("", Clock.System.now())) + private var _generatePresignedUrl = MutableStateFlow(viewModelScope, "") + + @NativeCoroutinesState + val bucketList get() = _bucketList.asStateFlow() + + @NativeCoroutinesState + val bucket get() = _bucket.asStateFlow() @NativeCoroutinesState - val bucket get() = _bucket + val generatePresignedUrl get() = _generatePresignedUrl.asStateFlow() + private val client = AWSS3.Builder() + .accessKey(BuildPublicConfig.accessKey) + .secretKey(BuildPublicConfig.secretKey) + .setEndpoint("s3.amazonaws.com") + .build() fun generatePresignedUrl( bucketName: String, key: String, - ): String? { - return client.generatePresignedUrl( + ) { + _generatePresignedUrl.value = client.generatePresignedUrl( bucketName = bucketName, key = key, expirationInSeconds = 3600L - ) + ) ?: "" } - fun createBucket(bucketName: String) = runBlocking { - client.createBucket(bucketName) + fun createBucket(bucketName: String) { + GlobalScope.launch { + client.createBucket(bucketName) + } } fun listBuckets() { GlobalScope.launch { val list = client.listBuckets() - print("$list") + _bucketList.value = list } } - fun deleteBucket(bucketName: String) = runBlocking { - client.deleteBucket(bucketName) + fun deleteBucket(bucketName: String) { + GlobalScope.launch { + client.deleteBucket(bucketName) + } } fun putObject(bucketName: String, key: String, imageFile: ImageFile) { diff --git a/example/wearapp/build.gradle.kts b/example/wearapp/build.gradle.kts index 3ca2a2c..a72b90a 100644 --- a/example/wearapp/build.gradle.kts +++ b/example/wearapp/build.gradle.kts @@ -30,11 +30,11 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "11" } buildFeatures { compose = true diff --git a/example/wearapp/src/main/java/com/estivensh4/wearapp/presentation/MainActivity.kt b/example/wearapp/src/main/java/com/estivensh4/wearapp/presentation/MainActivity.kt index 4a7d2c4..a74120e 100644 --- a/example/wearapp/src/main/java/com/estivensh4/wearapp/presentation/MainActivity.kt +++ b/example/wearapp/src/main/java/com/estivensh4/wearapp/presentation/MainActivity.kt @@ -91,9 +91,7 @@ fun WearApp() { item { Button( onClick = { - val result = - sampleViewModel.generatePresignedUrl(bucketName, key) ?: "" - Log.d("GeneratPresignedUrlResult", result) + sampleViewModel.generatePresignedUrl(bucketName, key) }, modifier = Modifier.fillMaxWidth() ) { diff --git a/gradle/aws.versions.toml b/gradle/aws.versions.toml index 64579b0..54b1332 100644 --- a/gradle/aws.versions.toml +++ b/gradle/aws.versions.toml @@ -1,5 +1,5 @@ [versions] -aws = "0.5.0" +aws = "0.5.1" [libraries] aws-common = { module = "io.github.estivensh4:aws-common", version.ref = "aws" }