Fix search bugs, fix #1403 (#1440)

main
Ivan Kupalov 5 years ago committed by Konrad Pozniak
parent 0454601ed6
commit dbaab6e612
  1. 10
      app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt
  2. 12
      app/src/main/java/com/keylesspalace/tusky/components/search/adapter/SearchDataSource.kt
  3. 6
      app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchFragment.kt

@ -21,9 +21,7 @@ import com.keylesspalace.tusky.util.ViewDataUtils
import com.keylesspalace.tusky.viewdata.StatusViewData
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import java.util.*
import javax.inject.Inject
import kotlin.collections.ArrayList
class SearchViewModel @Inject constructor(
mastodonApi: MastodonApi,
@ -78,9 +76,11 @@ class SearchViewModel @Inject constructor(
repoResultAccount.value = accountsRepository.getSearchData(SearchType.Account, query, disposables) {
it?.accounts ?: emptyList()
}
repoResultHashTag.value = hashtagsRepository.getSearchData(SearchType.Hashtag, String.format(Locale.getDefault(),"#%s",query), disposables) {
it?.hashtags ?: emptyList()
}
val hashtagQuery = if (query != null && query.startsWith("#")) query else "#$query"
repoResultHashTag.value =
hashtagsRepository.getSearchData(SearchType.Hashtag, hashtagQuery, disposables) {
it?.hashtags ?: emptyList()
}
}

@ -88,7 +88,17 @@ class SearchDataSource<T>(
}
.subscribe(
{ data ->
val res = parser(data)
// Working around Mastodon bug where exact match is returned no matter
// which offset is requested (so if we seach for a full username, it's
// infinite)
// see https://github.com/tootsuite/mastodon/issues/11365
val res = if (data.accounts.size == 1
&& data.accounts[0].username
.equals(searchRequest, ignoreCase = true)) {
listOf()
} else {
parser(data)
}
callback.onResult(res)
networkState.postValue(NetworkState.LOADED)

@ -24,9 +24,7 @@ import com.keylesspalace.tusky.di.ViewModelFactory
import com.keylesspalace.tusky.interfaces.LinkListener
import com.keylesspalace.tusky.util.*
import kotlinx.android.synthetic.main.fragment_search.*
import java.util.*
import javax.inject.Inject
import kotlin.concurrent.schedule
abstract class SearchFragment<T> : Fragment(),
LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener {
@ -135,10 +133,10 @@ abstract class SearchFragment<T> : Fragment(),
override fun onRefresh() {
// Dismissed here because the RecyclerView bottomProgressBar is shown as soon as the retry begins.
Timer("DelayDismiss", false).schedule(200) {
swipeRefreshLayout.post {
swipeRefreshLayout.isRefreshing = false
}
viewModel.retryAllSearches()
}
}

Loading…
Cancel
Save