Skip to content

Commit

Permalink
support java 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyunn15 committed Sep 22, 2023
1 parent e152cf5 commit 28983bf
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
kotlinCompilerExtensionVersion '1.4.3'
}
packagingOptions {
resources {
Expand All @@ -59,7 +59,7 @@ dependencies {
implementation 'androidx.activity:activity-compose:1.5.1'

//compose
implementation platform('androidx.compose:compose-bom:2023.01.00')
implementation platform('androidx.compose:compose-bom:2023.03.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
Expand All @@ -86,8 +86,8 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'

//hilt
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
implementation "com.google.dagger:hilt-android:2.44.2"
kapt "com.google.dagger:hilt-compiler:2.44.2"

implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.6.0-alpha01'
}
5 changes: 0 additions & 5 deletions app/src/main/java/com/jeremy/thunder/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.jeremy.thunder.OnLifecycleEvent
import com.jeremy.thunder.socket.model.AllMarketTickerResponseItem

@OptIn(ExperimentalLifecycleComposeApi::class, ExperimentalFoundationApi::class)
@Composable
fun HomeScreen(
viewModel: HomeViewModel = hiltViewModel()
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ buildscript {
}

plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.google.dagger.hilt.android' version '2.44' apply false
id 'com.android.application' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.google.dagger.hilt.android' version '2.44.2' apply false
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 27 20:02:19 KST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 4 additions & 6 deletions thunder-okhttp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ afterEvaluate {
from components.release
groupId = 'com.jeremy.thunder'
artifactId = 'thunder-okhttp'
version = '0.0.1'
}

debug(MavenPublication) {
from components.debug
groupId = 'com.jeremy.thunder'
artifactId = 'thunder-okhttp'
version = '0.0.1'
}
}
}
}

android {
namespace 'com.jeremy.thunder'
namespace 'com.jeremy.thunder.okhttp'
compileSdk 33

defaultConfig {
Expand All @@ -44,11 +42,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '1.8'
}
}

Expand Down
8 changes: 3 additions & 5 deletions thunder/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ afterEvaluate {
from components.release
groupId = 'com.jeremy.thunder'
artifactId = 'thunder'
version = '0.0.1'
}

debug(MavenPublication) {
from components.debug
groupId = 'com.jeremy.thunder'
artifactId = 'thunder'
version = '0.0.1'
}
}
}
Expand All @@ -44,11 +42,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = '1.8'
}
}

Expand Down
12 changes: 11 additions & 1 deletion thunder/src/main/java/com/jeremy/thunder/event/EventMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map

/**
* mapEvent 내에서 convert가 실패하면 다른 응답이기에 실패했다고 봐야 하는지?
* [EventMapper] - Convert WebSocketEvent to Generic type data.
* */

class EventMapper<T> constructor(
Expand All @@ -25,6 +25,16 @@ class EventMapper<T> constructor(
}
}

fun mapEvent(event: WebSocketEvent): T? = if (event is WebSocketEvent.OnMessageReceived) {
try {
converter.convert(event.data)
} catch (e: Exception) {
null
}
} else {
null
}

class Factory {
fun create(converter: Converter<*>): EventMapper<*> {
return EventMapper(converter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.lang.reflect.Method
import java.lang.reflect.ParameterizedType
Expand All @@ -30,33 +31,22 @@ class ServiceExecutor internal constructor(
return when (method.genericReturnType.getAboutRawType()) {
Flow::class.java -> {
method.requireParameterTypes { "Receive method must have zero parameter: $method" }

method.requireReturnTypeIsOneOf(ParameterizedType::class.java) { "Receive method must return ParameterizedType: $method" }

val returnType =
(method.genericReturnType as ParameterizedType).getParameterUpperBound(0)

val returnType = (method.genericReturnType as ParameterizedType).getParameterUpperBound(0)
val converter = ConvertAdapter.Factory().create(returnType)

// 특정 리턴 타입에 해당 하는 매퍼를 반환
val eventMapper =
SocketEventKeyStore().findEventMapper(returnType, method.annotations, converter)

// 특정 EventMapper로만 직렬화되는 파이프라인 생성
createReceivePipeline(
mappingEventFlow = eventMapper.mapEvent(thunderProvider.observeEvent()).filterNotNull()
).receiveFlow()
val eventMapper = SocketEventKeyStore().findEventMapper(returnType, method.annotations, converter)
thunderProvider.observeEvent()
.map(eventMapper::mapEvent)
.filterNotNull()
.createPipeline()
.receiveFlow()
}

else -> require(false) { "Wrapper Type must be Flow." }
}
}

private fun createReceivePipeline(
mappingEventFlow: Flow<Any>
): ReceivePipeline<*> {
return ReceivePipeline(socketEventFlow = mappingEventFlow, scope = scope)
}
private fun Flow<Any>.createPipeline(): ReceivePipeline<*> = ReceivePipeline(this, scope)

fun executeSend(method: Method, args: Array<out Any>) {
require(args.isNotEmpty()) { "@Send method require at least 1 arguments for execute service" }
Expand Down

0 comments on commit 28983bf

Please sign in to comment.