Search in sources :

Example 1 with LoadGalleryItemsTask

use of com.odysee.app.tasks.localdata.LoadGalleryItemsTask in project odysee-android by OdyseeTeam.

the class PublishFragment method loadGalleryItems.

private void loadGalleryItems() {
    Context context = getContext();
    Helper.setViewVisibility(noVideosLoaded, View.GONE);
    LoadGalleryItemsTask task = new LoadGalleryItemsTask(loading, context, new LoadGalleryItemsTask.LoadGalleryHandler() {

        @Override
        public void onItemLoaded(GalleryItem item) {
            if (context != null) {
                if (adapter == null) {
                    adapter = new GalleryGridAdapter(Arrays.asList(item), context);
                    adapter.setListener(new GalleryGridAdapter.GalleryItemClickListener() {

                        @Override
                        public void onGalleryItemClicked(GalleryItem item) {
                            Context context = getContext();
                            if (context instanceof MainActivity) {
                                Map<String, Object> params = new HashMap<>();
                                params.put("galleryItem", item);
                                params.put("suggestedUrl", getSuggestedPublishUrl());
                            // ((MainActivity) context).openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
                            }
                        }
                    });
                } else {
                    adapter.addItem(item);
                }
                if (galleryGrid.getAdapter() == null) {
                    galleryGrid.setAdapter(adapter);
                }
                Helper.setViewVisibility(loading, adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
            }
        }

        @Override
        public void onAllItemsLoaded(List<GalleryItem> items) {
            if (context != null) {
                if (adapter == null) {
                    adapter = new GalleryGridAdapter(items, context);
                } else {
                    adapter.addItems(items);
                }
                if (galleryGrid.getAdapter() == null) {
                    galleryGrid.setAdapter(adapter);
                }
            }
            checkNoVideosLoaded();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) LoadGalleryItemsTask(com.odysee.app.tasks.localdata.LoadGalleryItemsTask) MainActivity(com.odysee.app.MainActivity) GalleryItem(com.odysee.app.model.GalleryItem) GalleryGridAdapter(com.odysee.app.adapter.GalleryGridAdapter)

Aggregations

Context (android.content.Context)1 MainActivity (com.odysee.app.MainActivity)1 GalleryGridAdapter (com.odysee.app.adapter.GalleryGridAdapter)1 GalleryItem (com.odysee.app.model.GalleryItem)1 LoadGalleryItemsTask (com.odysee.app.tasks.localdata.LoadGalleryItemsTask)1 HashMap (java.util.HashMap)1