Skip to content

Commit

Permalink
Merge pull request #1537 from kiwix/issue/765
Browse files Browse the repository at this point in the history
Enhancement: Fixes #765 & uses updated kiwix-lib method
  • Loading branch information
macgills authored Nov 29, 2019
2 parents 4633dd0 + 42a53e3 commit 43f5f9b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -117,10 +118,13 @@ protected FilterResults performFiltering(CharSequence constraint) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 43f5f9b

Please sign in to comment.