class HomeActivity : AbstractActivity() {
private lateinit var homeStore: HomeStore
override fun initToolBar() {
//设置toolbar相关属性
toolBar.show()
toolBar.setTitle("当日天气")
toolBar.showBack()
}
override fun initView(savedInstanceState: Bundle?) {
super.initView(savedInstanceState)
//初始化HomeView
val homeView = HomeView(this)
addView(homeView)
}
override fun initData(savedInstanceState: Bundle?) {
//初始化HomeStore
homeStore = HomeStore()
//将homeStore注册到Dispatcher中
ActionCreator.createRegisterAction(homeStore)
}
override fun releaseResource() {
//页面销毁时,将homeStore从Dispatcher中注销
ActionCreator.createUnregisterAction(homeStore)
}
}
2、HomeView
class HomeView(activity: Activity) : BaseView(activity) {
override fun getViewLayoutId(): Int {
//加载布局
return R.layout.activity_home
}
private val btnGetWeatherInfo = realView.findViewById
3、HomeStore
class HomeStore : BaseStore() {
private var homeRepository: HomeRepository? = null
override fun register() {
super.register()
//初始化HomeRepository
homeRepository = HomeRepository()
}
override fun unregister() {
super.unregister()
//销毁HomeRepository
homeRepository!!.destroy()
homeRepository = null
}
override fun onActionDispatch(type: Int, data: T?) {
when (type) {
//接收到GET_WEATHER_INFO Action后从homeRepository获取天气信息
ActionType.GET_WEATHER_INFO -> {
homeRepository!!.getWeatherInfo(data as String, object : WeatherInfoCallback {
override fun onSuccess(weatherInfo: WeatherInfo) {
//获取天气信息成功,发射天气信息
postDataEvent(WeatherInfoEvent(weatherInfo))
}
override fun onError(fluxException: FluxException) {
//获取天气信息失败,发射失败信息
postDataEvent(FluxExceptionEvent(fluxException))
}
})
}
}
}
}
4、HomeRepository
class HomeRepository : BaseRepository() {
//初始化天气的Model
private val weather = Weather()
fun getWeatherInfo(city: String, weatherInfoCallback: WeatherInfoCallback) {
//调用model的方法,进行网络请求
weather.getWeatherInfo(city)
.subscribe(object : FluxDemoSingleObserver() {
override fun onSubscribe(d: Disposable) {
super.onSubscribe(d)
add(d)
}
override fun onSuccess(t: WeatherInfo) {
weatherInfoCallback.onSuccess(t)
}
override fun onError(e: RxException) {
weatherInfoCallback.onError(FluxException(e.msg, "获取天气信息失败,请重试", e.code))
}
})
}
}
5、Weather
//获取天气的Model
class Weather {
//获取天气信息的Single流
fun getWeatherInfo(city: String): Single {
return HttpRequest.create(WeatherApi::class.java)
.getWeatherInfo(city)
.compose(RxJavaUtil.applySingleMainSchedulers())
.compose(NetRxJavaUtil.applySingleFeedTransformer())
}
}
用原型函数(prototype)可以定义一些很方便的自定义函数,实现各种自定义功能。本次主要是实现了Array的去重、获取最大值和最小值。
实现代码如下:
<script type="text/javascript">
Array.prototype.unique = function() {
var a = {};
var le
ORACLE
下面这个效率很低
SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_FS_RETURN order by id desc) A ) WHERE RN <20;
下面这个效率很高
SELECT A.*, ROWNUM RN FROM (SELECT * FROM IPAY_RCD_
Reverse a singly linked list.
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
p