app/src/main/java/com/geekorum/ttrss/Application.kt
author Da Risk <da_risk@geekorum.com>
Tue, 28 May 2019 11:37:55 -0700
changeset 197 304a57b89da3
parent 137 5464f07a306c
child 216 1cace0058630
permissions -rw-r--r--
AppInitializers: sort them to be sure that some are initialized before others We want StrictMode to be initialized first. Crashlytics need to be initialized early in order to be available for Timber logging.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66
f67bb871a52f providers: Use Dagger android injection
Da Risk <da_risk@geekorum.com>
parents: 63
diff changeset
     1
/*
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     2
 * Geekttrss is a RSS feed reader application on the Android Platform.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     3
 *
137
5464f07a306c Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents: 131
diff changeset
     4
 * Copyright (C) 2017-2019 by Frederic-Charles Barthelery.
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     5
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     6
 * This file is part of Geekttrss.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     7
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     8
 * Geekttrss is free software: you can redistribute it and/or modify
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
     9
 * it under the terms of the GNU General Public License as published by
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    10
 * the Free Software Foundation, either version 3 of the License, or
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    11
 * (at your option) any later version.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    12
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    13
 * Geekttrss is distributed in the hope that it will be useful,
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    16
 * GNU General Public License for more details.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    17
 *
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    19
 * along with Geekttrss.  If not, see <http://www.gnu.org/licenses/>.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    20
 */
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    21
package com.geekorum.ttrss
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    22
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    23
import com.geekorum.geekdroid.dagger.AppInitializer
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    24
import com.geekorum.geekdroid.dagger.initialize
131
bd36980e2c08 Add StrictMode configuration
Da Risk <da_risk@geekorum.com>
parents: 77
diff changeset
    25
import com.geekorum.ttrss.debugtools.StrictModeInitializer
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    26
import com.geekorum.ttrss.di.ApplicationComponent
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    27
import com.geekorum.ttrss.di.DaggerApplicationComponent
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    28
import dagger.android.support.DaggerApplication
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    29
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    30
import javax.inject.Inject
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    31
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    32
/**
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    33
 * Initialize global component for the TTRSS application.
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    34
 */
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    35
open class Application : DaggerApplication() {
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    36
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    37
    @Inject
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    38
    lateinit var appInitializers: MutableSet<AppInitializer>
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    39
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    40
    override fun onCreate() {
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    41
        super.onCreate()
197
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    42
        // a few initializers need to be set up before others
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    43
        sortAppInitializers(appInitializers).initialize(this)
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    44
    }
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    45
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    46
    protected open fun sortAppInitializers(initializers: Set<AppInitializer>): List<AppInitializer> {
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    47
        val result = mutableListOf<AppInitializer>()
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    48
        val strictModeInitializer = initializers.find { it is StrictModeInitializer }
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    49
        strictModeInitializer?.let { result.add(it) }
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    50
        result.addAll(initializers)
304a57b89da3 AppInitializers: sort them to be sure that some are initialized before others
Da Risk <da_risk@geekorum.com>
parents: 137
diff changeset
    51
        return result.distinct()
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    52
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    53
77
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    54
    override fun applicationInjector(): ApplicationComponent {
961585710d33 Add DefaultNightModeInitializer
Da Risk <da_risk@geekorum.com>
parents: 74
diff changeset
    55
        return DaggerApplicationComponent.builder().bindApplication(this).build()
0
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    56
    }
14443efede32 Initial commit
Da Risk <da_risk@geekorum.com>
parents:
diff changeset
    57
}