Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 12, 2025
1 parent 8c5ec0d commit 1703139
Show file tree
Hide file tree
Showing 47 changed files with 114 additions and 39 deletions.
1 change: 1 addition & 0 deletions gauguin-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {
applicationId = "org.piepmeyer.gauguin"
minSdk = 24
targetSdk = 34
testInstrumentationRunner = "org.piepmeyer.gauguin.InstrumentationTestRunner"
}

if (keystoreExists) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.piepmeyer.gauguin

import android.content.SharedPreferences
import org.koin.core.module.Module
import org.koin.core.module.dsl.binds
import org.koin.core.module.dsl.createdAtStart
import org.koin.core.module.dsl.withOptions
import org.piepmeyer.gauguin.preferences.ApplicationPreferences
import org.piepmeyer.gauguin.preferences.ApplicationPreferencesImpl
import org.piepmeyer.gauguin.preferences.StatisticsManager
import org.piepmeyer.gauguin.preferences.StatisticsManagerImpl
import org.piepmeyer.gauguin.ui.ActivityUtils
import java.io.File

class ApplicationModule(
private val filesDir: File,
private val statisticsPreferences: SharedPreferences,
private val applicationPreferences: ApplicationPreferencesImpl,
) {
fun module(): Module =
org.koin.dsl.module {
single {
applicationPreferences
} withOptions { binds(listOf(ApplicationPreferences::class)) }
single {
StatisticsManagerImpl(
filesDir,
statisticsPreferences,
)
} withOptions {
binds(listOf(StatisticsManager::class))
createdAtStart()
}
single { ActivityUtils() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import android.content.Context
import com.google.android.material.color.DynamicColors
import com.google.android.material.color.DynamicColorsOptions
import io.github.oshai.kotlinlogging.KotlinLogging
import org.koin.android.ext.android.get
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.module.dsl.binds
import org.koin.core.module.dsl.createdAtStart
import org.koin.core.module.dsl.withOptions
import org.koin.dsl.module
import org.piepmeyer.gauguin.preferences.ApplicationPreferences
import org.piepmeyer.gauguin.preferences.ApplicationPreferencesImpl
import org.piepmeyer.gauguin.preferences.StatisticsManager
import org.piepmeyer.gauguin.preferences.StatisticsManagerImpl
import org.piepmeyer.gauguin.ui.ActivityUtils
import org.piepmeyer.gauguin.ui.DynamicColorsPrecondition

Expand All @@ -29,42 +23,32 @@ class MainApplication : Application() {

val applicationPreferences = ApplicationPreferencesImpl(this)

val koinApplication =
startKoin {
androidLogger()
androidContext(this@MainApplication)

val statisticsPreferences = getSharedPreferences("stats", Context.MODE_PRIVATE)

applicationPreferences.migrateGridSizeFromTwoToThree()

modules(
CoreModule(filesDir).module(),
ApplicationModule(filesDir, statisticsPreferences, applicationPreferences).module(),
)
}

val options =
DynamicColorsOptions.Builder()
DynamicColorsOptions
.Builder()
.setThemeOverlay(R.style.AppTheme_Overlay)
.setPrecondition(DynamicColorsPrecondition())
.build()

DynamicColors.applyToActivitiesIfAvailable(this, options)

startKoin {
androidLogger()
androidContext(this@MainApplication)

val appModule =
module {
single {
applicationPreferences
} withOptions { binds(listOf(ApplicationPreferences::class)) }
single {
StatisticsManagerImpl(
filesDir,
this@MainApplication.getSharedPreferences("stats", Context.MODE_PRIVATE),
)
} withOptions {
binds(listOf(StatisticsManager::class))
createdAtStart()
}
single { ActivityUtils() }
}

applicationPreferences.migrateGridSizeFromTwoToThree()

modules(
CoreModule(filesDir).module(),
appModule,
)
}
val activityUtils = get<ActivityUtils>()
activityUtils.configureNightMode()

logger.info {
"Gauguin application started successfully, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,25 @@ class ActivityUtils : KoinComponent {
when (applicationPreferences.theme) {
Theme.LIGHT -> {
activity.setTheme(R.style.AppTheme)
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
Theme.DARK -> {
activity.setTheme(R.style.AppTheme)
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
Theme.SYSTEM_DEFAULT, Theme.DYNAMIC_COLORS -> {
activity.setTheme(R.style.AppTheme)
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}

fun configureNightMode() {
when (applicationPreferences.theme) {
Theme.LIGHT -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
Theme.DARK -> {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
}
Theme.SYSTEM_DEFAULT, Theme.DYNAMIC_COLORS -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class NewGameActivity : AppCompatActivity() {
private lateinit var viewModel: NewGameViewModel

public override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
activityUtils.configureTheme(this)

super.onCreate(savedInstanceState)

val binding = ActivityNewgameBinding.inflate(layoutInflater)
setContentView(binding.root)

activityUtils.configureTheme(this)
activityUtils.configureFullscreen(this)

val startNewGameButton = binding.startnewgame
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.piepmeyer.gauguin

import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner

class InstrumentationTestRunner : AndroidJUnitRunner() {
override fun newApplication(
classLoader: ClassLoader?,
className: String?,
context: Context?,
): Application = super.newApplication(classLoader, TestApplication::class.java.name, context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.piepmeyer.gauguin

import android.app.Application
import io.mockk.every
import io.mockk.mockk
import org.koin.core.context.startKoin
import org.piepmeyer.gauguin.preferences.ApplicationPreferencesImpl
import kotlin.io.path.createTempDirectory

class TestApplication : Application() {
override fun onCreate() {
super.onCreate()

val mockedPreferences =
mockk<ApplicationPreferencesImpl> {
every { theme } returns Theme.LIGHT
}

startKoin {
modules(
CoreModule(createTempDirectory().toFile()).module(),
ApplicationModule(createTempDirectory().toFile(), mockk(), mockedPreferences).module(),
)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1703139

Please sign in to comment.