package com.gingersoft.gsa.cloud.webview.app.webviewUtils;

import android.content.Context;
import android.webkit.JavascriptInterface;

import java.util.ArrayList;

public class WebImageListener {

    private Context mContext;
    private Class mImageActivity;
    private ArrayList<String> mImages = new ArrayList<>();

    public WebImageListener(Context context, Class imageActivity) {
        mContext = context;
        mImageActivity = imageActivity;
    }

    public WebImageListener(Context context) {
        mContext = context;
    }
    public void collectImage(String url) {
        if (!url.startsWith("http")
                || url.startsWith("https://mp.weixin.qq.com/")
                || url.startsWith("https://res.wx.qq.com/")
                ) {
            return;
        }
        if (!mImages.contains(url))
            mImages.add(url);
    }

    @JavascriptInterface
    public void onImageClicked(String url) {
//        Logger.e("clicked:" + url);
//        if (mImageActivity != null) {
//            Intent intent = new Intent(mContext, mImageActivity);
//            intent.putExtra(ImageActivity.CURRENT_IMAGE_URL, url);
//            intent.putExtra(ImageActivity.ALL_IMAGE_URLS, mImages);
//            mContext.startActivity(intent);
//        }
//        ARouter.getInstance().build(PUBLIC_PHOTO)
//                .withString(EXTRA_PHOTO_URL, url)
//                .navigation();
    }
}
