mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 10:56:50 -04:00
Fix for some zim selection issues
This commit is contained in:
parent
a5ef6f6748
commit
843b0eb1fb
@ -38,6 +38,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -49,11 +50,15 @@ public class ZimContentProvider extends ContentProvider {
|
||||
|
||||
public static final Uri UI_URI = Uri.parse("content://org.kiwix.ui/");
|
||||
|
||||
public static String originalFileName = "";
|
||||
|
||||
public static Boolean canIterate = true;
|
||||
|
||||
private static final String VIDEO_PATTERN = "([^\\s]+(\\.(?i)(3gp|mp4|m4a|webm|mkv|ogg|ogv))$)";
|
||||
|
||||
private static final Pattern PATTERN = Pattern.compile(VIDEO_PATTERN, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private static String zimFileName;
|
||||
public static String zimFileName;
|
||||
|
||||
private static JNIKiwix jniKiwix;
|
||||
|
||||
@ -64,6 +69,7 @@ public class ZimContentProvider extends ContentProvider {
|
||||
Log.e(TAG_KIWIX, "Unable to open the file " + fileName);
|
||||
zimFileName = null;
|
||||
} else {
|
||||
Log.d(TAG_KIWIX, "Opening file");
|
||||
zimFileName = fileName;
|
||||
}
|
||||
return zimFileName;
|
||||
|
@ -147,6 +147,10 @@ public class ZimFileSelectFragment extends Fragment
|
||||
|
||||
mFiles = new ArrayList<LibraryNetworkEntity.Book>();
|
||||
progressBar = (RelativeLayout) super.getActivity().getLayoutInflater().inflate(R.layout.progress_bar, null);
|
||||
|
||||
// Allow temporary use of ZimContentProvider to query books
|
||||
ZimContentProvider.canIterate = true;
|
||||
|
||||
refreshFragment();
|
||||
|
||||
return llLayout; // We must return the loaded Layout
|
||||
@ -213,9 +217,10 @@ public class ZimFileSelectFragment extends Fragment
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
Log.d(TAG_KIWIX, " mZimFileList.onItemClick");
|
||||
// Stop file search from accessing content provider potentially opening wrong file
|
||||
ZimContentProvider.canIterate = false;
|
||||
|
||||
String file;
|
||||
|
||||
LibraryNetworkEntity.Book data = (LibraryNetworkEntity.Book) mZimFileList.getItemAtPosition(position);
|
||||
file = data.file.getPath();
|
||||
finishResult(file);
|
||||
|
@ -142,7 +142,11 @@ public class FileSearch {
|
||||
private ArrayList<LibraryNetworkEntity.Book> createDataForAdapter(List<String> list) {
|
||||
|
||||
ArrayList<LibraryNetworkEntity.Book> data = new ArrayList<>();
|
||||
ZimContentProvider.originalFileName = ZimContentProvider.zimFileName;
|
||||
for (String file : list) {
|
||||
// Check a file isn't being opened and temporally use content provider to access details
|
||||
// This is not a great solution as we shouldn't need to fully open our ZIM files to get their metadata
|
||||
if (ZimContentProvider.canIterate) {
|
||||
if (ZimContentProvider.setZimFile(file) != null) {
|
||||
LibraryNetworkEntity.Book b = new LibraryNetworkEntity.Book();
|
||||
b.title = ZimContentProvider.getZimFileTitle();
|
||||
@ -158,7 +162,10 @@ public class FileSearch {
|
||||
data.add(b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Return content provider to its previous state
|
||||
ZimContentProvider.setZimFile(ZimContentProvider.originalFileName);
|
||||
ZimContentProvider.originalFileName = "";
|
||||
data = sortDataModel(data);
|
||||
|
||||
return data;
|
||||
|
Loading…
x
Reference in New Issue
Block a user