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);
|
||||
|
@ -46,7 +46,7 @@ public class FileSearch {
|
||||
public static final String TAG_KIWIX = "kiwix";
|
||||
|
||||
// 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
|
||||
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];
|
||||
int j = 0;
|
||||
tempRoots[j] = "/mnt";
|
||||
for (StorageDevice storageDevice : StorageDeviceUtils.getStorageDevices((Activity) context, false)){
|
||||
for (StorageDevice storageDevice : StorageDeviceUtils.getStorageDevices((Activity) context, false)) {
|
||||
j++;
|
||||
tempRoots[j] = storageDevice.getName();
|
||||
}
|
||||
@ -142,23 +142,30 @@ 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) {
|
||||
if (ZimContentProvider.setZimFile(file) != null) {
|
||||
LibraryNetworkEntity.Book b = new LibraryNetworkEntity.Book();
|
||||
b.title = ZimContentProvider.getZimFileTitle();
|
||||
b.id = ZimContentProvider.getId();
|
||||
b.file = new File(file);
|
||||
b.size = String.valueOf(ZimContentProvider.getFileSize());
|
||||
b.favicon = ZimContentProvider.getFavicon();
|
||||
b.creator = ZimContentProvider.getCreator();
|
||||
b.publisher = ZimContentProvider.getPublisher();
|
||||
b.date = ZimContentProvider.getDate();
|
||||
b.description = ZimContentProvider.getDescription();
|
||||
b.language = ZimContentProvider.getLanguage();
|
||||
data.add(b);
|
||||
// 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();
|
||||
b.id = ZimContentProvider.getId();
|
||||
b.file = new File(file);
|
||||
b.size = String.valueOf(ZimContentProvider.getFileSize());
|
||||
b.favicon = ZimContentProvider.getFavicon();
|
||||
b.creator = ZimContentProvider.getCreator();
|
||||
b.publisher = ZimContentProvider.getPublisher();
|
||||
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);
|
||||
|
||||
return data;
|
||||
@ -166,7 +173,7 @@ public class FileSearch {
|
||||
|
||||
// Fill fileList with files found in the specific directory
|
||||
private void addFilesToFileList(String directory, FilenameFilter[] filter,
|
||||
List<String> fileList) {
|
||||
List<String> fileList) {
|
||||
Log.d(TAG_KIWIX, "Searching directory " + directory);
|
||||
File[] foundFiles = listFilesAsArray(new File(directory), filter, -1);
|
||||
for (File f : foundFiles) {
|
||||
@ -181,8 +188,8 @@ public class FileSearch {
|
||||
if (title.charAt(title.length() - 1) == "m".charAt(0)) {
|
||||
title = title.replaceFirst("[.][^.]+$", "");
|
||||
} else {
|
||||
title = title.replaceFirst("[.][^.]+$", "");
|
||||
title = title.replaceFirst("[.][^.]+$", "");
|
||||
title = title.replaceFirst("[.][^.]+$", "");
|
||||
title = title.replaceFirst("[.][^.]+$", "");
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user