Search in sources :

Example 11 with FileDescriptor

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

the class ImageViewerActivity method initComponents.

@Override
protected void initComponents(Bundle savedInstanceState) {
    Intent intent = getIntent();
    Bundle fileDescriptorBundle = intent.getBundleExtra(ImageViewerFragment.EXTRA_FILE_DESCRIPTOR_BUNDLE);
    if (fileDescriptorBundle != null && !fileDescriptorBundle.isEmpty()) {
        FileDescriptor fd = new FileDescriptor(fileDescriptorBundle);
        int position = intent.getIntExtra(ImageViewerFragment.EXTRA_ADAPTER_FILE_OFFSET, -1);
        ImageViewerFragment imageViewerFragment = findFragment(R.id.fragment_image_viewer);
        imageViewerFragment.updateData(fd, position);
        fileDescriptorBundle.clear();
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) ImageViewerFragment(com.frostwire.android.gui.fragments.ImageViewerFragment) FileDescriptor(com.frostwire.android.core.FileDescriptor)

Example 12 with FileDescriptor

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

the class FileListAdapter method convertFiles.

private static ArrayList<FileDescriptorItem> convertFiles(Collection<FileDescriptor> fds) {
    if (fds == null) {
        return new ArrayList<>();
    }
    ArrayList<FileDescriptorItem> list = new ArrayList<>(fds.size());
    for (FileDescriptor fd : fds) {
        FileDescriptorItem item = new FileDescriptorItem();
        item.fd = fd;
        list.add(item);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) FileDescriptorItem(com.frostwire.android.gui.adapters.menu.FileListAdapter.FileDescriptorItem) FileDescriptor(com.frostwire.android.core.FileDescriptor)

Example 13 with FileDescriptor

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

the class FileListAdapter method populateViewThumbnail.

private void populateViewThumbnail(View view, FileDescriptorItem item) {
    FileDescriptor fd = item.fd;
    final ImageButton fileThumbnail = 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);
    fileThumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);
    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);
    boolean inGridMode = inGridMode();
    final int thumbnailDimensions = inGridMode ? 256 : 96;
    if (fileType == Constants.FILE_TYPE_APPLICATIONS) {
        Uri uri = ImageLoader.getApplicationArtUri(fd.album);
        thumbnailLoader.load(uri, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
    } else {
        if (in(fileType, Constants.FILE_TYPE_AUDIO, Constants.FILE_TYPE_VIDEOS)) {
            if (fd.equals(Engine.instance().getMediaPlayer().getCurrentFD(getContext()))) {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.STOP);
            } else {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY);
            }
        } else if (fileType == Constants.FILE_TYPE_RINGTONES) {
            if (fd.equals(Engine.instance().getMediaPlayer().getSimplePlayerCurrentFD(getContext()))) {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.STOP);
            } else {
                mediaOverlayView.setPlaybackState(MediaPlaybackOverlayPainter.MediaPlaybackState.PLAY);
            }
        }
        if (fd.fileType == Constants.FILE_TYPE_AUDIO) {
            Uri uri = ImageLoader.getAlbumArtUri(fd.albumId);
            Uri uriRetry = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, fd.id);
            uriRetry = ImageLoader.getMetadataArtUri(uriRetry);
            thumbnailLoader.load(uri, uriRetry, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
        } else if (fd.fileType == Constants.FILE_TYPE_VIDEOS) {
            Uri uri = ContentUris.withAppendedId(Video.Media.EXTERNAL_CONTENT_URI, fd.id);
            Uri uriRetry = ImageLoader.getMetadataArtUri(uri);
            thumbnailLoader.load(uri, uriRetry, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
        } else if (fd.fileType == Constants.FILE_TYPE_PICTURES) {
            Uri uri = ContentUris.withAppendedId(Images.Media.EXTERNAL_CONTENT_URI, fd.id);
            thumbnailLoader.load(uri, fileThumbnail, thumbnailDimensions, thumbnailDimensions);
        }
    }
    if (!inGridMode) {
        TextView title = findView(view, R.id.view_my_files_thumbnail_list_image_item_file_title);
        title.setText(fd.title);
        if (fd.fileType == Constants.FILE_TYPE_AUDIO || fd.fileType == Constants.FILE_TYPE_APPLICATIONS) {
            TextView fileExtra = findView(view, R.id.view_my_files_thumbnail_list_image_item_extra_text);
            fileExtra.setText(fd.artist);
        } else {
            TextView fileExtra = findView(view, R.id.view_my_files_thumbnail_list_image_item_extra_text);
            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));
    }
    fileThumbnail.setTag(fd);
    fileThumbnail.setOnClickListener(downloadButtonClickListener);
    populateSDState(view, item);
}
Also used : ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) Uri(android.net.Uri) FileDescriptor(com.frostwire.android.core.FileDescriptor) MediaPlaybackStatusOverlayView(com.frostwire.android.gui.views.MediaPlaybackStatusOverlayView)

Example 14 with FileDescriptor

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

the class Librarian method deleteFiles.

/**
 * Deletes files.
 * If the fileType is audio it'll use MusicUtils.deleteTracks and
 * tell apollo to clean everything there, playslists, recents, etc.
 *
 * @param context
 * @param fileType
 * @param fds
 */
public void deleteFiles(final Context context, byte fileType, Collection<FileDescriptor> fds) {
    List<Integer> ids = new ArrayList<>(fds.size());
    final int audioMediaType = MediaType.getAudioMediaType().getId();
    if (fileType == audioMediaType) {
        ArrayList<Long> trackIdsToDelete = new ArrayList<>();
        for (FileDescriptor fd : fds) {
            // just in case, as we had similar checks in other code
            if (fd.fileType == audioMediaType) {
                trackIdsToDelete.add((long) fd.id);
                ids.add(fd.id);
            }
        }
        // wish I could do just trackIdsToDelete.toArray(new long[0]) ...
        long[] songsArray = new long[trackIdsToDelete.size()];
        int i = 0;
        for (Long l : trackIdsToDelete) {
            songsArray[i++] = l;
        }
        try {
            MusicUtils.deleteTracks(context, songsArray, false);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    } else {
        for (FileDescriptor fd : fds) {
            ids.add(fd.id);
        }
    }
    try {
        if (context != null) {
            ContentResolver cr = context.getContentResolver();
            TableFetcher fetcher = TableFetchers.getFetcher(fileType);
            cr.delete(fetcher.getContentUri(), MediaColumns._ID + " IN " + buildSet(ids), null);
        } else {
            Log.e(TAG, "Failed to delete files from media store, no context available");
        }
    } catch (Throwable e) {
        Log.e(TAG, "Failed to delete files from media store", e);
    }
    if (fileType == Constants.FILE_TYPE_TORRENTS) {
        FileSystem fs = Platforms.fileSystem();
        for (FileDescriptor fd : fds) {
            try {
                fs.delete(new File(fd.filePath));
            } catch (Throwable ignored) {
            }
        }
    }
    UIUtils.broadcastAction(context, Constants.ACTION_FILE_ADDED_OR_REMOVED, new UIUtils.IntentByteExtra(Constants.EXTRA_REFRESH_FILE_TYPE, fileType));
}
Also used : ArrayList(java.util.ArrayList) FileDescriptor(com.frostwire.android.core.FileDescriptor) ContentResolver(android.content.ContentResolver) FileSystem(com.frostwire.platform.FileSystem) TableFetcher(com.frostwire.android.core.providers.TableFetcher) UIUtils(com.frostwire.android.gui.util.UIUtils) File(java.io.File)

Example 15 with FileDescriptor

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

the class Librarian method getFiles.

/**
 * Returns a list of Files.
 *
 * @param offset   - from where (starting at 0)
 * @param pageSize - how many results
 * @param fetcher  - An implementation of TableFetcher
 * @return List<FileDescriptor>
 */
private List<FileDescriptor> getFiles(final Context context, int offset, int pageSize, TableFetcher fetcher, String where, String[] whereArgs) {
    List<FileDescriptor> result = new ArrayList<>(0);
    if (context == null || fetcher == null) {
        return result;
    }
    Cursor c = null;
    try {
        ContentResolver cr = context.getContentResolver();
        String[] columns = fetcher.getColumns();
        String sort = fetcher.getSortByExpression();
        if (where == null) {
            where = fetcher.where();
            whereArgs = fetcher.whereArgs();
        }
        c = cr.query(fetcher.getContentUri(), columns, where, whereArgs, sort);
        if (c == null || !c.moveToPosition(offset)) {
            return result;
        }
        fetcher.prepare(c);
        int count = 1;
        do {
            FileDescriptor fd = fetcher.fetch(c);
            result.add(fd);
        } while (c.moveToNext() && count++ < pageSize);
    } catch (Throwable e) {
        Log.e(TAG, "General failure getting files", e);
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) FileDescriptor(com.frostwire.android.core.FileDescriptor) ContentResolver(android.content.ContentResolver)

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