mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
add app di
This commit is contained in:
parent
6cd437175a
commit
bd15c47b69
10 changed files with 116 additions and 3 deletions
|
@ -50,10 +50,10 @@ ext {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':core_utils')
|
||||
|
||||
def applicationDependencies = rootProject.ext.mainApplication
|
||||
def unitTestDependencies = rootProject.ext.unitTesting
|
||||
def acceptanceTestDependencies = rootProject.ext.acceptanceTesting
|
||||
def developmentDependencies = rootProject.ext.development
|
||||
|
||||
//Compile time dependencies
|
||||
kapt applicationDependencies.daggerCompiler
|
||||
|
@ -72,6 +72,8 @@ dependencies {
|
|||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
|
||||
implementation applicationDependencies.glide
|
||||
implementation applicationDependencies.dagger
|
||||
implementation applicationDependencies.timber
|
||||
|
||||
//Redactor
|
||||
implementation 'com.ebolo:krichtexteditor:0.0.5'
|
||||
|
|
|
@ -3,16 +3,25 @@
|
|||
package="com.agileburo.anytype">
|
||||
|
||||
<application
|
||||
android:name=".AndroidApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:fullBackupContent="@xml/my_backup_rules"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter android:label="filter">
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http"
|
||||
android:host="www.anytype.io"
|
||||
android:pathPrefix="/todo" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package com.agileburo.anytype
|
||||
|
||||
import android.app.Application
|
||||
import com.agileburo.anytype.di.app.AppModule
|
||||
import com.agileburo.anytype.di.app.ApplicationComponent
|
||||
import com.agileburo.anytype.di.app.DaggerApplicationComponent
|
||||
import timber.log.Timber
|
||||
|
||||
class AndroidApplication : Application() {
|
||||
|
||||
|
||||
val applicationComponent: ApplicationComponent by lazy {
|
||||
DaggerApplicationComponent.builder()
|
||||
.appModule(AppModule(this))
|
||||
.build()
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
injectMembers()
|
||||
if(BuildConfig.DEBUG) {
|
||||
Timber.plant(Timber.DebugTree())
|
||||
}
|
||||
}
|
||||
|
||||
private fun injectMembers() = applicationComponent.inject(this)
|
||||
}
|
|
@ -1,13 +1,29 @@
|
|||
package com.agileburo.anytype
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.agileburo.anytype.di.app.MainScreenComponent
|
||||
import com.ebolo.krichtexteditor.fragments.kRichEditorFragment
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var context: Context
|
||||
|
||||
private val applicationComponent by lazy {
|
||||
(application as AndroidApplication).applicationComponent
|
||||
}
|
||||
|
||||
private val mainScreenComponent: MainScreenComponent by lazy {
|
||||
applicationComponent.mainScreenComponent()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
mainScreenComponent.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
btnART.setOnClickListener {
|
||||
|
@ -18,5 +34,6 @@ class MainActivity : AppCompatActivity() {
|
|||
.commit()
|
||||
|
||||
}
|
||||
Timber.d("Get context:$context")
|
||||
}
|
||||
}
|
||||
|
|
15
app/src/main/java/com/agileburo/anytype/di/app/AppModule.kt
Normal file
15
app/src/main/java/com/agileburo/anytype/di/app/AppModule.kt
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.agileburo.anytype.di.app
|
||||
|
||||
import android.content.Context
|
||||
import com.agileburo.anytype.AndroidApplication
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class AppModule(private val app: AndroidApplication) {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideContext(): Context = app.applicationContext
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.agileburo.anytype.di.app
|
||||
|
||||
import android.content.Context
|
||||
import com.agileburo.anytype.AndroidApplication
|
||||
import dagger.Component
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
@Component(modules = [AppModule::class])
|
||||
interface ApplicationComponent {
|
||||
|
||||
fun inject(app: AndroidApplication)
|
||||
fun mainScreenComponent(): MainScreenComponent
|
||||
fun context(): Context
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.agileburo.anytype.di.app
|
||||
|
||||
import com.agileburo.anytype.MainActivity
|
||||
import com.agileburo.anytype.core_utils.di.PerScreen
|
||||
import dagger.Subcomponent
|
||||
|
||||
@PerScreen
|
||||
@Subcomponent(modules = [MainScreenModule::class])
|
||||
interface MainScreenComponent{
|
||||
|
||||
fun inject(mainScreen: MainActivity)
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.agileburo.anytype.di.app
|
||||
|
||||
import dagger.Module
|
||||
|
||||
@Module
|
||||
class MainScreenModule{
|
||||
|
||||
|
||||
}
|
4
app/src/main/res/xml/my_backup_rules.xml
Normal file
4
app/src/main/res/xml/my_backup_rules.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
<include domain="sharedpref" path="."/>
|
||||
</full-backup-content>
|
|
@ -25,6 +25,7 @@ ext {
|
|||
javaxInject_version = '1'
|
||||
retrofit_version = '2.3.0'
|
||||
okhttp_logging_interceptor_version = '3.8.1'
|
||||
timber_version = '4.7.1'
|
||||
|
||||
//Unit Testing
|
||||
robolectric_version = '3.8'
|
||||
|
@ -61,6 +62,7 @@ ext {
|
|||
javaxInject: "javax.inject:javax.inject:$javaxInject_version",
|
||||
retrofit: "com.squareup.retrofit2:converter-gson:$retrofit_version",
|
||||
okhttpLoggingInterceptor: "com.squareup.okhttp3:logging-interceptor:$okhttp_logging_interceptor_version",
|
||||
timber: "com.jakewharton.timber:timber:$timber_version"
|
||||
]
|
||||
|
||||
unitTesting = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue