-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wangzhiyu1
committed
May 19, 2020
1 parent
4f063d4
commit 017756c
Showing
37 changed files
with
507 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/my/itgungnir/rxmvvm/redux/AsyncReduxActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package my.itgungnir.rxmvvm.redux | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import io.reactivex.Observable | ||
import io.reactivex.disposables.Disposable | ||
import io.reactivex.schedulers.Schedulers | ||
import kotlinx.android.synthetic.main.activity_redux_async.* | ||
import my.itgungnir.rxmvvm.R | ||
import my.itgungnir.rxmvvm.common.redux.AppState | ||
import my.itgungnir.rxmvvm.common.redux.MyRedux | ||
import my.itgungnir.rxmvvm.common.redux.action.Reset | ||
import my.itgungnir.rxmvvm.common.redux.action.ToastEvent | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author ITGungnir | ||
* @date 2020/5/19 | ||
*/ | ||
class AsyncReduxActivity : AppCompatActivity() { | ||
|
||
private var disposable: Disposable? = null | ||
|
||
@SuppressLint("CheckResult", "SetTextI18n") | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_redux_async) | ||
|
||
currentUserName.text = "当前用户名:${MyRedux.instance.currState.username}" | ||
|
||
syncToast.setOnClickListener { | ||
MyRedux.instance.dispatch(ToastEvent, listOf()) | ||
} | ||
|
||
asyncToast.setOnClickListener { | ||
Observable.just(1) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe { | ||
MyRedux.instance.dispatch(ToastEvent, listOf()) | ||
} | ||
} | ||
|
||
disposable = MyRedux.instance.pick(AppState::toastEvent).subscribe { | ||
it.a?.let { | ||
Toast.makeText(this, "消费ToastEvent事件", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
MyRedux.instance.dispatch(Reset, listOf()) | ||
disposable?.takeIf { !it.isDisposed }?.dispose() | ||
super.onDestroy() | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/my/itgungnir/rxmvvm/redux/BackPressureReduxActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package my.itgungnir.rxmvvm.redux | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.jakewharton.rxbinding2.view.RxView | ||
import io.reactivex.disposables.Disposable | ||
import kotlinx.android.synthetic.main.activity_redux_back_pressure.* | ||
import my.itgungnir.rxmvvm.R | ||
import my.itgungnir.rxmvvm.common.redux.AppState | ||
import my.itgungnir.rxmvvm.common.redux.MyRedux | ||
import my.itgungnir.rxmvvm.common.redux.action.AddNum | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Description: | ||
* | ||
* @author ITGungnir | ||
* @date 2020/5/19 | ||
*/ | ||
class BackPressureReduxActivity : AppCompatActivity() { | ||
|
||
private var disposable: Disposable? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_redux_back_pressure) | ||
|
||
initViews() | ||
observeVM() | ||
} | ||
|
||
@SuppressLint("CheckResult") | ||
private fun initViews() { | ||
RxView.clicks(btnAdd) | ||
.throttleFirst(1, TimeUnit.SECONDS) | ||
.subscribe { | ||
for (i in 0..1000) { | ||
MyRedux.instance.dispatch(AddNum, listOf()) | ||
} | ||
} | ||
} | ||
|
||
@SuppressLint("CheckResult") | ||
private fun observeVM() { | ||
disposable = MyRedux.instance.pick(AppState::backPressureNum).subscribe { | ||
println("---------->>${it.a}") | ||
tvResult.text = it.a.toString() | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
disposable?.takeIf { !it.isDisposed }?.dispose() | ||
super.onDestroy() | ||
} | ||
} |
Oops, something went wrong.