Skip to content

Commit c940238

Browse files
u_m10asu_m10as
authored andcommitted
Initial commit
0 parents  commit c940238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+928
-0
lines changed

.gitignore

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Built application files
2+
*.apk
3+
*.aar
4+
*.ap_
5+
*.aab
6+
7+
# Files for the ART/Dalvik VM
8+
*.dex
9+
10+
# Java class files
11+
*.class
12+
13+
# Generated files
14+
bin/
15+
gen/
16+
out/
17+
# Uncomment the following line in case you need and you don't have the release build type files in your app
18+
# release/
19+
20+
# Gradle files
21+
.gradle/
22+
build/
23+
24+
# Local configuration file (sdk path, etc)
25+
local.properties
26+
27+
# Proguard folder generated by Eclipse
28+
proguard/
29+
30+
# Log Files
31+
*.log
32+
33+
# Android Studio Navigation editor temp files
34+
.navigation/
35+
36+
# Android Studio captures folder
37+
captures/
38+
39+
# IntelliJ
40+
*.iml
41+
.idea
42+
43+
# Keystore files
44+
# Uncomment the following lines if you do not want to check your keystore files in.
45+
#*.jks
46+
#*.keystore
47+
48+
# External native build folder generated in Android Studio 2.2 and later
49+
.externalNativeBuild
50+
.cxx/
51+
52+
# Google Services (e.g. APIs or Firebase)
53+
# google-services.json
54+
55+
# Freeline
56+
freeline.py
57+
freeline/
58+
freeline_project_description.json
59+
60+
# fastlane
61+
fastlane/report.xml
62+
fastlane/Preview.html
63+
fastlane/screenshots
64+
fastlane/test_output
65+
fastlane/readme.md
66+
67+
# Version control
68+
vcs.xml
69+
70+
# lint
71+
lint/intermediates/
72+
lint/generated/
73+
lint/outputs/
74+
lint/tmp/
75+
# lint/reports/
76+
77+
# Android Profiling
78+
*.hprof

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### Реализуйте ApplicationComponent
2+
Это корень нашего дерева компонентов. Инициализируется в классе App, прокидывает в граф через Component Dependencies/Subcomponents ниже по графу следующие сущности:
3+
- Context(Application) до FragmentProducerComponent и FragmentReceiverComponent.
4+
Проброс Context в граф реализуйте через BindsInstance + ComponentFactory
5+
6+
### Реализуйте MainActivityComponent
7+
Инициализируется в MainActivity
8+
Добавляет в граф Context(Activity) и через провижен метод/сабкомпоненты прокидывает его компонентам ниже по графу. Проброс реализуйте через BindsInstance + ComponentFactory
9+
Подключите в MainActivityComponent модуль MainActivityModule:
10+
Создает scoped обсервер(Coroutine Channel/StateFlow/Subject либо другую реализацию обсервера). Он понадобится нам чтобы отправлять евенты из одного фрагмента и принимать их в другом, в обоих фрагментах должен быть один и тот же инстанс обсервера.
11+
12+
### FragmentReceiverComponent/FragmentProducerComponent
13+
Коммуникацию между Producer и Receiver осуществите через канал/StateFlow/Subject либо другую реализацию обсервера которая уже есть в графе. ViewModelProducer должна отправлять эвенты, ViewModelReceiver должна получать эвенты. Обсерверы должны прокидываться в конструкторы вьюмоделей и существовать в единственном экземпляре в Activity.
14+
Флоу отправки эвента выглядит следующим образом:
15+
Клик на кнопку button в FragmentProducer -> вызов метода вьюмодели -> проброс евента в обсервер -> евент ловится на стороне ViewModelReceiver -> евент передается FragmentReceiver и вызывается функция ru.otus.daggerhomework.FragmentReceiver#populateColor

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
id 'kotlin-kapt'
5+
}
6+
7+
android {
8+
compileSdkVersion 30
9+
buildToolsVersion "30.0.3"
10+
11+
defaultConfig {
12+
applicationId "ru.otus.daggerhomework"
13+
minSdkVersion 23
14+
targetSdkVersion 30
15+
versionCode 1
16+
versionName "1.0"
17+
18+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
minifyEnabled false
24+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25+
}
26+
}
27+
compileOptions {
28+
sourceCompatibility JavaVersion.VERSION_1_8
29+
targetCompatibility JavaVersion.VERSION_1_8
30+
}
31+
kotlinOptions {
32+
jvmTarget = '1.8'
33+
}
34+
}
35+
36+
dependencies {
37+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
38+
implementation 'androidx.core:core-ktx:1.6.0'
39+
implementation 'androidx.appcompat:appcompat:1.3.1'
40+
implementation 'com.google.android.material:material:1.4.0'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
42+
implementation 'com.google.dagger:dagger:2.38.1'
43+
kapt 'com.google.dagger:dagger-compiler:2.38.1'
44+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
package="ru.otus.daggerhomework">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/Theme.DaggerHomework">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package ru.otus.daggerhomework
2+
3+
import android.app.Application
4+
5+
class App :Application() {
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package ru.otus.daggerhomework
2+
3+
interface ApplicationComponent {
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.otus.daggerhomework
2+
3+
import android.graphics.Color
4+
import androidx.annotation.ColorInt
5+
import androidx.annotation.ColorRes
6+
import java.util.*
7+
8+
interface ColorGenerator {
9+
10+
@ColorInt
11+
fun generateColor(): Int
12+
}
13+
14+
class ColorGeneratorImpl : ColorGenerator {
15+
16+
override fun generateColor(): Int {
17+
val rnd = Random()
18+
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.otus.daggerhomework
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.Button
8+
import androidx.fragment.app.Fragment
9+
10+
class FragmentProducer : Fragment() {
11+
12+
override fun onCreateView(
13+
inflater: LayoutInflater,
14+
container: ViewGroup?,
15+
savedInstanceState: Bundle?
16+
): View? {
17+
return inflater.inflate(R.layout.fragment_a, container, true)
18+
}
19+
20+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
21+
super.onViewCreated(view, savedInstanceState)
22+
view.findViewById<Button>(R.id.button).setOnClickListener {
23+
//отправить результат через livedata в другой фрагмент
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)