Skip to content

Commit

Permalink
datasource: fix thread exception
Browse files Browse the repository at this point in the history
  • Loading branch information
iTaysonLab committed Apr 17, 2020
1 parent 96b197d commit 5e19aa8
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.app.Service
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import ua.itaysonlab.hfsdk.FeedItem
Expand All @@ -24,6 +26,8 @@ object PluginConnector {
private var index = 0
private var serviceSize = 0

private val handler = Handler(Looper.getMainLooper())

private val serviceConnection: ServiceConnection = object : ServiceConnection {
override fun onServiceConnected(componentName: ComponentName, iBinder: IBinder) {
Logger.log(TAG, "Connected to service ${componentName.packageName} / ${componentName.className}")
Expand Down Expand Up @@ -54,6 +58,8 @@ object PluginConnector {
}

fun getFeedAsItLoads(page: Int, onNewFeed: (List<FeedItem>) -> Unit, onLoadFinished: () -> Unit) {
Logger.log(TAG, "getFeedAsItLoads")

val stub = object: IFeedInterfaceCallback.Stub() {
override fun onFeedReceive(feed: MutableList<FeedItem>?) {
feed ?: return
Expand All @@ -65,7 +71,9 @@ object PluginConnector {
index++
if (index >= serviceSize) {
Logger.log(TAG, "Finished chain!")
onLoadFinished()
handler.post {
onLoadFinished()
}
}
}
}
Expand Down

0 comments on commit 5e19aa8

Please sign in to comment.