Skip to content

Commit 8acffdd

Browse files
committed
RecyclerViewExample module added
1 parent 17e0ddc commit 8acffdd

File tree

29 files changed

+321
-48
lines changed

29 files changed

+321
-48
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ dependencies {
5454
implementation project(path: ':features:example1')
5555

5656
implementation dagger
57+
implementation project(path: ':features:recycler_view_example')
5758
kapt daggerCompiler
5859
}

app/src/main/java/ru/bis/basearchitectureexample/App.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import ru.bis.example2.di.modules.CacheModule as Example2CacheModule
88
import ru.bis.example1.di.modules.CacheModule as Example1CacheModule
99
import ru.sir.presentation.base.BaseApplication
1010
import ru.sir.presentation.base.BaseDaggerComponent
11+
import ru.sir.recycler_view_example.di.components.RecyclerViewExampleComponent
12+
import ru.sir.recycler_view_example.di.modules.CacheModule as RecyclerViewExampleCacheModule
1113
import java.lang.IllegalArgumentException
1214

1315
class App : BaseApplication() {
@@ -28,6 +30,7 @@ class App : BaseApplication() {
2830
return when(type) {
2931
Example1Component::class.java -> appComponent.createExample1Component().create(Example1CacheModule(this))
3032
Example2Component::class.java -> appComponent.createExample2Component().create(Example2CacheModule(this))
33+
RecyclerViewExampleComponent::class.java -> appComponent.createRecyclerViewExampleComponent().create(RecyclerViewExampleCacheModule(this))
3134
else -> throw IllegalArgumentException("Dagger component not provided: $type")
3235
}
3336
}

app/src/main/java/ru/bis/basearchitectureexample/di/components/AppComponent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package ru.bis.basearchitectureexample.di.components
33
import dagger.Component
44
import ru.bis.example1.di.components.Example1Component
55
import ru.bis.example2.di.components.Example2Component
6+
import ru.sir.recycler_view_example.di.components.RecyclerViewExampleComponent
67

78
@Component
89
interface AppComponent {
910
fun createExample1Component(): Example1Component.Factory
1011
fun createExample2Component(): Example2Component.Factory
12+
fun createRecyclerViewExampleComponent(): RecyclerViewExampleComponent.Factory
1113
}

features/example1/src/main/java/ru/bis/example1/view_models/Example1ViewModel.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,18 @@ package ru.bis.example1.view_models
22

33
import android.app.Application
44
import androidx.databinding.ObservableField
5-
import ru.bis.example1.BR
65
import ru.bis.example1.R
76
import ru.bis.example1_api.interactor.GetDataFromCache
87
import ru.sir.core.None
98
import ru.sir.presentation.base.BaseViewModel
10-
import ru.sir.presentation.base.recycler_view.RecyclerViewAdapter
11-
import ru.sir.presentation.base.recycler_view.RecyclerViewBaseDataModel
129
import javax.inject.Inject
1310

1411
class Example1ViewModel @Inject constructor(
1512
application: Application,
1613
private val getDataFromCache: GetDataFromCache
1714
) : BaseViewModel(application) {
1815

19-
companion object {
20-
private const val RV_TITLE = 1
21-
private const val RV_ITEM = 2
22-
}
23-
2416
val result = ObservableField<String>()
25-
val items = mutableListOf(
26-
RecyclerViewBaseDataModel("Title 1", RV_TITLE),
27-
RecyclerViewBaseDataModel("Label 1", RV_ITEM),
28-
RecyclerViewBaseDataModel("Title 2", RV_TITLE),
29-
RecyclerViewBaseDataModel("Label 1", RV_ITEM),
30-
RecyclerViewBaseDataModel("Label 2", RV_ITEM),
31-
RecyclerViewBaseDataModel("Label 3", RV_ITEM),
32-
RecyclerViewBaseDataModel("Title 3", RV_TITLE),
33-
RecyclerViewBaseDataModel("Label 1", RV_ITEM),
34-
RecyclerViewBaseDataModel("Label 2", RV_ITEM),
35-
RecyclerViewBaseDataModel("Label 3", RV_ITEM),
36-
RecyclerViewBaseDataModel("Label 4", RV_ITEM)
37-
)
3817

3918
override fun init() {
4019
getDataFromCache(None()) { it.either(::onLoadDataFromCacheFailed, ::onLoadDataFromCacheSuccess) }
@@ -47,9 +26,4 @@ class Example1ViewModel @Inject constructor(
4726
private fun onLoadDataFromCacheFailed(failed: None) {
4827
result.set(context.getString(R.string.load_data_failed))
4928
}
50-
51-
fun recyclerViewAdapter() = RecyclerViewAdapter.Builder(this, BR.viewModel)
52-
.addProducer(RV_TITLE, R.layout.item_title, String::class.java, TitleViewModel::class.java)
53-
.addProducer(RV_ITEM, R.layout.item_example1, String::class.java, ItemViewModel::class.java)
54-
.build(items)
5529
}

features/example1/src/main/res/layout/fragment_example1.xml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
android:id="@+id/text"
2929
android:layout_width="wrap_content"
3030
android:layout_height="wrap_content"
31-
app:layout_constraintBottom_toTopOf="@id/rvExample"
31+
app:layout_constraintBottom_toTopOf="@id/nextBtn"
3232
app:layout_constraintEnd_toEndOf="parent"
3333
app:layout_constraintStart_toStartOf="parent"
3434
app:layout_constraintTop_toBottomOf="@id/title"
@@ -37,26 +37,14 @@
3737

3838
<Button
3939
android:id="@+id/nextBtn"
40-
android:layout_width="wrap_content"
40+
android:layout_width="0dp"
4141
android:layout_height="wrap_content"
4242
app:layout_constraintTop_toTopOf="parent"
4343
app:layout_constraintEnd_toEndOf="parent"
44-
app:layout_constraintBottom_toTopOf="@id/rvExample"
45-
app:layout_constraintStart_toStartOf="parent"
46-
app:layout_constraintHorizontal_bias="0.95"
47-
android:text="NEXT"/>
48-
49-
<androidx.recyclerview.widget.RecyclerView
50-
android:id="@+id/rvExample"
51-
android:layout_height="0dp"
52-
android:layout_width="match_parent"
53-
app:layout_constraintTop_toBottomOf="@id/text"
5444
app:layout_constraintBottom_toBottomOf="parent"
5545
app:layout_constraintStart_toStartOf="parent"
56-
app:layout_constraintEnd_toEndOf="parent"
57-
app:recyclerAdapter="@{viewModel.recyclerViewAdapter()}"
58-
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
59-
tools:listitem="@layout/item_example1"/>
46+
app:layout_constraintVertical_bias="0.95"
47+
android:text="Jump to Example 2"/>
6048

6149
</androidx.constraintlayout.widget.ConstraintLayout>
6250
</layout>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
id 'kotlin-kapt'
5+
}
6+
7+
android {
8+
compileSdkVersion 30
9+
buildToolsVersion "30.0.2"
10+
11+
defaultConfig {
12+
minSdkVersion 21
13+
targetSdkVersion 30
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
consumerProguardFiles "consumer-rules.pro"
19+
}
20+
21+
viewBinding {
22+
enabled = true
23+
}
24+
25+
dataBinding {
26+
enabled = true
27+
}
28+
29+
buildTypes {
30+
release {
31+
minifyEnabled false
32+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
33+
}
34+
}
35+
compileOptions {
36+
sourceCompatibility JavaVersion.VERSION_1_8
37+
targetCompatibility JavaVersion.VERSION_1_8
38+
}
39+
kotlinOptions {
40+
jvmTarget = '1.8'
41+
}
42+
}
43+
44+
apply from: "$rootDir/deps/deps_versions.gradle"
45+
46+
dependencies {
47+
api project(path: ':entities:presentation')
48+
api project(path: ':features:recycler_view_example_api')
49+
50+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
51+
implementation 'androidx.core:core-ktx:1.3.2'
52+
implementation 'androidx.appcompat:appcompat:1.2.0'
53+
implementation 'com.google.android.material:material:1.3.0'
54+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
55+
56+
implementation constraintLayout
57+
implementation dagger
58+
kapt daggerCompiler
59+
}

features/recycler_view_example/consumer-rules.pro

Whitespace-only changes.

0 commit comments

Comments
 (0)