Search in sources :

Example 1 with ContentLoadingProgressBar

use of androidx.core.widget.ContentLoadingProgressBar in project Signal-Android by WhisperSystems.

the class GiphyMp4Fragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    boolean isForMms = requireArguments().getBoolean(IS_FOR_MMS, false);
    FrameLayout frameLayout = view.findViewById(R.id.giphy_parent);
    RecyclerView recycler = view.findViewById(R.id.giphy_recycler);
    ContentLoadingProgressBar progressBar = view.findViewById(R.id.content_loading);
    TextView nothingFound = view.findViewById(R.id.nothing_found);
    GiphyMp4ViewModel viewModel = ViewModelProviders.of(requireActivity(), new GiphyMp4ViewModel.Factory(isForMms)).get(GiphyMp4ViewModel.class);
    GiphyMp4Adapter adapter = new GiphyMp4Adapter(viewModel::saveToBlob);
    List<GiphyMp4ProjectionPlayerHolder> holders = GiphyMp4ProjectionPlayerHolder.injectVideoViews(requireContext(), getViewLifecycleOwner().getLifecycle(), frameLayout, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
    GiphyMp4ProjectionRecycler callback = new GiphyMp4ProjectionRecycler(holders);
    recycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recycler.setAdapter(adapter);
    recycler.setItemAnimator(null);
    progressBar.show();
    GiphyMp4PlaybackController.attach(recycler, callback, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
    viewModel.getImages().observe(getViewLifecycleOwner(), images -> {
        nothingFound.setVisibility(images.isEmpty() ? View.VISIBLE : View.INVISIBLE);
        adapter.submitList(images, progressBar::hide);
    });
    viewModel.getPagingController().observe(getViewLifecycleOwner(), adapter::setPagingController);
    viewModel.getPagedData().observe(getViewLifecycleOwner(), unused -> recycler.scrollToPosition(0));
}
Also used : StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) FrameLayout(android.widget.FrameLayout) ContentLoadingProgressBar(androidx.core.widget.ContentLoadingProgressBar) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Example 2 with ContentLoadingProgressBar

use of androidx.core.widget.ContentLoadingProgressBar in project Signal-Android by signalapp.

the class GiphyMp4Fragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    boolean isForMms = requireArguments().getBoolean(IS_FOR_MMS, false);
    FrameLayout frameLayout = view.findViewById(R.id.giphy_parent);
    RecyclerView recycler = view.findViewById(R.id.giphy_recycler);
    ContentLoadingProgressBar progressBar = view.findViewById(R.id.content_loading);
    TextView nothingFound = view.findViewById(R.id.nothing_found);
    GiphyMp4ViewModel viewModel = ViewModelProviders.of(requireActivity(), new GiphyMp4ViewModel.Factory(isForMms)).get(GiphyMp4ViewModel.class);
    GiphyMp4Adapter adapter = new GiphyMp4Adapter(viewModel::saveToBlob);
    List<GiphyMp4ProjectionPlayerHolder> holders = GiphyMp4ProjectionPlayerHolder.injectVideoViews(requireContext(), getViewLifecycleOwner().getLifecycle(), frameLayout, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
    GiphyMp4ProjectionRecycler callback = new GiphyMp4ProjectionRecycler(holders);
    recycler.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    recycler.setAdapter(adapter);
    recycler.setItemAnimator(null);
    progressBar.show();
    GiphyMp4PlaybackController.attach(recycler, callback, GiphyMp4PlaybackPolicy.maxSimultaneousPlaybackInSearchResults());
    viewModel.getImages().observe(getViewLifecycleOwner(), images -> {
        nothingFound.setVisibility(images.isEmpty() ? View.VISIBLE : View.INVISIBLE);
        adapter.submitList(images, progressBar::hide);
    });
    viewModel.getPagingController().observe(getViewLifecycleOwner(), adapter::setPagingController);
    viewModel.getPagedData().observe(getViewLifecycleOwner(), unused -> recycler.scrollToPosition(0));
}
Also used : StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) FrameLayout(android.widget.FrameLayout) ContentLoadingProgressBar(androidx.core.widget.ContentLoadingProgressBar) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

FrameLayout (android.widget.FrameLayout)2 TextView (android.widget.TextView)2 ContentLoadingProgressBar (androidx.core.widget.ContentLoadingProgressBar)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)2