Skip to content

Commit 38112a9

Browse files
Merge pull request #17 from yogeshpaliyal/improvement/builder
Improvement in builder pattern
2 parents e2c4b79 + b5e228f commit 38112a9

File tree

9 files changed

+222
-74
lines changed

9 files changed

+222
-74
lines changed

.idea/misc.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.

app/build.gradle

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,23 @@ dependencies {
4040
implementation project(':universal_adapter')
4141

4242
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
43-
implementation 'androidx.appcompat:appcompat:1.2.0'
44-
implementation 'androidx.core:core-ktx:1.3.2'
45-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
46-
testImplementation 'junit:junit:4.13.1'
47-
androidTestImplementation 'androidx.test:runner:1.3.0'
48-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
43+
implementation 'androidx.appcompat:appcompat:1.3.1'
44+
implementation 'androidx.core:core-ktx:1.6.0'
45+
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
46+
47+
testImplementation 'junit:junit:4.13.2'
48+
androidTestImplementation 'androidx.test:core-ktx:1.4.0'
49+
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.3'
50+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
51+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
52+
53+
androidTestImplementation 'androidx.test:runner:1.4.0'
54+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
4955

5056

5157
//todo step 2
5258
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
53-
implementation 'com.google.android.material:material:1.3.0'
59+
implementation 'com.google.android.material:material:1.4.0'
5460
implementation 'com.makeramen:roundedimageview:2.3.0'
5561
// ViewModel
5662
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.techpaliyal.androidkotlinmvvm
2+
3+
import android.view.View
4+
import androidx.test.espresso.FailureHandler
5+
import org.hamcrest.Matcher
6+
7+
class CustomFailureHandler: FailureHandler {
8+
override fun handle(error: Throwable?, viewMatcher: Matcher<View>?) {
9+
assert(false)
10+
}
11+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.techpaliyal.androidkotlinmvvm.ui.activity
2+
3+
import androidx.test.espresso.Espresso.*
4+
import androidx.test.espresso.FailureHandler
5+
import androidx.test.espresso.action.ViewActions.click
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.ext.junit.rules.ActivityScenarioRule
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.techpaliyal.androidkotlinmvvm.R
10+
import org.junit.Assert.*
11+
import org.junit.Before
12+
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
16+
@RunWith(AndroidJUnit4::class)
17+
class MainActivityTest(){
18+
19+
@Rule
20+
@JvmField
21+
public var activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
22+
23+
@Before
24+
fun before(){
25+
/* setFailureHandler(FailureHandler { error, viewMatcher ->
26+
27+
})*/
28+
}
29+
30+
@Test
31+
fun launchBasicActivity(){
32+
onView(withId(R.id.btnBasicListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
33+
34+
35+
}
36+
37+
@Test
38+
fun launchMultiSelectActivity(){
39+
onView(withId(R.id.btnMultiSelect)).perform(click()).withFailureHandler { error, viewMatcher -> }
40+
41+
42+
}
43+
44+
@Test
45+
fun launchLoadingActivity(){
46+
onView(withId(R.id.btnLoadingListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
47+
}
48+
49+
@Test
50+
fun launchShimmerActivity(){
51+
onView(withId(R.id.btnShimmerListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
52+
}
53+
54+
55+
@Test
56+
fun launchPaginationActivity(){
57+
onView(withId(R.id.btnPaginationListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
58+
}
59+
60+
@Test
61+
fun launchBindingAdapterActivity(){
62+
onView(withId(R.id.btnBindingAdapter)).perform(click()).withFailureHandler { error, viewMatcher -> }
63+
}
64+
65+
@Test
66+
fun launchMultipleViewsActivity(){
67+
onView(withId(R.id.btnMultipleViews)).perform(click()).withFailureHandler { error, viewMatcher -> }
68+
onView(withId(R.id.btnSchoolListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
69+
pressBack()
70+
onView(withId(R.id.btnChatListing)).perform(click()).withFailureHandler { error, viewMatcher -> }
71+
pressBack()
72+
}
73+
74+
}

app/src/main/java/com/techpaliyal/androidkotlinmvvm/ui/activity/BasicListingActivity.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class BasicListingActivity : AppCompatActivity() {
3838
}
3939
}
4040

41-
private val mAdapter by lazy {
41+
/**
42+
* Old Builder way
43+
*/
44+
/* private val mAdapter by lazy {
4245
UniversalRecyclerAdapter.Builder<BasicModel>(
4346
lifecycleOwner = this,
4447
content = UniversalAdapterViewType.Content(
@@ -50,6 +53,21 @@ class BasicListingActivity : AppCompatActivity() {
5053
}
5154
})
5255
).build()
56+
}*/
57+
58+
/**
59+
* New Builder Way
60+
*/
61+
private val mAdapter by lazy{
62+
UniversalRecyclerAdapter.Builder<BasicModel>()
63+
.setLifecycleOwner(this)
64+
.setContent(R.layout.item_simple, object : BasicListener<BasicModel> {
65+
override fun onClick(model: BasicModel) {
66+
Toast.makeText(this@BasicListingActivity, model.name, Toast.LENGTH_SHORT)
67+
.show()
68+
}
69+
})
70+
.build()
5371
}
5472

5573
override fun onCreate(savedInstanceState: Bundle?) {

app/src/main/java/com/techpaliyal/androidkotlinmvvm/ui/activity/ShimmerListingActivity.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ class ShimmerListingActivity : AppCompatActivity() {
5757
}
5858
}),
5959
loading = UniversalAdapterViewType.Loading(resourceLoading = R.layout.item_user_shimmer),
60-
loadingFooter = UniversalAdapterViewType.LoadingFooter(),
61-
noData = UniversalAdapterViewType.NoData(),
62-
error = UniversalAdapterViewType.Error()
6360
).build()
6461
}
6562

universal_adapter/src/main/java/com/yogeshpaliyal/universalAdapter/adapter/UniversalAdapterViewType.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ sealed class UniversalAdapterViewType {
2121

2222
data class Loading<T>(
2323
@LayoutRes
24-
val resourceLoading: Int? = null,
24+
val resourceLoading: Int,
2525
val defaultLoadingItems: Int = 5,
2626
val additionalParams : HashMap<Int,Any>?= null,
2727
val customBindingMapping: ((itemBinding: ViewDataBinding, item: T) -> Unit)? = null
2828
)
2929

3030
data class LoadingFooter<T>(
3131
@LayoutRes
32-
val loaderFooter: Int? = null,
32+
val loaderFooter: Int,
3333
val additionalParams : HashMap<Int,Any>?= null,
3434
val customBindingMapping: ((itemBinding: ViewDataBinding, item: T) -> Unit)? = null
3535
)
3636

3737
data class NoData<T>(
3838
@LayoutRes
39-
val noDataLayout: Int? = null,
39+
val noDataLayout: Int,
4040
val listener: Any? = null,
4141
val additionalParams : HashMap<Int,Any>?= null,
4242
val customBindingMapping: ((itemBinding: ViewDataBinding, item: String?) -> Unit)? = null
4343
)
4444

4545
data class Error<T>(
4646
@LayoutRes
47-
val errorLayout: Int? = null,
47+
val errorLayout: Int,
4848
val listener: Any? = null,
4949
val additionalParams : HashMap<Int,Any>?= null,
5050
val customBindingMapping: ((itemBinding: ViewDataBinding, message: String?) -> Unit)? = null

0 commit comments

Comments
 (0)