// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static String getMimeType(String url) {
//     if (url.endsWith(".png") || url.endsWith(".PNG")) {
//         return "data:image/png;base64,";
//     } else if (url.endsWith(".jpg") || url.endsWith(".jpeg") || url.endsWith(".JPG") || url.endsWith(".JPEG")) {
//         return "data:image/jpg;base64,";
//     } else if (url.endsWith(".gif") || url.endsWith(".GIF")) {
//         return "data:image/gif;base64,";
//     } else {
//         return "";
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static boolean isGifSuffix(String url) {
//     return url.endsWith(".gif")
//             || url.endsWith(".GIF");
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static boolean isImageSuffix(String url) {
//     return url.endsWith(".png")
//             || url.endsWith(".PNG")
//             || url.endsWith(".jpg")
//             || url.endsWith(".JPG")
//             || url.endsWith(".jpeg")
//             || url.endsWith(".JPEG");
// }


import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import static android.text.TextUtils.isEmpty;
import static moe.yukinoneko.diycode.tool.UrlHelper.getMimeType;
import static moe.yukinoneko.diycode.tool.UrlHelper.isGifSuffix;
import static moe.yukinoneko.diycode.tool.UrlHelper.isImageSuffix;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bumptech.glide.Glide;
/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode.misc;





/**
 * Created by SamuelGjk on 2017/4/24.
 */

public class DiyCodeWebViewClient extends WebViewClient {

    private Context context;
    private ACache aCache;

    public DiyCodeWebViewClient(Context context) {
        this.context = context;
        aCache = ACache.get(context);
    }

    // 监听加载了哪些资源
    @Override
    public void onLoadResource(WebView view, final String url) {
        // 是图片就缓存
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static String getMimeType(String url) {
//     if (url.endsWith(".png") || url.endsWith(".PNG")) {
//         return "data:image/png;base64,";
//     } else if (url.endsWith(".jpg") || url.endsWith(".jpeg") || url.endsWith(".JPG") || url.endsWith(".JPEG")) {
//         return "data:image/jpg;base64,";
//     } else if (url.endsWith(".gif") || url.endsWith(".GIF")) {
//         return "data:image/gif;base64,";
//     } else {
//         return "";
//     }
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static boolean isGifSuffix(String url) {
//     return url.endsWith(".gif")
//             || url.endsWith(".GIF");
// }
// 
// Path: app/src/main/java/moe/yukinoneko/diycode/tool/UrlHelper.java
// public static boolean isImageSuffix(String url) {
//     return url.endsWith(".png")
//             || url.endsWith(".PNG")
//             || url.endsWith(".jpg")
//             || url.endsWith(".JPG")
//             || url.endsWith(".jpeg")
//             || url.endsWith(".JPEG");
// }


// Path: app/src/main/java/moe/yukinoneko/diycode/misc/DiyCodeWebViewClient.java
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import static android.text.TextUtils.isEmpty;
import static moe.yukinoneko.diycode.tool.UrlHelper.getMimeType;
import static moe.yukinoneko.diycode.tool.UrlHelper.isGifSuffix;
import static moe.yukinoneko.diycode.tool.UrlHelper.isImageSuffix;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bumptech.glide.Glide;

/*
 * Copyright (c) 2017 SamuelGjk <samuel.alva@outlook.com>
 *
 * This file is part of DiyCode
 *
 * DiyCode is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DiyCode is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DiyCode. If not, see <http://www.gnu.org/licenses/>.
 */

package moe.yukinoneko.diycode.misc;





/**
 * Created by SamuelGjk on 2017/4/24.
 */

public class DiyCodeWebViewClient extends WebViewClient {

    private Context context;
    private ACache aCache;

    public DiyCodeWebViewClient(Context context) {
        this.context = context;
        aCache = ACache.get(context);
    }

    // 监听加载了哪些资源
    @Override
    public void onLoadResource(WebView view, final String url) {
        // 是图片就缓存
        if (isImageSuffix(url) || isGifSuffix(url)) {