NetCapture v2.1.82021972349版本的 MD5 值为:dfbd8054127041af5d65fa43eaf2e1d0

以下内容为反编译后的 UpLoadSettingActivity.java 源代码,内容仅作参考


package com.minhui.networkcapture.upload;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import com.minhui.networkcapture.R;
import com.minhui.networkcapture.base.BaseActivity;
import com.minhui.networkcapture.tracker.Tracker;
import com.minhui.networkcapture.tracker.TrackerConstant;
import com.minhui.networkcapture.utils.AppConstants;
import com.minhui.networkcapture.view.CheckableImageView;
import com.minhui.vpn.log.VPNLog;
import com.minhui.vpn.upload.UpLoadConfig;
import com.minhui.vpn.utils.ACache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class UpLoadSettingActivity extends BaseActivity {
    private static final String TAG = "UpLoadSettingActivity";
    TextView addHeader;
    private CheckableImageView autoUpload;
    TextView demoText;
    private HeaderAdapter headerAdapter;
    ArrayList<Map.Entry<String, String>> headerList;
    ListView headerListView;
    EditText key;
    TextView keyLabel;
    EditText requestUrl;
    ScrollView scrollView;
    private SharedPreferences sp;
    private UpLoadConfig upLoadConfig;
    EditText value;
    TextView valueLabel;

    @Override
    protected int getLayout() {
        return R.layout.activity_upload_setting;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.save_reset, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == R.id.save_url) {
            saveConfig();
            return true;
        }
        return super.onOptionsItemSelected(menuItem);
    }

    private void saveConfig() {
        String trim = this.requestUrl.getText().toString().trim();
        if (!TextUtils.isEmpty(trim)) {
            this.upLoadConfig.setUrl(trim);
        }
        ACache.get(getApplicationContext()).put(AppConstants.UPLOAD_CONFIG, this.upLoadConfig);
        Toast.makeText(getApplicationContext(), getString(R.string.success_save_config), 0).show();
        Tracker.sendEvent(TrackerConstant.SAVE_UPLOAD_CONFIG);
        finish();
    }

    public void addHeader() {
        String trim = this.key.getText().toString().trim();
        String trim2 = this.value.getText().toString().trim();
        if (TextUtils.isEmpty(trim) || TextUtils.isEmpty(trim2)) {
            return;
        }
        if (this.upLoadConfig.getHeaders() == null) {
            this.upLoadConfig.setHeaders(new HashMap<>(8));
        }
        this.upLoadConfig.getHeaders().put(trim, trim2);
        refreshListData();
        this.headerAdapter.notifyDataSetChanged();
        refreshDemoData();
    }

    public void refreshDemoData() {
        this.demoText.setText("Server Demo:https://github.com/huolizhuminh/CaptureServerDemo");
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        initView();
        this.headerListView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                UpLoadSettingActivity.this.scrollView.requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });
        this.autoUpload = (CheckableImageView) findViewById(R.id.auto_upload);
        SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(AppConstants.DATA_SAVE, 0);
        this.sp = sharedPreferences;
        this.autoUpload.setChecked(sharedPreferences.getBoolean(AppConstants.AUTO_UPLOAD, false));
        this.autoUpload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UpLoadSettingActivity.this.switchAutoUpload();
            }
        });
    }

    private void initView() {
        this.addHeader = (TextView) findViewById(R.id.add_header);
        this.keyLabel = (TextView) findViewById(R.id.key_label);
        this.key = (EditText) findViewById(R.id.key);
        this.valueLabel = (TextView) findViewById(R.id.value_label);
        this.value = (EditText) findViewById(R.id.value);
        this.headerListView = (ListView) findViewById(R.id.added_header_container);
        this.requestUrl = (EditText) findViewById(R.id.request_url);
        this.demoText = (TextView) findViewById(R.id.demo_text);
        this.scrollView = (ScrollView) findViewById(R.id.scroll_view);
        this.addHeader.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UpLoadSettingActivity.this.addHeader();
            }
        });
    }

    public void switchAutoUpload() {
        UpLoadConfig upLoadConfig;
        boolean isChecked = this.autoUpload.isChecked();
        if (!isChecked && ((upLoadConfig = (UpLoadConfig) ACache.get(getApplicationContext()).getAsObject(AppConstants.UPLOAD_CONFIG)) == null || upLoadConfig.getUrl() == null)) {
            showNeedEditDialog();
        } else {
            this.autoUpload.setChecked(!isChecked);
            this.sp.edit().putBoolean(AppConstants.AUTO_UPLOAD, !isChecked).apply();
        }
    }

    private void showNeedEditDialog() {
        new AlertDialog.Builder(this).setMessage(getString(R.string.need_server)).setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
            }
        }).show();
    }

    @Override
    public void onStart() {
        super.onStart();
        if (this.headerAdapter == null) {
            UpLoadConfig upLoadConfig = (UpLoadConfig) ACache.get(getApplicationContext()).getAsObject(AppConstants.UPLOAD_CONFIG);
            this.upLoadConfig = upLoadConfig;
            if (upLoadConfig == null) {
                this.upLoadConfig = new UpLoadConfig();
            } else {
                this.requestUrl.setText(upLoadConfig.getUrl());
            }
            refreshListData();
            HeaderAdapter headerAdapter = new HeaderAdapter();
            this.headerAdapter = headerAdapter;
            this.headerListView.setAdapter((ListAdapter) headerAdapter);
            refreshDemoData();
        }
    }

    public void refreshListData() {
        HashMap<String, String> headers;
        if (this.headerList == null) {
            this.headerList = new ArrayList<>();
        }
        UpLoadConfig upLoadConfig = this.upLoadConfig;
        if (upLoadConfig == null || (headers = upLoadConfig.getHeaders()) == null) {
            return;
        }
        this.headerList.clear();
        this.headerList.addAll(headers.entrySet());
        VPNLog.d(TAG, "headerList " + this.headerList.size());
    }

    public class HeaderAdapter extends BaseAdapter {
        int defaultLength;

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0L;
        }

        public HeaderAdapter() {
            this.defaultLength = 0;
            this.defaultLength = UpLoadConfig.DEFAULT_HEADER.length;
        }

        @Override
        public int getCount() {
            if (UpLoadSettingActivity.this.upLoadConfig != null && UpLoadSettingActivity.this.upLoadConfig.getHeaders() != null) {
                return UpLoadSettingActivity.this.upLoadConfig.getHeaders().size() + this.defaultLength;
            }
            return this.defaultLength;
        }

        @Override
        public View getView(final int i, View view, ViewGroup viewGroup) {
            Holder holder;
            if (view == null) {
                view = View.inflate(UpLoadSettingActivity.this.getApplicationContext(), R.layout.item_add_header, null);
                holder = new Holder(view);
                view.setTag(holder);
            } else {
                holder = (Holder) view.getTag();
            }
            if (i < this.defaultLength) {
                holder.checkBox.setEnabled(false);
                holder.textView.setText(UpLoadConfig.DEFAULT_HEADER[i]);
            } else {
                holder.checkBox.setEnabled(true);
                Map.Entry<String, String> entry = UpLoadSettingActivity.this.headerList.get(i - this.defaultLength);
                holder.textView.setText(entry.getKey() + ":" + entry.getValue());
            }
            holder.checkBox.setChecked(true);
            holder.checkBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view2) {
                    HashMap<String, String> headers = UpLoadSettingActivity.this.upLoadConfig.getHeaders();
                    if (headers == null) {
                        return;
                    }
                    headers.remove(UpLoadSettingActivity.this.headerList.get(i - HeaderAdapter.this.defaultLength).getKey());
                    UpLoadSettingActivity.this.refreshListData();
                    HeaderAdapter.this.notifyDataSetChanged();
                    UpLoadSettingActivity.this.refreshDemoData();
                }
            });
            return view;
        }

        class Holder {
            CheckBox checkBox;
            TextView textView;

            Holder(View view) {
                this.checkBox = (CheckBox) view.findViewById(R.id.item_check);
                this.textView = (TextView) view.findViewById(R.id.item_default_header);
            }
        }
    }
}