-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f758bd
commit cdd2cb4
Showing
27 changed files
with
353 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/androidInstrumentedTest/kotlin/br/alexandregpereira/hunter/app/KoinTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package br.alexandregpereira.hunter.app | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import br.alexandregpereira.hunter.data.Database | ||
import br.alexandregpereira.hunter.localization.Language | ||
import com.russhwolf.settings.MapSettings | ||
import com.russhwolf.settings.Settings | ||
import com.squareup.sqldelight.android.AndroidSqliteDriver | ||
import com.squareup.sqldelight.db.SqlDriver | ||
import org.koin.core.context.startKoin | ||
import org.koin.dsl.module | ||
|
||
internal class KoinTestRunner : AndroidJUnitRunner() { | ||
|
||
override fun newApplication( | ||
cl: ClassLoader?, | ||
className: String?, | ||
context: Context? | ||
): Application { | ||
return super.newApplication(cl, KoinTestApplication::class.qualifiedName, context) | ||
} | ||
} | ||
|
||
internal class KoinTestApplication : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
startKoin { | ||
initAndroidModules(this@KoinTestApplication) | ||
allowOverride(true) | ||
module { | ||
factory<SqlDriver> { | ||
AndroidSqliteDriver( | ||
schema = Database.Schema, | ||
context = get<Application>(), | ||
name = null | ||
) | ||
} | ||
single<Settings> { MapSettings() } | ||
factory<Language> { Language.ENGLISH } | ||
}.also { | ||
modules(it) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/sync/IsFirstTimeUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package br.alexandregpereira.hunter.domain.sync | ||
|
||
import br.alexandregpereira.hunter.domain.settings.SettingsRepository | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.single | ||
|
||
fun interface IsFirstTime { | ||
suspend operator fun invoke(): Boolean | ||
} | ||
|
||
fun interface ResetFirstTime { | ||
suspend operator fun invoke() | ||
} | ||
|
||
private const val IsFirstTimeKey = "isFirstTimeKey" | ||
|
||
|
||
internal fun IsFirstTime( | ||
repository: SettingsRepository, | ||
): IsFirstTime = IsFirstTime { | ||
repository.getInt(key = IsFirstTimeKey).map { it ?: 1 }.map { it == 1 }.single() | ||
} | ||
|
||
internal fun ResetFirstTime( | ||
repository: SettingsRepository, | ||
): ResetFirstTime = ResetFirstTime { | ||
repository.saveInt(key = IsFirstTimeKey, value = 0).single() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.