Skip to content

Commit a1140a5

Browse files
Code Refactoring
1 parent 54ccbcc commit a1140a5

File tree

16 files changed

+255
-221
lines changed

16 files changed

+255
-221
lines changed

app/src/main/java/co/yml/coreui/MainActivity.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import androidx.compose.foundation.layout.padding
1111
import androidx.compose.material3.ExperimentalMaterial3Api
1212
import androidx.compose.material3.Scaffold
1313
import androidx.compose.ui.Modifier
14-
import co.yml.coreui.feature.ytag.ui.YTagActivity
1514
import co.yml.coreui.core.ui.templates.AppBar
1615
import co.yml.coreui.core.ui.theme.CoreUICatalogTheme
16+
import co.yml.coreui.feature.ytag.ui.YTagActivity
1717
import co.yml.coreui.ui.R
1818
import co.yml.coreui.ui.presentation.CoreUIComponents
1919
import dagger.hilt.android.AndroidEntryPoint
@@ -30,10 +30,11 @@ class MainActivity : ComponentActivity() {
3030
super.onCreate(savedInstanceState)
3131
setContent {
3232
CoreUICatalogTheme {
33-
Scaffold(modifier = Modifier.fillMaxSize(),
33+
Scaffold(
34+
modifier = Modifier.fillMaxSize(),
3435
containerColor = CoreUICatalogTheme.colors.background,
35-
topBar = { AppBar() })
36-
{
36+
topBar = { AppBar() }
37+
) {
3738
Column(
3839
modifier = Modifier
3940
.padding(it)

app/src/main/java/co/yml/coreui/ui/presentation/CoreUIComponents.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ fun CoreUIComponents(title: String, onClick: () -> Unit) {
2424
)
2525
)
2626
.fillMaxWidth()
27-
.height(48.dp), onClick = onClick,
27+
.height(48.dp),
28+
onClick = onClick,
2829
colors = ButtonDefaults.buttonColors(containerColor = CoreUICatalogTheme.colors.button)
2930
) {
3031
Text(

core/common/src/test/java/co/yml/coreui/common/TestCoroutineProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package co.yml.coreui.common
22

3+
import co.yml.coreui.core.common.di.DispatcherModule
4+
import co.yml.coreui.core.common.di.DispatcherModule_ProvideNetworkDispatcherFactory.provideNetworkDispatcher
35
import kotlinx.coroutines.test.runTest
46
import org.junit.Assert.assertTrue
57
import org.junit.Test
6-
import co.yml.coreui.core.common.di.DispatcherModule
7-
import co.yml.coreui.core.common.di.DispatcherModule_ProvideNetworkDispatcherFactory.provideNetworkDispatcher
88

99
/**
1010
* Test coroutine provider

core/data/src/main/java/co/yml/coreui/core/data/di/RepositoryModule.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ import dagger.hilt.components.SingletonComponent
1111
*/
1212
@Module
1313
@InstallIn(SingletonComponent::class)
14-
interface RepositoryModule {
15-
16-
}
14+
interface RepositoryModule

core/ui/src/androidTest/java/co/yml/coreui/ui/ytag/TagViewContainerTesting.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ class TagViewContainerTesting {
8282
}
8383

8484
@Test
85-
fun tagViewContainer_tags_shown(){
85+
fun tagViewContainer_tags_shown() {
8686
launchTagViewContainer()
8787

8888
composeTestRule.onNodeWithText("Tag 1").assertIsDisplayed()
8989
}
9090

9191
@Test
92-
fun tagViewContainer_with_less_space_more_tag_shown(){
92+
fun tagViewContainer_with_less_space_more_tag_shown() {
9393
val tagViewContainerModifiers = TagViewContainerModifiers.Builder()
9494
.width(150.dp)
9595
.height(50.dp)

core/ui/src/androidTest/java/co/yml/coreui/ui/ytag/TagViewTest.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import androidx.compose.ui.text.style.TextDecoration
2121
import androidx.compose.ui.text.style.TextOverflow
2222
import androidx.compose.ui.unit.dp
2323
import androidx.compose.ui.unit.sp
24-
import co.yml.coreui.core.ui.ytag.model.TagViewModifiers
2524
import co.yml.coreui.core.ui.ytag.TagView
25+
import co.yml.coreui.core.ui.ytag.model.TagViewModifiers
2626
import org.junit.Rule
2727
import org.junit.Test
2828

@@ -50,7 +50,6 @@ class TagViewTest {
5050

5151
@Test
5252
fun tagView_shown() {
53-
5453
launchYTag(text = "YTag")
5554
composeTestRule.onNodeWithTag("tag_view", useUnmergedTree = true).printToString()
5655

@@ -94,7 +93,6 @@ class TagViewTest {
9493

9594
@Test
9695
fun tagView_leading_and_trailing_icon_shown() {
97-
9896
launchYTag(text = "YTag", leadingIcon = {
9997
IconButton(onClick = {}, modifier = Modifier.testTag("leading_icon")) {
10098
Icon(
@@ -103,20 +101,20 @@ class TagViewTest {
103101
)
104102
}
105103
}, trailingIcon = {
106-
IconButton(onClick = {}, modifier = Modifier.testTag("trailing_icon")) {
107-
Icon(
108-
painter = painterResource(id = R.drawable.ic_menu_mylocation),
109-
contentDescription = null
110-
)
111-
}
112-
})
104+
IconButton(onClick = {}, modifier = Modifier.testTag("trailing_icon")) {
105+
Icon(
106+
painter = painterResource(id = R.drawable.ic_menu_mylocation),
107+
contentDescription = null
108+
)
109+
}
110+
})
113111

114112
composeTestRule.onNodeWithTag("leading_icon", useUnmergedTree = true).assertIsDisplayed()
115113
composeTestRule.onNodeWithTag("trailing_icon", useUnmergedTree = true).assertIsDisplayed()
116114
}
117115

118116
@Test
119-
fun tag_with_modifiers_are_executed(){
117+
fun tag_with_modifiers_are_executed() {
120118
val tagViewModifiers = TagViewModifiers.Builder()
121119
.minWidth(32.dp)
122120
.minHeight(100.dp)
@@ -134,7 +132,7 @@ class TagViewTest {
134132
.overFlow(TextOverflow.Ellipsis)
135133
.softWrap(true)
136134
.maxLines(1)
137-
.onTextLayout { }
135+
.onTextLayout { }
138136
.style(TextStyle())
139137
.enableBorder(true)
140138
.borderColor(Color.Red)
@@ -145,7 +143,7 @@ class TagViewTest {
145143
.tonalElevation(2.dp)
146144
.shadowElevation(2.dp)
147145
.containerPaddingValues(PaddingValues(4.dp))
148-
.onCLick { }
146+
.onCLick { }
149147
.borderWidth(1.dp)
150148
.build()
151149

core/ui/src/main/java/co/yml/coreui/core/ui/templates/AppBar.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ fun AppBar() {
3838
}
3939
}
4040

41-
4241
/**
4342
* Top app bars display information and actions at the top of a screen.
4443
*
@@ -77,30 +76,31 @@ fun AppBarWithBackButton(title: String, onBackPressed: () -> Unit) {
7776
}
7877
}
7978

80-
8179
@Preview(showBackground = true)
8280
@Composable
8381
fun DefaultPreview() {
8482
CoreUICatalogTheme {
85-
Scaffold(modifier = Modifier.fillMaxSize(),
83+
Scaffold(
84+
modifier = Modifier.fillMaxSize(),
8685
containerColor = CoreUICatalogTheme.colors.background,
8786
topBar = { AppBar() },
88-
content = { Box(Modifier.padding(it)) {} })
87+
content = { Box(Modifier.padding(it)) {} }
88+
)
8989
}
9090
}
9191

92-
9392
@Preview(showBackground = true)
9493
@Composable
9594
fun AppBarWithBackButton() {
9695
CoreUICatalogTheme {
97-
Scaffold(modifier = Modifier.fillMaxSize(),
96+
Scaffold(
97+
modifier = Modifier.fillMaxSize(),
9898
containerColor = CoreUICatalogTheme.colors.background,
9999
topBar = {
100100
AppBarWithBackButton(title = stringResource(id = R.string.title_y_tag)) {
101101
}
102102
},
103-
content = { Box(Modifier.padding(it)) {} })
104-
103+
content = { Box(Modifier.padding(it)) {} }
104+
)
105105
}
106106
}

core/ui/src/main/java/co/yml/coreui/core/ui/theme/Shape.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ data class CoreUICatalogShapes(
1010
val large: RoundedCornerShape = RoundedCornerShape(0.dp)
1111
)
1212

13-
internal val LocalShapes = staticCompositionLocalOf {CoreUICatalogShapes() }
13+
internal val LocalShapes = staticCompositionLocalOf { CoreUICatalogShapes() }

core/ui/src/main/java/co/yml/coreui/core/ui/ytag/TagView.kt

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package co.yml.coreui.core.ui.ytag
22

33
import android.R
44
import android.annotation.SuppressLint
5-
import android.util.Log
65
import androidx.compose.animation.AnimatedVisibility
76
import androidx.compose.animation.core.*
87
import androidx.compose.animation.fadeIn
@@ -27,7 +26,6 @@ import androidx.compose.ui.res.painterResource
2726
import androidx.compose.ui.semantics.contentDescription
2827
import androidx.compose.ui.semantics.semantics
2928
import androidx.compose.ui.tooling.preview.Preview
30-
import androidx.compose.ui.unit.Dp
3129
import androidx.compose.ui.unit.dp
3230
import androidx.compose.ui.unit.sp
3331
import androidx.constraintlayout.compose.ConstraintLayout
@@ -60,16 +58,17 @@ fun TagView(
6058
trailingIcon = trailingIcon,
6159
enabled = enabled,
6260
tagViewModifiers = tagViewModifiers,
63-
overFlowText = { overFlowText })
61+
overFlowText = { overFlowText }
62+
)
6463

65-
//used for visibility animation
64+
// used for visibility animation
6665
val state = remember {
6766
MutableTransitionState(false).apply {
6867
targetState = true
6968
}
7069
}
7170

72-
//used for alpha animation
71+
// used for alpha animation
7372
var tagVisible by remember {
7473
mutableStateOf(true)
7574
}
@@ -78,10 +77,10 @@ fun TagView(
7877
targetValue = if (tagVisible) 1f else 0f,
7978
animationSpec = tween(
8079
durationMillis = tagViewModifiers.alphaAnimation.durationMillis,
81-
easing = LinearEasing,
80+
easing = LinearEasing
8281
),
8382
finishedListener = {
84-
//execute once remove animation is performed
83+
// delegate the click event once remove animation is completed
8584
tagViewModifiers.onClick.invoke(tagViewData)
8685
}
8786
)
@@ -104,7 +103,6 @@ fun TagView(
104103
) {
105104
ConstraintLayout(
106105
modifier = Modifier
107-
108106
.width(width = width)
109107
.height(height)
110108
.run {
@@ -120,10 +118,10 @@ fun TagView(
120118
}
121119
.clickable {
122120
if (enabled) {
123-
if (tagViewModifiers.alphaAnimation.enabled){
121+
if (tagViewModifiers.alphaAnimation.enabled) {
124122
tagVisible = false
125123
state.targetState = false
126-
}else{
124+
} else {
127125
tagViewModifiers.onClick.invoke(tagViewData)
128126
}
129127
}
@@ -135,16 +133,16 @@ fun TagView(
135133
shape = shape
136134
)
137135

138-
139136
) {
140137
val (leading_icon, text_view, trailing_icon) = createRefs()
141138

142-
Box(modifier = Modifier
143-
.constrainAs(leading_icon) {
144-
start.linkTo(parent.start)
145-
top.linkTo(parent.top)
146-
bottom.linkTo(parent.bottom)
147-
}
139+
Box(
140+
modifier = Modifier
141+
.constrainAs(leading_icon) {
142+
start.linkTo(parent.start)
143+
top.linkTo(parent.top)
144+
bottom.linkTo(parent.bottom)
145+
}
148146
) {
149147
leadingIcon?.invoke(tagViewData)
150148
}
@@ -180,11 +178,12 @@ fun TagView(
180178
maxLines = maxLines,
181179
onTextLayout = onTextLayout
182180
)
183-
Box(modifier = Modifier.constrainAs(trailing_icon) {
184-
end.linkTo(parent.end)
185-
top.linkTo(parent.top)
186-
bottom.linkTo(parent.bottom)
187-
}
181+
Box(
182+
modifier = Modifier.constrainAs(trailing_icon) {
183+
end.linkTo(parent.end)
184+
top.linkTo(parent.top)
185+
bottom.linkTo(parent.bottom)
186+
}
188187
) {
189188
trailingIcon?.invoke(tagViewData)
190189
}
@@ -324,13 +323,13 @@ fun LeadingTrailingIconTag() {
324323
)
325324
}
326325
}, trailingIcon = {
327-
IconButton(onClick = {}) {
328-
Icon(
329-
painter = painterResource(id = R.drawable.ic_menu_close_clear_cancel),
330-
contentDescription = null
331-
)
332-
}
333-
}, tagViewModifiers = tagViewModifiers)
326+
IconButton(onClick = {}) {
327+
Icon(
328+
painter = painterResource(id = R.drawable.ic_menu_close_clear_cancel),
329+
contentDescription = null
330+
)
331+
}
332+
}, tagViewModifiers = tagViewModifiers)
334333
}
335334

336335
@Preview(name = "Tag with min width and height")

0 commit comments

Comments
 (0)