package com.genlot.ninglottery.module.function.log;

import android.os.Bundle;

import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.ZipUtils;
import com.genlot.nativesdk.SystemNI;
import com.genlot.ninglottery.R;
import com.genlot.ninglottery.base.BaseFragment;
import com.genlot.ninglottery.toolkit.TimeUtils;

import java.io.IOException;

import butterknife.OnClick;

/**
 * @author ZhuYongKang
 * @description 日志上传界面
 * @date 2019/9/24
 */
public class LogUploadFragment extends BaseFragment {

    @OnClick(R.id.bt_confirm)
    public void uploadLog() {
        String path = SystemNI.getLogPath();
        String localFile = path + "/../log.zip";
        showLoading("正在压缩...");
        try {
            ZipUtils.zipFile(path, localFile);
            dismissLoading();
            showLoading("正在上传...");
            String serverFile = "log" + TimeUtils.getDetailTimeMil(System.currentTimeMillis()) + ".zip";
            int result = SystemNI.uploadFile(serverFile, localFile);
            ToastUtils.showShort(result == 0 ? "上传成功!" : "上传失败!");
            dismissLoading();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_log_upload;
    }

    @Override
    public void onCreateViewFinished(Bundle state) {

    }
}
