mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Merge pull request #1537 from kiwix/issue/765
Enhancement: Fixes #765 & uses updated kiwix-lib method
This commit is contained in:
commit
43f5f9bf63
@ -125,7 +125,7 @@ object Versions {
|
||||
|
||||
const val io_mockk: String = "1.9" // available: "1.9.3"
|
||||
|
||||
const val kiwixlib: String = "8.1.0"
|
||||
const val kiwixlib: String = "8.2.1"
|
||||
|
||||
const val material: String = "1.0.0"
|
||||
|
||||
|
@ -36,6 +36,7 @@ import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book
|
||||
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
|
||||
import org.kiwix.kiwixmobile.core.utils.files.FileUtils
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Companion.CONTENT_URI
|
||||
import org.kiwix.kiwixmobile.core.search.SearchSuggestion
|
||||
import java.io.File
|
||||
import java.io.FileDescriptor
|
||||
import java.io.FileOutputStream
|
||||
@ -98,8 +99,14 @@ class ZimFileReader(
|
||||
fun searchSuggestions(prefix: String, count: Int) =
|
||||
jniKiwixReader.searchSuggestions(prefix, count)
|
||||
|
||||
fun getNextSuggestion(): String? =
|
||||
valueOfJniStringAfter(jniKiwixReader::getNextSuggestion)
|
||||
fun getNextSuggestion(): SearchSuggestion? {
|
||||
val title = JNIKiwixString()
|
||||
val url = JNIKiwixString()
|
||||
|
||||
return if (jniKiwixReader.getNextSuggestion(title, url))
|
||||
SearchSuggestion(title.value, url.value)
|
||||
else null
|
||||
}
|
||||
|
||||
fun getPageUrlFrom(title: String): String? =
|
||||
valueOfJniStringAfter { jniKiwixReader.getPageUrlFromTitle(title, it) }
|
||||
|
@ -26,6 +26,7 @@ import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.TextView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.kiwix.kiwixlib.JNIKiwix;
|
||||
@ -117,10 +118,13 @@ public class AutoCompleteAdapter extends ArrayAdapter<String> implements Filtera
|
||||
zimReaderContainer.searchSuggestions(query, 200);
|
||||
String suggestion;
|
||||
String suggestionUrl;
|
||||
SearchSuggestion results;
|
||||
List<String> alreadyAdded = new ArrayList<>();
|
||||
while ((suggestion = zimReaderContainer.getNextSuggestion()) != null) {
|
||||
suggestionUrl = zimReaderContainer.getPageUrlFromTitle(suggestion);
|
||||
if (!alreadyAdded.contains(suggestionUrl)) {
|
||||
while ((results = zimReaderContainer.getNextSuggestion()) != null) {
|
||||
suggestion = results.getTitle();
|
||||
suggestionUrl = results.getUrl();
|
||||
|
||||
if (!alreadyAdded.contains(suggestionUrl)) {
|
||||
alreadyAdded.add(suggestionUrl);
|
||||
data.add(suggestion);
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.search
|
||||
|
||||
data class SearchSuggestion(val title: String, val url: String)
|
Loading…
x
Reference in New Issue
Block a user