From 0b29b0330b42dd832af140ad15874794cabee0b7 Mon Sep 17 00:00:00 2001 From: Ivan Kupalov Date: Sun, 4 Aug 2019 20:32:44 +0200 Subject: [PATCH] Fix search bugs, fix #1403 (#1440) --- .../tusky/components/search/SearchViewModel.kt | 10 +++++----- .../components/search/adapter/SearchDataSource.kt | 12 +++++++++++- .../components/search/fragments/SearchFragment.kt | 6 ++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt index c3c6b9762..1b254e1c0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/SearchViewModel.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() + } } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/adapter/SearchDataSource.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/adapter/SearchDataSource.kt index 8035beb40..9cb1895ae 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/adapter/SearchDataSource.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/adapter/SearchDataSource.kt @@ -88,7 +88,17 @@ class SearchDataSource( } .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) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchFragment.kt b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchFragment.kt index e003d6cf1..9968a0950 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchFragment.kt @@ -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 : Fragment(), LinkListener, Injectable, SwipeRefreshLayout.OnRefreshListener { @@ -135,10 +133,10 @@ abstract class SearchFragment : 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() } }