Skip to content

Commit 52182f6

Browse files
committed
封装LiveDataBus
1 parent f0d3a74 commit 52182f6

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

app/build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ dependencies {
5454
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5555
//Androidx
5656
implementation 'androidx.appcompat:appcompat:1.2.0'
57-
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
57+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
5858
implementation project(path: ':common')
59-
testImplementation 'junit:junit:4.13'
59+
testImplementation 'junit:junit:4.13.1'
6060
androidTestImplementation 'androidx.test:runner:1.3.0'
6161
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
6262
implementation 'androidx.recyclerview:recyclerview:1.1.0'
@@ -71,7 +71,7 @@ dependencies {
7171
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
7272
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
7373
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
74-
74+
implementation 'com.github.fmtjava:LiveDataBus:1.0.0'
7575

7676
//okhttp + retrofit(2.6.0以后支持协程)
7777
implementation("com.squareup.okhttp3:logging-interceptor:4.0.0")
@@ -84,11 +84,11 @@ dependencies {
8484
implementation "androidx.room:room-ktx:2.2.5"
8585

8686
//navigation
87-
implementation "androidx.navigation:navigation-fragment-ktx:2.3.0"
88-
implementation "androidx.navigation:navigation-ui-ktx:2.3.0"
87+
implementation "androidx.navigation:navigation-fragment-ktx:2.3.1"
88+
implementation "androidx.navigation:navigation-ui-ktx:2.3.1"
8989

9090
//paging
91-
implementation "androidx.paging:paging-runtime:3.0.0-alpha07"
91+
implementation "androidx.paging:paging-runtime:3.0.0-alpha09"
9292

9393
//WorkManager
9494
implementation "androidx.work:work-runtime-ktx:2.4.0"
@@ -111,7 +111,6 @@ dependencies {
111111
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
112112
implementation 'com.github.Kennyc1012:MultiStateView:2.1.2'
113113
implementation 'com.jaredrummler:animated-svg-view:1.0.6'
114-
implementation 'com.jeremyliao:live-event-bus-x:1.4.4'
115114
implementation 'com.github.nitrico.lastadapter:lastadapter:2.3.0'
116115
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
117116
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'

app/src/main/java/com/fmt/github/App.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class App : Application() {
1919
.addTask(InitBuGlyTask())
2020
.addTask(InitKoInTask())
2121
.addTask(InitImageLoaderTask())
22-
.addTask(InitLiveEventBusTask())
2322
.addTask(InitSmartRefreshLayoutTask())
2423
.start()
2524
}

app/src/main/java/com/fmt/github/repos/activity/ReposDetailActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import com.fmt.github.repos.delegate.AgentWebContainer
1717
import com.fmt.github.repos.delegate.WebDelegate
1818
import com.fmt.github.repos.viewmodel.ReposViewModel
1919
import com.fmt.github.utils.ShareUtils
20-
import com.jeremyliao.liveeventbus.LiveEventBus
20+
import com.fmt.livedatabus.LiveDataBus
2121
import com.like.LikeButton
2222
import com.like.OnLikeListener
2323
import kotlinx.android.synthetic.main.activity_repos_detail.*
@@ -103,15 +103,15 @@ class ReposDetailActivity : BaseVMActivity() {
103103
mViewModel.starRepo(mOwner, mRepos)
104104
.observe(this@ReposDetailActivity, {
105105
successToast(getString(R.string.stared))
106-
LiveEventBus.get().with(Constant.STAR_EVENT_KEY).post(ReposStarEvent())
106+
LiveDataBus.with<ReposStarEvent>(Constant.STAR_EVENT_KEY).postData(ReposStarEvent())
107107
})
108108
}
109109

110110
private fun unStarRepo() {
111111
mViewModel.unStarRepo(mOwner, mRepos)
112112
.observe(this@ReposDetailActivity, {
113113
successToast(getString(R.string.un_stared))
114-
LiveEventBus.get().with(Constant.STAR_EVENT_KEY).post(ReposStarEvent())
114+
LiveDataBus.with<ReposStarEvent>(Constant.STAR_EVENT_KEY).postData(ReposStarEvent())
115115
})
116116
}
117117

app/src/main/java/com/fmt/github/tasks/InitLiveEventBusTask.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/src/main/java/com/fmt/github/user/fragment/UserReposFragment.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fmt.github.user.fragment
22

33
import android.os.Bundle
4-
import androidx.lifecycle.Observer
54
import androidx.recyclerview.widget.LinearLayoutManager
65
import com.fmt.github.BR
76
import com.fmt.github.R
@@ -14,13 +13,13 @@ import com.fmt.github.home.event.ReposStarEvent
1413
import com.fmt.github.repos.activity.go2ReposDetailActivity
1514
import com.fmt.github.repos.model.ReposItemModel
1615
import com.fmt.github.user.viewmodel.UserViewModel
16+
import com.fmt.livedatabus.LiveDataBus
1717
import com.github.nitrico.lastadapter.LastAdapter
1818
import com.github.nitrico.lastadapter.Type
19-
import com.jeremyliao.liveeventbus.LiveEventBus
2019
import kotlinx.android.synthetic.main.common_refresh_recyclerview.*
2120
import org.koin.androidx.viewmodel.ext.android.viewModel
2221

23-
class UserReposFragment : BaseListMVFragment<ReposItemModel>(){
22+
class UserReposFragment : BaseListMVFragment<ReposItemModel>() {
2423

2524
private val mViewModel: UserViewModel by viewModel()
2625
private var mUserName = ""
@@ -47,7 +46,12 @@ class UserReposFragment : BaseListMVFragment<ReposItemModel>(){
4746
val type = Type<LayoutReposBinding>(R.layout.layout_repos)
4847
.onClick {
4948
val reposItemModel = mListData[it.bindingAdapterPosition]
50-
go2ReposDetailActivity(mActivity,reposItemModel.html_url,reposItemModel.name,reposItemModel.owner.login)
49+
go2ReposDetailActivity(
50+
mActivity,
51+
reposItemModel.html_url,
52+
reposItemModel.name,
53+
reposItemModel.owner.login
54+
)
5155
}
5256
LastAdapter(mListData, BR.item)
5357
.map<ReposItemModel>(type)
@@ -75,9 +79,8 @@ class UserReposFragment : BaseListMVFragment<ReposItemModel>(){
7579

7680
//LiveEventBus实现Android消息总线
7781
private fun initStarEvent() {
78-
LiveEventBus.get()
79-
.with(Constant.STAR_EVENT_KEY, ReposStarEvent::class.java)
80-
.observe(this, Observer {
82+
LiveDataBus.with<ReposStarEvent>(Constant.STAR_EVENT_KEY)
83+
.observe(this, {
8184
onRefresh(mRefreshLayout)
8285
})
8386
}

0 commit comments

Comments
 (0)