Author: Adam <git@apiote.xyz>
use server pagination in Items
%!v(PANIC=String method: strings: negative Repeat count)
diff --git a/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt b/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt index 8141e3022c5c7737454c10e19ec6c0765c430d8a..673a603bcbb414dae90c71f1eb7eec1d2230c9a7 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt @@ -15,8 +15,12 @@ suspend fun getFeeds(server: Server): InputStream? { // todo if 401 then needs token return rawRequest(URL("${hostWithScheme(server.host)}/api/"), server) } -suspend fun queryItems(server: Server, query: String): InputStream? { - return request(server, "items", mapOf("q" to query)) +suspend fun queryItems(server: Server, query: String, limit: Int? = null): InputStream? { + val params = mutableMapOf("q" to query) + if (limit != null) { + params["limit"] = limit.toString() + } + return request(server, "items", params) } suspend fun locateItems(server: Server, plusCode: String): InputStream? { diff --git a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeFragment.kt b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeFragment.kt index 6485bded6ea46f7590d1e0a1a69fe774fe8b691e..75a59703aebdf54c2ea9c9e5e41a97cf50dc0eba 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeFragment.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeFragment.kt @@ -37,7 +37,7 @@ val shp = requireContext().getSharedPreferences("shp", AppCompatActivity.MODE_PRIVATE) binding.searchBar.lastSuggestions = listOf<Item>() homeViewModel.items.observe(viewLifecycleOwner) { - binding.searchBar.updateLastSuggestions(it.take(6)) // xxx workaround for suggestions behind navbar; should be paginated server-side + binding.searchBar.updateLastSuggestions(it) } binding.searchBar.lastSuggestions = lastSuggestions diff --git a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeViewModel.kt b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeViewModel.kt index 2f80380ccffae7b029abef53266549b5be85a5c8..287426107c8a599cba17349d16ab17c50bb03fdc 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeViewModel.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/dashboard/ui/home/HomeViewModel.kt @@ -22,10 +22,8 @@ val items: LiveData> = mutableItems fun getItems(server: Server, query: String) { viewModelScope.launch { - val itemsStream = queryItems(server, query) - if (itemsStream == null) { - // todo Toast.makeText(context, "Couldn't get response", Toast.LENGTH_SHORT).show() - } else { + val itemsStream = queryItems(server, query, limit = 6) + if (itemsStream != null) { mutableItems.value = unmarshallItemResponse(itemsStream) } }