Search in sources :

Example 1 with VideosMenuItem

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");
    }
}
Also used : VideosMenuItem(com.zype.android.ui.main.fragments.videos.VideosMenuItem) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) VideoMenuDialogFragment(com.zype.android.ui.dialog.VideoMenuDialogFragment) AdapterView(android.widget.AdapterView)

Example 2 with VideosMenuItem

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;
}
Also used : VideosMenuItem(com.zype.android.ui.main.fragments.videos.VideosMenuItem) ArrayList(java.util.ArrayList)

Example 3 with VideosMenuItem

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);
    }
}
Also used : ZypeConfiguration(com.zype.android.ZypeConfiguration) Thumbnail(com.zype.android.webapi.model.video.Thumbnail) ProgressBar(android.widget.ProgressBar) VideoHelper(com.zype.android.core.provider.helpers.VideoHelper) Tracker(com.google.android.gms.analytics.Tracker) ImageView(android.widget.ImageView) VideosMenuItem(com.zype.android.ui.main.fragments.videos.VideosMenuItem) ArrayList(java.util.ArrayList) Map(java.util.Map) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) DataHelper(com.zype.android.core.provider.DataHelper) ContextCompat(androidx.core.content.ContextCompat) HitBuilders(com.google.android.gms.analytics.HitBuilders) LayoutInflater(android.view.LayoutInflater) VideoMenuDialogFragment(com.zype.android.ui.dialog.VideoMenuDialogFragment) ZypeSettings(com.zype.android.ZypeSettings) TextUtils(android.text.TextUtils) AuthHelper(com.zype.android.Auth.AuthHelper) Image(com.zype.android.webapi.model.video.Image) UiUtils(com.zype.android.utils.UiUtils) ViewGroup(android.view.ViewGroup) DownloaderService(com.zype.android.service.DownloaderService) List(java.util.List) TextView(android.widget.TextView) FileUtils(com.zype.android.utils.FileUtils) GONE(android.view.View.GONE) R(com.zype.android.R) ZypeApp(com.zype.android.ZypeApp) DownloadHelper(com.zype.android.service.DownloadHelper) Activity(android.app.Activity) Video(com.zype.android.Db.Entity.Video) Tracker(com.google.android.gms.analytics.Tracker) VideosMenuItem(com.zype.android.ui.main.fragments.videos.VideosMenuItem) ArrayList(java.util.ArrayList) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) VideoMenuDialogFragment(com.zype.android.ui.dialog.VideoMenuDialogFragment) AdapterView(android.widget.AdapterView)

Aggregations

VideosMenuItem (com.zype.android.ui.main.fragments.videos.VideosMenuItem)3 ArrayList (java.util.ArrayList)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 VideoMenuDialogFragment (com.zype.android.ui.dialog.VideoMenuDialogFragment)2 Activity (android.app.Activity)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 GONE (android.view.View.GONE)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 ContextCompat (androidx.core.content.ContextCompat)1 HitBuilders (com.google.android.gms.analytics.HitBuilders)1 Tracker (com.google.android.gms.analytics.Tracker)1 AuthHelper (com.zype.android.Auth.AuthHelper)1 Video (com.zype.android.Db.Entity.Video)1 R (com.zype.android.R)1