use of com.frostwire.android.gui.Librarian in project frostwire by frostwire.
the class UIBittorrentDownload method deleteFilesFromContentResolver.
private void deleteFilesFromContentResolver(Context context, boolean deleteTorrent) {
final List<TransferItem> items = getItems();
final ContentResolver cr = context.getContentResolver();
Librarian librarian = Librarian.instance();
if (librarian == null) {
return;
}
for (TransferItem item : items) {
final List<FileDescriptor> fileDescriptors = librarian.getFiles(context, item.getFile().getAbsolutePath(), true);
for (FileDescriptor fd : fileDescriptors) {
File file = new File(fd.filePath);
if (file.isFile()) {
try {
TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType);
if (fetcher != null) {
cr.delete(fetcher.getContentUri(), MediaStore.MediaColumns._ID + " = " + fd.id, null);
}
} catch (Throwable e) {
LOG.error("Failed to delete file from media store. (" + fd.filePath + ")", e);
}
}
}
}
if (deleteTorrent) {
File torrent = dl.getTorrentFile();
if (torrent != null) {
final List<FileDescriptor> fds = librarian.getFiles(context, Constants.FILE_TYPE_TORRENTS, torrent.getAbsolutePath(), true);
librarian.deleteFiles(context, Constants.FILE_TYPE_TORRENTS, fds);
}
}
}
use of com.frostwire.android.gui.Librarian in project frostwire by frostwire.
the class ImageViewerFragment method loadSurroundingFileDescriptors.
private static void loadSurroundingFileDescriptors(ImageViewerFragment fragment) {
Activity activity = fragment.getActivity();
int offset = fragment.position;
Librarian librarian = Librarian.instance();
List<FileDescriptor> fileDescriptors = new ArrayList<>(0);
// We're at the beginning
if (offset == 0) {
fileDescriptors.addAll(librarian.getFiles(activity, Constants.FILE_TYPE_PICTURES, offset + 1, 1));
fragment.setPreviousStateBundle(null);
if (fileDescriptors.size() == 1) {
fragment.setNextStateBundle(fragment.prepareFileBundle(fileDescriptors.get(0), offset + 1, fragment.inFullScreenMode));
}
} else if (offset > 0) {
fileDescriptors.addAll(librarian.getFiles(activity, Constants.FILE_TYPE_PICTURES, offset - 1, 3));
// We're at the end
if (fileDescriptors.size() == 2) {
fragment.setPreviousStateBundle(fragment.prepareFileBundle(fileDescriptors.get(0), offset - 1, fragment.inFullScreenMode));
fragment.setNextStateBundle(null);
} else // We're somewhere in the list of files
if (fileDescriptors.size() == 3) {
fragment.setPreviousStateBundle(fragment.prepareFileBundle(fileDescriptors.get(0), offset - 1, fragment.inFullScreenMode));
fragment.setPreviousStateBundle(fragment.prepareFileBundle(fileDescriptors.get(2), offset + 1, fragment.inFullScreenMode));
}
}
}
Aggregations