mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 04:33:54 -04:00
Added better ZIM file search code
This commit is contained in:
parent
6fc656a6a5
commit
319c998ed9
@ -405,7 +405,7 @@ public class ZimFileSelectFragment extends Fragment
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
||||||
mFiles = new FileSearch().findFiles();
|
mFiles = new FileSearch().findFiles(context);
|
||||||
Collections.sort(mFiles, new fileComparator());
|
Collections.sort(mFiles, new fileComparator());
|
||||||
bookDao.saveBooks(mFiles);
|
bookDao.saveBooks(mFiles);
|
||||||
return null;
|
return null;
|
||||||
|
@ -19,9 +19,12 @@
|
|||||||
|
|
||||||
package org.kiwix.kiwixmobile.utils.files;
|
package org.kiwix.kiwixmobile.utils.files;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||||
import org.kiwix.kiwixmobile.ZimContentProvider;
|
import org.kiwix.kiwixmobile.ZimContentProvider;
|
||||||
import org.kiwix.kiwixmobile.library.LibraryAdapter;
|
import org.kiwix.kiwixmobile.library.LibraryAdapter;
|
||||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||||
@ -35,6 +38,9 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import eu.mhutti1.utils.storage.StorageDevice;
|
||||||
|
import eu.mhutti1.utils.storage.StorageDeviceUtils;
|
||||||
|
|
||||||
public class FileSearch {
|
public class FileSearch {
|
||||||
|
|
||||||
public static final String TAG_KIWIX = "kiwix";
|
public static final String TAG_KIWIX = "kiwix";
|
||||||
@ -43,17 +49,20 @@ public class FileSearch {
|
|||||||
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() {
|
public ArrayList<LibraryNetworkEntity.Book> findFiles(Context context) {
|
||||||
final List<String> fileList = new ArrayList<>();
|
final List<String> fileList = new ArrayList<>();
|
||||||
FilenameFilter[] filter = new FilenameFilter[zimFiles.length];
|
FilenameFilter[] filter = new FilenameFilter[zimFiles.length];
|
||||||
|
|
||||||
// Android doesn't provide an easy way to enumerate additional sdcards
|
// Search all external directories that we can find.
|
||||||
// present on the device besides the primary one. If enumerating these
|
String[] tempRoots = new String[StorageDeviceUtils.getStorageDevices((Activity) context).size() + 1];
|
||||||
// paths proves insufficient, the alternatives used by some projects
|
int j = 0;
|
||||||
// is to read and parse contents of /proc/mounts.
|
tempRoots[j] = "/mnt";
|
||||||
final String[] additionalRoots = {
|
for (StorageDevice storageDevice : StorageDeviceUtils.getStorageDevices((Activity) context)){
|
||||||
"/mnt"
|
j++;
|
||||||
};
|
tempRoots[j] = storageDevice.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
final String[] additionalRoots = tempRoots;
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (final String extension : zimFiles) {
|
for (final String extension : zimFiles) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user