Skip to content

Commit 3c1eee5

Browse files
Merge pull request #14 from Omega-R/develop
Develop
2 parents 31384f8 + b14b47d commit 3c1eee5

File tree

10 files changed

+59
-33
lines changed

10 files changed

+59
-33
lines changed

app/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ 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-
implementation "com.github.Omega-R:OmegaRecyclerView:${omegaRecyclerView}"
52-
implementation 'com.github.Omega-R.OmegaMoxy:moxy:1.5.7'
53-
implementation 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.5.7'
5451
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.5.7'
55-
implementation 'com.github.Omega-R.OmegaTypes:omegatypes:1.0.1'
56-
implementation 'com.github.Omega-R.OmegaTypes:glide:1.0.1'
57-
implementation 'com.github.Omega-R:OmegaLaunchers:1.0.1'
5852

5953

6054
}
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.omega_r.base.simple
22

3-
import com.omega_r.base.mvp.presenters.OmegaPresenter
43
import com.omega_r.base.mvp.model.Action
4+
import com.omega_r.base.mvp.presenters.OmegaPresenter
55
import com.omega_r.libs.omegatypes.Text
66
import com.omegar.mvp.InjectViewState
7+
import java.io.Serializable
78

89
/**
910
* Created by Anton Knyazev on 06.05.19.
@@ -12,16 +13,25 @@ import com.omegar.mvp.InjectViewState
1213
class MainPresenter : OmegaPresenter<MainView>() {
1314

1415
init {
15-
viewState.showMessage(Text.from("test"), Action(Text.from("Test")){
16+
viewState.showMessage(Text.from("test"), Action(Text.from("Test")) {
1617
viewState.showToast(Text.from("test"))
1718
})
1819

19-
viewState.showQuery(Text.from("message"), Text.from("title"), positiveAction = Action("Yes") {
20+
viewState.showQuery(
21+
Text.from("message"),
22+
Text.from("title"),
23+
positiveAction = Action("Yes"),
24+
negativeAction = Action("No")
25+
)
2026

21-
}, negativeAction = Action("No", {
22-
23-
}))
27+
intentBuilder.settings()
28+
.application()
29+
.launch()
30+
}
2431

32+
override fun onLaunchResult(requestCode: Int, success: Boolean, data: Serializable?): Boolean {
33+
viewState.showToast(Text.from("onLaunchResult = $requestCode"))
34+
return super.onLaunchResult(requestCode, success, data)
2535
}
2636

2737
}

lib/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ dependencies {
5353
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${kotlinCorutines_version}"
5454
implementation "org.jetbrains.kotlin:kotlin-android-extensions-runtime:${kotlin_version}"
5555

56-
implementation 'com.github.Omega-R.OmegaMoxy:moxy:1.5.8'
57-
implementation 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.5.8'
58-
implementation 'com.github.Omega-R:OmegaLaunchers:1.0.1'
56+
api 'com.github.Omega-R.OmegaMoxy:moxy:1.5.8'
57+
api 'com.github.Omega-R.OmegaMoxy:moxy-androidx:1.5.8'
5958

6059
kapt 'com.github.Omega-R.OmegaMoxy:moxy-compiler:1.5.8'
6160

62-
implementation "com.github.Omega-R:OmegaRecyclerView:${omegaRecyclerView}@aar"
63-
implementation 'com.github.Omega-R.OmegaTypes:omegatypes:1.0.1'
64-
implementation 'com.github.Omega-R.OmegaTypes:glide:1.0.1'
61+
api "com.github.Omega-R:OmegaRecyclerView:${omegaRecyclerView}@aar"
62+
api 'com.github.Omega-R.OmegaTypes:glide:1.0.2'
63+
api 'com.github.Omega-R:OmegaIntentBuilder:1.2.0'
64+
api 'com.github.Omega-R:OmegaLaunchers:1.0.2'
6565

66-
implementation "com.squareup.retrofit2:retrofit:2.4.0"
67-
implementation "com.squareup.moshi:moshi-kotlin:1.8.0"
66+
api "com.squareup.retrofit2:retrofit:2.6.1"
67+
api "com.squareup.moshi:moshi-kotlin:1.8.0"
6868

6969
implementation 'com.google.android.material:material:1.1.0-alpha06'
7070

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.omega_r.base.mvp.views.findAnnotation
2222
import com.omega_r.base.tools.WaitingDialog
2323
import com.omega_r.libs.omegatypes.Text
2424
import com.omegar.libs.omegalaunchers.ActivityLauncher
25+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
2526
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
2627
import com.omegar.libs.omegalaunchers.FragmentLauncher
2728
import com.omegar.mvp.MvpAppCompatActivity
@@ -233,7 +234,7 @@ abstract class OmegaActivity : MvpAppCompatActivity(), OmegaComponent {
233234
}
234235
}
235236

236-
override fun launchForResult(launcher: ActivityLauncher, requestCode: Int) {
237+
override fun launchForResult(launcher: BaseIntentLauncher, requestCode: Int) {
237238
launcher.launchForResult(this, requestCode)
238239
}
239240

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.omega_r.base.mvp.model.Action
1717
import com.omega_r.base.mvp.views.findAnnotation
1818
import com.omega_r.libs.omegatypes.Text
1919
import com.omegar.libs.omegalaunchers.ActivityLauncher
20+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
2021
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
2122
import com.omegar.libs.omegalaunchers.FragmentLauncher
2223
import com.omegar.mvp.MvpBottomSheetDialogFragment
@@ -148,7 +149,7 @@ abstract class OmegaBottomSheetDialogFragment : MvpBottomSheetDialogFragment(),
148149
}
149150
}
150151

151-
override fun launchForResult(launcher: ActivityLauncher, requestCode: Int) {
152+
override fun launchForResult(launcher: BaseIntentLauncher, requestCode: Int) {
152153
launcher.launchForResult(this, requestCode)
153154
}
154155

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ import com.omega_r.base.binders.managers.ResettableBindersManager
1515
import com.omega_r.base.clickers.ClickManager
1616
import com.omega_r.base.mvp.views.findAnnotation
1717
import com.omega_r.base.mvp.model.Action
18-
import com.omega_r.base.mvp.views.OmegaView
1918
import com.omega_r.libs.omegatypes.Text
2019
import com.omegar.libs.omegalaunchers.ActivityLauncher
20+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
2121
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
2222
import com.omegar.libs.omegalaunchers.FragmentLauncher
2323
import com.omegar.mvp.MvpAppCompatDialogFragment
24-
import java.io.Serializable
2524

2625
/**
2726
* Created by Anton Knyazev on 04.04.2019.
@@ -153,7 +152,7 @@ abstract class OmegaDialogFragment : MvpAppCompatDialogFragment(), OmegaComponen
153152
}
154153
}
155154

156-
override fun launchForResult(launcher: ActivityLauncher, requestCode: Int) {
155+
override fun launchForResult(launcher: BaseIntentLauncher, requestCode: Int) {
157156
launcher.launchForResult(this, requestCode)
158157
}
159158

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.omega_r.base.mvp.views.findAnnotation
1717
import com.omega_r.base.mvp.model.Action
1818
import com.omega_r.libs.omegatypes.Text
1919
import com.omegar.libs.omegalaunchers.ActivityLauncher
20+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
2021
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
2122
import com.omegar.libs.omegalaunchers.FragmentLauncher
2223
import com.omegar.mvp.MvpAppCompatFragment
@@ -155,7 +156,7 @@ abstract class OmegaFragment : MvpAppCompatFragment(), OmegaComponent {
155156
}
156157
}
157158

158-
override fun launchForResult(launcher: ActivityLauncher, requestCode: Int) {
159+
override fun launchForResult(launcher: BaseIntentLauncher, requestCode: Int) {
159160
launcher.launchForResult(this, requestCode)
160161
}
161162

lib/src/main/java/com/omega_r/base/errors/ErrorHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open class ErrorHandler : (Throwable) -> Exception, CoroutineExceptionHandler {
1919
protected open fun handleHttpException(httpException: HttpException): AppException {
2020
val response = httpException.response()
2121

22-
when (response.code()) {
22+
when (response?.code()) {
2323
HTTP_INTERNAL_ERROR -> return AppException.ServerProblem(
2424
"Internal server error",
2525
httpException

lib/src/main/java/com/omega_r/base/mvp/presenters/OmegaPresenter.kt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package com.omega_r.base.mvp.presenters
33
import com.omega_r.base.data.OmegaRepository
44
import com.omega_r.base.data.sources.Source
55
import com.omega_r.base.mvp.views.OmegaView
6+
import com.omega_r.libs.omegaintentbuilder.OmegaIntentBuilder
7+
import com.omega_r.libs.omegaintentbuilder.interfaces.IntentBuilder
68
import com.omegar.libs.omegalaunchers.ActivityLauncher
9+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
710
import com.omegar.libs.omegalaunchers.Launcher
811
import com.omegar.mvp.MvpPresenter
912
import kotlinx.coroutines.*
@@ -14,14 +17,17 @@ import kotlin.coroutines.CoroutineContext
1417
/**
1518
* Created by Anton Knyazev on 04.04.2019.
1619
*/
17-
open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope {
20+
open class OmegaPresenter<View : OmegaView> : MvpPresenter<View>(), CoroutineScope {
1821

1922
private val handler = CoroutineExceptionHandler { _, throwable -> handleErrors(throwable) }
2023

2124
private val job = SupervisorJob()
2225

2326
override val coroutineContext: CoroutineContext = Dispatchers.Main + job + handler
2427

28+
protected val intentBuilder
29+
get() = OmegaIntentBuilder
30+
2531
protected open fun handleErrors(throwable: Throwable) {
2632
throwable.printStackTrace()
2733
}
@@ -46,14 +52,14 @@ open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope
4652
}
4753

4854

49-
protected fun <R> ReceiveChannel<R>.request(waiting: Boolean = true, block: suspend View.(R) -> Unit) {
55+
protected fun <R> ReceiveChannel<R>.request(waiting: Boolean = true, block: (suspend View.(R) -> Unit)? = null) {
5056
if (waiting) viewState.setWaiting(true)
5157
val channel = this
5258
launch {
5359
var hideWaiting = waiting
5460
try {
5561
for (item in channel) {
56-
block(viewState, item)
62+
block?.invoke(viewState, item)
5763

5864
if (hideWaiting) {
5965
hideWaiting = false
@@ -77,6 +83,15 @@ open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope
7783
createChannel(strategy, sourceBlock).request(waiting = waiting, block = viewStateBlock)
7884
}
7985

86+
protected fun <S : Source> OmegaRepository<S>.request(
87+
strategy: OmegaRepository.Strategy = OmegaRepository.Strategy.CACHE_AND_REMOTE,
88+
waiting: Boolean = true,
89+
sourceBlock: suspend S.() -> Unit
90+
) {
91+
createChannel(strategy, sourceBlock)
92+
.request(waiting = waiting)
93+
}
94+
8095
fun hideQueryOrMessage() = viewState.hideQueryOrMessage()
8196

8297
protected open fun Launcher.launch() {
@@ -87,10 +102,14 @@ open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope
87102
viewState.launch(createLauncher())
88103
}
89104

90-
protected fun ActivityLauncher.launchForResult(requestCode: Int) {
105+
protected fun BaseIntentLauncher.launchForResult(requestCode: Int) {
91106
viewState.launchForResult(this, requestCode)
92107
}
93108

109+
protected fun IntentBuilder.launch() = createLauncher().launch()
110+
111+
protected fun IntentBuilder.launchForResult(requestCode: Int) = createLauncher().launchForResult(requestCode)
112+
94113
open fun onLaunchResult(requestCode: Int, success: Boolean, data: Serializable?): Boolean {
95114
return false
96115
}
@@ -109,4 +128,5 @@ open class OmegaPresenter<View: OmegaView>: MvpPresenter<View>(), CoroutineScope
109128
job.cancel()
110129
}
111130

131+
112132
}

lib/src/main/java/com/omega_r/base/mvp/views/OmegaView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.omega_r.base.mvp.views
33
import com.omega_r.base.mvp.model.Action
44
import com.omega_r.base.mvp.strategies.RemoveEndTagStrategy
55
import com.omega_r.libs.omegatypes.Text
6-
import com.omegar.libs.omegalaunchers.ActivityLauncher
6+
import com.omegar.libs.omegalaunchers.BaseIntentLauncher
77
import com.omegar.libs.omegalaunchers.DialogFragmentLauncher
88
import com.omegar.libs.omegalaunchers.Launcher
99
import com.omegar.mvp.MvpView
@@ -48,7 +48,7 @@ interface OmegaView : MvpView {
4848
fun launch(launcher: DialogFragmentLauncher)
4949

5050
@StateStrategyType(OneExecutionStateStrategy::class)
51-
fun launchForResult(launcher: ActivityLauncher, requestCode: Int)
51+
fun launchForResult(launcher: BaseIntentLauncher, requestCode: Int)
5252

5353
@StateStrategyType(OneExecutionStateStrategy::class)
5454
fun setResult(success: Boolean, data: Serializable?)

0 commit comments

Comments
 (0)