package com.mjsheng.myappstore.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.blankj.utilcode.util.SPStaticUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.comm.CommonDatas;
import com.mjsheng.myappstore.utils.update.ToastTool;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class SaveListUtils {
    private static List<String> downLoadList = new ArrayList<>();

    public static List<String> getList() {
        String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL);
        Log.e("mjshenglistdata", data);

        Gson gson = new Gson();
        Type listType = new TypeToken<List<String>>() {
        }.getType();
        List<String> list = gson.fromJson(data, listType);

//        Log.e("mjshenglist1", list.toString());
        return list;
    }

    public static void addToList(String data) {
        List<String> list = getList();
//        Log.e("mjshenglist2", list.toString());

        if (list == null) {
            list = new ArrayList<>();
        }
        if (!list.contains(data)) {
            list.add(data);
            Gson gson = new Gson();
            String gsonData = gson.toJson(list);
            SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
        }
    }

    public static List<String> getDownLoadList() {

        return downLoadList;
    }

    public static void addDownLoadList(String packageName) {
        if (downLoadList == null) {
            downLoadList = new ArrayList<>();
                downLoadList.add(packageName);
        } else {
            if (!downLoadList.contains(packageName)) {
                downLoadList.add(packageName);
            }
        }
    }

    public static boolean isDownLoading(String packageName) {
        if (downLoadList.contains(packageName)) {
            return true;
        } else return false;
    }
}
