use of com.zype.android.ui.main.fragments.videos.VideosMenuItem in project zype-android by zype.
the class OptionsFragment method showDownloadMenu.
private void showDownloadMenu() {
ArrayList<VideosMenuItem> downloadItems = new ArrayList<>();
if (isAudioDownloading || isVideoDownloading) {
downloadItems.add(new VideosMenuItem(0, R.string.menu_cancel_download));
} else {
boolean downloadUrlExist = true;
if (isAudioDownloaded) {
downloadItems.add(new VideosMenuItem(1, R.string.menu_delete_download_audio));
} else {
String audioUrl = DataHelper.getAudioUrl(getActivity().getContentResolver(), videoId);
if (!TextUtils.isEmpty(audioUrl)) {
downloadItems.add(new VideosMenuItem(2, R.string.option_download_audio));
} else {
downloadUrlExist = false;
}
}
if (isVideoDownloaded) {
downloadItems.add(new VideosMenuItem(3, R.string.menu_delete_download_video));
} else {
String videoUrl = DataHelper.getVideoUrl(getActivity().getContentResolver(), videoId);
if (!TextUtils.isEmpty(videoUrl)) {
downloadItems.add(new VideosMenuItem(4, R.string.option_download_video));
} else {
downloadUrlExist = false;
}
}
// Get audio and video download urls if not exist
if (!downloadUrlExist) {
// ((VideoDetailActivity) getActivity()).down(videoId);
}
}
final VideoMenuDialogFragment fragment = VideoMenuDialogFragment.newInstance(downloadItems);
fragment.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(fragment.getList().get(position).getId()) {
case 0:
DownloadHelper.stopDownload(mContext.getContentResolver(), videoId);
break;
case 1:
FileUtils.deleteAudioFile(videoId, mContext);
DataHelper.setAudioDeleted(mContext.getContentResolver(), videoId);
isAudioDownloaded = false;
break;
case 2:
mListener.onDownloadAudio(videoId);
break;
case 3:
FileUtils.deleteVideoFile(videoId, mContext);
DataHelper.setVideoDeleted(mContext.getContentResolver(), videoId);
isVideoDownloaded = false;
break;
case 4:
mListener.onDownloadVideo(videoId);
break;
}
fragment.dismiss();
}
});
if (!downloadItems.isEmpty()) {
fragment.show(getActivity().getFragmentManager(), "menu");
} else {
videoDetailViewModel.checkDownloadsAvailable(videoDetailViewModel.getVideoSync());
// UiUtils.showErrorSnackbar(getView(), "Download url not found");
Logger.v("Still don't have url to load");
}
}
use of com.zype.android.ui.main.fragments.videos.VideosMenuItem in project zype-android by zype.
the class VideosAdapter method getPopupMenuItems.
private List<VideosMenuItem> getPopupMenuItems(ViewHolder holder) {
List<VideosMenuItem> list = new ArrayList<>();
int currentProgress = DownloaderService.currentProgress(holder.item.id);
if (AuthHelper.isLoggedIn() || !ZypeApp.get(holder.view.getContext()).getAppConfiguration().hideFavoritesActionWhenSignedOut) {
if (holder.item.isFavorite != null && holder.item.isFavorite == 1) {
list.add(new VideosMenuItem(ITEM_UNFAVORITE, R.string.menu_unfavorite));
} else {
list.add(new VideosMenuItem(ITEM_FAVORITE, R.string.menu_favorite));
}
}
if (ZypeConfiguration.isDownloadsEnabled(holder.view.getContext()) && showDownloadOptions) {
if (currentProgress > -1) {
list.add(new VideosMenuItem(ITEM_DOWNLOAD_STOP, R.string.menu_download_stop));
} else {
if (holder.item.onAir != 1) {
if (holder.item.isDownloadedVideo == 1) {
list.add(new VideosMenuItem(ITEM_DELETE_VIDEO, R.string.menu_download_delete_video));
}
//
if (holder.item.isDownloadedAudio == 1) {
list.add(new VideosMenuItem(ITEM_DELETE_AUDIO, R.string.menu_download_delete_audio));
}
// else {
// list.add(new VideosMenuItem(ITEM_DOWNLOAD_AUDIO, R.string.menu_download_audio));
// }
}
}
}
if (ZypeSettings.SHARE_VIDEO_ENABLED) {
list.add(new VideosMenuItem(ITEM_SHARE, R.string.menu_share));
}
return list;
}
use of com.zype.android.ui.main.fragments.videos.VideosMenuItem in project zype-android by zype.
the class VideosAdapter method updatePopupMenu.
private void updatePopupMenu(final ViewHolder holder) {
final ArrayList<VideosMenuItem> items = new ArrayList<>(getPopupMenuItems(holder));
View.OnClickListener listener = view -> {
holder.view.showContextMenu();
final VideoMenuDialogFragment fragment = VideoMenuDialogFragment.newInstance(items);
fragment.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Map<String, String> event;
Tracker tracker = ZypeApp.getTracker();
switch(fragment.getList().get(position).getId()) {
case ITEM_UNFAVORITE:
if (menuListener != null) {
menuListener.onMenuItemSelected(VideoActionsHelper.ACTION_UNFAVORITE, holder.item);
}
// VideoActionsHelper.onUnfavorite(holder.item, (Activity) holder.view.getContext(), null);
event = new HitBuilders.EventBuilder().setAction("Unfavorite").setLabel("id=" + holder.item.id).build();
break;
case ITEM_FAVORITE:
if (menuListener != null) {
menuListener.onMenuItemSelected(VideoActionsHelper.ACTION_FAVORITE, holder.item);
}
// VideoActionsHelper.onFavorite(holder.item, (Activity) holder.view.getContext(), null);
event = new HitBuilders.EventBuilder().setAction("Favorite").setLabel("id=" + holder.item.id).build();
break;
case ITEM_SHARE:
if (menuListener != null) {
menuListener.onMenuItemSelected(VideoActionsHelper.ACTION_SHARE, holder.item);
}
// videoActionListener.onShareVideo(holder.item.id);
event = new HitBuilders.EventBuilder().setAction("Share").setLabel("id=" + holder.item.id).build();
break;
case ITEM_DOWNLOAD_STOP:
DownloadHelper.stopDownload(holder.view.getContext().getContentResolver(), holder.item.id);
event = new HitBuilders.EventBuilder().setAction("Stop Download").setLabel("id=" + holder.item.id).build();
break;
// break;
case ITEM_DELETE_AUDIO:
FileUtils.deleteAudioFile(holder.item.id, holder.view.getContext());
DataHelper.setAudioDeleted(holder.view.getContext().getContentResolver(), holder.item.id);
event = new HitBuilders.EventBuilder().setAction("Delete Downloaded Audio").setLabel("id=" + holder.item.id).build();
break;
case ITEM_DELETE_VIDEO:
FileUtils.deleteVideoFile(holder.item.id, holder.view.getContext());
DataHelper.setVideoDeleted(holder.view.getContext().getContentResolver(), holder.item.id);
event = new HitBuilders.EventBuilder().setAction("Delete Downloaded VideoList").setLabel("id=" + holder.item.id).build();
break;
default:
throw new IllegalStateException("unknown id=" + fragment.getList().get(position).getId());
}
fragment.dismiss();
if (tracker != null) {
tracker.send(event);
}
}
});
fragment.show(((Activity) holder.view.getContext()).getFragmentManager(), "menu");
// }
};
if (items.isEmpty()) {
holder.imagePopup.setVisibility(GONE);
} else {
holder.imagePopup.setVisibility(View.VISIBLE);
holder.imagePopup.setOnClickListener(listener);
}
}
Aggregations