forked from upstream-mirrors/OpenTracks
Import: replaced async task with thread.
Extracted directory chooser into a separate activity.
This commit is contained in:
@@ -29,6 +29,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import de.dennisguse.opentracks.BuildConfig;
|
||||
@@ -111,6 +112,10 @@ public class FileUtils {
|
||||
return fileName.substring(index + 1);
|
||||
}
|
||||
|
||||
public static String getExtension(DocumentFile file) {
|
||||
return getExtension(file.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a filename with the given base and the given extension, possibly adding a suffix to ensure the file doesn't exist.
|
||||
*
|
||||
@@ -229,13 +234,13 @@ public class FileUtils {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Copy a File (src) to a File (dst).
|
||||
*
|
||||
* @param src source file.
|
||||
* @param dst destination file.
|
||||
*/
|
||||
public static void copy(FileDescriptor src, File dst) {
|
||||
*/
|
||||
public static void copy(FileDescriptor src, File dst) {
|
||||
try (FileChannel in = new FileInputStream(src).getChannel();
|
||||
FileChannel out = new FileOutputStream(dst).getChannel()) {
|
||||
in.transferTo(0, in.size(), out);
|
||||
@@ -262,7 +267,7 @@ public class FileUtils {
|
||||
* @param context the Context.
|
||||
* @param trackId the id of the Track.
|
||||
* @param uri the uri to check.
|
||||
* @return File object or null.
|
||||
* @return File object or null.
|
||||
*/
|
||||
public static File getPhotoFileIfExists(Context context, long trackId, Uri uri) {
|
||||
if (uri == null) {
|
||||
@@ -300,4 +305,18 @@ public class FileUtils {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public static ArrayList<DocumentFile> getFiles(DocumentFile file) {
|
||||
ArrayList<DocumentFile> files = new ArrayList<>();
|
||||
|
||||
for (DocumentFile candidate : file.listFiles()) {
|
||||
if (!candidate.isDirectory()) {
|
||||
files.add(candidate);
|
||||
} else {
|
||||
files.addAll(getFiles(candidate));
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user