导航菜单

页面标题

页面副标题

微商客 v2.1.2 - LogUploadActivity.java 源代码

正在查看: 微商客 v2.1.2 应用的 LogUploadActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.jianzhen.wsk.v1;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.Toast;
import com.auxiliary.library.util.PackageUtil;
import com.auxiliary.library.util.SettingUtil;
import com.auxiliary.library.widget.ExecutorWindow;
import com.jianzhen.wsk.App;
import com.jianzhen.wsk.BaseActivity;
import com.jianzhen.wsk.R;
import com.jianzhen.wsk.utils.DataSaveUtils;
import com.jianzhen.wsk.v1.api.UserService;
import com.jianzhen.wsk.v1.http.HttpCallback;
import com.jianzhen.wsk.v1.http.HttpUtil;
import com.jianzhen.wsk.v1.http.LoadingCallback;
import java.io.File;
import java.net.URLEncoder;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import retrofit2.Call;

public class LogUploadActivity extends BaseActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, LoadingCallback<Void> {
    public static final String OPEN = "open";
    public static final String OPEN_DETAIL = "open_detail";
    public static final String STATUS = "status";
    private Switch mDetailSwitch;
    private Switch mOpenSwitch;
    private ProgressDialog mProgressDialog;
    private UserService mService = (UserService) HttpUtil.create(UserService.class, DataSaveUtils.getTokenData(App.getContext()));
    private SharedPreferences mSharedPreferences;
    private Switch mStatusSwitch;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_log_upload2;
    }

    @Override
    protected boolean isSetBaseTitle() {
        return false;
    }

    @Override
    protected void initTitle() {
        setBaseTitle(this, "上传任务日志");
    }

    @Override
    protected void initPageView() {
        this.mOpenSwitch = (Switch) findViewById(R.id.sw_open_log);
        this.mDetailSwitch = (Switch) findViewById(R.id.sw_open_detail);
        this.mStatusSwitch = (Switch) findViewById(R.id.sw_open_status);
        findViewById(R.id.bt_upload_log).setOnClickListener(this);
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        this.mSharedPreferences = defaultSharedPreferences;
        defaultSharedPreferences.edit().putBoolean(OPEN_DETAIL, false).apply();
        this.mStatusSwitch.setChecked(this.mSharedPreferences.getBoolean(STATUS, true));
        if (this.mSharedPreferences.getBoolean(STATUS, false)) {
            this.mOpenSwitch.setChecked(this.mSharedPreferences.getBoolean(OPEN, true));
            this.mDetailSwitch.setChecked(this.mSharedPreferences.getBoolean(OPEN_DETAIL, false));
        } else {
            this.mOpenSwitch.setChecked(ExecutorWindow.FILE_DEBUG);
            this.mDetailSwitch.setChecked(ExecutorWindow.FILE_DEBUG_TREE);
        }
        this.mOpenSwitch.setOnCheckedChangeListener(this);
        this.mStatusSwitch.setOnCheckedChangeListener(this);
        this.mDetailSwitch.setOnCheckedChangeListener(this);
        findViewById(R.id.log_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                LogUploadActivity.this.lambda$initPageView$0(view);
            }
        });
    }

    public void lambda$initPageView$0(View view) {
        finish();
    }

    @Override
    public void onClick(View view) {
        if (!SettingUtil.isUsageAccess(this)) {
            SettingUtil.startUsageAccess(this, 1);
            return;
        }
        File[] logFiles = ExecutorWindow.getLogFiles(this);
        if (logFiles == null || logFiles.length == 0) {
            Toast.makeText((Context) this, (CharSequence) "暂无日志,请先执行任务后再试", 1).show();
            return;
        }
        MultipartBody.Builder addFormDataPart = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("productCode", "400").addFormDataPart("versionCode", String.valueOf(PackageUtil.getVersionName(this, getPackageName()).replaceAll("\\.", "")));
        MediaType parse = MediaType.parse("multipart/form-data");
        for (File file : logFiles) {
            addFormDataPart.addFormDataPart("files", URLEncoder.encode(file.getName()), RequestBody.create(parse, file));
        }
        this.mService.uploadLogs(addFormDataPart.build().parts()).enqueue(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
        Switch r0 = this.mOpenSwitch;
        if (compoundButton == r0) {
            this.mSharedPreferences.edit().putBoolean(OPEN, z).apply();
            ExecutorWindow.FILE_DEBUG = z;
            if (z || !this.mDetailSwitch.isChecked()) {
                return;
            }
            this.mDetailSwitch.setChecked(false);
            this.mStatusSwitch.setChecked(false);
            return;
        }
        if (compoundButton == this.mDetailSwitch) {
            if (!z || r0.isChecked()) {
                this.mSharedPreferences.edit().putBoolean(OPEN_DETAIL, z).apply();
                ExecutorWindow.FILE_DEBUG_TREE = z;
                return;
            } else {
                this.mDetailSwitch.setChecked(false);
                Toast.makeText((Context) this, (CharSequence) "请先开启日志", 1).show();
                return;
            }
        }
        if (compoundButton == this.mStatusSwitch) {
            if (!z || r0.isChecked()) {
                this.mSharedPreferences.edit().putBoolean(STATUS, z).apply();
            } else {
                this.mStatusSwitch.setChecked(false);
                Toast.makeText((Context) this, (CharSequence) "请先开启日志", 1).show();
            }
        }
    }

    @Override
    public void onStart(Request request) {
        ProgressDialog progressDialog = this.mProgressDialog;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        ProgressDialog progressDialog2 = new ProgressDialog(this);
        this.mProgressDialog = progressDialog2;
        progressDialog2.setCancelable(false);
        this.mProgressDialog.setMessage("正在上传...");
        this.mProgressDialog.setProgressStyle(0);
        this.mProgressDialog.show();
    }

    @Override
    public void onFinish(Request request) {
        ProgressDialog progressDialog = this.mProgressDialog;
        if (progressDialog != null) {
            progressDialog.dismiss();
        }
        this.mProgressDialog = null;
    }

    @Override
    public void onResponse(Void r2) {
        Toast.makeText((Context) this, (CharSequence) "上传成功", 1).show();
    }

    public void onFailure(Call<HttpCallback.Result<Void>> call, Throwable th) {
        Toast.makeText((Context) this, (CharSequence) ("上传失败 : " + th.getMessage()), 1).show();
    }
}