Skip to content

Commit d2e1df1

Browse files
committed
refactor(common): small improvements
1 parent e6e6710 commit d2e1df1

File tree

3 files changed

+20
-23
lines changed
  • application/src/androidMain/kotlin/com/neoutils/neoregex
  • feature
    • saved/src/commonMain/kotlin/com/neoutils/neoregex/feature/saved
    • validator/src/commonMain/kotlin/com/neoutils/neoregex/feature/validator/usecase

3 files changed

+20
-23
lines changed

application/src/androidMain/kotlin/com/neoutils/neoregex/NeoAndroidApp.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.neoutils.neoregex
2020

2121
import android.app.Application
22-
import android.content.Context
2322
import com.neoutils.neoregex.core.common.di.commonModule
2423
import com.neoutils.neoregex.core.database.di.databaseModule
2524
import com.neoutils.neoregex.core.datasource.di.dataSourceModule
@@ -28,21 +27,17 @@ import com.neoutils.neoregex.core.repository.di.repositoryModule
2827
import com.neoutils.neoregex.feature.matcher.di.matcherModule
2928
import com.neoutils.neoregex.feature.saved.di.savedModule
3029
import com.neoutils.neoregex.feature.validator.di.validatorModule
30+
import org.koin.android.ext.koin.androidContext
3131
import org.koin.core.context.GlobalContext.startKoin
32-
import org.koin.dsl.module
3332

3433
class NeoAndroidApp : Application() {
3534

36-
private val module = module {
37-
single<Context> { applicationContext }
38-
}
39-
4035
override fun onCreate() {
4136
super.onCreate()
4237

4338
startKoin {
39+
androidContext(this@NeoAndroidApp)
4440
modules(
45-
module,
4641
commonModule,
4742
managerModule,
4843
dataSourceModule,

feature/saved/src/commonMain/kotlin/com/neoutils/neoregex/feature/saved/SavedScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ import androidx.compose.material.icons.automirrored.outlined.OpenInNew
3232
import androidx.compose.material.icons.outlined.ContentCopy
3333
import androidx.compose.material.icons.outlined.Delete
3434
import androidx.compose.material.icons.outlined.Edit
35-
import androidx.compose.material3.HorizontalDivider
36-
import androidx.compose.material3.Icon
35+
import androidx.compose.material3.*
3736
import androidx.compose.material3.MaterialTheme.colorScheme
3837
import androidx.compose.material3.MaterialTheme.typography
39-
import androidx.compose.material3.Surface
40-
import androidx.compose.material3.Text
4138
import androidx.compose.runtime.*
4239
import androidx.compose.ui.Alignment
4340
import androidx.compose.ui.Modifier
@@ -226,6 +223,9 @@ private fun Pattern(
226223
Icon(
227224
imageVector = Icons.AutoMirrored.Outlined.OpenInNew,
228225
contentDescription = null,
226+
tint = LocalContentColor.current.copy(
227+
alpha = if (pattern.opened) 0.5f else 1f
228+
),
229229
modifier = Modifier
230230
.clip(CircleShape)
231231
.clickable(

feature/validator/src/commonMain/kotlin/com/neoutils/neoregex/feature/validator/usecase/ValidateUseCase.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,27 @@ package com.neoutils.neoregex.feature.validator.usecase
2121
import com.neoutils.neoregex.core.common.model.Match
2222
import com.neoutils.neoregex.core.common.model.TestCase
2323
import com.neoutils.neoregex.feature.validator.model.TestCaseValidation
24+
import kotlinx.coroutines.Dispatchers
25+
import kotlinx.coroutines.withContext
2426

2527
class ValidateUseCase {
2628

27-
operator fun invoke(
29+
suspend operator fun invoke(
2830
testCase: TestCase,
2931
regex: Regex
3032
): TestCaseValidation {
3133

32-
val results = regex.findAll(testCase.text)
33-
34-
val matches = mutableListOf<Match>()
35-
36-
results.mapIndexedTo(matches) { index, match ->
37-
Match(
38-
text = match.value,
39-
range = match.range,
40-
groups = match.groupValues.drop(n = 1),
41-
number = index.inc(),
42-
)
34+
val matches = withContext(Dispatchers.Default) {
35+
regex
36+
.findAll(testCase.text)
37+
.mapIndexedTo(mutableListOf()) { index, match ->
38+
Match(
39+
text = match.value,
40+
range = match.range,
41+
groups = match.groupValues.drop(n = 1),
42+
number = index.inc(),
43+
)
44+
}
4345
}
4446

4547
return when (testCase.case) {

0 commit comments

Comments
 (0)