Search in sources :

Example 11 with NavigationHelper

use of com.zype.android.ui.NavigationHelper in project zype-android by zype.

the class VideosFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    model = ViewModelProviders.of(this).get(PlaylistVideosViewModel.class);
    model.setPlaylistId(playlistId);
    showProgress();
    model.getVideos().observe(this, videos -> {
        if (videos.state == DataState.READY) {
            Logger.d("getVideos(): size=" + videos.data.size());
            adapter.setData(videos.data);
            hideProgress();
        } else if (videos.state == DataState.LOADING) {
            showProgress();
        } else if (videos.state == DataState.ERROR) {
            hideProgress();
            if (!TextUtils.isEmpty(videos.errorMessage)) {
                hideProgress();
                Snackbar.make(getView(), videos.errorMessage, Snackbar.LENGTH_INDEFINITE).show();
            }
        }
    });
    model.getSelectedVideo().observe(this, video -> {
        if (video != null) {
            NavigationHelper navigationHelper = NavigationHelper.getInstance(getActivity());
            navigationHelper.handleVideoClick(getActivity(), video, playlistId, false);
            model.onSelectedVideoProcessed();
        }
    });
    adapter.setVideoListener((video) -> {
        model.onVideoClicked(video);
    });
    adapter.setPopupMenuListener((action, video) -> {
        model.handleVideoAction(action, video, success -> {
            if (success) {
                model.retrieveVideos(false);
            } else {
                NavigationHelper.getInstance(getActivity()).switchToLoginScreen(getActivity());
            }
        });
    });
}
Also used : NavigationHelper(com.zype.android.ui.NavigationHelper)

Example 12 with NavigationHelper

use of com.zype.android.ui.NavigationHelper in project zype-android by zype.

the class FavoritesFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    model = ViewModelProviders.of(getActivity()).get(FavoriteVideosViewModel.class);
    showProgress();
    model.getVideos().observe(this, videos -> {
        if (!AuthHelper.isLoggedIn() && ZypeApp.get(getActivity()).getAppConfiguration().hideFavoritesActionWhenSignedOut) {
            showEmpty(true);
            return;
        }
        if (videos == null) {
            return;
        }
        if (videos.data == null) {
            Logger.e("getVideos(): videos list is mull");
            showEmpty(true);
        } else {
            Logger.d("getVideos(): size=" + videos.data.size());
            adapter.setData(videos.data);
            if (videos.data.size() > 0) {
                showEmpty(false);
            } else {
                showEmpty(true);
            }
        }
        hideProgress();
    });
    model.getSelectedVideo().observe(this, video -> {
        if (video != null) {
            NavigationHelper navigationHelper = NavigationHelper.getInstance(getActivity());
            navigationHelper.handleVideoClick(getActivity(), video, null, false);
            model.onSelectedVideoProcessed();
        }
    });
    adapter.setVideoListener((video) -> {
        model.onVideoClicked(video);
    });
    adapter.setPopupMenuListener((action, video) -> {
        model.handleVideoAction(action, video, success -> {
            if (success) {
                model.retrieveVideos(false);
            } else {
                NavigationHelper.getInstance(getActivity()).switchToLoginScreen(getActivity());
            }
        });
    });
}
Also used : NavigationHelper(com.zype.android.ui.NavigationHelper)

Example 13 with NavigationHelper

use of com.zype.android.ui.NavigationHelper in project zype-android by zype.

the class HeroImageFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_hero_image, container, false);
    final NavigationHelper navigationHelper = NavigationHelper.getInstance(getActivity());
    ImageView imageHero = rootView.findViewById(R.id.imageHero);
    UiUtils.loadImage(getActivity(), imageUrl, imageHero);
    imageHero.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(videoId)) {
                Video video = DataRepository.getInstance(getActivity().getApplication()).getVideoSync(videoId);
                if (video == null || video.active != 1) {
                    DialogHelper.showErrorAlert(getActivity(), getString(R.string.gallery_hero_image_error_video));
                } else {
                    navigationHelper.handleVideoClick(getActivity(), video, null, false);
                }
            } else if (!TextUtils.isEmpty(playlistId)) {
                Playlist playlist = DataRepository.getInstance(getActivity().getApplication()).getPlaylistSync(playlistId);
                if (playlist == null || playlist.active != 1) {
                    DialogHelper.showErrorAlert(getActivity(), getString(R.string.gallery_hero_image_error_playlist));
                } else {
                    navigationHelper.handlePlaylistClick(getActivity(), playlist);
                }
            }
        }
    });
    return rootView;
}
Also used : Playlist(com.zype.android.Db.Entity.Playlist) NavigationHelper(com.zype.android.ui.NavigationHelper) Video(com.zype.android.Db.Entity.Video) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

NavigationHelper (com.zype.android.ui.NavigationHelper)13 Video (com.zype.android.Db.Entity.Video)4 View (android.view.View)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Playlist (com.zype.android.Db.Entity.Playlist)2 VideosCursorAdapter (com.zype.android.ui.main.fragments.videos.VideosCursorAdapter)2 Activity (android.app.Activity)1 Button (android.widget.Button)1 Nullable (androidx.annotation.Nullable)1 SearchView (androidx.appcompat.widget.SearchView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 Observer (androidx.lifecycle.Observer)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Purchase (com.android.billingclient.api.Purchase)1 Subscription (com.zype.android.Billing.Subscription)1 VideosAdapter (com.zype.android.ui.v2.videos.VideosAdapter)1 ConsumerFavoriteVideo (com.zype.android.webapi.model.consumers.ConsumerFavoriteVideo)1