package com.celerysoft.imagepager.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import com.celerysoft.imagepager.util.ImageUtil;

import uk.co.senab.photoview.PhotoView;

/**
 * Created by Celery on 2015-11-18.
 */
public class SimpleImagePagerAdapter extends ImagePagerAdapter {

    private Context mContext;

    private int[] mImageResIds;
    public void setImageResIds(int[] imageResIds) {
        mImageResIds = imageResIds;
        mImagePaths = null;
    }

    private String[] mImagePaths;
    public void setImagePaths(String[] imagePaths) {
        mImageResIds = null;
        mImagePaths = imagePaths;
        mImageDrawables = new Drawable[imagePaths.length];
    }
    private Drawable[] mImageDrawables;

    public SimpleImagePagerAdapter(Context context) {
        mContext = context;
    }

    @Override
    public PhotoView getItem(int position) {
        PhotoView photoView = new PhotoView(mContext);
        if (mImageResIds != null && mImageResIds.length > position) {
            photoView.setImageResource(mImageResIds[position]);
        } else if (mImagePaths != null && mImagePaths.length > position) {
            Drawable drawable;
            if (mImageDrawables[position] != null) {
                drawable = mImageDrawables[position];
            } else {
                Bitmap bitmap = ImageUtil.getBitmap(mContext, mImagePaths[position]);
                drawable = new BitmapDrawable(mContext.getResources(), bitmap);
                //Drawable drawable = new BitmapDrawable(bitmap);
            }
            photoView.setImageDrawable(drawable);
        }
        return photoView;
    }

    @Override
    public int getCount() {
        if (mImageResIds != null) {
            return mImageResIds.length;
        } else if (mImagePaths != null) {
            return mImagePaths.length;
        }
        return 0;
    }
}

@@ -104,100 +104,8 @@
 map;
-%0Aimport android.graphics.drawable.BitmapDrawable;%0Aimport android.graphics.drawable.Drawable;
 %0A%0Aim
@@ -197,16 +197,46 @@
 w;%0A%0A/**%0A
+ * Simple image pager adapter%0A
  * Creat
@@ -444,24 +444,55 @@
 geResIds) %7B%0A
+        removeAllCollection();%0A
         mIma
@@ -519,36 +519,8 @@
 ds;%0A
-        mImagePaths = null;%0A
     
@@ -621,27 +621,29 @@
     
-mImageResIds = null
+removeAllCollection()
 ;%0A  
@@ -692,32 +692,28 @@
 mage
-Drawables = new Drawable
+Bitmaps = new Bitmap
 %5Bima
@@ -751,35 +751,185 @@
 ate 
-Drawable%5B%5D mImageDrawables;
+Bitmap%5B%5D mImageBitmaps;%0A%0A    private String%5B%5D mImageUris;%0A    public void setImageUris(String%5B%5D imageUris) %7B%0A        removeAllCollection();%0A        mImageUris = imageUris;%0A    %7D
 %0A%0A  
@@ -1350,33 +1350,29 @@
         
-Drawable drawable
+Bitmap bitmap
 ;%0A      
@@ -1383,32 +1383,30 @@
   if (mImage
-Drawable
+Bitmap
 s%5Bposition%5D 
@@ -1432,24 +1432,22 @@
         
-drawable
+bitmap
  = mImag
@@ -1447,24 +1447,22 @@
 = mImage
-Drawable
+Bitmap
 s%5Bpositi
@@ -1499,31 +1499,24 @@
             
-Bitmap 
 bitmap = Ima
@@ -1586,70 +1586,40 @@
     
-drawable = new BitmapDrawable(mContext.getResources(),
+mImageBitmaps%5Bposition%5D =
  bitmap
-)
 ;%0A  
@@ -1636,121 +1636,55 @@
     
-//Drawable drawable = new BitmapDrawable(bitmap);%0A            %7D%0A            photoView.setImageDrawable(drawable);
+photoView.setImageBitmap(bitmap);%0A            %7D
 %0A   
@@ -1955,11 +1955,173 @@
 0;%0A    %7D
+%0A%0A    private void removeAllCollection() %7B%0A        mImageResIds = null;%0A        mImagePaths = null;%0A        mImageBitmaps = null;%0A        mImageUris = null;%0A    %7D
 %0A%7D%0A

add load internet image interface