Skip to content

Commit

Permalink
Merge pull request #26 from Trendyol/stability
Browse files Browse the repository at this point in the history
Stability Improvements
  • Loading branch information
yigitozgumus authored Oct 11, 2024
2 parents cd12235 + 1f4c2d7 commit e7f4612
Show file tree
Hide file tree
Showing 57 changed files with 873 additions and 611 deletions.
13 changes: 7 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.jetbrainsKotlinJvm) apply false
alias(libs.plugins.android.hilt) apply false
alias(libs.plugins.jetbrains.kotlin.kapt) apply false
}
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.jetbrainsKotlinJvm) apply false
alias(libs.plugins.android.hilt) apply false
alias(libs.plugins.jetbrains.kotlin.kapt) apply false
alias(libs.plugins.compose.compiler) apply false
}
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
agp = "8.2.2"
hiltAndroid = "2.50"
hiltAndroidCompiler = "2.50"
kotlin = "1.9.0"
kotlin = "2.0.20"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
Expand All @@ -12,7 +12,7 @@ kotlinxCoroutinesTest = "1.8.0"
lifecycleRuntimeKtx = "2.7.0"
activityCompose = "1.8.2"
composeBom = "2024.02.01"
jetbrainsKotlinJvm = "1.9.21"
jetbrainsKotlinJvm = "2.0.20"
lifecycleRuntimeCompose = "2.7.0"
hilt = "2.50"
org-jetbrains-kotlin-android = "1.9.0"
Expand Down Expand Up @@ -40,10 +40,12 @@ androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-ru
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycleRuntimeKtx" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutinesTest" }
turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
jetbrainsKotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" }
android-hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
jetbrains-kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "org-jetbrains-kotlin-android" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
4 changes: 1 addition & 3 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.android.hilt)
alias(libs.plugins.jetbrains.kotlin.kapt)
alias(libs.plugins.compose.compiler)
}

android {
Expand Down Expand Up @@ -42,9 +43,6 @@ android {
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.7"
}
kapt {
correctErrorTypes = true
}
Expand Down
295 changes: 7 additions & 288 deletions sample/src/main/java/com/trendyol/transmission/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,306 +5,25 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.trendyol.transmission.features.colorpicker.ColorPickerSignal
import com.trendyol.transmission.features.input.InputSignal
import com.trendyol.transmission.components.ComponentScreen
import com.trendyol.transmission.components.ComponentViewModel
import com.trendyol.transmission.counter.CounterViewModel
import com.trendyol.transmission.ui.theme.TransmissionTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SampleActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val viewModel: SampleViewModel by viewModels()
val componentVM: ComponentViewModel by viewModels()
val counterVM: CounterViewModel by viewModels()
enableEdgeToEdge()
setContent {
TransmissionTheme {
SampleScreen(viewModel)
ComponentScreen(componentVM)
// CounterScreen(counterVM)
}
}
}
}

@Composable
fun SampleScreen(viewModel: SampleViewModel) {
val inputUiState by viewModel.inputUiState.collectAsStateWithLifecycle()
val outputUiState by viewModel.outputUiState.collectAsStateWithLifecycle()
val colorPickerUiState by viewModel.colorPickerUiState.collectAsStateWithLifecycle()
val multiOutputUiState by viewModel.multiOutputUiState.collectAsStateWithLifecycle()
val transmissionList by viewModel.transmissionList.collectAsStateWithLifecycle()
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Column(
modifier = Modifier.padding(innerPadding),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
InputComponent(
backgroundColor = inputUiState.backgroundColor,
onSignal = viewModel::processSignal
)
OutputComponent(
writtenText = outputUiState.outputText,
backgroundColor = outputUiState.backgroundColor
)
ColorPickerComponent(
backgroundColor = colorPickerUiState.backgroundColor,
onSignal = viewModel::processSignal,
selectedColorIndex = colorPickerUiState.selectedColorIndex
)
MultiOutputComponent(
writtenText = multiOutputUiState.writtenUppercaseText,
selectedColor = multiOutputUiState.selectedColor,
backgroundColor = multiOutputUiState.backgroundColor
)
TransmissionComponent(transmissionList = transmissionList)
}
}
}

@Composable
fun TransmissionComponent(
modifier: Modifier = Modifier,
transmissionList: List<String>
) {
val scrollState = rememberLazyListState()
LaunchedEffect(transmissionList.size) {
if (transmissionList.lastIndex > 0) {
scrollState.scrollToItem(transmissionList.lastIndex)
}
}
LazyColumn(modifier = modifier.padding(8.dp), state = scrollState) {
items(transmissionList) {
Text(it, fontSize = 10.sp)
}

}
}

@Composable
fun InputComponent(
modifier: Modifier = Modifier,
backgroundColor: Color,
onSignal: (Transmission.Signal) -> Unit
) {
var text by remember { mutableStateOf("") }
val keyboardController = LocalSoftwareKeyboardController.current
Column(
modifier = modifier
.fillMaxWidth()
.padding(12.dp)
.background(color = backgroundColor)
.border(1.dp, color = Color.Gray)
.padding(12.dp)
) {
Text(text = "Input Component")
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
TextField(
modifier = Modifier.weight(2.5f),
shape = RoundedCornerShape(4.dp),
colors = TextFieldDefaults.colors(
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent
),
value = text,
onValueChange = { text = it },
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text),
trailingIcon = {
if (text.isNotEmpty()) {
Icon(
imageVector = Icons.Default.Clear,
contentDescription = "Clear text",
modifier = Modifier.clickable { text = "" }
)
}
}
)
Button(
onClick = {
keyboardController?.hide()
onSignal.invoke(InputSignal.InputUpdate(text))
},
modifier = Modifier
.padding(horizontal = 4.dp)
.weight(1f)
) {
Text("Update")
}
}
}
}

@Composable
fun OutputComponent(
modifier: Modifier = Modifier,
writtenText: String = "",
backgroundColor: Color
) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(12.dp)
.background(color = backgroundColor)
.border(1.dp, color = Color.Gray)
.padding(12.dp)
) {
Text("Output Component")
val annotatedString = AnnotatedString.Builder().apply {
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
append("Written text is: ")
}
withStyle(SpanStyle(textDecoration = TextDecoration.None, fontSize = 16.sp)) {
append(writtenText)
}
}.toAnnotatedString()
Text(annotatedString)
}
}

@Composable
fun ColorPickerComponent(
modifier: Modifier = Modifier,
backgroundColor: Color,
selectedColorIndex: Int,
onSignal: (Transmission.Signal) -> Unit
) {
val items =
listOf(
Color.White,
Color.Green,
Color.DarkGray,
Color.Yellow,
Color.Magenta,
Color.Black,
Color.Blue
)
Column(
modifier = modifier
.fillMaxWidth()
.padding(12.dp)
.background(color = backgroundColor)
.border(1.dp, color = Color.Gray)
.padding(12.dp)
) {
Text("Color Picker Component")
LazyRow(
horizontalArrangement = Arrangement.SpaceAround,
modifier = Modifier.fillMaxWidth()
) {
itemsIndexed(items) { index, item ->
ColorItem(item, selectedColorIndex == index) {
onSignal(ColorPickerSignal.SelectColor(index, item))
}
}
}
}
}


@Composable
fun ColorItem(color: Color, isSelected: Boolean, onClickColor: (Color) -> Unit) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(bottom = 8.dp)
) {
Box(
modifier = Modifier
.size(40.dp)
.background(color, CircleShape)
.border(
width = 2.dp,
color = if (isSelected) Color.Black else Color.Gray,
shape = CircleShape
)
.clickable { onClickColor(color) }
)
Spacer(modifier = Modifier.height(8.dp))
}
}

@Composable
fun MultiOutputComponent(
modifier: Modifier = Modifier,
writtenText: String,
selectedColor: Color,
backgroundColor: Color
) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(12.dp)
.background(color = backgroundColor)
.border(1.dp, color = Color.Gray)
.padding(12.dp)
) {
Text("Multi Output Component")
val annotatedString = AnnotatedString.Builder().apply {
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
append("Written Uppercase text is: ")
}
withStyle(SpanStyle(textDecoration = TextDecoration.None, fontSize = 16.sp)) {
append(writtenText)
}
}.toAnnotatedString()
Text(annotatedString)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Text("Selected background is")
Spacer(modifier = Modifier.width(8.dp))
ColorItem(color = selectedColor, false, {})
}
}
}
Loading

0 comments on commit e7f4612

Please sign in to comment.