From 71a136ecefa5e13a2e327752d81ae2904255df16 Mon Sep 17 00:00:00 2001 From: mym0404 Date: Tue, 2 Jul 2024 15:56:53 +0900 Subject: [PATCH] style(android): apply ktlint 1.3.0 rullset --- .../rnkakao/channel/RNCKakaoChannelModule.kt | 271 ++++---- .../rnkakao/channel/RNCKakaoChannelPackage.kt | 10 +- .../android/src/newarch/KakaoChannelSpec.kt | 5 +- .../android/src/oldarch/KakaoChannelSpec.kt | 85 +-- .../rnkakao/core/RNCKakaoCoreModule.kt | 33 +- .../rnkakao/core/RNCKakaoCorePackage.kt | 10 +- .../rnkakao/core/util/RNCKakaoException.kt | 24 +- .../rnkakao/core/util/RNCKakaoUtil.kt | 24 +- .../core/android/src/newarch/KakaoCoreSpec.kt | 5 +- .../core/android/src/oldarch/KakaoCoreSpec.kt | 11 +- .../mjstudio/rnkakao/map/RNCKakaoMapModule.kt | 29 +- .../rnkakao/map/RNCKakaoMapPackage.kt | 10 +- .../map/android/src/newarch/KakaoMapSpec.kt | 5 +- .../map/android/src/oldarch/KakaoMapSpec.kt | 15 +- .../rnkakao/navi/RNCKakaoNaviModule.kt | 93 ++- .../rnkakao/navi/RNCKakaoNaviPackage.kt | 10 +- .../navi/android/src/newarch/KakaoNaviSpec.kt | 5 +- .../navi/android/src/oldarch/KakaoNaviSpec.kt | 23 +- .../rnkakao/share/RNCKakaoShareModule.kt | 451 +++++++------ .../rnkakao/share/RNCKakaoSharePackage.kt | 10 +- .../rnkakao/share/RNCKakaoShareTemplates.kt | 5 +- .../android/src/newarch/KakaoShareSpec.kt | 5 +- .../android/src/oldarch/KakaoShareSpec.kt | 29 +- .../rnkakao/social/RNCKakaoSocialModule.kt | 293 ++++---- .../rnkakao/social/RNCKakaoSocialPackage.kt | 10 +- .../android/src/newarch/KakaoSocialSpec.kt | 5 +- .../android/src/oldarch/KakaoSocialSpec.kt | 29 +- .../rnkakao/user/RNCKakaoUserModule.kt | 632 +++++++++--------- .../rnkakao/user/RNCKakaoUserPackage.kt | 10 +- .../user/android/src/newarch/KakaoUserSpec.kt | 5 +- .../user/android/src/oldarch/KakaoUserSpec.kt | 53 +- 31 files changed, 1100 insertions(+), 1105 deletions(-) diff --git a/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelModule.kt b/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelModule.kt index 0f393ce..cc9f81d 100644 --- a/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelModule.kt +++ b/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelModule.kt @@ -18,166 +18,165 @@ import net.mjstudio.rnkakao.core.util.putS import net.mjstudio.rnkakao.core.util.rejectWith import net.mjstudio.rnkakao.core.util.unix -class RNCKakaoChannelModule internal constructor(context: ReactApplicationContext) : - KakaoChannelSpec(context) { - override fun getName(): String { - return NAME - } +class RNCKakaoChannelModule internal constructor( + context: ReactApplicationContext, +) : KakaoChannelSpec(context) { + override fun getName(): String = NAME - @ReactMethod - override fun followChannel( - channelPublicId: String, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } + @ReactMethod + override fun followChannel( + channelPublicId: String, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain + } - TalkApiClient.instance.followChannel(context, channelPublicId) { followChannelResult, error -> - if (error != null) { - promise.rejectWith(error) - } else if (followChannelResult == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("followChannelResult")) - } else { - promise.resolve(followChannelResult.success) - } + TalkApiClient.instance.followChannel(context, channelPublicId) { followChannelResult, error -> + if (error != null) { + promise.rejectWith(error) + } else if (followChannelResult == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("followChannelResult")) + } else { + promise.resolve(followChannelResult.success) } } + } - @ReactMethod - override fun addChannel( - channelPublicId: String, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } + @ReactMethod + override fun addChannel( + channelPublicId: String, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain + } - TalkApiClient.instance.addChannel(context, channelPublicId) { error -> - if (error != null) { - promise.rejectWith(error) - } else { - promise.resolve(42) - } + TalkApiClient.instance.addChannel(context, channelPublicId) { error -> + if (error != null) { + promise.rejectWith(error) + } else { + promise.resolve(42) } } + } - @ReactMethod - override fun getAddChannelUrl( - channelPublicId: String, - promise: Promise, - ) = onMain { - runCatching { - val url = TalkApiClient.instance.addChannelUrl(channelPublicId) - promise.resolve(url.toString()) - }.onFailure { - promise.rejectWith(it) - } + @ReactMethod + override fun getAddChannelUrl( + channelPublicId: String, + promise: Promise, + ) = onMain { + runCatching { + val url = TalkApiClient.instance.addChannelUrl(channelPublicId) + promise.resolve(url.toString()) + }.onFailure { + promise.rejectWith(it) } + } - @ReactMethod - override fun openAddChannelUrl( - channelPublicId: String, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } - runCatching { - val url = TalkApiClient.instance.addChannelUrl(channelPublicId) - KakaoCustomTabsClient.openWithDefault(context, url) - promise.resolve(url.toString()) - }.onFailure { - promise.rejectWith(it) + @ReactMethod + override fun openAddChannelUrl( + channelPublicId: String, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain } + runCatching { + val url = TalkApiClient.instance.addChannelUrl(channelPublicId) + KakaoCustomTabsClient.openWithDefault(context, url) + promise.resolve(url.toString()) + }.onFailure { + promise.rejectWith(it) } + } - @ReactMethod - override fun chatChannel( - channelPublicId: String, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } + @ReactMethod + override fun chatChannel( + channelPublicId: String, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain + } - TalkApiClient.instance.chatChannel(context, channelPublicId) { error -> - if (error != null) { - promise.rejectWith(error) - } else { - promise.resolve(42) - } + TalkApiClient.instance.chatChannel(context, channelPublicId) { error -> + if (error != null) { + promise.rejectWith(error) + } else { + promise.resolve(42) } } + } - @ReactMethod - override fun getChatChannelUrl( - channelPublicId: String, - promise: Promise, - ) = onMain { - runCatching { - val url = TalkApiClient.instance.chatChannelUrl(channelPublicId) - promise.resolve(url.toString()) - }.onFailure { - promise.rejectWith(it) - } + @ReactMethod + override fun getChatChannelUrl( + channelPublicId: String, + promise: Promise, + ) = onMain { + runCatching { + val url = TalkApiClient.instance.chatChannelUrl(channelPublicId) + promise.resolve(url.toString()) + }.onFailure { + promise.rejectWith(it) } + } - @ReactMethod - override fun openChatChannelUrl( - channelPublicId: String, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } - runCatching { - val url = TalkApiClient.instance.chatChannelUrl(channelPublicId) - KakaoCustomTabsClient.openWithDefault(context, url) - promise.resolve(url.toString()) - }.onFailure { - promise.rejectWith(it) + @ReactMethod + override fun openChatChannelUrl( + channelPublicId: String, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain } + runCatching { + val url = TalkApiClient.instance.chatChannelUrl(channelPublicId) + KakaoCustomTabsClient.openWithDefault(context, url) + promise.resolve(url.toString()) + }.onFailure { + promise.rejectWith(it) } + } - @ReactMethod - override fun channels( - channelPublicIds: ReadableArray?, - promise: Promise, - ) = onMain { - TalkApiClient.instance.channels(publicIds = channelPublicIds?.filterIsInstance()) { relations, error -> - if (error != null) { - promise.rejectWith(error) - } else if (relations?.channels == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("channels")) - } else { - promise.resolve( - argArr().pushMapList( - relations.channels!!.map { - argMap().apply { - putS("uuid", it.uuid) - putS("encodedId", it.encodedId) - putS("relation", it.relation.name.lowercase()) - putL("updateAt", it.updatedAt?.unix) - } - }, - ), - ) - } + @ReactMethod + override fun channels( + channelPublicIds: ReadableArray?, + promise: Promise, + ) = onMain { + TalkApiClient.instance.channels(publicIds = channelPublicIds?.filterIsInstance()) { relations, error -> + if (error != null) { + promise.rejectWith(error) + } else if (relations?.channels == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("channels")) + } else { + promise.resolve( + argArr().pushMapList( + relations.channels!!.map { + argMap().apply { + putS("uuid", it.uuid) + putS("encodedId", it.encodedId) + putS("relation", it.relation.name.lowercase()) + putL("updateAt", it.updatedAt?.unix) + } + }, + ), + ) } } + } - companion object { - const val NAME = "RNCKakaoChannel" - } + companion object { + const val NAME = "RNCKakaoChannel" } +} diff --git a/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelPackage.kt b/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelPackage.kt index 66fe249..22caec4 100644 --- a/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelPackage.kt +++ b/packages/channel/android/src/main/java/net/mjstudio/rnkakao/channel/RNCKakaoChannelPackage.kt @@ -10,16 +10,15 @@ class RNCKakaoChannelPackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoChannelModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoChannelModule.NAME) { RNCKakaoChannelModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoChannelModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoChannelPackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/channel/android/src/newarch/KakaoChannelSpec.kt b/packages/channel/android/src/newarch/KakaoChannelSpec.kt index eb9364f..f13cc66 100644 --- a/packages/channel/android/src/newarch/KakaoChannelSpec.kt +++ b/packages/channel/android/src/newarch/KakaoChannelSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.channel import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoChannelSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoChannelSpec(context) +abstract class KakaoChannelSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoChannelSpec(context) diff --git a/packages/channel/android/src/oldarch/KakaoChannelSpec.kt b/packages/channel/android/src/oldarch/KakaoChannelSpec.kt index c10720b..ff09113 100644 --- a/packages/channel/android/src/oldarch/KakaoChannelSpec.kt +++ b/packages/channel/android/src/oldarch/KakaoChannelSpec.kt @@ -5,45 +5,46 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReadableArray -abstract class KakaoChannelSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun followChannel( - channelPublicId: String, - promise: Promise, - ) - - abstract fun addChannel( - channelPublicId: String, - promise: Promise, - ) - - abstract fun getAddChannelUrl( - channelPublicId: String, - promise: Promise, - ) - - abstract fun openAddChannelUrl( - channelPublicId: String, - promise: Promise, - ) - - abstract fun chatChannel( - channelPublicId: String, - promise: Promise, - ) - - abstract fun getChatChannelUrl( - channelPublicId: String, - promise: Promise, - ) - - abstract fun openChatChannelUrl( - channelPublicId: String, - promise: Promise, - ) - - abstract fun channels( - channelPublicIds: ReadableArray?, - promise: Promise, - ) - } +abstract class KakaoChannelSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun followChannel( + channelPublicId: String, + promise: Promise, + ) + + abstract fun addChannel( + channelPublicId: String, + promise: Promise, + ) + + abstract fun getAddChannelUrl( + channelPublicId: String, + promise: Promise, + ) + + abstract fun openAddChannelUrl( + channelPublicId: String, + promise: Promise, + ) + + abstract fun chatChannel( + channelPublicId: String, + promise: Promise, + ) + + abstract fun getChatChannelUrl( + channelPublicId: String, + promise: Promise, + ) + + abstract fun openChatChannelUrl( + channelPublicId: String, + promise: Promise, + ) + + abstract fun channels( + channelPublicIds: ReadableArray?, + promise: Promise, + ) +} diff --git a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCoreModule.kt b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCoreModule.kt index 7714f81..576e61a 100644 --- a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCoreModule.kt +++ b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCoreModule.kt @@ -7,24 +7,23 @@ import com.kakao.sdk.common.KakaoSdk import com.kakao.sdk.common.util.Utility import net.mjstudio.rnkakao.core.util.onMain -class RNCKakaoCoreModule internal constructor(context: ReactApplicationContext) : - KakaoCoreSpec(context) { - override fun getName(): String { - return NAME - } - - @ReactMethod - override fun initializeKakaoSDK(appKey: String) = - onMain { - KakaoSdk.init(context = reactApplicationContext, appKey = appKey) - } +class RNCKakaoCoreModule internal constructor( + context: ReactApplicationContext, +) : KakaoCoreSpec(context) { + override fun getName(): String = NAME - @ReactMethod - override fun getKeyHashAndroid(promise: Promise) { - promise.resolve(Utility.getKeyHash(reactApplicationContext)) + @ReactMethod + override fun initializeKakaoSDK(appKey: String) = + onMain { + KakaoSdk.init(context = reactApplicationContext, appKey = appKey) } - companion object { - const val NAME = "RNCKakaoCore" - } + @ReactMethod + override fun getKeyHashAndroid(promise: Promise) { + promise.resolve(Utility.getKeyHash(reactApplicationContext)) + } + + companion object { + const val NAME = "RNCKakaoCore" } +} diff --git a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCorePackage.kt b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCorePackage.kt index 4a69bcb..4463e69 100644 --- a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCorePackage.kt +++ b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/RNCKakaoCorePackage.kt @@ -10,16 +10,15 @@ class RNCKakaoCorePackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoCoreModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoCoreModule.NAME) { RNCKakaoCoreModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoCoreModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoCorePackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoException.kt b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoException.kt index 4a479ae..853407f 100644 --- a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoException.kt +++ b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoException.kt @@ -1,16 +1,22 @@ package net.mjstudio.rnkakao.core.util -sealed class RNCKakaoException(message: String) : Exception(message) { +sealed class RNCKakaoException( + message: String, +) : Exception(message) { abstract val code: String } -class RNCKakaoUnknownException(message: String? = null) : RNCKakaoException( - "Unknown error from package. This can be a bug of react-native-kakao package. message: ${message ?: "None"}", -) { +class RNCKakaoUnknownException( + message: String? = null, +) : RNCKakaoException( + "Unknown error from package. This can be a bug of react-native-kakao package. message: ${message ?: "None"}", + ) { override val code: String = "Package-Unknown" } -class RNCKakaoResponseNotFoundException(name: String) : RNCKakaoException("The API response from Kakao Native SDK missing. name: $name") { +class RNCKakaoResponseNotFoundException( + name: String, +) : RNCKakaoException("The API response from Kakao Native SDK missing. name: $name") { override val code: String = "Package-APIResponseNotFound" } @@ -18,11 +24,15 @@ class RNCKakaoSdkNotInitializedException : RNCKakaoException("The SDK is not ini override val code: String = "Package-SDKNotInitialized" } -enum class KakaoApp(val appName: String) { +enum class KakaoApp( + val appName: String, +) { TALK("talk"), NAVI("navi"), } -class RNCKakaoAppNotAvailableException(val app: KakaoApp) : RNCKakaoException("Kakao application is not available. app: ${app.appName}") { +class RNCKakaoAppNotAvailableException( + val app: KakaoApp, +) : RNCKakaoException("Kakao application is not available. app: ${app.appName}") { override val code: String = "Package-KakaoAppNotAvailable" } diff --git a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoUtil.kt b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoUtil.kt index 5c1ae3c..b1f42f8 100644 --- a/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoUtil.kt +++ b/packages/core/android/src/main/java/net/mjstudio/rnkakao/core/util/RNCKakaoUtil.kt @@ -71,9 +71,7 @@ fun Promise.rejectWith(e: Throwable) { } } -inline fun ReadableArray.filterIsInstance(): List { - return toArrayList().filterIsInstance() -} +inline fun ReadableArray.filterIsInstance(): List = toArrayList().filterIsInstance() fun ReadableArray.filterIsReadableMap(): List { val ret = mutableListOf() @@ -144,9 +142,7 @@ fun WritableMap.putD( fun WritableMap.putL( key: String, value: Long?, -): WritableMap { - return putD(key, value?.toDouble()) -} +): WritableMap = putD(key, value?.toDouble()) fun WritableMap.putS( key: String, @@ -156,17 +152,11 @@ fun WritableMap.putS( return this } -fun argMap(): WritableMap { - return Arguments.createMap() -} +fun argMap(): WritableMap = Arguments.createMap() -fun argArr(): WritableArray { - return Arguments.createArray() -} +fun argArr(): WritableArray = Arguments.createArray() -fun ReadableMap.toStringMap(): Map { - return toHashMap().filterValues { it is String }.mapValues { it.value.toString() } -} +fun ReadableMap.toStringMap(): Map = toHashMap().filterValues { it is String }.mapValues { it.value.toString() } fun ReadableMap.getIntElseNull(key: String): Int? { if (hasKey(key)) return getInt(key) @@ -197,9 +187,7 @@ object RNCKakaoUtil { fun diffSec( d1: Date, d2: Date, - ): Long { - return (d1.time - d2.time) / 1000L - } + ): Long = (d1.time - d2.time) / 1000L } val Date.unix: Long diff --git a/packages/core/android/src/newarch/KakaoCoreSpec.kt b/packages/core/android/src/newarch/KakaoCoreSpec.kt index edb127c..e24c021 100644 --- a/packages/core/android/src/newarch/KakaoCoreSpec.kt +++ b/packages/core/android/src/newarch/KakaoCoreSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.core import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoCoreSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoCoreSpec(context) +abstract class KakaoCoreSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoCoreSpec(context) diff --git a/packages/core/android/src/oldarch/KakaoCoreSpec.kt b/packages/core/android/src/oldarch/KakaoCoreSpec.kt index 19f9c9f..e0d5621 100644 --- a/packages/core/android/src/oldarch/KakaoCoreSpec.kt +++ b/packages/core/android/src/oldarch/KakaoCoreSpec.kt @@ -4,9 +4,10 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule -abstract class KakaoCoreSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun initializeKakaoSDK(appKey: String) +abstract class KakaoCoreSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun initializeKakaoSDK(appKey: String) - abstract fun getKeyHashAndroid(promise: Promise) - } + abstract fun getKeyHashAndroid(promise: Promise) +} diff --git a/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapModule.kt b/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapModule.kt index 25f3907..54a21f5 100644 --- a/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapModule.kt +++ b/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapModule.kt @@ -4,21 +4,20 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.kakao.vectormap.KakaoMapSdk -class RNCKakaoMapModule internal constructor(context: ReactApplicationContext) : - KakaoMapSpec(context) { - override fun getName(): String { - return NAME - } +class RNCKakaoMapModule internal constructor( + context: ReactApplicationContext, +) : KakaoMapSpec(context) { + override fun getName(): String = NAME - override fun initializeKakaoMapSDK( - appKey: String, - promise: Promise, - ) { - KakaoMapSdk.init(reactApplicationContext, appKey) - promise.resolve(42) - } + override fun initializeKakaoMapSDK( + appKey: String, + promise: Promise, + ) { + KakaoMapSdk.init(reactApplicationContext, appKey) + promise.resolve(42) + } - companion object { - const val NAME = "RNCKakaoMap" - } + companion object { + const val NAME = "RNCKakaoMap" } +} diff --git a/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapPackage.kt b/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapPackage.kt index 1ab0ec3..c3a003d 100644 --- a/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapPackage.kt +++ b/packages/map/android/src/main/java/net/mjstudio/rnkakao/map/RNCKakaoMapPackage.kt @@ -10,16 +10,15 @@ class RNCKakaoMapPackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoMapModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoMapModule.NAME) { RNCKakaoMapModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoMapModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoMapPackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/map/android/src/newarch/KakaoMapSpec.kt b/packages/map/android/src/newarch/KakaoMapSpec.kt index e7bdfec..2534ee6 100644 --- a/packages/map/android/src/newarch/KakaoMapSpec.kt +++ b/packages/map/android/src/newarch/KakaoMapSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.map import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoMapSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoMapSpec(context) +abstract class KakaoMapSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoMapSpec(context) diff --git a/packages/map/android/src/oldarch/KakaoMapSpec.kt b/packages/map/android/src/oldarch/KakaoMapSpec.kt index b6f4846..e0982af 100644 --- a/packages/map/android/src/oldarch/KakaoMapSpec.kt +++ b/packages/map/android/src/oldarch/KakaoMapSpec.kt @@ -4,10 +4,11 @@ import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule -abstract class KakaoMapSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun initializeKakaoMapSDK( - appKey: String, - promise: Promise, - ) - } +abstract class KakaoMapSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun initializeKakaoMapSDK( + appKey: String, + promise: Promise, + ) +} diff --git a/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviModule.kt b/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviModule.kt index c27296e..ae39531 100644 --- a/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviModule.kt +++ b/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviModule.kt @@ -27,62 +27,61 @@ import net.mjstudio.rnkakao.core.util.getDoubleElseNull import net.mjstudio.rnkakao.core.util.onMain import net.mjstudio.rnkakao.core.util.rejectWith -class RNCKakaoNaviModule internal constructor(context: ReactApplicationContext) : - KakaoNaviSpec(context) { - override fun getName(): String { - return NAME - } +class RNCKakaoNaviModule internal constructor( + context: ReactApplicationContext, +) : KakaoNaviSpec(context) { + override fun getName(): String = NAME - override fun navigateOrShareTo( - destination: ReadableMap, - option: ReadableMap?, - viaList: ReadableArray?, - openWebInstallUrlIfNaviAppNotAvailable: Boolean?, - isShare: Boolean?, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } + override fun navigateOrShareTo( + destination: ReadableMap, + option: ReadableMap?, + viaList: ReadableArray?, + openWebInstallUrlIfNaviAppNotAvailable: Boolean?, + isShare: Boolean?, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain + } - if (NaviClient.instance.isKakaoNaviInstalled(reactApplicationContext)) { - if (isShare == true) { - context.startActivity( - NaviClient.instance.shareDestinationIntent( - destination.toLocation(), - option?.toOption(), - viaList?.filterIsReadableMap()?.map { it.toLocation() }, - ), - ) - } else { - context.startActivity( - NaviClient.instance.navigateIntent( - destination.toLocation(), - option?.toOption(), - viaList?.filterIsReadableMap()?.map { it.toLocation() }, - ), - ) - } - promise.resolve(true) - } else if (openWebInstallUrlIfNaviAppNotAvailable == true) { + if (NaviClient.instance.isKakaoNaviInstalled(reactApplicationContext)) { + if (isShare == true) { context.startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse(Constants.WEB_NAVI_INSTALL), - ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP), + NaviClient.instance.shareDestinationIntent( + destination.toLocation(), + option?.toOption(), + viaList?.filterIsReadableMap()?.map { it.toLocation() }, + ), ) - promise.resolve(false) } else { - promise.resolve(false) + context.startActivity( + NaviClient.instance.navigateIntent( + destination.toLocation(), + option?.toOption(), + viaList?.filterIsReadableMap()?.map { it.toLocation() }, + ), + ) } + promise.resolve(true) + } else if (openWebInstallUrlIfNaviAppNotAvailable == true) { + context.startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse(Constants.WEB_NAVI_INSTALL), + ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP), + ) + promise.resolve(false) + } else { + promise.resolve(false) } + } - companion object { - const val NAME = "RNCKakaoNavi" - } + companion object { + const val NAME = "RNCKakaoNavi" } +} private fun ReadableMap.toLocation() = Location( diff --git a/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviPackage.kt b/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviPackage.kt index 32c7cf7..c9a54e7 100644 --- a/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviPackage.kt +++ b/packages/navi/android/src/main/java/net/mjstudio/rnkakao/navi/RNCKakaoNaviPackage.kt @@ -10,16 +10,15 @@ class RNCKakaoNaviPackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoNaviModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoNaviModule.NAME) { RNCKakaoNaviModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoNaviModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoNaviPackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/navi/android/src/newarch/KakaoNaviSpec.kt b/packages/navi/android/src/newarch/KakaoNaviSpec.kt index 5b0c527..23d7ca8 100644 --- a/packages/navi/android/src/newarch/KakaoNaviSpec.kt +++ b/packages/navi/android/src/newarch/KakaoNaviSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.navi import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoNaviSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoNaviSpec(context) +abstract class KakaoNaviSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoNaviSpec(context) diff --git a/packages/navi/android/src/oldarch/KakaoNaviSpec.kt b/packages/navi/android/src/oldarch/KakaoNaviSpec.kt index bda5b5c..13ae950 100644 --- a/packages/navi/android/src/oldarch/KakaoNaviSpec.kt +++ b/packages/navi/android/src/oldarch/KakaoNaviSpec.kt @@ -6,14 +6,15 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap -abstract class KakaoNaviSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun navigateOrShareTo( - destination: ReadableMap, - option: ReadableMap?, - viaList: ReadableArray?, - openWebInstallUrlIfNaviAppNotAvailable: Boolean?, - isShare: Boolean?, - promise: Promise, - ) - } +abstract class KakaoNaviSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun navigateOrShareTo( + destination: ReadableMap, + option: ReadableMap?, + viaList: ReadableArray?, + openWebInstallUrlIfNaviAppNotAvailable: Boolean?, + isShare: Boolean?, + promise: Promise, + ) +} diff --git a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareModule.kt b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareModule.kt index 622f83c..c5878d0 100644 --- a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareModule.kt +++ b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareModule.kt @@ -24,261 +24,260 @@ import net.mjstudio.rnkakao.core.util.pushStringList import net.mjstudio.rnkakao.core.util.rejectWith import net.mjstudio.rnkakao.core.util.toStringMap -class RNCKakaoShareModule internal constructor(context: ReactApplicationContext) : - KakaoShareSpec(context) { - override fun getName(): String { - return NAME - } +class RNCKakaoShareModule internal constructor( + context: ReactApplicationContext, +) : KakaoShareSpec(context) { + override fun getName(): String = NAME - @ReactMethod - override fun shareOrSendMeOrSendFriendOrWhatever( - sendType: String, - templateType: String, - templateId: Double, - templateJson: ReadableMap, - receiverUuids: ReadableArray, - useWebBrowserIfKakaoTalkNotAvailable: Boolean, - templateArgs: ReadableMap, - serverCallbackArgs: ReadableMap, - promise: Promise, - ) = onMain { - if (templateType == "custom") { - shareOrSendCustom( - sendType, - templateType, - templateId, - receiverUuids = receiverUuids.filterIsInstance(), - useWebBrowserIfKakaoTalkNotAvailable, - templateArgs, - serverCallbackArgs, - promise, - ) - } else { - shareOrSendDefaultTemplate( - sendType, - templateType, - templateJson, - receiverUuids = receiverUuids.filterIsInstance(), - useWebBrowserIfKakaoTalkNotAvailable, - serverCallbackArgs, - promise, - ) - } + @ReactMethod + override fun shareOrSendMeOrSendFriendOrWhatever( + sendType: String, + templateType: String, + templateId: Double, + templateJson: ReadableMap, + receiverUuids: ReadableArray, + useWebBrowserIfKakaoTalkNotAvailable: Boolean, + templateArgs: ReadableMap, + serverCallbackArgs: ReadableMap, + promise: Promise, + ) = onMain { + if (templateType == "custom") { + shareOrSendCustom( + sendType, + templateType, + templateId, + receiverUuids = receiverUuids.filterIsInstance(), + useWebBrowserIfKakaoTalkNotAvailable, + templateArgs, + serverCallbackArgs, + promise, + ) + } else { + shareOrSendDefaultTemplate( + sendType, + templateType, + templateJson, + receiverUuids = receiverUuids.filterIsInstance(), + useWebBrowserIfKakaoTalkNotAvailable, + serverCallbackArgs, + promise, + ) } + } - private fun shareOrSendCustom( - sendType: String, - templateType: String, - templateId: Double, - receiverUuids: List, - useWebBrowserIfKakaoTalkNotAvailable: Boolean, - templateArgs: ReadableMap?, - serverCallbackArgs: ReadableMap?, - promise: Promise, - ) = when (sendType) { - "share" -> { - runShare( - templateType, - templateId, - null, - useWebBrowserIfKakaoTalkNotAvailable, - templateArgs, - serverCallbackArgs, - promise, - ) - } - "send-me" -> { - runSendToMe(templateType, templateId, null, templateArgs, promise) - } - "send-friend" -> { - runSendToFriends(templateType, receiverUuids, templateId, null, templateArgs, promise) - } - else -> { - promise.rejectWith(RNCKakaoUnknownException("Unknown sendType: $sendType")) - } + private fun shareOrSendCustom( + sendType: String, + templateType: String, + templateId: Double, + receiverUuids: List, + useWebBrowserIfKakaoTalkNotAvailable: Boolean, + templateArgs: ReadableMap?, + serverCallbackArgs: ReadableMap?, + promise: Promise, + ) = when (sendType) { + "share" -> { + runShare( + templateType, + templateId, + null, + useWebBrowserIfKakaoTalkNotAvailable, + templateArgs, + serverCallbackArgs, + promise, + ) + } + "send-me" -> { + runSendToMe(templateType, templateId, null, templateArgs, promise) + } + "send-friend" -> { + runSendToFriends(templateType, receiverUuids, templateId, null, templateArgs, promise) } + else -> { + promise.rejectWith(RNCKakaoUnknownException("Unknown sendType: $sendType")) + } + } - private fun shareOrSendDefaultTemplate( - sendType: String, - templateType: String, - template: ReadableMap, - receiverUuids: List, - useWebBrowserIfKakaoTalkNotAvailable: Boolean, - serverCallbackArgs: ReadableMap?, - promise: Promise, - ) = when (sendType) { - "share" -> { - runShare( - templateType, - null, - template, - useWebBrowserIfKakaoTalkNotAvailable, - argMap(), - serverCallbackArgs, - promise, - ) - } - "send-me" -> { - runSendToMe(templateType, null, template, null, promise) - } - "send-friend" -> { - runSendToFriends(templateType, receiverUuids, null, template, null, promise) - } - else -> { - promise.rejectWith(RNCKakaoUnknownException("Unknown sendType: $sendType")) - } + private fun shareOrSendDefaultTemplate( + sendType: String, + templateType: String, + template: ReadableMap, + receiverUuids: List, + useWebBrowserIfKakaoTalkNotAvailable: Boolean, + serverCallbackArgs: ReadableMap?, + promise: Promise, + ) = when (sendType) { + "share" -> { + runShare( + templateType, + null, + template, + useWebBrowserIfKakaoTalkNotAvailable, + argMap(), + serverCallbackArgs, + promise, + ) } + "send-me" -> { + runSendToMe(templateType, null, template, null, promise) + } + "send-friend" -> { + runSendToFriends(templateType, receiverUuids, null, template, null, promise) + } + else -> { + promise.rejectWith(RNCKakaoUnknownException("Unknown sendType: $sendType")) + } + } - private fun runSendToMe( - templateType: String, - templateId: Double? = null, - defaultTemplate: ReadableMap? = null, - templateArgs: ReadableMap? = null, - promise: Promise, - ) { - val callback = { e: Throwable? -> - if (e != null) { - promise.rejectWith(e) - } else { - promise.resolve(42) - } - } - if (templateId != null) { - TalkApiClient.instance.sendCustomMemo(templateId.toLong(), templateArgs?.toStringMap(), callback) - } else if (defaultTemplate != null) { - runCatching { - TalkApiClient.instance.sendDefaultMemo( - RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), - callback, - ) - }.onFailure { promise.rejectWith(it) } + private fun runSendToMe( + templateType: String, + templateId: Double? = null, + defaultTemplate: ReadableMap? = null, + templateArgs: ReadableMap? = null, + promise: Promise, + ) { + val callback = { e: Throwable? -> + if (e != null) { + promise.rejectWith(e) } else { - promise.rejectWith(RNCKakaoUnknownException("one of templateId or defaultTemplate should exist")) + promise.resolve(42) } } + if (templateId != null) { + TalkApiClient.instance.sendCustomMemo(templateId.toLong(), templateArgs?.toStringMap(), callback) + } else if (defaultTemplate != null) { + runCatching { + TalkApiClient.instance.sendDefaultMemo( + RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), + callback, + ) + }.onFailure { promise.rejectWith(it) } + } else { + promise.rejectWith(RNCKakaoUnknownException("one of templateId or defaultTemplate should exist")) + } + } - private fun runSendToFriends( - templateType: String, - receiverUuids: List, - templateId: Double? = null, - defaultTemplate: ReadableMap? = null, - templateArgs: ReadableMap? = null, - promise: Promise, - ) { - val callback = { messageSendResult: MessageSendResult?, e: Throwable? -> - if (e != null) { - promise.rejectWith(e) - } else if (messageSendResult == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("messageSendResult")) - } else { - promise.resolve(argArr().pushStringList(messageSendResult.successfulReceiverUuids ?: listOf())) - } - } - if (templateId != null) { - TalkApiClient.instance.sendCustomMessage(receiverUuids, templateId.toLong(), templateArgs?.toStringMap(), callback) - } else if (defaultTemplate != null) { - runCatching { - TalkApiClient.instance.sendDefaultMessage( - receiverUuids, - RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), - callback, - ) - }.onFailure { promise.rejectWith(it) } + private fun runSendToFriends( + templateType: String, + receiverUuids: List, + templateId: Double? = null, + defaultTemplate: ReadableMap? = null, + templateArgs: ReadableMap? = null, + promise: Promise, + ) { + val callback = { messageSendResult: MessageSendResult?, e: Throwable? -> + if (e != null) { + promise.rejectWith(e) + } else if (messageSendResult == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("messageSendResult")) } else { - promise.rejectWith(RNCKakaoUnknownException("one of templateId or defaultTemplate should exist")) + promise.resolve(argArr().pushStringList(messageSendResult.successfulReceiverUuids ?: listOf())) } } + if (templateId != null) { + TalkApiClient.instance.sendCustomMessage(receiverUuids, templateId.toLong(), templateArgs?.toStringMap(), callback) + } else if (defaultTemplate != null) { + runCatching { + TalkApiClient.instance.sendDefaultMessage( + receiverUuids, + RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), + callback, + ) + }.onFailure { promise.rejectWith(it) } + } else { + promise.rejectWith(RNCKakaoUnknownException("one of templateId or defaultTemplate should exist")) + } + } - private fun runShare( - templateType: String, - templateId: Double? = null, - defaultTemplate: ReadableMap? = null, - useWebBrowserIfKakaoTalkNotAvailable: Boolean, - templateArgs: ReadableMap? = null, - serverCallbackArgs: ReadableMap? = null, - promise: Promise, - ) { - val context = currentActivity - if (context == null) { - promise.rejectWith(ActivityNotFoundException()) - return - } + private fun runShare( + templateType: String, + templateId: Double? = null, + defaultTemplate: ReadableMap? = null, + useWebBrowserIfKakaoTalkNotAvailable: Boolean, + templateArgs: ReadableMap? = null, + serverCallbackArgs: ReadableMap? = null, + promise: Promise, + ) { + val context = currentActivity + if (context == null) { + promise.rejectWith(ActivityNotFoundException()) + return + } - val callback = { sharingResult: SharingResult?, error: Throwable? -> - if (error != null) { - promise.rejectWith(error) - } else if (sharingResult != null) { - context.startActivity(sharingResult.intent) - promise.resolve(42) - } else { - promise.resolve(42) - } + val callback = { sharingResult: SharingResult?, error: Throwable? -> + if (error != null) { + promise.rejectWith(error) + } else if (sharingResult != null) { + context.startActivity(sharingResult.intent) + promise.resolve(42) + } else { + promise.resolve(42) } + } - if (ShareClient.instance.isKakaoTalkSharingAvailable(context)) { - if (templateId != null) { - ShareClient.instance.shareCustom( + if (ShareClient.instance.isKakaoTalkSharingAvailable(context)) { + if (templateId != null) { + ShareClient.instance.shareCustom( + context, + templateId.toLong(), + templateArgs = templateArgs?.toStringMap(), + serverCallbackArgs = serverCallbackArgs?.toStringMap(), + callback = callback, + ) + } else if (defaultTemplate != null) { + runCatching { + ShareClient.instance.shareDefault( context, - templateId.toLong(), - templateArgs = templateArgs?.toStringMap(), + RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), serverCallbackArgs = serverCallbackArgs?.toStringMap(), callback = callback, ) - } else if (defaultTemplate != null) { - runCatching { - ShareClient.instance.shareDefault( - context, + }.onFailure { + promise.rejectWith(it) + } + } + } else if (useWebBrowserIfKakaoTalkNotAvailable) { + runCatching { + val sharerUrl = + if (templateId != null) { + WebSharerClient.instance.makeCustomUrl( + templateId.toLong(), + templateArgs = templateArgs?.toStringMap(), + serverCallbackArgs = serverCallbackArgs?.toStringMap(), + ) + } else if (defaultTemplate != null) { + WebSharerClient.instance.makeDefaultUrl( RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), serverCallbackArgs = serverCallbackArgs?.toStringMap(), - callback = callback, ) - }.onFailure { - promise.rejectWith(it) - } - } - } else if (useWebBrowserIfKakaoTalkNotAvailable) { - runCatching { - val sharerUrl = - if (templateId != null) { - WebSharerClient.instance.makeCustomUrl( - templateId.toLong(), - templateArgs = templateArgs?.toStringMap(), - serverCallbackArgs = serverCallbackArgs?.toStringMap(), - ) - } else if (defaultTemplate != null) { - WebSharerClient.instance.makeDefaultUrl( - RNCKakaoShareTemplates.createDefaultTemplate(defaultTemplate, templateType), - serverCallbackArgs = serverCallbackArgs?.toStringMap(), - ) - } else { - run { - promise.rejectWith(RNCKakaoUnknownException("one of templateId or template shouldn't be null")) - return - } + } else { + run { + promise.rejectWith(RNCKakaoUnknownException("one of templateId or template shouldn't be null")) + return } - try { - KakaoCustomTabsClient.openWithDefault(context, sharerUrl) - promise.resolve(42) - return - } catch (_: UnsupportedOperationException) { } - try { - KakaoCustomTabsClient.open(context, sharerUrl) - promise.resolve(42) - return - } catch (_: ActivityNotFoundException) { - } - - promise.rejectWith(RNCKakaoUnknownException("web url open failed $sharerUrl")) - }.onFailure { - promise.rejectWith(it) + try { + KakaoCustomTabsClient.openWithDefault(context, sharerUrl) + promise.resolve(42) + return + } catch (_: UnsupportedOperationException) { } - } else { - promise.rejectWith(RNCKakaoAppNotAvailableException(TALK)) + try { + KakaoCustomTabsClient.open(context, sharerUrl) + promise.resolve(42) + return + } catch (_: ActivityNotFoundException) { + } + + promise.rejectWith(RNCKakaoUnknownException("web url open failed $sharerUrl")) + }.onFailure { + promise.rejectWith(it) } + } else { + promise.rejectWith(RNCKakaoAppNotAvailableException(TALK)) } + } - companion object { - const val NAME = "RNCKakaoShare" - } + companion object { + const val NAME = "RNCKakaoShare" } +} diff --git a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoSharePackage.kt b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoSharePackage.kt index 248d438..f90dbca 100644 --- a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoSharePackage.kt +++ b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoSharePackage.kt @@ -11,16 +11,15 @@ class RNCKakaoSharePackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoShareModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoShareModule.NAME) { RNCKakaoShareModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoShareModule.NAME] = @@ -34,5 +33,4 @@ class RNCKakaoSharePackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareTemplates.kt b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareTemplates.kt index 69e0194..bfda14c 100644 --- a/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareTemplates.kt +++ b/packages/share/android/src/main/java/net/mjstudio/rnkakao/share/RNCKakaoShareTemplates.kt @@ -108,8 +108,8 @@ object RNCKakaoShareTemplates { buttonTitle = map.getString("buttonTitle"), ) - private fun createListTemplate(map: ReadableMap): ListTemplate { - return ListTemplate( + private fun createListTemplate(map: ReadableMap): ListTemplate = + ListTemplate( headerTitle = map.getString("headerTitle") ?: "", headerLink = map.getMap("headerLink")?.toLink() ?: Link(), contents = @@ -118,7 +118,6 @@ object RNCKakaoShareTemplates { buttons = map.getArray("buttons")?.filterIsReadableMap()?.map { it.toButton() }, buttonTitle = map.getString("buttonTitle"), ) - } private fun createLocationTemplate(map: ReadableMap) = LocationTemplate( diff --git a/packages/share/android/src/newarch/KakaoShareSpec.kt b/packages/share/android/src/newarch/KakaoShareSpec.kt index bd3e34f..b9ea773 100644 --- a/packages/share/android/src/newarch/KakaoShareSpec.kt +++ b/packages/share/android/src/newarch/KakaoShareSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.share import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoShareSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoShareSpec(context) +abstract class KakaoShareSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoShareSpec(context) diff --git a/packages/share/android/src/oldarch/KakaoShareSpec.kt b/packages/share/android/src/oldarch/KakaoShareSpec.kt index a5c6b53..e568031 100644 --- a/packages/share/android/src/oldarch/KakaoShareSpec.kt +++ b/packages/share/android/src/oldarch/KakaoShareSpec.kt @@ -6,17 +6,18 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap -abstract class KakaoShareSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun shareOrSendMeOrSendFriendOrWhatever( - sendType: String, - templateType: String, - templateId: Double, - templateJson: ReadableMap, - receiverUuids: ReadableArray, - useWebBrowserIfKakaoTalkNotAvailable: Boolean, - templateArgs: ReadableMap, - serverCallbackArgs: ReadableMap, - promise: Promise, - ) - } +abstract class KakaoShareSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun shareOrSendMeOrSendFriendOrWhatever( + sendType: String, + templateType: String, + templateId: Double, + templateJson: ReadableMap, + receiverUuids: ReadableArray, + useWebBrowserIfKakaoTalkNotAvailable: Boolean, + templateArgs: ReadableMap, + serverCallbackArgs: ReadableMap, + promise: Promise, + ) +} diff --git a/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialModule.kt b/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialModule.kt index 0aaf326..7b0388c 100644 --- a/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialModule.kt +++ b/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialModule.kt @@ -29,166 +29,165 @@ import net.mjstudio.rnkakao.core.util.putD import net.mjstudio.rnkakao.core.util.putI import net.mjstudio.rnkakao.core.util.rejectWith -class RNCKakaoSocialModule internal constructor(context: ReactApplicationContext) : - KakaoSocialSpec(context) { - override fun getName(): String { - return NAME - } - - @ReactMethod - override fun getProfile(promise: Promise) = - onMain { - TalkApiClient.instance.profile { profile, error -> - if (error != null) { - promise.rejectWith(error) - return@profile - } - if (profile == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("profile")) - return@profile - } - promise.resolve( - argMap().apply { - putString("nickname", profile.nickname) - putString("countryISO", profile.countryISO) - putString("profileImageUrl", profile.profileImageUrl) - putString("thumbnailUrl", profile.thumbnailUrl) - }, - ) - } - } +class RNCKakaoSocialModule internal constructor( + context: ReactApplicationContext, +) : KakaoSocialSpec(context) { + override fun getName(): String = NAME - @ReactMethod - override fun selectFriends( - multiple: Boolean, - mode: String?, - options: ReadableMap?, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.reject(ActivityNotFoundException()) - return@onMain - } - val callback = { users: SelectedUsers?, error: Throwable? -> + @ReactMethod + override fun getProfile(promise: Promise) = + onMain { + TalkApiClient.instance.profile { profile, error -> if (error != null) { promise.rejectWith(error) - } else if (users == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("users")) - } else { - promise.resolve( - argMap().apply { - putInt("totalCount", users.totalCount) - putArray( - "users", - argArr().pushMapList( - users.users?.map { - argMap().apply { - putString("uuid", it.uuid) - putD("id", it.id?.toDouble()) - putB("favorite", it.favorite) - putString("profileNickname", it.profileNickname) - putString("profileThumbnailImage", it.profileThumbnailImage) - } - } ?: listOf(), - ), - ) - }, - ) + return@profile + } + if (profile == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("profile")) + return@profile } + promise.resolve( + argMap().apply { + putString("nickname", profile.nickname) + putString("countryISO", profile.countryISO) + putString("profileImageUrl", profile.profileImageUrl) + putString("thumbnailUrl", profile.thumbnailUrl) + }, + ) } + } - if (!multiple) { - if (mode == "popup") { - PickerClient.instance.selectFriendPopup(context, getParams(options), callback) - } else { - PickerClient.instance.selectFriend(context, getParams(options), callback) - } + @ReactMethod + override fun selectFriends( + multiple: Boolean, + mode: String?, + options: ReadableMap?, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.reject(ActivityNotFoundException()) + return@onMain + } + val callback = { users: SelectedUsers?, error: Throwable? -> + if (error != null) { + promise.rejectWith(error) + } else if (users == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("users")) } else { - if (mode == "popup") { - PickerClient.instance.selectFriendsPopup(context, getParams(options), callback) - } else { - PickerClient.instance.selectFriends(context, getParams(options), callback) - } + promise.resolve( + argMap().apply { + putInt("totalCount", users.totalCount) + putArray( + "users", + argArr().pushMapList( + users.users?.map { + argMap().apply { + putString("uuid", it.uuid) + putD("id", it.id?.toDouble()) + putB("favorite", it.favorite) + putString("profileNickname", it.profileNickname) + putString("profileThumbnailImage", it.profileThumbnailImage) + } + } ?: listOf(), + ), + ) + }, + ) } } - private fun getParams(options: ReadableMap?) = - OpenPickerFriendRequestParams( - title = options?.getString("title"), - viewAppearance = - when (options?.getString("viewAppearance")) { - "dark" -> DARK - "light" -> LIGHT - else -> AUTO - }, - orientation = - when (options?.getString("orientation")) { - "portrait" -> PORTRAIT - "landscape" -> LANDSCAPE - else -> PickerOrientation.AUTO - }, - enableSearch = options?.getBooleanElseNull("enableSearch"), - showMyProfile = options?.getBooleanElseNull("showMyProfile"), - showFavorite = options?.getBooleanElseNull("showFavorite"), - showPickedFriend = options?.getBooleanElseNull("showPickedFriend"), - maxPickableCount = options?.getIntElseNull("maxPickableCount"), - minPickableCount = options?.getIntElseNull("minPickableCount"), - ) + if (!multiple) { + if (mode == "popup") { + PickerClient.instance.selectFriendPopup(context, getParams(options), callback) + } else { + PickerClient.instance.selectFriend(context, getParams(options), callback) + } + } else { + if (mode == "popup") { + PickerClient.instance.selectFriendsPopup(context, getParams(options), callback) + } else { + PickerClient.instance.selectFriends(context, getParams(options), callback) + } + } + } - @ReactMethod - override fun getFriends( - options: ReadableMap?, - promise: Promise, - ) = onMain { - TalkApiClient.instance.friends( - offset = options?.getIntElseNull("offset"), - limit = options?.getIntElseNull("limit"), - order = - when (options?.getString("order")) { - "asc" -> Order.ASC - "desc" -> Order.DESC - else -> null - }, - friendOrder = - when (options?.getString("friendOrder")) { - "nickname" -> FriendOrder.NICKNAME - "age" -> FriendOrder.AGE - "favorite" -> FriendOrder.FAVORITE - else -> null + private fun getParams(options: ReadableMap?) = + OpenPickerFriendRequestParams( + title = options?.getString("title"), + viewAppearance = + when (options?.getString("viewAppearance")) { + "dark" -> DARK + "light" -> LIGHT + else -> AUTO + }, + orientation = + when (options?.getString("orientation")) { + "portrait" -> PORTRAIT + "landscape" -> LANDSCAPE + else -> PickerOrientation.AUTO + }, + enableSearch = options?.getBooleanElseNull("enableSearch"), + showMyProfile = options?.getBooleanElseNull("showMyProfile"), + showFavorite = options?.getBooleanElseNull("showFavorite"), + showPickedFriend = options?.getBooleanElseNull("showPickedFriend"), + maxPickableCount = options?.getIntElseNull("maxPickableCount"), + minPickableCount = options?.getIntElseNull("minPickableCount"), + ) + + @ReactMethod + override fun getFriends( + options: ReadableMap?, + promise: Promise, + ) = onMain { + TalkApiClient.instance.friends( + offset = options?.getIntElseNull("offset"), + limit = options?.getIntElseNull("limit"), + order = + when (options?.getString("order")) { + "asc" -> Order.ASC + "desc" -> Order.DESC + else -> null + }, + friendOrder = + when (options?.getString("friendOrder")) { + "nickname" -> FriendOrder.NICKNAME + "age" -> FriendOrder.AGE + "favorite" -> FriendOrder.FAVORITE + else -> null + }, + ) { friends, error -> + if (error != null) { + promise.rejectWith(error) + } else if (friends?.elements == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("friends")) + } else { + promise.resolve( + argMap().apply { + putInt("totalCount", friends.totalCount) + putI("favoriteCount", friends.favoriteCount) + putArray( + "friends", + argArr().pushMapList( + friends.elements!!.map { + argMap().apply { + putD("id", it.id?.toDouble()) + putString("uuid", it.uuid) + putString("profileNickname", it.profileNickname) + putString("profileThumbnailImage", it.profileThumbnailImage) + putB("favorite", it.favorite) + putB("allowedMsg", it.allowedMsg) + } + }, + ), + ) }, - ) { friends, error -> - if (error != null) { - promise.rejectWith(error) - } else if (friends?.elements == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("friends")) - } else { - promise.resolve( - argMap().apply { - putInt("totalCount", friends.totalCount) - putI("favoriteCount", friends.favoriteCount) - putArray( - "friends", - argArr().pushMapList( - friends.elements!!.map { - argMap().apply { - putD("id", it.id?.toDouble()) - putString("uuid", it.uuid) - putString("profileNickname", it.profileNickname) - putString("profileThumbnailImage", it.profileThumbnailImage) - putB("favorite", it.favorite) - putB("allowedMsg", it.allowedMsg) - } - }, - ), - ) - }, - ) - } + ) } } + } - companion object { - const val NAME = "RNCKakaoSocial" - } + companion object { + const val NAME = "RNCKakaoSocial" } +} diff --git a/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialPackage.kt b/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialPackage.kt index 9cffc72..3644352 100644 --- a/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialPackage.kt +++ b/packages/social/android/src/main/java/net/mjstudio/rnkakao/social/RNCKakaoSocialPackage.kt @@ -10,16 +10,15 @@ class RNCKakaoSocialPackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoSocialModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoSocialModule.NAME) { RNCKakaoSocialModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoSocialModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoSocialPackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/social/android/src/newarch/KakaoSocialSpec.kt b/packages/social/android/src/newarch/KakaoSocialSpec.kt index 32be188..4e1d390 100644 --- a/packages/social/android/src/newarch/KakaoSocialSpec.kt +++ b/packages/social/android/src/newarch/KakaoSocialSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.social import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoSocialSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoSocialSpec(context) +abstract class KakaoSocialSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoSocialSpec(context) diff --git a/packages/social/android/src/oldarch/KakaoSocialSpec.kt b/packages/social/android/src/oldarch/KakaoSocialSpec.kt index 9096c14..6025724 100644 --- a/packages/social/android/src/oldarch/KakaoSocialSpec.kt +++ b/packages/social/android/src/oldarch/KakaoSocialSpec.kt @@ -5,19 +5,20 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReadableMap -abstract class KakaoSocialSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun getProfile(promise: Promise) +abstract class KakaoSocialSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun getProfile(promise: Promise) - abstract fun selectFriends( - multiple: Boolean, - mode: String?, - options: ReadableMap?, - promise: Promise, - ) + abstract fun selectFriends( + multiple: Boolean, + mode: String?, + options: ReadableMap?, + promise: Promise, + ) - abstract fun getFriends( - options: ReadableMap?, - promise: Promise, - ) - } + abstract fun getFriends( + options: ReadableMap?, + promise: Promise, + ) +} diff --git a/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserModule.kt b/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserModule.kt index 66b9c15..c0cf7ee 100644 --- a/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserModule.kt +++ b/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserModule.kt @@ -29,83 +29,87 @@ import net.mjstudio.rnkakao.core.util.rejectWith import net.mjstudio.rnkakao.core.util.unix import java.util.Date -class RNCKakaoUserModule internal constructor(context: ReactApplicationContext) : - KakaoUserSpec(context) { - override fun getName(): String { - return NAME - } +class RNCKakaoUserModule internal constructor( + context: ReactApplicationContext, +) : KakaoUserSpec(context) { + override fun getName(): String = NAME - @ReactMethod - override fun login( - serviceTerms: ReadableArray?, - prompts: ReadableArray?, - useKakaoAccountLogin: Boolean, - scopes: ReadableArray?, - promise: Promise, - ) = onMain { - val context = - currentActivity ?: run { - promise.rejectWith(ActivityNotFoundException()) - return@onMain - } - val callback: (OAuthToken?, Throwable?) -> Unit = { token, error -> - if (error != null) { - promise.rejectWith(error) - } else if (token == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("token")) - } else { - promise.resolve( - argMap().apply { - putString("accessToken", token.accessToken) - putString("refreshToken", token.refreshToken) - putString("tokenType", null) - putString("idToken", token.idToken) - putDouble( - "accessTokenExpiresAt", - token.accessTokenExpiresAt.unix.toDouble(), - ) - putDouble( - "refreshTokenExpiresAt", - token.refreshTokenExpiresAt.unix.toDouble(), - ) - putDouble( - "accessTokenExpiresIn", - RNCKakaoUtil.diffSec(token.accessTokenExpiresAt, Date()).toDouble(), - ) - putDouble( - "refreshTokenExpiresIn", - RNCKakaoUtil.diffSec(token.refreshTokenExpiresAt, Date()).toDouble(), - ) - putArray( - "scopes", - argArr().apply { - pushStringList(token.scopes ?: listOf()) - }, - ) - }, - ) - } + @ReactMethod + override fun login( + serviceTerms: ReadableArray?, + prompts: ReadableArray?, + useKakaoAccountLogin: Boolean, + scopes: ReadableArray?, + promise: Promise, + ) = onMain { + val context = + currentActivity ?: run { + promise.rejectWith(ActivityNotFoundException()) + return@onMain } - - if (scopes?.filterIsInstance()?.isEmpty() == false) { - UserApiClient.instance.loginWithNewScopes( - context, - scopes = scopes.filterIsInstance(), - callback = callback, - ) - } else if (UserApiClient.instance.isKakaoTalkLoginAvailable(context) && !useKakaoAccountLogin && scopes?.filterIsInstance() - ?.isEmpty() == true - ) { - UserApiClient.instance.loginWithKakaoTalk( - context, - serviceTerms = serviceTerms?.filterIsInstance()?.ifEmpty { null }, - callback = callback, - ) + val callback: (OAuthToken?, Throwable?) -> Unit = { token, error -> + if (error != null) { + promise.rejectWith(error) + } else if (token == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("token")) } else { - UserApiClient.instance.loginWithKakaoAccount( - context, - prompts = - prompts?.filterIsInstance()?.mapNotNull { + promise.resolve( + argMap().apply { + putString("accessToken", token.accessToken) + putString("refreshToken", token.refreshToken) + putString("tokenType", null) + putString("idToken", token.idToken) + putDouble( + "accessTokenExpiresAt", + token.accessTokenExpiresAt.unix.toDouble(), + ) + putDouble( + "refreshTokenExpiresAt", + token.refreshTokenExpiresAt.unix.toDouble(), + ) + putDouble( + "accessTokenExpiresIn", + RNCKakaoUtil.diffSec(token.accessTokenExpiresAt, Date()).toDouble(), + ) + putDouble( + "refreshTokenExpiresIn", + RNCKakaoUtil.diffSec(token.refreshTokenExpiresAt, Date()).toDouble(), + ) + putArray( + "scopes", + argArr().apply { + pushStringList(token.scopes ?: listOf()) + }, + ) + }, + ) + } + } + + if (scopes?.filterIsInstance()?.isEmpty() == false) { + UserApiClient.instance.loginWithNewScopes( + context, + scopes = scopes.filterIsInstance(), + callback = callback, + ) + } else if (UserApiClient.instance.isKakaoTalkLoginAvailable(context) && + !useKakaoAccountLogin && + scopes + ?.filterIsInstance() + ?.isEmpty() == true + ) { + UserApiClient.instance.loginWithKakaoTalk( + context, + serviceTerms = serviceTerms?.filterIsInstance()?.ifEmpty { null }, + callback = callback, + ) + } else { + UserApiClient.instance.loginWithKakaoAccount( + context, + prompts = + prompts + ?.filterIsInstance() + ?.mapNotNull { when (it) { "Login" -> LOGIN "Create" -> CREATE @@ -115,282 +119,282 @@ class RNCKakaoUserModule internal constructor(context: ReactApplicationContext) else -> null } }?.ifEmpty { null }, - serviceTerms = serviceTerms?.filterIsInstance()?.ifEmpty { null }, - callback = callback, - ) - } + serviceTerms = serviceTerms?.filterIsInstance()?.ifEmpty { null }, + callback = callback, + ) + } + } + + @ReactMethod + override fun isKakaoTalkLoginAvailable(promise: Promise) = + onMain { + promise.resolve(UserApiClient.instance.isKakaoTalkLoginAvailable(reactApplicationContext)) } - @ReactMethod - override fun isKakaoTalkLoginAvailable(promise: Promise) = - onMain { - promise.resolve(UserApiClient.instance.isKakaoTalkLoginAvailable(reactApplicationContext)) + @ReactMethod + override fun logout(promise: Promise) = + onMain { + UserApiClient.instance.logout { + if (it != null) { + promise.rejectWith(it) + } else { + promise.resolve(42) + } } + } - @ReactMethod - override fun logout(promise: Promise) = - onMain { - UserApiClient.instance.logout { - if (it != null) { - promise.rejectWith(it) - } else { - promise.resolve(42) - } + @ReactMethod + override fun unlink(promise: Promise) = + onMain { + UserApiClient.instance.unlink { + if (it != null) { + promise.rejectWith(it) + } else { + promise.resolve(42) } } + } - @ReactMethod - override fun unlink(promise: Promise) = - onMain { - UserApiClient.instance.unlink { - if (it != null) { - promise.rejectWith(it) + @ReactMethod + override fun isLogined(promise: Promise) = + onMain { + if (AuthApiClient.instance.hasToken()) { + UserApiClient.instance.accessTokenInfo { _, error -> + if (error != null) { + promise.rejectWith(error) } else { - promise.resolve(42) + promise.resolve(true) } } + } else { + promise.resolve(false) } + } - @ReactMethod - override fun isLogined(promise: Promise) = - onMain { - if (AuthApiClient.instance.hasToken()) { - UserApiClient.instance.accessTokenInfo { _, error -> - if (error != null) { - promise.rejectWith(error) - } else { - promise.resolve(true) + @ReactMethod + override fun scopes( + scopes: ReadableArray?, + promise: Promise, + ) = onMain { + UserApiClient.instance.scopes { scopeInfo, error -> + if (error != null) { + promise.rejectWith(error) + } else if (scopeInfo?.scopes == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("scopes")) + } else { + promise.resolve( + argArr().also { arr -> + scopeInfo.scopes!!.forEach { scope -> + arr.pushMap( + argMap().also { map -> + map.putString("id", scope.id) + map.putString("displayName", scope.displayName) + map.putString("type", scope.type.name) + map.putBoolean("using", scope.using) + map.putB("delegated", scope.delegated) + map.putBoolean("agreed", scope.agreed) + map.putB("revocable", scope.revocable) + }, + ) } - } - } else { - promise.resolve(false) - } + }, + ) } + } + } - @ReactMethod - override fun scopes( - scopes: ReadableArray?, - promise: Promise, - ) = onMain { - UserApiClient.instance.scopes { scopeInfo, error -> + @ReactMethod + override fun revokeScopes( + scopes: ReadableArray, + promise: Promise, + ) = onMain { + UserApiClient.instance.revokeScopes( + scopes = scopes.filterIsInstance(), + ) { scopeInfo, error -> + if (error != null) { + promise.rejectWith(error) + } else if (scopeInfo == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("scopeInfo")) + } else { + promise.resolve(42) + } + } + } + + @ReactMethod + override fun serviceTerms(promise: Promise) = + onMain { + UserApiClient.instance.serviceTerms { serviceTerms, error -> if (error != null) { promise.rejectWith(error) - } else if (scopeInfo?.scopes == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("scopes")) + } else if (serviceTerms?.serviceTerms == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("serviceTerms")) } else { promise.resolve( - argArr().also { arr -> - scopeInfo.scopes!!.forEach { scope -> - arr.pushMap( - argMap().also { map -> - map.putString("id", scope.id) - map.putString("displayName", scope.displayName) - map.putString("type", scope.type.name) - map.putBoolean("using", scope.using) - map.putB("delegated", scope.delegated) - map.putBoolean("agreed", scope.agreed) - map.putB("revocable", scope.revocable) - }, - ) - } - }, + argArr().pushMapList( + serviceTerms.serviceTerms?.map { term -> + argMap().apply { + putString("tag", term.tag) + putD("agreedAt", term.agreedAt?.unix?.toDouble()) + putBoolean("agreed", term.agreed) + putBoolean("required", term.required) + putBoolean("revocable", term.revocable) + } + } ?: listOf(), + ), ) } } } - @ReactMethod - override fun revokeScopes( - scopes: ReadableArray, - promise: Promise, - ) = onMain { - UserApiClient.instance.revokeScopes( - scopes = scopes.filterIsInstance(), - ) { scopeInfo, error -> + @ReactMethod + override fun shippingAddresses(promise: Promise) = + onMain { + UserApiClient.instance.shippingAddresses { addrs, error -> if (error != null) { promise.rejectWith(error) - } else if (scopeInfo == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("scopeInfo")) + } else if (addrs == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("shippingAddresses")) } else { - promise.resolve(42) + promise.resolve( + argMap().apply { + putD("userId", addrs.userId?.toDouble()) + putB("needsAgreement", addrs.needsAgreement) + putArray( + "shippingAddresses", + argArr().apply { + pushMapList( + addrs.shippingAddresses?.map { addr -> + argMap().apply { + putDouble("id", addr.id.toDouble()) + putString("name", addr.name) + putBoolean("isDefault", addr.isDefault) + putD("updatedAt", addr.updatedAt?.unix?.toDouble()) + putString("type", addr.type?.name) + putString("baseAddress", addr.baseAddress) + putString("detailAddress", addr.detailAddress) + putString("receiverName", addr.receiverName) + putString("receiverPhoneNumber1", addr.receiverPhoneNumber1) + putString("receiverPhoneNumber2", addr.receiverPhoneNumber2) + putString("zoneNumber", addr.zoneNumber) + putString("zipCode", addr.zipCode) + } + } ?: listOf(), + ) + }, + ) + }, + ) } } } - @ReactMethod - override fun serviceTerms(promise: Promise) = - onMain { - UserApiClient.instance.serviceTerms { serviceTerms, error -> - if (error != null) { - promise.rejectWith(error) - } else if (serviceTerms?.serviceTerms == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("serviceTerms")) - } else { - promise.resolve( - argArr().pushMapList( - serviceTerms.serviceTerms?.map { term -> - argMap().apply { - putString("tag", term.tag) - putD("agreedAt", term.agreedAt?.unix?.toDouble()) - putBoolean("agreed", term.agreed) - putBoolean("required", term.required) - putBoolean("revocable", term.revocable) - } - } ?: listOf(), - ), - ) - } - } - } - - @ReactMethod - override fun shippingAddresses(promise: Promise) = - onMain { - UserApiClient.instance.shippingAddresses { addrs, error -> - if (error != null) { - promise.rejectWith(error) - } else if (addrs == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("shippingAddresses")) - } else { - promise.resolve( - argMap().apply { - putD("userId", addrs.userId?.toDouble()) - putB("needsAgreement", addrs.needsAgreement) - putArray( - "shippingAddresses", - argArr().apply { - pushMapList( - addrs.shippingAddresses?.map { addr -> - argMap().apply { - putDouble("id", addr.id.toDouble()) - putString("name", addr.name) - putBoolean("isDefault", addr.isDefault) - putD("updatedAt", addr.updatedAt?.unix?.toDouble()) - putString("type", addr.type?.name) - putString("baseAddress", addr.baseAddress) - putString("detailAddress", addr.detailAddress) - putString("receiverName", addr.receiverName) - putString("receiverPhoneNumber1", addr.receiverPhoneNumber1) - putString("receiverPhoneNumber2", addr.receiverPhoneNumber2) - putString("zoneNumber", addr.zoneNumber) - putString("zipCode", addr.zipCode) - } - } ?: listOf(), - ) - }, - ) - }, - ) - } - } - } - - @ReactMethod - override fun me(promise: Promise) = - onMain { - UserApiClient.instance.me { user, error -> - if (error != null) { - promise.rejectWith(error) - } else if (user == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("user")) - } else { - promise.resolve( - argMap().apply { - putD("id", user.id?.toDouble()) - putString("name", user.kakaoAccount?.name) + @ReactMethod + override fun me(promise: Promise) = + onMain { + UserApiClient.instance.me { user, error -> + if (error != null) { + promise.rejectWith(error) + } else if (user == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("user")) + } else { + promise.resolve( + argMap().apply { + putD("id", user.id?.toDouble()) + putString("name", user.kakaoAccount?.name) - putString("email", user.kakaoAccount?.email) - putString("nickname", user.kakaoAccount?.profile?.nickname) - putString("profileImageUrl", user.kakaoAccount?.profile?.profileImageUrl) - putString("thumbnailImageUrl", user.kakaoAccount?.profile?.thumbnailImageUrl) - putString("phoneNumber", user.kakaoAccount?.phoneNumber) - putString("ageRange", user.kakaoAccount?.ageRange?.name) - putString("birthday", user.kakaoAccount?.birthday) - putString("birthdayType", user.kakaoAccount?.birthdayType?.name) - putString("birthyear", user.kakaoAccount?.birthyear) - putString("gender", user.kakaoAccount?.gender?.name) - putB("isEmailValid", user.kakaoAccount?.isEmailValid) - putB("isEmailVerified", user.kakaoAccount?.isEmailVerified) - putB("isKorean", user.kakaoAccount?.isKorean) - putB( - "ageRangeNeedsAgreement", - user.kakaoAccount?.ageRangeNeedsAgreement, - ) - putB( - "birthdayNeedsAgreement", - user.kakaoAccount?.birthdayNeedsAgreement, - ) - putB( - "birthyearNeedsAgreement", - user.kakaoAccount?.birthyearNeedsAgreement, - ) - putB( - "emailNeedsAgreement", - user.kakaoAccount?.emailNeedsAgreement, - ) - putB( - "genderNeedsAgreement", - user.kakaoAccount?.genderNeedsAgreement, - ) - putB( - "isKoreanNeedsAgreement", - user.kakaoAccount?.isKoreanNeedsAgreement, - ) - putB( - "phoneNumberNeedsAgreement", - user.kakaoAccount?.phoneNumberNeedsAgreement, - ) - putB( - "profileNeedsAgreement", - user.kakaoAccount?.profileNeedsAgreement, - ) - putB( - "ciNeedsAgreement", - user.kakaoAccount?.ciNeedsAgreement, - ) - putB( - "nameNeedsAgreement", - user.kakaoAccount?.nameNeedsAgreement, - ) - putB( - "profileImageNeedsAgreement", - user.kakaoAccount?.profileImageNeedsAgreement, - ) - putB( - "profileNicknameNeedsAgreement", - user.kakaoAccount?.profileNicknameNeedsAgreement, - ) - putB( - "legalBirthDateNeedsAgreement", - user.kakaoAccount?.legalBirthDateNeedsAgreement, - ) - }, - ) - } + putString("email", user.kakaoAccount?.email) + putString("nickname", user.kakaoAccount?.profile?.nickname) + putString("profileImageUrl", user.kakaoAccount?.profile?.profileImageUrl) + putString("thumbnailImageUrl", user.kakaoAccount?.profile?.thumbnailImageUrl) + putString("phoneNumber", user.kakaoAccount?.phoneNumber) + putString("ageRange", user.kakaoAccount?.ageRange?.name) + putString("birthday", user.kakaoAccount?.birthday) + putString("birthdayType", user.kakaoAccount?.birthdayType?.name) + putString("birthyear", user.kakaoAccount?.birthyear) + putString("gender", user.kakaoAccount?.gender?.name) + putB("isEmailValid", user.kakaoAccount?.isEmailValid) + putB("isEmailVerified", user.kakaoAccount?.isEmailVerified) + putB("isKorean", user.kakaoAccount?.isKorean) + putB( + "ageRangeNeedsAgreement", + user.kakaoAccount?.ageRangeNeedsAgreement, + ) + putB( + "birthdayNeedsAgreement", + user.kakaoAccount?.birthdayNeedsAgreement, + ) + putB( + "birthyearNeedsAgreement", + user.kakaoAccount?.birthyearNeedsAgreement, + ) + putB( + "emailNeedsAgreement", + user.kakaoAccount?.emailNeedsAgreement, + ) + putB( + "genderNeedsAgreement", + user.kakaoAccount?.genderNeedsAgreement, + ) + putB( + "isKoreanNeedsAgreement", + user.kakaoAccount?.isKoreanNeedsAgreement, + ) + putB( + "phoneNumberNeedsAgreement", + user.kakaoAccount?.phoneNumberNeedsAgreement, + ) + putB( + "profileNeedsAgreement", + user.kakaoAccount?.profileNeedsAgreement, + ) + putB( + "ciNeedsAgreement", + user.kakaoAccount?.ciNeedsAgreement, + ) + putB( + "nameNeedsAgreement", + user.kakaoAccount?.nameNeedsAgreement, + ) + putB( + "profileImageNeedsAgreement", + user.kakaoAccount?.profileImageNeedsAgreement, + ) + putB( + "profileNicknameNeedsAgreement", + user.kakaoAccount?.profileNicknameNeedsAgreement, + ) + putB( + "legalBirthDateNeedsAgreement", + user.kakaoAccount?.legalBirthDateNeedsAgreement, + ) + }, + ) } } + } - @ReactMethod - override fun getAccessToken(promise: Promise) = - onMain { - UserApiClient.instance.accessTokenInfo { accessTokenInfo, error -> - if (error != null) { - promise.rejectWith(error) - } else if (accessTokenInfo == null) { - promise.rejectWith(RNCKakaoResponseNotFoundException("accessTokenInfo")) - } else { - promise.resolve( - argMap().apply { - putL("id", accessTokenInfo.id) - putL("expiresIn", accessTokenInfo.expiresIn) - putI("appID", accessTokenInfo.appId) - }, - ) - } + @ReactMethod + override fun getAccessToken(promise: Promise) = + onMain { + UserApiClient.instance.accessTokenInfo { accessTokenInfo, error -> + if (error != null) { + promise.rejectWith(error) + } else if (accessTokenInfo == null) { + promise.rejectWith(RNCKakaoResponseNotFoundException("accessTokenInfo")) + } else { + promise.resolve( + argMap().apply { + putL("id", accessTokenInfo.id) + putL("expiresIn", accessTokenInfo.expiresIn) + putI("appID", accessTokenInfo.appId) + }, + ) } } - - companion object { - const val NAME = "RNCKakaoUser" } + + companion object { + const val NAME = "RNCKakaoUser" } +} diff --git a/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserPackage.kt b/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserPackage.kt index 9d93e16..02a8c91 100644 --- a/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserPackage.kt +++ b/packages/user/android/src/main/java/net/mjstudio/rnkakao/user/RNCKakaoUserPackage.kt @@ -10,16 +10,15 @@ class RNCKakaoUserPackage : TurboReactPackage() { override fun getModule( name: String, reactContext: ReactApplicationContext, - ): NativeModule? { - return if (name == RNCKakaoUserModule.NAME) { + ): NativeModule? = + if (name == RNCKakaoUserModule.NAME) { RNCKakaoUserModule(reactContext) } else { null } - } - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED moduleInfos[RNCKakaoUserModule.NAME] = @@ -33,5 +32,4 @@ class RNCKakaoUserPackage : TurboReactPackage() { ) moduleInfos } - } } diff --git a/packages/user/android/src/newarch/KakaoUserSpec.kt b/packages/user/android/src/newarch/KakaoUserSpec.kt index 123c1f2..f35fc21 100644 --- a/packages/user/android/src/newarch/KakaoUserSpec.kt +++ b/packages/user/android/src/newarch/KakaoUserSpec.kt @@ -2,5 +2,6 @@ package net.mjstudio.rnkakao.user import com.facebook.react.bridge.ReactApplicationContext -abstract class KakaoUserSpec internal constructor(context: ReactApplicationContext) : - NativeKakaoUserSpec(context) +abstract class KakaoUserSpec internal constructor( + context: ReactApplicationContext, +) : NativeKakaoUserSpec(context) diff --git a/packages/user/android/src/oldarch/KakaoUserSpec.kt b/packages/user/android/src/oldarch/KakaoUserSpec.kt index 2232420..669a5f1 100644 --- a/packages/user/android/src/oldarch/KakaoUserSpec.kt +++ b/packages/user/android/src/oldarch/KakaoUserSpec.kt @@ -5,39 +5,40 @@ import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReadableArray -abstract class KakaoUserSpec internal constructor(context: ReactApplicationContext) : - ReactContextBaseJavaModule(context) { - abstract fun login( - serviceTerms: ReadableArray?, - prompts: ReadableArray?, - useKakaoAccountLogin: Boolean, - scopes: ReadableArray?, - promise: Promise, - ) +abstract class KakaoUserSpec internal constructor( + context: ReactApplicationContext, +) : ReactContextBaseJavaModule(context) { + abstract fun login( + serviceTerms: ReadableArray?, + prompts: ReadableArray?, + useKakaoAccountLogin: Boolean, + scopes: ReadableArray?, + promise: Promise, + ) - abstract fun isKakaoTalkLoginAvailable(promise: Promise) + abstract fun isKakaoTalkLoginAvailable(promise: Promise) - abstract fun logout(promise: Promise) + abstract fun logout(promise: Promise) - abstract fun unlink(promise: Promise) + abstract fun unlink(promise: Promise) - abstract fun isLogined(promise: Promise) + abstract fun isLogined(promise: Promise) - abstract fun scopes( - scopes: ReadableArray?, - promise: Promise, - ) + abstract fun scopes( + scopes: ReadableArray?, + promise: Promise, + ) - abstract fun revokeScopes( - scopes: ReadableArray, - promise: Promise, - ) + abstract fun revokeScopes( + scopes: ReadableArray, + promise: Promise, + ) - abstract fun serviceTerms(promise: Promise) + abstract fun serviceTerms(promise: Promise) - abstract fun shippingAddresses(promise: Promise) + abstract fun shippingAddresses(promise: Promise) - abstract fun me(promise: Promise) + abstract fun me(promise: Promise) - abstract fun getAccessToken(promise: Promise) - } + abstract fun getAccessToken(promise: Promise) +}