Привет
Разрабатываю Android клиент под Instagram. При реализации поиска в реальном времени получаю thread interrupted exception.
Это ссылка, на ту часть проекта где реализуется поиск
https://github.com/Shokhrukh1/InstaStoryApp/tree/m...
Поиск реализуется с помощью RxJava и библиотеки instagram4Android
Ошибка вылетает в switchMap
class RxSearchObservable {
companion object {
fun fromView(searchView: MaterialSearchView): Observable<String> {
val subject = PublishSubject.create<String>()
searchView.setOnQueryTextListener(object : MaterialSearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
subject.onComplete()
return true
}
override fun onQueryTextChange(newText: String?): Boolean {
subject.onNext(newText!!)
return true
}
})
return subject
}
}
}
class WelcomeActivity : BaseActivity(), WelcomeView, OnItemClickListener<InstagramSearchUsersResultUser> {
@Inject
lateinit var presenter: WelcomePresenter
lateinit var adapter: UserAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_welcome)
setSupportActionBar(toolbar)
initSearchView()
rvUsers.layoutManager = LinearLayoutManager(this)
adapter = UserAdapter(this)
rvUsers.adapter = adapter
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu, menu)
searchView.setMenuItem(menu?.findItem(R.id.search))
return true
}
override fun onBackPressed() {
if (searchView.isSearchOpen) {
searchView.closeSearch()
} else {
super.onBackPressed()
}
}
override fun onItemClick(item: InstagramSearchUsersResultUser) {
val intent = Intent(this, StoryActivity::class.java)
intent.putExtra(EXTRA_USER_ID, item.pk)
startActivity(intent)
}
private fun initSearchView() {
RxSearchObservable.fromView(searchView)
.debounce(300, TimeUnit.MILLISECONDS)
.filter {
if (it.isEmpty())
false
else
true
}
.distinctUntilChanged()
.switchMap {
presenter.searchUser(it)
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
adapter.users = it.users
adapter.notifyDataSetChanged()
Log.d("myLogs", "${it.users.size}")
}, {
Log.d("myLogs", it.message)
})
}
}
class WelcomePresenterImpl @Inject constructor(view: WelcomeView, val instagram: Instagram4Android) : BasePresenterImpl<WelcomeView>(view), WelcomePresenter {
override fun searchUser(userName: String): Observable<InstagramSearchUsersResult> {
return Observable.create<InstagramSearchUsersResult> {
it.onNext(instagram.sendRequest(InstagramSearchUsersRequest(userName)))
}
}
}