Move night mode initialization to WulkanowyApp (#180)

Fixes #162
This commit is contained in:
Mikołaj Pich 2018-11-10 23:24:33 +01:00 committed by Rafał Borcz
parent 2f24b25399
commit 2b60f555e9
6 changed files with 10 additions and 20 deletions

View File

@ -1,5 +1,3 @@
exclude:
- /app/src/main/java/io/github/wulkanowy/data/db/dao/entities/.*
component_depth: 1
component_depth: 8
languages:
- java
- kotlin

View File

@ -1,6 +1,7 @@
package io.github.wulkanowy
import android.content.Context
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDex
import com.akaita.java.rxjava2debug.RxJava2Debug
import com.crashlytics.android.Crashlytics
@ -13,13 +14,18 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.utils.Log
import io.fabric.sdk.android.Fabric
import io.github.wulkanowy.BuildConfig.DEBUG
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.di.DaggerAppComponent
import io.github.wulkanowy.utils.CrashlyticsTree
import io.github.wulkanowy.utils.DebugLogTree
import timber.log.Timber
import javax.inject.Inject
class WulkanowyApp : DaggerApplication() {
@Inject
lateinit var prefRepository: PreferencesRepository
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
MultiDex.install(this)
@ -31,6 +37,7 @@ class WulkanowyApp : DaggerApplication() {
initializeFabric()
if (DEBUG) enableDebugLog()
RxJava2Debug.enableRxJava2AssemblyTracking(arrayOf(BuildConfig.APPLICATION_ID))
AppCompatDelegate.setDefaultNightMode(prefRepository.currentTheme)
}
private fun enableDebugLog() {

View File

@ -1,12 +1,10 @@
package io.github.wulkanowy.ui.modules.splash
import android.os.Bundle
import io.github.wulkanowy.services.notification.GradeNotification
import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.modules.login.LoginActivity
import io.github.wulkanowy.ui.modules.main.MainActivity
import javax.inject.Inject
import androidx.appcompat.app.AppCompatDelegate
class SplashActivity : BaseActivity(), SplashView {
@ -28,10 +26,6 @@ class SplashActivity : BaseActivity(), SplashView {
finish()
}
override fun setCurrentThemeMode(mode: Int) {
AppCompatDelegate.setDefaultNightMode(mode)
}
override fun onDestroy() {
presenter.onDetachView()
super.onDestroy()

View File

@ -1,7 +1,6 @@
package io.github.wulkanowy.ui.modules.splash
import io.github.wulkanowy.data.ErrorHandler
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.data.repositories.SessionRepository
import io.github.wulkanowy.ui.base.BasePresenter
import io.github.wulkanowy.utils.logLogin
@ -9,14 +8,12 @@ import javax.inject.Inject
class SplashPresenter @Inject constructor(
private val sessionRepository: SessionRepository,
private val preferencesRepository: PreferencesRepository,
errorHandler: ErrorHandler
) : BasePresenter<SplashView>(errorHandler) {
override fun onAttachView(view: SplashView) {
super.onAttachView(view)
view.run {
setCurrentThemeMode(preferencesRepository.currentTheme)
if (sessionRepository.isSessionSaved) {
logLogin("Open app")
openMainView()

View File

@ -7,6 +7,4 @@ interface SplashView : BaseView {
fun openLoginView()
fun openMainView()
fun setCurrentThemeMode(mode: Int)
}

View File

@ -1,7 +1,6 @@
package io.github.wulkanowy.ui.modules.splash
import io.github.wulkanowy.data.ErrorHandler
import io.github.wulkanowy.data.repositories.PreferencesRepository
import io.github.wulkanowy.data.repositories.SessionRepository
import org.junit.Before
import org.junit.Test
@ -21,15 +20,12 @@ class SplashPresenterTest {
@Mock
lateinit var errorHandler: ErrorHandler
@Mock
lateinit var preferencesRepository: PreferencesRepository
private lateinit var presenter: SplashPresenter
@Before
fun initPresenter() {
MockitoAnnotations.initMocks(this)
presenter = SplashPresenter(sessionRepository, preferencesRepository, errorHandler)
presenter = SplashPresenter(sessionRepository, errorHandler)
}
@Test