Skip to content

Commit

Permalink
Solves issue #765 on updated develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-Sood committed Nov 7, 2019
1 parent 1882523 commit 78cba41
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
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.NextSearchSuggestion
import java.io.File
import java.io.FileDescriptor
import java.io.FileOutputStream
Expand Down Expand Up @@ -98,8 +99,16 @@ class ZimFileReader(
fun searchSuggestions(prefix: String, count: Int) =
jniKiwixReader.searchSuggestions(prefix, count)

fun getNextSuggestion(): String? =
valueOfJniStringAfter(jniKiwixReader::getNextSuggestion)
fun getNextSuggestion(): NextSearchSuggestion? {
val title = JNIKiwixString()
val url = JNIKiwixString()
if (jniKiwixReader.getNextSuggestion(title, url)) {
val results = NextSearchSuggestion(title.value, url.value)
return results
} else {
return 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;
NextSearchSuggestion 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,37 @@
/*
* 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;

public class NextSearchSuggestion {
private String title;
private String url;

public NextSearchSuggestion(String title, String url) {
this.title = title;
this.url = url;
}

public String getTitle() {
return title;
}

public String getUrl() {
return url;
}
}

0 comments on commit 78cba41

Please sign in to comment.