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 c3c6b976..1b254e1c 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 8035beb4..9cb1895a 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 e003d6cf..9968a095 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() } }