// Path: library/src/main/java/com/veinhorn/scrollgalleryview/builder/GalleryBuilder.java
// public interface GalleryBuilder {
//     /**
//      * Sets up settings for gallery
//      * @param settings contains options for gallery
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder settings(GallerySettings settings);
// 
//     GalleryBuilder onImageClickListener(ScrollGalleryView.OnImageClickListener listener);
// 
//     GalleryBuilder onImageLongClickListener(ScrollGalleryView.OnImageLongClickListener listener);
// 
//     GalleryBuilder onPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener);
// 
//     /**
//      * Adds single MediaInfo to gallery
//      * @param media is a single MediaInfo object
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder add(MediaInfo media);
// 
//     /**
//      * Adds a list of MediaInfos to gallery
//      * @param medias is a list of MediaInfo objects
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder add(List<MediaInfo> medias);
// 
//     /**
//      * Builds gallery from provided medias
//      * @return initialized ScrollGalleryView
//      */
//     ScrollGalleryView build();
// }
// 
// Path: library/src/main/java/com/veinhorn/scrollgalleryview/builder/GalleryBuilderImpl.java
// public class GalleryBuilderImpl implements GalleryBuilder {
//     private ScrollGalleryView galleryView;
//     private GallerySettings settings;
// 
//     private ScrollGalleryView.OnImageClickListener onImageClickListener;
//     private ScrollGalleryView.OnImageLongClickListener onImageLongClickListener;
//     private ViewPager.OnPageChangeListener onPageChangeListener;
// 
//     private List<MediaInfo> medias;
// 
//     public GalleryBuilderImpl(ScrollGalleryView galleryView) {
//         this.galleryView = galleryView;
//         this.medias = new ArrayList<>();
//     }
// 
//     @Override
//     public GalleryBuilder settings(GallerySettings settings) {
//         this.settings = settings;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onImageClickListener(ScrollGalleryView.OnImageClickListener onImageClickListener) {
//         this.onImageClickListener = onImageClickListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onImageLongClickListener(ScrollGalleryView.OnImageLongClickListener onImageLongClickListener) {
//         this.onImageLongClickListener = onImageLongClickListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener) {
//         this.onPageChangeListener = onPageChangeListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder add(MediaInfo media) {
//         this.medias.add(media);
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder add(List<MediaInfo> medias) {
//         this.medias.addAll(medias);
//         return this;
//     }
// 
//     @Override
//     public ScrollGalleryView build() {
//         // check here all parameters
// 
//         return galleryView
//                 .setThumbnailSize(settings.getThumbnailSize())
//                 .setZoom(settings.isZoomEnabled())
//                 .addOnImageClickListener(onImageClickListener)
//                 .addOnImageLongClickListener(onImageLongClickListener)
//                 .setFragmentManager(settings.getFragmentManager())
//                 .addOnPageChangeListener(onPageChangeListener)
//                 .addMedia(medias);
//     }
// }
// 
// Path: library/src/main/java/com/veinhorn/scrollgalleryview/loader/MediaLoader.java
// public interface MediaLoader {
// 
//     /**
//      * @return true if implementation load's image, otherwise false
//      */
//     boolean isImage();
// 
//     /**
//      * Loads image and sets it to imageView. After that implementation can call callback to set imageView's
//      * scale type to ScaleType.FIT_CENTER.
//      */
//     void loadMedia(Context context, ImageView imageView, SuccessCallback callback);
// 
//     /**
//      * Loads thumbnail image and sets it to thumbnailView. After that implementation can call callback
//      * to set thumbnailView's scale type to ScaleType.FIT_CENTER.
//      */
// 
//     void loadThumbnail(Context context, ImageView thumbnailView, SuccessCallback callback);
// 
//     /**
//      * Implementation may call this callback for report to imageView, what it's image was changed
//      */
//     interface SuccessCallback {
//         void onSuccess();
//     }
// }


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.media.ThumbnailUtils;
import android.os.Build;
import android.support.transition.Transition;
import android.support.transition.TransitionManager;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.veinhorn.scrollgalleryview.builder.GalleryBuilder;
import com.veinhorn.scrollgalleryview.builder.GalleryBuilderImpl;
import com.veinhorn.scrollgalleryview.loader.MediaLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
    public void clearGallery() {
        // remove all media infos
        mListOfMedia.clear();

        pagerAdapter = new ScreenSlidePagerAdapter(
                fragmentManager,
                mListOfMedia,
                zoomEnabled,
                innerOnImageClickListener,
                innerOnImageLongClickListener
        );

        viewPager.setAdapter(pagerAdapter);
        // remove thumbnails
        thumbnailsContainer.removeAllViews();
    }

    /**
     * Remove a media from the gallery
     *
     * @param position media's position to remove
     */
    public void removeMedia(int position) {
        if (position >= mListOfMedia.size() || position < 0) {
            return;
        }
        pagerAdapter.removeItem(position);
        removeThumbnail(position);
    }

// Path: library/src/main/java/com/veinhorn/scrollgalleryview/builder/GalleryBuilder.java
// public interface GalleryBuilder {
//     /**
//      * Sets up settings for gallery
//      * @param settings contains options for gallery
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder settings(GallerySettings settings);
// 
//     GalleryBuilder onImageClickListener(ScrollGalleryView.OnImageClickListener listener);
// 
//     GalleryBuilder onImageLongClickListener(ScrollGalleryView.OnImageLongClickListener listener);
// 
//     GalleryBuilder onPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener);
// 
//     /**
//      * Adds single MediaInfo to gallery
//      * @param media is a single MediaInfo object
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder add(MediaInfo media);
// 
//     /**
//      * Adds a list of MediaInfos to gallery
//      * @param medias is a list of MediaInfo objects
//      * @return GalleryBuilder object
//      */
//     GalleryBuilder add(List<MediaInfo> medias);
// 
//     /**
//      * Builds gallery from provided medias
//      * @return initialized ScrollGalleryView
//      */
//     ScrollGalleryView build();
// }
// 
// Path: library/src/main/java/com/veinhorn/scrollgalleryview/builder/GalleryBuilderImpl.java
// public class GalleryBuilderImpl implements GalleryBuilder {
//     private ScrollGalleryView galleryView;
//     private GallerySettings settings;
// 
//     private ScrollGalleryView.OnImageClickListener onImageClickListener;
//     private ScrollGalleryView.OnImageLongClickListener onImageLongClickListener;
//     private ViewPager.OnPageChangeListener onPageChangeListener;
// 
//     private List<MediaInfo> medias;
// 
//     public GalleryBuilderImpl(ScrollGalleryView galleryView) {
//         this.galleryView = galleryView;
//         this.medias = new ArrayList<>();
//     }
// 
//     @Override
//     public GalleryBuilder settings(GallerySettings settings) {
//         this.settings = settings;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onImageClickListener(ScrollGalleryView.OnImageClickListener onImageClickListener) {
//         this.onImageClickListener = onImageClickListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onImageLongClickListener(ScrollGalleryView.OnImageLongClickListener onImageLongClickListener) {
//         this.onImageLongClickListener = onImageLongClickListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder onPageChangeListener(ViewPager.OnPageChangeListener onPageChangeListener) {
//         this.onPageChangeListener = onPageChangeListener;
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder add(MediaInfo media) {
//         this.medias.add(media);
//         return this;
//     }
// 
//     @Override
//     public GalleryBuilder add(List<MediaInfo> medias) {
//         this.medias.addAll(medias);
//         return this;
//     }
// 
//     @Override
//     public ScrollGalleryView build() {
//         // check here all parameters
// 
//         return galleryView
//                 .setThumbnailSize(settings.getThumbnailSize())
//                 .setZoom(settings.isZoomEnabled())
//                 .addOnImageClickListener(onImageClickListener)
//                 .addOnImageLongClickListener(onImageLongClickListener)
//                 .setFragmentManager(settings.getFragmentManager())
//                 .addOnPageChangeListener(onPageChangeListener)
//                 .addMedia(medias);
//     }
// }
// 
// Path: library/src/main/java/com/veinhorn/scrollgalleryview/loader/MediaLoader.java
// public interface MediaLoader {
// 
//     /**
//      * @return true if implementation load's image, otherwise false
//      */
//     boolean isImage();
// 
//     /**
//      * Loads image and sets it to imageView. After that implementation can call callback to set imageView's
//      * scale type to ScaleType.FIT_CENTER.
//      */
//     void loadMedia(Context context, ImageView imageView, SuccessCallback callback);
// 
//     /**
//      * Loads thumbnail image and sets it to thumbnailView. After that implementation can call callback
//      * to set thumbnailView's scale type to ScaleType.FIT_CENTER.
//      */
// 
//     void loadThumbnail(Context context, ImageView thumbnailView, SuccessCallback callback);
// 
//     /**
//      * Implementation may call this callback for report to imageView, what it's image was changed
//      */
//     interface SuccessCallback {
//         void onSuccess();
//     }
// }


// Path: library/src/main/java/com/veinhorn/scrollgalleryview/ScrollGalleryView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.media.ThumbnailUtils;
import android.os.Build;
import android.support.transition.Transition;
import android.support.transition.TransitionManager;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.veinhorn.scrollgalleryview.builder.GalleryBuilder;
import com.veinhorn.scrollgalleryview.builder.GalleryBuilderImpl;
import com.veinhorn.scrollgalleryview.loader.MediaLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

    public void clearGallery() {
        // remove all media infos
        mListOfMedia.clear();

        pagerAdapter = new ScreenSlidePagerAdapter(
                fragmentManager,
                mListOfMedia,
                zoomEnabled,
                innerOnImageClickListener,
                innerOnImageLongClickListener
        );

        viewPager.setAdapter(pagerAdapter);
        // remove thumbnails
        thumbnailsContainer.removeAllViews();
    }

    /**
     * Remove a media from the gallery
     *
     * @param position media's position to remove
     */
    public void removeMedia(int position) {
        if (position >= mListOfMedia.size() || position < 0) {
            return;
        }
        pagerAdapter.removeItem(position);
        removeThumbnail(position);
    }

    public static GalleryBuilder from(ScrollGalleryView galleryView) {