Search in sources :

Example 6 with FileDescriptor

use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.

the class FileListAdapter method populateViewPlain.

private void populateViewPlain(View view, FileDescriptorItem item) {
    FileDescriptor fd = item.fd;
    TextView title = findView(view, R.id.view_my_files_thumbnail_list_image_item_file_title);
    title.setText(fd.title);
    TextView fileExtra = findView(view, R.id.view_my_files_thumbnail_list_image_item_extra_text);
    if (fd.fileType == Constants.FILE_TYPE_AUDIO || fd.fileType == Constants.FILE_TYPE_APPLICATIONS) {
        fileExtra.setText(fd.artist);
    } else if (fd.fileType == Constants.FILE_TYPE_DOCUMENTS) {
        fileExtra.setText(FilenameUtils.getExtension(fd.filePath));
    } else {
        fileExtra.setText(R.string.empty_string);
    }
    TextView fileSize = findView(view, R.id.view_my_files_thumbnail_list_image_item_file_size);
    fileSize.setText(UIUtils.getBytesInHuman(fd.fileSize));
    ImageButton downloadButton = findView(view, inGridMode() ? R.id.view_my_files_thumbnail_grid_item_browse_thumbnail_image_button : R.id.view_my_files_thumbnail_list_item_browse_thumbnail_image_button);
    MediaPlaybackStatusOverlayView mediaOverlayView = findView(view, inGridMode() ? R.id.view_my_files_thumbnail_grid_item_playback_overlay_view : R.id.view_my_files_thumbnail_list_item_playback_overlay_view);
    CoreMediaPlayer mediaPlayer = Engine.instance().getMediaPlayer();
    if (mediaPlayer != null) {
        if (fd.equals(mediaPlayer.getCurrentFD(getContext())) || fd.equals(mediaPlayer.getSimplePlayerCurrentFD(getContext()))) {
            mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.STOP);
        } else {
            mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY);
        }
    }
    downloadButton.setTag(fd);
    downloadButton.setOnClickListener(downloadButtonClickListener);
    populateSDState(view, item);
}
Also used : ImageButton(android.widget.ImageButton) CoreMediaPlayer(com.frostwire.android.core.player.CoreMediaPlayer) TextView(android.widget.TextView) FileDescriptor(com.frostwire.android.core.FileDescriptor) MediaPlaybackStatusOverlayView(com.frostwire.android.gui.views.MediaPlaybackStatusOverlayView)

Example 7 with FileDescriptor

use of com.frostwire.android.core.FileDescriptor 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 8 with FileDescriptor

use of com.frostwire.android.core.FileDescriptor 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)

Example 9 with FileDescriptor

use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.

the class ImageViewerFragment method loadPicture.

private void loadPicture(Bundle stateBundle) {
    if (stateBundle != null) {
        Bundle data = stateBundle.getBundle(EXTRA_FILE_DESCRIPTOR_BUNDLE);
        int position = stateBundle.getInt(ImageViewerFragment.EXTRA_ADAPTER_FILE_OFFSET, -1);
        if (data != null) {
            inFullScreenMode = stateBundle.getBoolean(EXTRA_IN_FULL_SCREEN_MODE);
            updateData(new FileDescriptor(data), position);
        }
    }
}
Also used : Bundle(android.os.Bundle) Point(android.graphics.Point) FileDescriptor(com.frostwire.android.core.FileDescriptor)

Example 10 with FileDescriptor

use of com.frostwire.android.core.FileDescriptor in project frostwire by frostwire.

the class ApolloMediaPlayer method getCurrentFD.

@Override
public FileDescriptor getCurrentFD(final Context context) {
    try {
        long audioId = MusicUtils.getCurrentAudioId();
        FileDescriptor fd = idMap.get(audioId);
        if (audioId != -1 && fd == null && context != null) {
            fd = Librarian.instance().getFileDescriptor(context, Constants.FILE_TYPE_AUDIO, (int) audioId);
            if (fd != null) {
                idMap.put(audioId, fd);
            }
        }
        return fd;
    } catch (Throwable ignored) {
    }
    return null;
}
Also used : FileDescriptor(com.frostwire.android.core.FileDescriptor)

Aggregations

FileDescriptor (com.frostwire.android.core.FileDescriptor)15 ArrayList (java.util.ArrayList)6 File (java.io.File)4 ContentResolver (android.content.ContentResolver)3 TextView (android.widget.TextView)3 Point (android.graphics.Point)2 Bundle (android.os.Bundle)2 ImageButton (android.widget.ImageButton)2 TableFetcher (com.frostwire.android.core.providers.TableFetcher)2 Librarian (com.frostwire.android.gui.Librarian)2 FileDescriptorItem (com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem)2 MediaPlaybackStatusOverlayView (com.frostwire.android.gui.views.MediaPlaybackStatusOverlayView)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 GridView (android.widget.GridView)1