diff options
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt')
-rw-r--r-- | app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt b/app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt index 14b89d8c..ad194225 100644 --- a/app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt +++ b/app/src/main/java/net/lacolaco/smileessence/view/page/SearchPageFragment.kt @@ -23,7 +23,6 @@ import net.lacolaco.smileessence.util.launchUi import net.lacolaco.smileessence.view.Partials import net.lacolaco.smileessence.view.PopupMenu import net.lacolaco.smileessence.view.confirm -import twitter4j.Query import java.util.* class SearchPageFragment : RefreshableTimelinePageFragment<Tweet, PageInfo.SearchPageInfo>() { @@ -32,7 +31,8 @@ class SearchPageFragment : RefreshableTimelinePageFragment<Tweet, PageInfo.Searc startSearch(pageInfo.query) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, + savedInstanceState: Bundle?): View { return inflater.inflate(R.layout.page_fragment_search, container, false) } @@ -104,27 +104,18 @@ class SearchPageFragment : RefreshableTimelinePageFragment<Tweet, PageInfo.Searc } override fun onSwipeDown(view: SwipyRefreshLayout) { - val query = Query() - query.query = pageInfo.query - query.count = 200 - query.resultType = Query.RECENT - if (adapter.sortedList.size > 0) { - query.sinceId = adapter.sortedList[0].id - } - runRefreshTask(query) { + val sinceId = if (adapter.sortedList.size > 0) adapter.sortedList[0].id else null + runRefreshTask(pageInfo.query, sinceId = sinceId) { view.isRefreshing = false } } override fun onSwipeUp(view: SwipyRefreshLayout) { - val query = Query() - query.query = pageInfo.query - query.count = 200 - query.resultType = Query.RECENT - if (adapter.sortedList.size > 0) { - query.maxId = adapter.sortedList[adapter.sortedList.size - 1].id - 1 - } - runRefreshTask(query) { + val maxId = if (adapter.sortedList.size > 0) + adapter.sortedList[adapter.sortedList.size - 1].id - 1 + else + null + runRefreshTask(pageInfo.query, maxId = maxId) { view.isRefreshing = false } } @@ -159,17 +150,14 @@ class SearchPageFragment : RefreshableTimelinePageFragment<Tweet, PageInfo.Searc setSwipeRefreshEnabled(queryString.isNotBlank()) adapter.sortedList.clear() if (queryString.isNotBlank()) { - val query = Query() - query.query = queryString - query.count = 200 - query.resultType = Query.RECENT - runRefreshTask(query) { } + runRefreshTask(queryString) { } } } - private fun runRefreshTask(query: Query, onFinish: () -> Unit) = launchUi { + private fun runRefreshTask(query: String, sinceId: Long? = null, maxId: Long? = null, + onFinish: () -> Unit) = launchUi { try { - val tweets = world.doSearch(query).await() + val tweets = world.doSearch(query, sinceId = sinceId, maxId = maxId).await() adapter.sortedList.addAll(tweets) onFinish() } catch (e: TwitterTaskException) { |