Skip to content

Commit ef930a3

Browse files
Merge pull request #7 from Omega-R/develop
Fixed
2 parents a7f95a0 + 2e40853 commit ef930a3

File tree

8 files changed

+67
-17
lines changed

8 files changed

+67
-17
lines changed

.idea/misc.xml

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

app/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ android {
1919
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2020
}
2121
}
22+
23+
packagingOptions {
24+
pickFirst 'META-INF/kotlinx-io.kotlin_module'
25+
pickFirst 'META-INF/atomicfu.kotlin_module'
26+
pickFirst 'META-INF/kotlinx-coroutines-io.kotlin_module'
27+
}
2228
}
2329

2430
dependencies {

lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ dependencies {
3636
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
3737
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
3838
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
39-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
39+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.0"
4040

4141
implementation 'com.github.Omega-R.OmegaMoxy:moxy:1.5.7'
4242
implementation 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.5.7'
4343
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.5.7'
4444

45-
implementation 'com.github.Omega-R:OmegaRecyclerView:1.9.4@aar'
45+
implementation 'com.github.Omega-R:OmegaRecyclerView:1.9.5@aar'
4646
implementation 'com.github.Omega-R.OmegaTypes:omegatypes:0.0.8'
4747

4848
implementation 'com.google.android.material:material:1.1.0-alpha05'

lib/src/main/java/com/omega_r/base/adapters/OmegaAutoAdapter.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import org.intellij.lang.annotations.Identifier
1010
* Created by Anton Knyazev on 07.04.2019.
1111
*/
1212
class OmegaAutoAdapter<M> (
13-
@LayoutRes private val layoutRes: Int, private val bindModel: AutoBindModel<M>,
13+
@LayoutRes private val layoutRes: Int,
14+
private val bindModel: AutoBindModel<M>,
1415
private val callback: Callback<M>? = null
1516
) : OmegaListAdapter<M, OmegaAutoAdapter<M>.ViewHolder>() {
1617

lib/src/main/java/com/omega_r/base/adapters/model/AutoBindModel.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import androidx.annotation.IdRes
1010
import androidx.recyclerview.widget.RecyclerView
1111
import com.omega_r.base.R
1212
import com.omega_r.base.adapters.OmegaAutoAdapter
13+
import com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
14+
import com.omega_r.libs.omegarecyclerview.header.HeaderFooterWrapperAdapter
15+
import com.omega_r.libs.omegarecyclerview.pagination.WrapperAdapter
1316
import com.omega_r.libs.omegatypes.Image
1417
import com.omega_r.libs.omegatypes.Text
1518
import com.omega_r.libs.omegatypes.setImage
@@ -81,6 +84,15 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
8184
return this
8285
}
8386

87+
fun bindCharSequence(@IdRes id: Int, property: KProperty<CharSequence?>): Builder<M> {
88+
return bindCharSequence(id, property)
89+
}
90+
91+
fun bindCharSequence(@IdRes id: Int, vararg properties: KProperty<*>): Builder<M> {
92+
list += CharSequenceBinder(id, *properties)
93+
return this
94+
}
95+
8496
fun bind(@IdRes id: Int, property: KProperty<Text?>): Builder<M> {
8597
return bindText(id, property)
8698
}
@@ -95,7 +107,7 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
95107
property: KProperty<List<SM>>,
96108
callback: OmegaAutoAdapter.Callback<SM>? = null,
97109
block: Builder<SM>.() -> Unit): Builder<M> {
98-
return bindRecycler(id, layoutRes, property , block = block, callback = callback)
110+
return bindRecycler(id, layoutRes, properties = *arrayOf(property), block = block, callback = callback)
99111
}
100112

101113
fun <SM> bindRecycler(@IdRes id: Int,
@@ -181,6 +193,18 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
181193

182194
}
183195

196+
class CharSequenceBinder<M>(
197+
override val id: Int,
198+
private vararg val properties: KProperty<*>
199+
) : Binder<TextView, M>() {
200+
201+
override fun bind(itemView: TextView, item: M) {
202+
val charSequence: CharSequence? = item.findValue(item, properties)
203+
itemView.text = charSequence
204+
}
205+
206+
}
207+
184208
class TextBinder<M>(
185209
override val id: Int,
186210
private vararg val properties: KProperty<*>
@@ -212,9 +236,20 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
212236
@Suppress("UNCHECKED_CAST")
213237
override fun bind(itemView: RecyclerView, item: M) {
214238
val list: List<SM>? = item.findValue(item, properties)
215-
(itemView.adapter as OmegaAutoAdapter<SM>).list = list ?: emptyList()
239+
240+
getAdapter(itemView).list = list ?: emptyList()
216241
}
217242

243+
@Suppress("UNCHECKED_CAST")
244+
private fun getAdapter(itemView: RecyclerView): OmegaAutoAdapter<SM> {
245+
val adapter = when (itemView) {
246+
is OmegaRecyclerView -> itemView.realAdapter
247+
else -> itemView.adapter
248+
}
249+
return adapter as OmegaAutoAdapter<SM>
250+
}
251+
252+
218253
}
219254

220255
class CustomBinder<V : View, M>(override val id: Int, val binder: (view: V, item: M) -> Unit) : Binder<V, M>() {

lib/src/main/java/com/omega_r/base/binders/OmegaBindable.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ interface OmegaBindable: OmegaContext, OmegaViewFindable {
1818
val bindersManager: BindersManager
1919

2020
private val resources: Resources
21-
get() = getContext()!!.resources
21+
get() = getContext()?.resources ?: error("Context is null")
2222

2323
fun <T : View> bind(@IdRes res: Int, initBlock: T.() -> Unit) = bindersManager.bind(RESETTABLE_WITH_AUTO_INIT) {
24-
val view = findViewById<T>(res)!!
24+
val view = findViewById<T>(res) ?: error("Bind is not found R.id.${resources.getResourceEntryName(res)} (${this::class.java.name})")
2525
initBlock(view)
2626
view
2727
}
2828

2929
fun <T : View> bind(@IdRes res: Int) = bindersManager.bind(RESETTABLE) {
30-
findViewById<T>(res)!!
30+
findViewById<T>(res) ?: error("Bind is not found R.id.${resources.getResourceEntryName(res)} (${this::class.java.name})")
3131
}
3232

3333
fun <T> bind(init: () -> T) = bindersManager.bind(RESETTABLE, init)
3434

3535
fun <T: View> bind(@IdRes vararg ids: Int) = bindersManager.bind(RESETTABLE) {
3636
val list = ArrayList<T>(ids.size)
3737
for (id in ids) {
38-
list += findViewById<T>(id)!!
38+
list += findViewById<T>(id) ?: error("Bind is not found R.id.${resources.getResourceEntryName(id)} (${this::class.java.name})")
3939
}
4040
list
4141
}
4242

4343
fun <T: View> bind(@IdRes vararg ids: Int, initBlock: T.() -> Unit) = bindersManager.bind(RESETTABLE_WITH_AUTO_INIT) {
4444
val list = ArrayList<T>(ids.size)
4545
for (id in ids) {
46-
val view = findViewById<T>(id)!!
46+
val view = findViewById<T>(id) ?: error("Bind is not found R.id.${resources.getResourceEntryName(id)} (${this::class.java.name})")
4747
list += view
4848
initBlock(view)
4949
}
@@ -53,15 +53,15 @@ interface OmegaBindable: OmegaContext, OmegaViewFindable {
5353
fun <T: View, IH: IdHolder> bind(ids: Array<out IH>) = bindersManager.bind(RESETTABLE) {
5454
val map = HashMap<IH, T>(ids.size)
5555
for (id in ids) {
56-
map[id] = findViewById(id.id)!!
56+
map[id] = findViewById(id.id) ?: error("Bind is not found R.id.${resources.getResourceEntryName(id.id)} (${this::class.java.name})")
5757
}
5858
map
5959
}
6060

6161
fun <T: View, IH: IdHolder> bind(ids: Array<out IH>, initBlock: T.(IdHolder) -> Unit) = bindersManager.bind(RESETTABLE_WITH_AUTO_INIT) {
6262
val map = HashMap<IH, T>(ids.size)
6363
for (idHolder in ids) {
64-
val view = findViewById<T>(idHolder.id)!!
64+
val view = findViewById<T>(idHolder.id) ?: error("Bind is not found R.id.${resources.getResourceEntryName(idHolder.id)} (${this::class.java.name})")
6565
map[idHolder] = view
6666
initBlock(view, idHolder)
6767
}
@@ -72,7 +72,7 @@ interface OmegaBindable: OmegaContext, OmegaViewFindable {
7272
fun <T: View, E> bind(vararg idsPair: Pair<E, Int>) = bindersManager.bind(RESETTABLE) {
7373
val map = HashMap<E, T>(idsPair.size)
7474
for (idHolder in idsPair) {
75-
val view = findViewById<T>(idHolder.second)!!
75+
val view = findViewById<T>(idHolder.second) ?: error("Bind is not found R.id.${resources.getResourceEntryName(idHolder.second)} (${this::class.java.name})")
7676
map[idHolder.first] = view
7777
}
7878

@@ -82,7 +82,7 @@ interface OmegaBindable: OmegaContext, OmegaViewFindable {
8282
fun <T: View, E> bind(vararg idsPair: Pair<E, Int>, initBlock: T.(E) -> Unit) = bindersManager.bind(RESETTABLE_WITH_AUTO_INIT) {
8383
val map = HashMap<E, T>(idsPair.size)
8484
for (idHolder in idsPair) {
85-
val view = findViewById<T>(idHolder.second)!!
85+
val view = findViewById<T>(idHolder.second) ?: error("Bind is not found R.id.${resources.getResourceEntryName(idHolder.second)} (${this::class.java.name})")
8686
map[idHolder.first] = view
8787
initBlock(view, idHolder.first)
8888
}
@@ -99,7 +99,7 @@ interface OmegaBindable: OmegaContext, OmegaViewFindable {
9999
}
100100

101101
fun bindDrawable(@DrawableRes res: Int) = bindersManager.bind {
102-
ContextCompat.getDrawable(getContext()!!, res)!!
102+
ContextCompat.getDrawable(getContext()!!, res) ?: error("BindDrawable is not found R.drawable.${resources.getResourceEntryName(res)} (${this::class.java.name})")
103103
}
104104

105105
fun bindDimen(@DimenRes res: Int) = bindersManager.bind {

lib/src/main/java/com/omega_r/base/clickers/OmegaClickable.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ interface OmegaClickable: OmegaViewFindable {
3939
ids.forEach { findViewById<View>(it)!!.setOnClickListener(clickManager.wrap(it, block)) }
4040
}
4141

42+
fun <E> setOnClickListeners(vararg pairs: Pair<Int, E>, block: (E) -> Unit) {
43+
val list = pairs.map { it.first }
44+
val map = pairs.toMap()
45+
setOnClickListeners(ids = *list.toIntArray()) {
46+
block(map[it.id]!!)
47+
}
48+
}
49+
4250
fun setMenuListener(vararg pairs: Pair<Int, () -> Unit>) {
4351
pairs.forEach { setMenuListener(it.first, it.second) }
4452
}

lib/src/main/java/com/omega_r/base/components/OmegaPresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope
1919
override val coroutineContext: CoroutineContext = Dispatchers.Main + job + handler
2020

2121
protected open fun handleErrors(throwable: Throwable) {
22-
// nothing
22+
throwable.printStackTrace()
2323
}
2424

2525
protected suspend fun <T> CoroutineScope.withWaiting(block: suspend () -> T): T {

0 commit comments

Comments
 (0)