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);
}
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);
}
}
}
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));
}
}
}
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);
}
}
}
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;
}
Aggregations