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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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 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 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 final Pattern PATTERN = Pattern.compile(VIDEO_PATTERN, Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
private static String zimFileName;
|
public static String zimFileName;
|
||||||
|
|
||||||
private static JNIKiwix jniKiwix;
|
private static JNIKiwix jniKiwix;
|
||||||
|
|
||||||
@ -64,6 +69,7 @@ public class ZimContentProvider extends ContentProvider {
|
|||||||
Log.e(TAG_KIWIX, "Unable to open the file " + fileName);
|
Log.e(TAG_KIWIX, "Unable to open the file " + fileName);
|
||||||
zimFileName = null;
|
zimFileName = null;
|
||||||
} else {
|
} else {
|
||||||
|
Log.d(TAG_KIWIX, "Opening file");
|
||||||
zimFileName = fileName;
|
zimFileName = fileName;
|
||||||
}
|
}
|
||||||
return zimFileName;
|
return zimFileName;
|
||||||
|
@ -147,6 +147,10 @@ public class ZimFileSelectFragment extends Fragment
|
|||||||
|
|
||||||
mFiles = new ArrayList<LibraryNetworkEntity.Book>();
|
mFiles = new ArrayList<LibraryNetworkEntity.Book>();
|
||||||
progressBar = (RelativeLayout) super.getActivity().getLayoutInflater().inflate(R.layout.progress_bar, null);
|
progressBar = (RelativeLayout) super.getActivity().getLayoutInflater().inflate(R.layout.progress_bar, null);
|
||||||
|
|
||||||
|
// Allow temporary use of ZimContentProvider to query books
|
||||||
|
ZimContentProvider.canIterate = true;
|
||||||
|
|
||||||
refreshFragment();
|
refreshFragment();
|
||||||
|
|
||||||
return llLayout; // We must return the loaded Layout
|
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) {
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
|
||||||
Log.d(TAG_KIWIX, " mZimFileList.onItemClick");
|
Log.d(TAG_KIWIX, " mZimFileList.onItemClick");
|
||||||
|
// Stop file search from accessing content provider potentially opening wrong file
|
||||||
|
ZimContentProvider.canIterate = false;
|
||||||
|
|
||||||
String file;
|
String file;
|
||||||
|
|
||||||
LibraryNetworkEntity.Book data = (LibraryNetworkEntity.Book) mZimFileList.getItemAtPosition(position);
|
LibraryNetworkEntity.Book data = (LibraryNetworkEntity.Book) mZimFileList.getItemAtPosition(position);
|
||||||
file = data.file.getPath();
|
file = data.file.getPath();
|
||||||
finishResult(file);
|
finishResult(file);
|
||||||
|
@ -46,7 +46,7 @@ public class FileSearch {
|
|||||||
public static final String TAG_KIWIX = "kiwix";
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
|
|
||||||
// Array of zim file extensions
|
// Array of zim file extensions
|
||||||
public static final String[] zimFiles = { "zim", "zimaa" };
|
public static final String[] zimFiles = {"zim", "zimaa"};
|
||||||
|
|
||||||
// Scan through the file system and find all the files with .zim and .zimaa extensions
|
// Scan through the file system and find all the files with .zim and .zimaa extensions
|
||||||
public ArrayList<LibraryNetworkEntity.Book> findFiles(Context context) {
|
public ArrayList<LibraryNetworkEntity.Book> findFiles(Context context) {
|
||||||
@ -57,7 +57,7 @@ public class FileSearch {
|
|||||||
String[] tempRoots = new String[StorageDeviceUtils.getStorageDevices((Activity) context, false).size() + 1];
|
String[] tempRoots = new String[StorageDeviceUtils.getStorageDevices((Activity) context, false).size() + 1];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
tempRoots[j] = "/mnt";
|
tempRoots[j] = "/mnt";
|
||||||
for (StorageDevice storageDevice : StorageDeviceUtils.getStorageDevices((Activity) context, false)){
|
for (StorageDevice storageDevice : StorageDeviceUtils.getStorageDevices((Activity) context, false)) {
|
||||||
j++;
|
j++;
|
||||||
tempRoots[j] = storageDevice.getName();
|
tempRoots[j] = storageDevice.getName();
|
||||||
}
|
}
|
||||||
@ -142,23 +142,30 @@ public class FileSearch {
|
|||||||
private ArrayList<LibraryNetworkEntity.Book> createDataForAdapter(List<String> list) {
|
private ArrayList<LibraryNetworkEntity.Book> createDataForAdapter(List<String> list) {
|
||||||
|
|
||||||
ArrayList<LibraryNetworkEntity.Book> data = new ArrayList<>();
|
ArrayList<LibraryNetworkEntity.Book> data = new ArrayList<>();
|
||||||
|
ZimContentProvider.originalFileName = ZimContentProvider.zimFileName;
|
||||||
for (String file : list) {
|
for (String file : list) {
|
||||||
if (ZimContentProvider.setZimFile(file) != null) {
|
// Check a file isn't being opened and temporally use content provider to access details
|
||||||
LibraryNetworkEntity.Book b = new LibraryNetworkEntity.Book();
|
// This is not a great solution as we shouldn't need to fully open our ZIM files to get their metadata
|
||||||
b.title = ZimContentProvider.getZimFileTitle();
|
if (ZimContentProvider.canIterate) {
|
||||||
b.id = ZimContentProvider.getId();
|
if (ZimContentProvider.setZimFile(file) != null) {
|
||||||
b.file = new File(file);
|
LibraryNetworkEntity.Book b = new LibraryNetworkEntity.Book();
|
||||||
b.size = String.valueOf(ZimContentProvider.getFileSize());
|
b.title = ZimContentProvider.getZimFileTitle();
|
||||||
b.favicon = ZimContentProvider.getFavicon();
|
b.id = ZimContentProvider.getId();
|
||||||
b.creator = ZimContentProvider.getCreator();
|
b.file = new File(file);
|
||||||
b.publisher = ZimContentProvider.getPublisher();
|
b.size = String.valueOf(ZimContentProvider.getFileSize());
|
||||||
b.date = ZimContentProvider.getDate();
|
b.favicon = ZimContentProvider.getFavicon();
|
||||||
b.description = ZimContentProvider.getDescription();
|
b.creator = ZimContentProvider.getCreator();
|
||||||
b.language = ZimContentProvider.getLanguage();
|
b.publisher = ZimContentProvider.getPublisher();
|
||||||
data.add(b);
|
b.date = ZimContentProvider.getDate();
|
||||||
|
b.description = ZimContentProvider.getDescription();
|
||||||
|
b.language = ZimContentProvider.getLanguage();
|
||||||
|
data.add(b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Return content provider to its previous state
|
||||||
|
ZimContentProvider.setZimFile(ZimContentProvider.originalFileName);
|
||||||
|
ZimContentProvider.originalFileName = "";
|
||||||
data = sortDataModel(data);
|
data = sortDataModel(data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -166,7 +173,7 @@ public class FileSearch {
|
|||||||
|
|
||||||
// Fill fileList with files found in the specific directory
|
// Fill fileList with files found in the specific directory
|
||||||
private void addFilesToFileList(String directory, FilenameFilter[] filter,
|
private void addFilesToFileList(String directory, FilenameFilter[] filter,
|
||||||
List<String> fileList) {
|
List<String> fileList) {
|
||||||
Log.d(TAG_KIWIX, "Searching directory " + directory);
|
Log.d(TAG_KIWIX, "Searching directory " + directory);
|
||||||
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
||||||
for (File f : foundFiles) {
|
for (File f : foundFiles) {
|
||||||
@ -181,8 +188,8 @@ public class FileSearch {
|
|||||||
if (title.charAt(title.length() - 1) == "m".charAt(0)) {
|
if (title.charAt(title.length() - 1) == "m".charAt(0)) {
|
||||||
title = title.replaceFirst("[.][^.]+$", "");
|
title = title.replaceFirst("[.][^.]+$", "");
|
||||||
} else {
|
} else {
|
||||||
title = title.replaceFirst("[.][^.]+$", "");
|
title = title.replaceFirst("[.][^.]+$", "");
|
||||||
title = title.replaceFirst("[.][^.]+$", "");
|
title = title.replaceFirst("[.][^.]+$", "");
|
||||||
}
|
}
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user