Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Готовая домашняя работа #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
23 changes: 15 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id("org.jetbrains.kotlin.kapt")
}

android {
namespace 'ru.otus.basicarchitecture'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "ru.otus.basicarchitecture"
minSdk 24
targetSdk 33
minSdk = 26
targetSdk = 34
versionCode 1
versionName "1.0"

Expand All @@ -24,19 +25,25 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}


}

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
//dagger2
implementation("com.google.dagger:dagger:2.48.1")
kapt("com.google.dagger:dagger-compiler:2.48.1")

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -13,8 +14,17 @@
android:theme="@style/Theme.BasicArchitecture"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="false" />
android:name=".presentation.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>



</application>

</manifest>
10 changes: 10 additions & 0 deletions app/src/main/java/ru/otus/basicarchitecture/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ru.otus.basicarchitecture

import android.app.Application
import ru.otus.basicarchitecture.DI.MainComponent.DaggerMainComponent

class App : Application() {
val component by lazy {
DaggerMainComponent.builder().build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.FirstScreen

import dagger.Subcomponent
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.presentation.FirstScreen.FirstScreenFragment


/**
* Подкомпонент для первого фрагмента
*/
@FragmentScope
@Subcomponent(modules = [PersonModule::class, FirstViewModelModule::class])
interface FirstScreenSubComponent {

@Subcomponent.Builder
interface Builder {
fun build() : FirstScreenSubComponent
}

fun inject(fragmentFirst: FirstScreenFragment)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.FirstScreen

import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import dagger.multibindings.StringKey
import ru.otus.basicarchitecture.presentation.FirstScreen.FirstScreenViewModel

@Module
interface FirstViewModelModule {

@IntoMap
@StringKey("FirstScreenViewModel")
@Binds
fun bindFirstScreenViewModel(impl: FirstScreenViewModel): ViewModel

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.FirstScreen

import dagger.Module
import dagger.Provides
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.domain.Model.Address
import ru.otus.basicarchitecture.domain.Model.Person

@Module
class PersonModule {
@FragmentScope
@Provides
fun providePerson(): Person{
return Person.defaultPerson()
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.FourthScreen

import dagger.Subcomponent
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.presentation.FourthScreen.FourthScreenFragment

@FragmentScope
@Subcomponent(modules = [FourthViewModelModule::class])
interface FourthScreenSubComponent {


@Subcomponent.Builder
interface Builder {
fun build() : FourthScreenSubComponent
}

fun inject(fragment: FourthScreenFragment)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.FourthScreen

import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import dagger.multibindings.StringKey
import ru.otus.basicarchitecture.presentation.FourthScreen.FourthScreenViewModel


@Module
interface FourthViewModelModule {

@IntoMap
@StringKey("FourthScreenViewModel")
@Binds
fun bindFourthScreenViewModel(impl: FourthScreenViewModel): ViewModel
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.otus.basicarchitecture.DI.FragmentComponents

import javax.inject.Scope

//Синглтон внутри сабкомпонентов для фрагментов
@Scope
@Retention(value = AnnotationRetention.RUNTIME)
annotation class FragmentScope()
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.SecondScreen

import dagger.Module
import dagger.Provides
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.domain.Model.Address

@Module
class AddressModule {
@FragmentScope
@Provides
fun providesAddress(): Address{
return Address("","","")
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.SecondScreen

import dagger.Subcomponent
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.presentation.SecondScreen.SecondScreenFragment
import ru.otus.basicarchitecture.presentation.SecondScreen.SecondScreenViewModel


@FragmentScope
@Subcomponent(modules = [AddressModule::class, SecondViewModelModule::class])
interface SecondScreenSubComponent {

@Subcomponent.Builder
interface Builder {
fun build() : SecondScreenSubComponent
}

fun inject(fragmentSecond: SecondScreenFragment)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.SecondScreen

import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import dagger.multibindings.StringKey
import ru.otus.basicarchitecture.presentation.SecondScreen.SecondScreenViewModel
@Module
interface SecondViewModelModule {

@IntoMap
@StringKey("SecondScreenViewModel")
@Binds
fun bindSecondScreenViewModel(impl: SecondScreenViewModel): ViewModel

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.ThirdScreen

import dagger.Subcomponent
import ru.otus.basicarchitecture.DI.FragmentComponents.FragmentScope
import ru.otus.basicarchitecture.presentation.ThirdScreen.ThirdScreenFragment

@FragmentScope
@Subcomponent(modules = [ThirdViewModelModule::class])
interface ThirdScreenSubComponent {

@Subcomponent.Builder
interface Builder {
fun build() : ThirdScreenSubComponent
}

fun inject(fragmentThird: ThirdScreenFragment)


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.otus.basicarchitecture.DI.FragmentComponents.ThirdScreen

import androidx.lifecycle.ViewModel
import dagger.Binds
import dagger.Module
import dagger.multibindings.IntoMap
import dagger.multibindings.StringKey
import ru.otus.basicarchitecture.presentation.ThirdScreen.ThirdScreenViewModel

@Module
interface ThirdViewModelModule {

@IntoMap
@StringKey("ThirdScreenViewModel")
@Binds
fun bindThirdScreenViewModel(impl: ThirdScreenViewModel): ViewModel

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.otus.basicarchitecture.DI.MainComponent

import dagger.Component
import ru.otus.basicarchitecture.DI.FragmentComponents.FirstScreen.FirstScreenSubComponent
import ru.otus.basicarchitecture.DI.FragmentComponents.FourthScreen.FourthScreenSubComponent
import ru.otus.basicarchitecture.DI.FragmentComponents.SecondScreen.SecondScreenSubComponent
import ru.otus.basicarchitecture.DI.FragmentComponents.ThirdScreen.ThirdScreenSubComponent
import ru.otus.basicarchitecture.data.WizardCache
import ru.otus.basicarchitecture.domain.Repository
import javax.inject.Singleton

@Singleton
@Component(modules = [WizardCacheModule::class, RepositoryModule::class])
interface MainComponent {
fun firstScreenSubComponent() : FirstScreenSubComponent.Builder

fun secondScreenSubComponent() : SecondScreenSubComponent.Builder

fun thirdScreenSubComponent() : ThirdScreenSubComponent.Builder

fun fourthScreenSubComponent(): FourthScreenSubComponent.Builder

fun wizardCache(): WizardCache

fun repository(): Repository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.otus.basicarchitecture.DI.MainComponent

import dagger.Binds
import dagger.Module
import ru.otus.basicarchitecture.data.RepositoryImpl
import ru.otus.basicarchitecture.domain.Repository
import javax.inject.Singleton

@Module
interface RepositoryModule {
@Singleton
@Binds
fun getRepository(impl: RepositoryImpl) : Repository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.otus.basicarchitecture.DI.MainComponent

import dagger.Module
import dagger.Provides
import ru.otus.basicarchitecture.data.WizardCache
import javax.inject.Singleton

@Module
class WizardCacheModule {
@Singleton
@Provides
fun provideWizardCache() : WizardCache{
return WizardCache(
"",
"",
"",
"",
"",
"",
""
)
}
}
11 changes: 0 additions & 11 deletions app/src/main/java/ru/otus/basicarchitecture/MainActivity.kt

This file was deleted.

Loading