Commit 20013e44 by LouisWang

feat(项目):调整代码规范

parent 754147f8
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".demo.list.ListActivity" /> <activity android:name=".demo.list.PopularWebsitesActivity" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -23,8 +23,6 @@ inline fun <reified D : Any> BaseRequest<*>.asResponse(): HttpObservable<D> { ...@@ -23,8 +23,6 @@ inline fun <reified D : Any> BaseRequest<*>.asResponse(): HttpObservable<D> {
/** /**
* 将Http响应数据转换成一个列表,去除最外层封装 * 将Http响应数据转换成一个列表,去除最外层封装
*
* @param isAuth 是否需要添加认证参数,默认是true。
*/ */
inline fun <reified D : Any> BaseRequest<*>.asResponseList(): HttpObservable<ArrayList<D>> { inline fun <reified D : Any> BaseRequest<*>.asResponseList(): HttpObservable<ArrayList<D>> {
return HttpObservableImpl(this, ResponseListConverter(D::class.java)) return HttpObservableImpl(this, ResponseListConverter(D::class.java))
......
...@@ -4,7 +4,7 @@ import com.autocareai.lib.net.HttpUtil ...@@ -4,7 +4,7 @@ import com.autocareai.lib.net.HttpUtil
import com.autocareai.lib.net.observable.HttpObservable import com.autocareai.lib.net.observable.HttpObservable
import com.autocareai.mvvmdemo.common.http.asResponse import com.autocareai.mvvmdemo.common.http.asResponse
import com.autocareai.mvvmdemo.common.http.asResponseList import com.autocareai.mvvmdemo.common.http.asResponseList
import com.autocareai.mvvmdemo.demo.enity.ListEntity import com.autocareai.mvvmdemo.demo.enity.PopularWebsitesEntity
import com.autocareai.mvvmdemo.demo.enity.UserEntity import com.autocareai.mvvmdemo.demo.enity.UserEntity
/** /**
...@@ -35,7 +35,7 @@ object DemoApi { ...@@ -35,7 +35,7 @@ object DemoApi {
/** /**
* 获取常用网站 * 获取常用网站
*/ */
fun getPopularWebsites(): HttpObservable<ArrayList<ListEntity>> { fun getPopularWebsites(): HttpObservable<ArrayList<PopularWebsitesEntity>> {
return HttpUtil.get("friend/json") return HttpUtil.get("friend/json")
.asResponseList() .asResponseList()
} }
......
...@@ -12,7 +12,7 @@ import kotlinx.android.parcel.Parcelize ...@@ -12,7 +12,7 @@ import kotlinx.android.parcel.Parcelize
* </pre> * </pre>
*/ */
@Parcelize @Parcelize
class ListEntity : Parcelable { class PopularWebsitesEntity : Parcelable {
//网站id //网站id
var id = 0 var id = 0
......
...@@ -7,35 +7,40 @@ import com.autocareai.lib.route.Route ...@@ -7,35 +7,40 @@ import com.autocareai.lib.route.Route
import com.autocareai.mvvmdemo.R import com.autocareai.mvvmdemo.R
import com.autocareai.mvvmdemo.common.view.BaseLifecycleActivity import com.autocareai.mvvmdemo.common.view.BaseLifecycleActivity
import com.autocareai.mvvmdemo.demo.route.DemoRoute import com.autocareai.mvvmdemo.demo.route.DemoRoute
import kotlinx.android.synthetic.main.list_activity.* import kotlinx.android.synthetic.main.activity_popular_websites.*
/** /**
* <pre> * <pre>
* author : louis wang * author : louis wang
* time : 2020/06/28 * time : 2020/06/28
* desc : * desc : 常用网站界面
* version: 1.0 * version: 1.0
* </pre> * </pre>
*/ */
@Route(path = DemoRoute.DEMO_LIST) @Route(path = DemoRoute.POPULAR_WEBSITES)
class ListActivity : BaseLifecycleActivity<ListViewModel>() { class PopularWebsitesActivity : BaseLifecycleActivity<PopularWebsitesViewModel>() {
private val adapter by lazy { ListAdapter() } //常用网站适配器
private val mPopularWebsitesAdapter by lazy { PopularWebsitesAdapter() }
override fun getLayoutId(): Int = R.layout.list_activity override fun getLayoutId(): Int = R.layout.activity_popular_websites
override fun getViewModelClass(): Class<ListViewModel> = ListViewModel::class.java override fun getViewModelClass(): Class<PopularWebsitesViewModel> =
PopularWebsitesViewModel::class.java
override fun initView(savedInstanceState: Bundle?) { override fun initView(savedInstanceState: Bundle?) {
swipeRefresh.setOnRefreshListener { loadDataOnCreate() }
recycleView.layoutManager = LinearLayoutManager(this) recycleView.layoutManager = LinearLayoutManager(this)
recycleView.adapter = adapter recycleView.adapter = mPopularWebsitesAdapter
}
override fun initListener() {
swipeRefresh.setOnRefreshListener { loadDataOnCreate() }
} }
override fun initLifecycleObserver() { override fun initLifecycleObserver() {
mViewModel.listDataEvent.observe(this, Observer { mViewModel.listDataEvent.observe(this, Observer {
swipeRefresh.isRefreshing = false swipeRefresh.isRefreshing = false
adapter.setNewData(it) mPopularWebsitesAdapter.setNewData(it)
}) })
} }
......
...@@ -5,7 +5,7 @@ import com.autocareai.lib.extension.load ...@@ -5,7 +5,7 @@ import com.autocareai.lib.extension.load
import com.autocareai.lib.widget.recyclerview.BaseViewHolder import com.autocareai.lib.widget.recyclerview.BaseViewHolder
import com.autocareai.mvvmdemo.R import com.autocareai.mvvmdemo.R
import com.autocareai.mvvmdemo.common.view.BaseAdapter import com.autocareai.mvvmdemo.common.view.BaseAdapter
import com.autocareai.mvvmdemo.demo.enity.ListEntity import com.autocareai.mvvmdemo.demo.enity.PopularWebsitesEntity
/** /**
...@@ -16,13 +16,15 @@ import com.autocareai.mvvmdemo.demo.enity.ListEntity ...@@ -16,13 +16,15 @@ import com.autocareai.mvvmdemo.demo.enity.ListEntity
* version: 1.0 * version: 1.0
* </pre> * </pre>
*/ */
class ListAdapter : BaseAdapter<ListEntity>(R.layout.list_item) { class PopularWebsitesAdapter :
BaseAdapter<PopularWebsitesEntity>(R.layout.recycle_item_popular_websites) {
override fun convert(helper: BaseViewHolder, item: ListEntity) { override fun convert(helper: BaseViewHolder, item: PopularWebsitesEntity) {
super.convert(helper, item) super.convert(helper, item)
helper.setText(R.id.tvTitle, item.name) helper.setText(R.id.tvTitle, item.name)
helper.setText(R.id.tvLink, item.link) helper.setText(R.id.tvLink, item.link)
helper.getView<ImageView>(R.id.image).load(item.link, R.mipmap.ic_launcher, R.mipmap.ic_launcher) helper.getView<ImageView>(R.id.image)
.load(item.link, R.mipmap.ic_launcher, R.mipmap.ic_launcher)
} }
} }
\ No newline at end of file
...@@ -5,22 +5,22 @@ import com.autocareai.lib.lifecycle.extension.post ...@@ -5,22 +5,22 @@ import com.autocareai.lib.lifecycle.extension.post
import com.autocareai.lib.lifecycle.livedata.SingleLiveEvent import com.autocareai.lib.lifecycle.livedata.SingleLiveEvent
import com.autocareai.mvvmdemo.common.view.BaseViewModel import com.autocareai.mvvmdemo.common.view.BaseViewModel
import com.autocareai.mvvmdemo.demo.api.DemoApi import com.autocareai.mvvmdemo.demo.api.DemoApi
import com.autocareai.mvvmdemo.demo.enity.ListEntity import com.autocareai.mvvmdemo.demo.enity.PopularWebsitesEntity
/** /**
* <pre> * <pre>
* author : louis wang * author : louis wang
* time : 2020/06/28 * time : 2020/06/28
* desc : * desc : 常用网站ViewModel
* version: 1.0 * version: 1.0
* </pre> * </pre>
*/ */
class ListViewModel : BaseViewModel() { class PopularWebsitesViewModel : BaseViewModel() {
/** /**
* 常用网站数据 * 常用网站数据
*/ */
var listDataEvent = SingleLiveEvent<ArrayList<ListEntity>>() var listDataEvent = SingleLiveEvent<ArrayList<PopularWebsitesEntity>>()
/** /**
* 获取常用网站 * 获取常用网站
......
...@@ -38,7 +38,7 @@ class MainActivity : BaseLifecycleActivity<MainViewModel>() { ...@@ -38,7 +38,7 @@ class MainActivity : BaseLifecycleActivity<MainViewModel>() {
mViewModel.toListEvent.observe(this, Observer { mViewModel.toListEvent.observe(this, Observer {
// 跳转至列表界面 // 跳转至列表界面
DemoRoute.toList().navigation(this) DemoRoute.toPopularWebsites().navigation(this)
}) })
} }
} }
...@@ -12,12 +12,17 @@ import com.autocareai.lib.route.RouteNavigation ...@@ -12,12 +12,17 @@ import com.autocareai.lib.route.RouteNavigation
*/ */
object DemoRoute { object DemoRoute {
//登录界面
const val LOGIN = "/demo/login" const val LOGIN = "/demo/login"
const val DEMO_LIST = "/demo/list" //常用网站界面
const val POPULAR_WEBSITES = "/demo/list"
fun toList(): RouteNavigation { /**
return RouteNavigation(DEMO_LIST) * 跳转常用网站界面
*/
fun toPopularWebsites(): RouteNavigation {
return RouteNavigation(POPULAR_WEBSITES)
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment