Search in sources :

Example 1 with Librarian

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);
        }
    }
}
Also used : TableFetcher(com.frostwire.android.core.providers.TableFetcher) Librarian(com.frostwire.android.gui.Librarian) TransferItem(com.frostwire.transfers.TransferItem) File(java.io.File) FileDescriptor(com.frostwire.android.core.FileDescriptor) ContentResolver(android.content.ContentResolver)

Example 2 with Librarian

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));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractActivity(com.frostwire.android.gui.views.AbstractActivity) Activity(android.app.Activity) Librarian(com.frostwire.android.gui.Librarian) Point(android.graphics.Point) FileDescriptor(com.frostwire.android.core.FileDescriptor)

Aggregations

FileDescriptor (com.frostwire.android.core.FileDescriptor)2 Librarian (com.frostwire.android.gui.Librarian)2 Activity (android.app.Activity)1 ContentResolver (android.content.ContentResolver)1 Point (android.graphics.Point)1 TableFetcher (com.frostwire.android.core.providers.TableFetcher)1 AbstractActivity (com.frostwire.android.gui.views.AbstractActivity)1 TransferItem (com.frostwire.transfers.TransferItem)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1