|
@@ -39,6 +39,7 @@ import com.compdfkit.core.document.signature.CPDFOwnerInfo;
|
|
|
import com.compdfkit.tools.R;
|
|
|
import com.compdfkit.tools.common.basic.fragment.CBasicBottomSheetDialogFragment;
|
|
|
import com.compdfkit.tools.common.utils.CFileUtils;
|
|
|
+import com.compdfkit.tools.common.utils.CToastUtil;
|
|
|
import com.compdfkit.tools.common.utils.dialog.CDialogFragmentUtil;
|
|
|
import com.compdfkit.tools.common.utils.threadpools.CThreadPoolUtils;
|
|
|
import com.compdfkit.tools.common.utils.view.CEditText;
|
|
@@ -58,8 +59,6 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
|
|
|
private AppCompatTextView tvTitle;
|
|
|
|
|
|
- private AppCompatImageView ivClose;
|
|
|
-
|
|
|
private CEditText etName;
|
|
|
|
|
|
private CEditText etOrganizationUnit;
|
|
@@ -84,8 +83,6 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
|
|
|
private CEditText etConfirmPassword;
|
|
|
|
|
|
- private AppCompatButton btnConfirmCreate;
|
|
|
-
|
|
|
private boolean showSaveStatus = false;
|
|
|
|
|
|
private OnBackPressedCallback callback;
|
|
@@ -96,8 +93,6 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
|
|
|
private COnSelectCertFileListener selectCertFileListener;
|
|
|
|
|
|
- private ScrollView scrollView;
|
|
|
-
|
|
|
private CountryReginSpinnerAdapter countryReginSpinnerAdapter;
|
|
|
|
|
|
private String fileName = "";
|
|
@@ -106,7 +101,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
if (result.getData() != null && result.getData().getData() != null) {
|
|
|
Uri uri = result.getData().getData();
|
|
|
CFileUtils.takeUriPermission(getContext(), result.getData().getData());
|
|
|
- customSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + uri.getPath().replace("/tree/primary:", "");
|
|
|
+ customSavePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + uri.getPath().replace("/tree/primary:", "");
|
|
|
tvSaveAddress.setText(getSaveAddress() + File.separator + fileName);
|
|
|
}
|
|
|
});
|
|
@@ -164,11 +159,11 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
@Override
|
|
|
protected void onCreateView(View view) {
|
|
|
tvTitle = view.findViewById(R.id.tv_tool_bar_title);
|
|
|
- ivClose = view.findViewById(R.id.iv_tool_bar_close);
|
|
|
+ AppCompatImageView ivClose = view.findViewById(R.id.iv_tool_bar_close);
|
|
|
etName = view.findViewById(R.id.et_name);
|
|
|
etOrganizationUnit = view.findViewById(R.id.et_organization_unit);
|
|
|
etOrganizationName = view.findViewById(R.id.et_organization_name);
|
|
|
- scrollView = view.findViewById(R.id.scroll_view);
|
|
|
+ ScrollView scrollView = view.findViewById(R.id.scroll_view);
|
|
|
etEmailAddress = view.findViewById(R.id.et_email_address);
|
|
|
spinnerCountry = view.findViewById(R.id.spinner_country_regin);
|
|
|
swSaveToFile = view.findViewById(R.id.sw_save_to_file);
|
|
@@ -178,7 +173,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
llSaveAddress = view.findViewById(R.id.ll_save_address);
|
|
|
etPassword = view.findViewById(R.id.et_password);
|
|
|
etConfirmPassword = view.findViewById(R.id.et_confirm_password);
|
|
|
- btnConfirmCreate = view.findViewById(R.id.btn_save);
|
|
|
+ AppCompatButton btnConfirmCreate = view.findViewById(R.id.btn_save);
|
|
|
tvPasswordError = view.findViewById(R.id.tv_password_error);
|
|
|
btnOk.setOnClickListener(this);
|
|
|
tvSaveAddress.setOnClickListener(this);
|
|
@@ -189,7 +184,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
@Override
|
|
|
protected void onViewCreate() {
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
- fileName = "new_cert_"+ uuid.substring(uuid.length()-4, uuid.length())+".p12";
|
|
|
+ fileName = "new_cert_" + uuid.substring(uuid.length() - 4, uuid.length()) + ".p12";
|
|
|
tvTitle.setText(R.string.tools_create_a_self_signed_digital_id);
|
|
|
initCountryReginData();
|
|
|
etName.addTextChangedListener((s, start, before, count) -> {
|
|
@@ -222,7 +217,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
dismiss();
|
|
|
} else if (v.getId() == R.id.tv_save_address) {
|
|
|
selectDirLauncher.launch(CFileUtils.selectSystemDir(true));
|
|
|
- } else if (v.getId() == R.id.btn_save){
|
|
|
+ } else if (v.getId() == R.id.btn_save) {
|
|
|
String name = etName.getText();
|
|
|
String grantor = etOrganizationUnit.getText();
|
|
|
String sectoral = etOrganizationName.getText();
|
|
@@ -231,7 +226,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
String password = etPassword.getText();
|
|
|
String verifyPassword = etConfirmPassword.getText();
|
|
|
|
|
|
- if (TextUtils.isEmpty(password) || TextUtils.isEmpty(verifyPassword) || !password.equals(verifyPassword)){
|
|
|
+ if (TextUtils.isEmpty(password) || TextUtils.isEmpty(verifyPassword) || !password.equals(verifyPassword)) {
|
|
|
etPassword.setError(true);
|
|
|
etConfirmPassword.setError(true);
|
|
|
tvPasswordError.setVisibility(View.VISIBLE);
|
|
@@ -251,22 +246,30 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
String saveDir = getSaveAddress();
|
|
|
boolean success = CertificateDigitalDatas.generatePKCS12Cert(ownerInfo, etPassword.getText(),
|
|
|
saveDir, fileName);
|
|
|
- if (success){
|
|
|
+ File certFile = new File(saveDir, fileName);
|
|
|
+ boolean exists = certFile.exists();
|
|
|
+ if (success && certFile.exists()) {
|
|
|
if (selectCertFileListener != null) {
|
|
|
- selectCertFileListener.certificateFile(new File(saveDir, fileName).getAbsolutePath(), etPassword.getText());
|
|
|
+ selectCertFileListener.certificateFile(certFile.getAbsolutePath(), etPassword.getText());
|
|
|
}
|
|
|
+ } else {
|
|
|
+ CToastUtil.showToast(getContext(), R.string.tools_digital_create_error);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void initCountryReginData(){
|
|
|
- CThreadPoolUtils.getInstance().execute(()->{
|
|
|
+ private void initCountryReginData() {
|
|
|
+ CThreadPoolUtils.getInstance().execute(() -> {
|
|
|
List<Locale> datas = getLocals();
|
|
|
if (getActivity() != null) {
|
|
|
- getActivity().runOnUiThread(()->{
|
|
|
- countryReginSpinnerAdapter = new CountryReginSpinnerAdapter(getContext(), datas);
|
|
|
- spinnerCountry.setAdapter(countryReginSpinnerAdapter);
|
|
|
- spinnerCountry.setSelection(countryReginSpinnerAdapter.getSelectPosition());
|
|
|
+ getActivity().runOnUiThread(() -> {
|
|
|
+ try {
|
|
|
+ countryReginSpinnerAdapter = new CountryReginSpinnerAdapter(getContext(), datas);
|
|
|
+ spinnerCountry.setAdapter(countryReginSpinnerAdapter);
|
|
|
+ spinnerCountry.setSelection(countryReginSpinnerAdapter.getSelectPosition());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
});
|
|
@@ -312,7 +315,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
}
|
|
|
|
|
|
private String getSaveAddress() {
|
|
|
- if (!TextUtils.isEmpty(customSavePath)){
|
|
|
+ if (!TextUtils.isEmpty(customSavePath)) {
|
|
|
return customSavePath;
|
|
|
}
|
|
|
File file;
|
|
@@ -324,7 +327,7 @@ public class CreateCertificateDigitalDialog extends CBasicBottomSheetDialogFragm
|
|
|
return file.getAbsolutePath();
|
|
|
}
|
|
|
|
|
|
- private List<Locale> getLocals(){
|
|
|
+ private List<Locale> getLocals() {
|
|
|
String[] isos = Locale.getISOCountries();
|
|
|
List<Locale> list = new ArrayList<>();
|
|
|
for (String iso : isos) {
|