use of org.lukhnos.nnio.file.Path in project android by nextcloud.
the class FilesSyncHelper method insertAllDBEntriesForSyncedFolder.
public static void insertAllDBEntriesForSyncedFolder(SyncedFolder syncedFolder) {
final Context context = MainApp.getAppContext();
final ContentResolver contentResolver = context.getContentResolver();
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(contentResolver);
Long currentTime = System.currentTimeMillis();
double currentTimeInSeconds = currentTime / 1000.0;
String currentTimeString = Long.toString((long) currentTimeInSeconds);
String syncedFolderInitiatedKey = SYNCEDFOLDERINITIATED + syncedFolder.getId();
boolean dryRun = TextUtils.isEmpty(arbitraryDataProvider.getValue(GLOBAL, syncedFolderInitiatedKey));
if (MediaFolderType.IMAGE == syncedFolder.getType()) {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey, currentTimeString);
} else {
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, syncedFolder);
FilesSyncHelper.insertContentIntoDB(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, syncedFolder);
}
} else if (MediaFolderType.VIDEO == syncedFolder.getType()) {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey, currentTimeString);
} else {
FilesSyncHelper.insertContentIntoDB(android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI, syncedFolder);
FilesSyncHelper.insertContentIntoDB(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, syncedFolder);
}
} else {
try {
if (dryRun) {
arbitraryDataProvider.storeOrUpdateKeyValue(GLOBAL, syncedFolderInitiatedKey, currentTimeString);
} else {
FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
Path path = Paths.get(syncedFolder.getLocalPath());
String dateInitiated = arbitraryDataProvider.getValue(GLOBAL, syncedFolderInitiatedKey);
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
File file = path.toFile();
if (attrs.lastModifiedTime().toMillis() >= Long.parseLong(dateInitiated) * 1000) {
filesystemDataProvider.storeOrUpdateFileValue(path.toAbsolutePath().toString(), attrs.lastModifiedTime().toMillis(), file.isDirectory(), syncedFolder);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
return FileVisitResult.CONTINUE;
}
});
}
} catch (IOException e) {
Log.e(TAG, "Something went wrong while indexing files for auto upload " + e.getLocalizedMessage());
}
}
}
Aggregations