Implemented setting up dependency injection in Application class to fix at least in first instance that when restoring a Dialog that MainActivity hasn't been restored and therefore dependency injection not instantiated yet (still missing: set latest Activity in BankingModule / RouterAndroid)
This commit is contained in:
parent
07144c2a2d
commit
35572a0906
|
@ -6,17 +6,20 @@
|
|||
|
||||
|
||||
<application
|
||||
android:testOnly="false"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
android:name=".BankingApp"
|
||||
android:testOnly="false"
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package net.dankito.banking.fints4java.android
|
||||
|
||||
import android.app.Application
|
||||
import net.dankito.banking.fints4java.android.di.BankingComponent
|
||||
import net.dankito.banking.fints4java.android.di.BankingModule
|
||||
import net.dankito.banking.fints4java.android.di.DaggerBankingComponent
|
||||
|
||||
|
||||
class BankingApp : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
setupDependencyInjection()
|
||||
}
|
||||
|
||||
private fun setupDependencyInjection() {
|
||||
val component = DaggerBankingComponent.builder()
|
||||
.bankingModule(BankingModule(this))
|
||||
.build()
|
||||
|
||||
BankingComponent.component = component
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@ import com.github.clans.fab.FloatingActionMenu
|
|||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import net.dankito.banking.fints4java.android.di.BankingComponent
|
||||
import net.dankito.banking.fints4java.android.di.BankingModule
|
||||
import net.dankito.banking.fints4java.android.di.DaggerBankingComponent
|
||||
import net.dankito.banking.fints4java.android.ui.views.DrawerView
|
||||
import net.dankito.banking.fints4java.android.ui.views.MainActivityFloatingActionMenuButton
|
||||
import net.dankito.banking.ui.presenter.BankingPresenter
|
||||
|
@ -42,21 +41,13 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setupDependencyInjection()
|
||||
BankingModule.mainActivity = this
|
||||
|
||||
BankingComponent.component.inject(this)
|
||||
|
||||
initUi()
|
||||
}
|
||||
|
||||
private fun setupDependencyInjection() {
|
||||
val component = DaggerBankingComponent.builder()
|
||||
.bankingModule(BankingModule(this))
|
||||
.build()
|
||||
|
||||
BankingComponent.component = component
|
||||
}
|
||||
|
||||
private fun initUi() {
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import javax.inject.Singleton
|
|||
|
||||
|
||||
@Module
|
||||
class BankingModule(internal val mainActivity: AppCompatActivity) {
|
||||
class BankingModule(private val applicationContext: Context) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -40,12 +40,11 @@ class BankingModule(internal val mainActivity: AppCompatActivity) {
|
|||
|
||||
const val IndexFolderKey = "index.folder"
|
||||
|
||||
// TODO: implement activity listener to always get latest activity
|
||||
lateinit var mainActivity: AppCompatActivity
|
||||
}
|
||||
|
||||
|
||||
private val applicationContext = mainActivity.applicationContext
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideApplicationContext() : Context {
|
||||
|
|
Loading…
Reference in New Issue