private boolean handleContextItemSelected(MenuItem menu, int position) { if (position >= mVideoAdapter.getCount()) return false; MediaWrapper media = mVideoAdapter.getItem(position); if (media == null) return false; switch (menu.getItemId()) { case R.id.video_list_play_from_start: playVideo(media, true); return true; case R.id.video_list_play_audio: playAudio(media); return true; case R.id.video_list_info: Activity activity = getActivity(); if (activity instanceof MainActivity) ((MainActivity) activity) .showSecondaryFragment(SecondaryActivity.MEDIA_INFO, media.getLocation()); else { Intent i = new Intent(activity, SecondaryActivity.class); i.putExtra("fragment", "mediaInfo"); i.putExtra("param", media.getLocation()); startActivity(i); } return true; case R.id.video_list_delete: Snackbar.make(getView(), getString(R.string.file_deleted), Snackbar.LENGTH_LONG) .setAction(android.R.string.cancel, mCancelDeleteMediaListener) .show(); Message msg = mDeleteHandler.obtainMessage(DELETE_MEDIA, position, 0); mDeleteHandler.sendMessageDelayed(msg, DELETE_DURATION); return true; } return false; }
public void deleteMedia(int position) { final MediaWrapper media = mVideoAdapter.getItem(position); final String path = media.getUri().getPath(); new Thread( new Runnable() { public void run() { Util.recursiveDelete(VLCApplication.getAppContext(), new File(path)); } }) .start(); mMediaLibrary.getMediaItems().remove(media); mVideoAdapter.remove(media); PlaybackServiceClient.getMediaLocations( getActivity(), new PlaybackServiceClient.ResultCallback<List<String>>() { @Override public void onResult(PlaybackServiceClient client, List<String> result) { if (result != null && result.contains(media.getLocation())) client.removeLocation(media.getLocation()); } @Override public void onError(PlaybackServiceClient client) {} }); }
@Override public void onDestroy() { super.onDestroy(); if (mThumbnailer != null) mThumbnailer.clearJobs(); mBarrier.reset(); mVideoAdapter.clear(); }
public void updateItem() { mVideoAdapter.update(mItemToUpdate); try { mBarrier.await(); } catch (InterruptedException e) { } catch (BrokenBarrierException e) { } }
private void updateList(Collection<VideoInfoItem> list) { try { videoListAdapter.addVideoList(list); terminateThreads(); loadThumbsRunnable = new LoadThumbsRunnable( videoListAdapter.getVideoList(), videoListAdapter.getDownloadedThumbnailList(), currentRequestId); loadThumbsThread = new Thread(loadThumbsRunnable); loadThumbsThread.start(); } catch (java.lang.IllegalStateException e) { Log.w(TAG, "Trying to set value while activity doesn't exist anymore."); } catch (Exception e) { e.printStackTrace(); } }
public void search(String query) { mode = SEARCH_MODE; this.query = query; this.lastPage = 1; videoListAdapter.clearVideoList(); setListShown(false); startSearch(query, lastPage); getListView().smoothScrollToPosition(0); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MediaWrapper media = mVideoAdapter.getItem(position); if (media == null) return; if (media instanceof MediaGroup) { MainActivity activity = (MainActivity) getActivity(); activity.showSecondaryFragment(SecondaryActivity.VIDEO_GROUP_LIST, media.getTitle()); } else playVideo(media, false); }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // Do not show the menu of media group. AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; MediaWrapper media = mVideoAdapter.getItem(info.position); if (media == null || media instanceof MediaGroup) return; MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.menu.video_list, menu); setContextMenuItems(menu, media); }
public void search(String query) { mode = SEARCH_MODE; this.query = query; this.lastPage = 1; videoListAdapter.clearVideoList(); setListShown(false); startSearch(query, lastPage); // todo: Somehow this command is not working on older devices, // although it was introduced with API level 8. Test this and find a solution. getListView().smoothScrollToPosition(0); }
private void updateViewMode() { if (getView() == null || getActivity() == null) { Log.w(TAG, "Unable to setup the view"); return; } Resources res = getResources(); boolean listMode = res.getBoolean(R.bool.list_mode); listMode |= res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT && PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("force_list_portrait", false); // Compute the left/right padding dynamically DisplayMetrics outMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); int sidePadding; // Select between grid or list if (!listMode) { sidePadding = (int) ((float) outMetrics.widthPixels / 100f * (float) Math.pow(outMetrics.density, 3) / 2f); mGridView.setNumColumns(GridView.AUTO_FIT); mGridView.setStretchMode(GRID_STRETCH_MODE); mGridView.setColumnWidth(res.getDimensionPixelSize(R.dimen.grid_card_width)); mGridView.setVerticalSpacing(res.getDimensionPixelSize(R.dimen.grid_card_vertical_spacing)); mVideoAdapter.setListMode(false); } else { sidePadding = res.getDimensionPixelSize(R.dimen.listview_side_padding); mGridView.setNumColumns(1); mGridView.setStretchMode(LIST_STRETCH_MODE); mGridView.setVerticalSpacing(0); mGridView.setHorizontalSpacing(0); mVideoAdapter.setListMode(true); } sidePadding = Math.max(0, Math.min(100, sidePadding)); mGridView.setPadding( sidePadding, mGridView.getPaddingTop(), sidePadding, mGridView.getPaddingBottom()); }
/** * Callback method from {@link VideoItemListFragment.Callbacks} indicating that the item with the * given ID was selected. */ @Override public void onItemSelected(String id) { VideoListAdapter listAdapter = (VideoListAdapter) ((VideoItemListFragment) getSupportFragmentManager().findFragmentById(R.id.videoitem_list)) .getListAdapter(); String webpageUrl = listAdapter.getVideoList().get((int) Long.parseLong(id)).webpage_url; if (mTwoPane) { // In two-pane mode, show the detail view in this activity by // adding or replacing the detail fragment using a // fragment transaction. Bundle arguments = new Bundle(); // arguments.putString(VideoItemDetailFragment.ARG_ITEM_ID, id); arguments.putString(VideoItemDetailFragment.VIDEO_URL, webpageUrl); arguments.putInt(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingServiceId); videoFragment = new VideoItemDetailFragment(); videoFragment.setArguments(arguments); videoFragment.setOnInvokeCreateOptionsMenuListener( new VideoItemDetailFragment.OnInvokeCreateOptionsMenuListener() { @Override public void createOptionsMenu() { menu.clear(); onCreateOptionsMenu(menu); } }); getSupportFragmentManager() .beginTransaction() .replace(R.id.videoitem_detail_container, videoFragment) .commit(); } else { // In single-pane mode, simply start the detail activity // for the selected item ID. Intent detailIntent = new Intent(this, VideoItemDetailActivity.class); // detailIntent.putExtra(VideoItemDetailFragment.ARG_ITEM_ID, id); detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, webpageUrl); detailIntent.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, currentStreamingServiceId); startActivity(detailIntent); } }
@Override public void onResume() { super.onResume(); if ((getActivity() instanceof MainActivity)) mMainActivity = (MainActivity) getActivity(); mMediaLibrary.setBrowser(this); mMediaLibrary.addUpdateHandler(mHandler); final boolean refresh = mVideoAdapter.isEmpty(); if (refresh) updateList(); else { mViewNomedia.setVisibility(View.GONE); focusHelper(false); } // Get & set times HashMap<String, Long> times = MediaDatabase.getInstance().getVideoTimes(); mVideoAdapter.setTimes(times); mGridView.setSelection(mGVFirstVisiblePos); updateViewMode(); if (mGroup == null && refresh) mAnimator.animate(); /* Start the thumbnailer */ if (mThumbnailer != null) mThumbnailer.start(this); }
public void updateList() { if (!mSwipeRefreshLayout.isRefreshing()) mSwipeRefreshLayout.setRefreshing(true); final List<MediaWrapper> itemList = mMediaLibrary.getVideoItems(); if (mThumbnailer != null) mThumbnailer.clearJobs(); else Log.w(TAG, "Can't generate thumbnails, the thumbnailer is missing"); mVideoAdapter.setNotifyOnChange(true); mVideoAdapter.clear(); if (itemList.size() > 0) { new Thread( new Runnable() { @Override public void run() { if (mGroup != null || itemList.size() <= 10) { for (MediaWrapper item : itemList) { if (mGroup == null || item.getTitle().startsWith(mGroup)) { mVideoAdapter.setNotifyOnChange(false); mVideoAdapter.add(item); if (mThumbnailer != null) mThumbnailer.addJob(item); } } } else { List<MediaGroup> groups = MediaGroup.group(itemList); for (MediaGroup item : groups) { mVideoAdapter.setNotifyOnChange(false); mVideoAdapter.add(item.getMedia()); if (mThumbnailer != null) mThumbnailer.addJob(item); } } if (mReadyToDisplay) display(); } }) .start(); } else focusHelper(true); stopRefresh(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Application.getInstance().setAppContext(getApplicationContext()); uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.movie); handler = new Handler(); actionbarSize = (int) (getResources().getDimension(R.dimen.action_bar_size) * Resources.getSystem().getDisplayMetrics().density); ButterKnife.bind(this); setupToolbar(); setupVideoList(); if (savedInstanceState == null) { pendingIntroAnimation = true; } else { adapter.updateItems(false); } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public void onContextPopupMenu(View anchor, final int position) { if (!AndroidUtil.isHoneycombOrLater()) { // Call the "classic" context menu anchor.performLongClick(); return; } PopupMenu popupMenu = new PopupMenu(getActivity(), anchor); popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu()); MediaWrapper media = mVideoAdapter.getItem(position); if (media == null) return; setContextMenuItems(popupMenu.getMenu(), media); popupMenu.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return handleContextItemSelected(item, position); } }); popupMenu.show(); }
public void clear() { mVideoAdapter.clear(); }
@Override public int sortDirection(int sortby) { return mVideoAdapter.sortDirection(sortby); }
@Override public void sortBy(int sortby) { mVideoAdapter.sortBy(sortby); }