// Path: app/src/main/java/am/project/x/business/others/ftp/FtpFragmentCallback.java
// public interface FtpFragmentCallback {
// 
//     /**
//      * 切换
//      *
//      * @param legacy 是否为传统方式
//      */
//     void onSwitch(boolean legacy);
// }


import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.am.appcompat.app.Fragment;
import com.am.tool.support.utils.InputMethodUtils;
import java.io.File;
import java.util.Locale;
import am.project.x.R;
import am.project.x.business.others.ftp.FtpFragmentCallback;
import am.project.x.utils.ContextUtils;
        mConfig = new LegacyFtpConfig(requireContext());
        mVPort.setText(String.format(Locale.getDefault(), "%d", mConfig.getPort()));
        mVAuto.setChecked(mConfig.isAutoChangePort());
        if (Build.VERSION.SDK_INT >= 23 &&
                !ContextUtils.hasWriteExternalStoragePermission(requireContext()))
            mVPath.setText(null);
        else {
            if (mConfig.getPath() == null)
                mConfig.setPath(Environment.getExternalStorageDirectory().getAbsolutePath());
            mVPath.setText(mConfig.getPath());
        }

        mVPort.addTextChangedListener(this);
        mVAuto.setOnCheckedChangeListener(this);
        mVPath.addTextChangedListener(this);
        findViewById(R.id.legacy_btn_open).setOnClickListener(this);
        findViewById(R.id.legacy_btn_close).setOnClickListener(this);
        mVPath.setOnClickListener(this);
    }

    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu_ftp_legacy, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.ftp_advanced) {
            final Activity activity = getActivity();
// Path: app/src/main/java/am/project/x/business/others/ftp/FtpFragmentCallback.java
// public interface FtpFragmentCallback {
// 
//     /**
//      * 切换
//      *
//      * @param legacy 是否为传统方式
//      */
//     void onSwitch(boolean legacy);
// }


// Path: app/src/main/java/am/project/x/business/others/ftp/legacy/LegacyFragment.java
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.am.appcompat.app.Fragment;
import com.am.tool.support.utils.InputMethodUtils;
import java.io.File;
import java.util.Locale;
import am.project.x.R;
import am.project.x.business.others.ftp.FtpFragmentCallback;
import am.project.x.utils.ContextUtils;

        mConfig = new LegacyFtpConfig(requireContext());
        mVPort.setText(String.format(Locale.getDefault(), "%d", mConfig.getPort()));
        mVAuto.setChecked(mConfig.isAutoChangePort());
        if (Build.VERSION.SDK_INT >= 23 &&
                !ContextUtils.hasWriteExternalStoragePermission(requireContext()))
            mVPath.setText(null);
        else {
            if (mConfig.getPath() == null)
                mConfig.setPath(Environment.getExternalStorageDirectory().getAbsolutePath());
            mVPath.setText(mConfig.getPath());
        }

        mVPort.addTextChangedListener(this);
        mVAuto.setOnCheckedChangeListener(this);
        mVPath.addTextChangedListener(this);
        findViewById(R.id.legacy_btn_open).setOnClickListener(this);
        findViewById(R.id.legacy_btn_close).setOnClickListener(this);
        mVPath.setOnClickListener(this);
    }

    @Override
    public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu_ftp_legacy, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.ftp_advanced) {
            final Activity activity = getActivity();
            if (activity instanceof FtpFragmentCallback)