Skip to content

Commit c7f5dbb

Browse files
Merge pull request #20 from Omega-R/develop
Develop
2 parents 502650d + 76a127f commit c7f5dbb

File tree

23 files changed

+596
-198
lines changed

23 files changed

+596
-198
lines changed

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ dependencies {
4848
androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
4949
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
5050
implementation project(':lib')
51-
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.5.7'
51+
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.6.2'
52+
implementation 'com.github.bumptech.glide:glide:4.9.0'
53+
5254

5355

5456
}

app/src/main/java/com/omega_r/base/simple/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import com.omega_r.base.adapters.OmegaListAdapter
88
import com.omega_r.base.annotations.OmegaContentView
99
import com.omega_r.base.binders.IdHolder
1010
import com.omega_r.base.components.OmegaActivity
11-
import com.omega_r.libs.omegatypes.Image
1211
import com.omega_r.libs.omegatypes.Text
13-
import com.omega_r.libs.omegatypes.from
12+
import com.omega_r.libs.omegatypes.image.Image
13+
import com.omega_r.libs.omegatypes.image.from
1414
import com.omegar.libs.omegalaunchers.createActivityLauncher
1515
import com.omegar.libs.omegalaunchers.tools.put
1616
import com.omegar.mvp.presenter.InjectPresenter

app/src/main/java/com/omega_r/base/simple/MainPresenter.kt

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.omega_r.base.simple
22

3+
import com.omega_r.base.enitity.contains
34
import com.omega_r.base.mvp.model.Action
45
import com.omega_r.base.mvp.presenters.OmegaPresenter
56
import com.omega_r.libs.omegatypes.Text
67
import com.omegar.mvp.InjectViewState
8+
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.delay
10+
import kotlinx.coroutines.launch
711
import java.io.Serializable
812

913
/**
@@ -13,20 +17,27 @@ import java.io.Serializable
1317
class MainPresenter : OmegaPresenter<MainView>() {
1418

1519
init {
16-
viewState.showMessage(Text.from("test"), Action(Text.from("Test")) {
17-
viewState.showToast(Text.from("test"))
18-
})
19-
20-
viewState.showQuery(
21-
Text.from("message"),
22-
Text.from("title"),
23-
positiveAction = Action("Yes"),
24-
negativeAction = Action("No")
25-
)
26-
27-
intentBuilder.settings()
28-
.application()
29-
.launch()
20+
launch {
21+
delay(5000)
22+
viewState.showToast(Text.from("Go"))
23+
viewState.setWaiting(true)
24+
delay(5000)
25+
viewState.setWaiting(false)
26+
}
27+
28+
29+
30+
31+
// viewState.showMessage(Text.from("test"), Action(Text.from("Test")) {
32+
// viewState.showToast(Text.from("test"))
33+
// })
34+
//
35+
// viewState.showQuery(
36+
// Text.from("message"),
37+
// Text.from("title"),
38+
// positiveAction = Action("Yes"),
39+
// negativeAction = Action("No")
40+
// )
3041
}
3142

3243
override fun onLaunchResult(requestCode: Int, success: Boolean, data: Serializable?): Boolean {

app/src/main/res/layout/activity_main.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
77
tools:context=".MainActivity">
88

9+
<EditText
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"/>
12+
913
<com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
1014
android:id="@+id/recyclerview"
1115
android:layout_width="match_parent"

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ext {
2-
omegaRecyclerView = '1.9.7'
2+
omegaRecyclerView = '1.9.8'
33
kotlinCorutines_version = '1.2.1'
44

55
}// Top-level build file where you can add configuration options common to all sub-projects/modules.

lib/build.gradle

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,29 @@ android {
4343
dependencies {
4444
implementation fileTree(dir: 'libs', include: ['*.jar'])
4545

46-
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
46+
implementation 'androidx.appcompat:appcompat:1.1.0'
4747
testImplementation 'junit:junit:4.13-beta-3'
48-
androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
49-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
48+
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
49+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
5050
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"
5151
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}"
5252
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinCorutines_version}"
5353
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${kotlinCorutines_version}"
5454
implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:${kotlin_version}"
5555

56-
api 'com.github.Omega-R.OmegaMoxy:moxy:1.5.8'
57-
api 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.5.8'
58-
59-
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.5.8'
56+
api 'com.github.Omega-R.OmegaMoxy:moxy:1.6.2'
57+
api 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.6.2'
6058

6159
api "com.github.Omega-R:OmegaRecyclerView:${omegaRecyclerView}@aar"
62-
api 'com.github.Omega-R.OmegaTypes:glide:1.0.2'
60+
api 'com.github.Omega-R.OmegaTypes:glide:2.0.1'
6361
api 'com.github.Omega-R:OmegaIntentBuilder:1.2.0'
6462
api 'com.github.Omega-R:OmegaLaunchers:1.0.2'
63+
api 'com.github.Omega-R:OmegaExtensions:1.0.3'
6564

6665
api "com.squareup.retrofit2:retrofit:2.6.1"
6766
api "com.squareup.moshi:moshi-kotlin:1.8.0"
6867

69-
implementation 'com.google.android.material:material:1.1.0-alpha06'
68+
implementation 'com.google.android.material:material:1.1.0-beta01'
7069

7170
}
7271
repositories {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import android.view.LayoutInflater
44
import android.view.View
55
import android.view.ViewGroup
66
import androidx.recyclerview.widget.RecyclerView
7-
import com.omega_r.libs.omegatypes.Image
7+
import com.omega_r.libs.omegatypes.image.Image
8+
import com.omega_r.libs.omegatypes.image.ImageProcessors
9+
import com.omega_r.libs.omegatypes.image.preload
810

911
/**
1012
* Created by Anton Knyazev on 04.04.2019.
@@ -63,6 +65,8 @@ abstract class OmegaListAdapter<M, VH> : OmegaAdapter<VH>(), ListableAdapter<M>
6365
} else {
6466
position - childCount
6567
}
68+
69+
6670
adapter.list.getOrNull(preloadPosition)?.preload(recyclerView.context)
6771

6872
lastPosition = position

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

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.omega_r.base.adapters
22

33
import android.content.Context
4+
import android.view.View
5+
import android.view.ViewGroup
46
import android.widget.AdapterView.INVALID_POSITION
57
import android.widget.ArrayAdapter
68
import android.widget.Spinner
9+
import android.widget.SpinnerAdapter
710
import androidx.annotation.LayoutRes
11+
import com.omega_r.base.enitity.Identifiable
812
import java.util.*
913

1014
/**
@@ -15,7 +19,8 @@ abstract class OmegaSpinnerAdapter<M>(
1519
context: Context,
1620
@LayoutRes res: Int = android.R.layout.simple_spinner_item,
1721
list: List<M> = Collections.emptyList()
18-
) : ArrayAdapter<CharSequence>(context, res, Collections.emptyList()), ListableAdapter<M> {
22+
) : ArrayAdapter<CharSequence>(context, res, Collections.emptyList()), ListableAdapter<M>,
23+
SpinnerAdapter {
1924

2025
override var list: List<M> = list
2126
set(value) {
@@ -29,18 +34,51 @@ abstract class OmegaSpinnerAdapter<M>(
2934
notifyDataSetChanged()
3035
}
3136

32-
abstract fun getItemName(item: M): CharSequence
37+
private var hasStableId: Boolean? = null
38+
get() {
39+
if (field == null) {
40+
field = (list.firstOrNull() is Identifiable<*>)
41+
}
42+
return field
43+
}
44+
45+
private var viewPosition: Int = -1
46+
47+
abstract fun getItemName(item: M, isDropDown: Boolean): CharSequence
3348

3449
override fun getItem(position: Int): CharSequence? {
35-
if (nonSelectedItem == null) {
36-
return getItemName(list[position])
37-
} else if (position == 0) {
38-
return getItemName(nonSelectedItem!!)
39-
} else {
40-
return getItemName(list[position - 1])
50+
val isDropDown = if (position == viewPosition) {
51+
viewPosition = -1
52+
false
53+
} else true
54+
return when {
55+
nonSelectedItem == null -> getItemName(list[position], isDropDown)
56+
position == 0 -> getItemName(nonSelectedItem!!, isDropDown)
57+
else -> getItemName(list[position - 1], isDropDown)
4158
}
4259
}
4360

61+
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
62+
viewPosition = position
63+
return super.getView(position, convertView, parent)
64+
}
65+
66+
override fun getItemId(position: Int): Long {
67+
val newPosition = position + (if (nonSelectedItem == null) 0 else 1)
68+
return when (val item = list.getOrNull(newPosition)) {
69+
is Identifiable<*> -> item.idAsLong
70+
else -> super.getItemId(position)
71+
}
72+
}
73+
74+
fun setHasStableId(hasStableId: Boolean) {
75+
this.hasStableId = hasStableId
76+
}
77+
78+
override fun hasStableIds(): Boolean {
79+
return hasStableId!!
80+
}
81+
4482
override fun getCount(): Int = list.size + (if (nonSelectedItem == null) 0 else 1)
4583

4684
fun setSelection(spinner: Spinner, item: M?) {
@@ -50,7 +88,13 @@ abstract class OmegaSpinnerAdapter<M>(
5088
}
5189
for (i in list.indices) {
5290
val position = if (nonSelectedItem == null) i else i + 1
53-
if (list[i] == item) {
91+
val listItem = list[i]
92+
if (listItem == item ||
93+
(hasStableId!!
94+
&& item is Identifiable<*>
95+
&& listItem is Identifiable<*>
96+
&& item.id == listItem.id)
97+
) {
5498
setSelection(spinner, position)
5599
return
56100
}
@@ -76,36 +120,41 @@ abstract class OmegaSpinnerAdapter<M>(
76120
return position
77121
}
78122

79-
class Text(
123+
class TextAdapter(
80124
context: Context,
81125
res: Int = android.R.layout.simple_spinner_item,
82126
list: List<com.omega_r.libs.omegatypes.Text> = emptyList()
83127
) :
84128
OmegaSpinnerAdapter<com.omega_r.libs.omegatypes.Text>(context, res, list) {
85129

86-
override fun getItemName(item: com.omega_r.libs.omegatypes.Text) = item.getCharSequence(context) ?: ""
130+
override fun getItemName(
131+
item: com.omega_r.libs.omegatypes.Text,
132+
isDropDown: Boolean
133+
): CharSequence =
134+
item.getCharSequence(context) ?: ""
87135

88136
}
89137

90-
class String(
138+
class StringAdapter(
91139
context: Context,
92140
res: Int = android.R.layout.simple_spinner_item,
93141
list: List<kotlin.String> = emptyList()
94142
) :
95143
OmegaSpinnerAdapter<kotlin.String>(context, res, list) {
96144

97-
override fun getItemName(item: kotlin.String): CharSequence = item
145+
override fun getItemName(item: kotlin.String, isDropDown: Boolean): CharSequence = item
98146
}
99147

100-
class Custom<M>(
148+
class CustomAdapter<M>(
101149
context: Context,
102150
res: Int = android.R.layout.simple_spinner_item,
103-
private val converter: (Context, M) -> CharSequence,
151+
private val converter: (Context, item: M, isDropDown: Boolean) -> CharSequence,
104152
list: List<M> = emptyList()
105153
) :
106154
OmegaSpinnerAdapter<M>(context, res, list) {
107155

108-
override fun getItemName(item: M): CharSequence = converter(context, item)
156+
override fun getItemName(item: M, isDropDown: Boolean): CharSequence =
157+
converter(context, item, isDropDown)
109158
}
110159

111160

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import com.omega_r.base.adapters.OmegaAutoAdapter
1616
import com.omega_r.base.adapters.OmegaSpinnerAdapter
1717
import com.omega_r.base.clickers.ClickManager
1818
import com.omega_r.libs.omegarecyclerview.OmegaRecyclerView
19-
import com.omega_r.libs.omegatypes.Image
2019
import com.omega_r.libs.omegatypes.Text
21-
import com.omega_r.libs.omegatypes.setImage
20+
import com.omega_r.libs.omegatypes.image.Image
21+
import com.omega_r.libs.omegatypes.image.setImage
2222
import com.omega_r.libs.omegatypes.setText
2323
import kotlin.reflect.KProperty
2424

@@ -87,7 +87,7 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
8787
list.forEach { binder -> binder.dispatchBind(viewCache, item) }
8888
}
8989

90-
class Builder<M>(private val parentModel: AutoBindModel<M>? = null) {
90+
open class Builder<M>(private val parentModel: AutoBindModel<M>? = null) {
9191

9292
private val list: MutableList<Binder<*, M>> = mutableListOf()
9393

@@ -166,7 +166,7 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
166166
nonSelectedItem: SM? = null,
167167
callback: ((M, SM?, Int) -> Unit)? = null,
168168
selector: (M) -> SM?,
169-
converter: (Context, SM) -> CharSequence
169+
converter: (Context, SM, isDropDown: Boolean) -> CharSequence
170170
) = bindBinder(
171171
SpinnerListBinder(
172172
id,
@@ -430,14 +430,14 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
430430
val list: List<SM>? = item.findValue(item, properties)
431431
getAdapter(itemView).also {
432432
it.list = list ?: emptyList()
433-
(it.callback as? Callback<M, SM>)?.run {
433+
(it.callback as? Callback<M, SM>)?.apply {
434434
model = item
435435
}
436436
}
437437
}
438438

439439
@Suppress("UNCHECKED_CAST")
440-
private fun getAdapter(itemView: RecyclerView): OmegaAutoAdapter<SM, *> {
440+
protected fun getAdapter(itemView: RecyclerView): OmegaAutoAdapter<SM, *> {
441441
val adapter = when (itemView) {
442442
is OmegaRecyclerView -> itemView.realAdapter
443443
else -> itemView.adapter
@@ -450,10 +450,7 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
450450
var model: M? = null
451451

452452
override fun invoke(subModel: SM) {
453-
model?.let {
454-
block(it, subModel)
455-
}
456-
453+
block(model ?: return, subModel)
457454
}
458455

459456
}
@@ -601,11 +598,11 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
601598
private val nonSelectedItem: SM? = null,
602599
private val callback: ((M, SM?, Int) -> Unit)? = null,
603600
private val selector: (M) -> SM?,
604-
private val converter: (Context, SM) -> CharSequence
601+
private val converter: (Context, SM, isDropDown: Boolean) -> CharSequence
605602
) : Binder<Spinner, M>() {
606603

607604
override fun onCreateView(itemView: Spinner) {
608-
itemView.adapter = OmegaSpinnerAdapter.Custom(itemView.context, layoutRes, converter).also {
605+
itemView.adapter = OmegaSpinnerAdapter.CustomAdapter(itemView.context, layoutRes, converter).also {
609606
it.nonSelectedItem = nonSelectedItem
610607
}
611608
}
@@ -614,7 +611,7 @@ class AutoBindModel<M>(private val list: List<Binder<*, M>>) {
614611
override fun bind(spinner: Spinner, item: M) {
615612
val list: List<SM>? = item.findValue(item, properties)
616613

617-
val adapter = spinner.adapter as OmegaSpinnerAdapter.Custom<SM>
614+
val adapter = spinner.adapter as OmegaSpinnerAdapter.CustomAdapter<SM>
618615

619616
adapter.list = list ?: emptyList()
620617

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.omega_r.base.annotations
2+
3+
import androidx.annotation.StringRes
4+
5+
/**
6+
* Created by Anton Knyazev on 2019-09-19.
7+
*/
8+
@Target(AnnotationTarget.CLASS)
9+
@Retention(AnnotationRetention.RUNTIME)
10+
annotation class OmegaTitle(@StringRes val resId: Int)

0 commit comments

Comments
 (0)