Refactoring

pull/200/head
M66B 3 years ago
parent bb31f099fb
commit a9d24170cb

@ -448,11 +448,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
}
try {
Bundle args = new Bundle();
args.putBoolean("export", export);
FragmentDialogPassword fragment = new FragmentDialogPassword();
fragment.setArguments(args);
FragmentDialogBase fragment =
(export ? new FragmentDialogExport() : new FragmentDialogImport());
fragment.show(getSupportFragmentManager(), "password");
} catch (Throwable ex) {
Log.unexpectedError(getSupportFragmentManager(), ex);
@ -1313,7 +1310,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
return intent;
}
public static class FragmentDialogPassword extends FragmentDialogBase {
public static class FragmentDialogExport extends FragmentDialogBase {
private TextInputLayout etPassword1;
private TextInputLayout etPassword2;
@ -1327,31 +1324,17 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final boolean export = getArguments().getBoolean("export");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_password, null);
TextView tvCaption = dview.findViewById(R.id.tvCaption);
Context context = getContext();
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_export, null);
etPassword1 = dview.findViewById(R.id.tilPassword1);
etPassword2 = dview.findViewById(R.id.tilPassword2);
TextView tvImportGmail = dview.findViewById(R.id.tvImportGmail);
Group grpExport = dview.findViewById(R.id.grpExport);
Group grpImport = dview.findViewById(R.id.grpImport);
tvCaption.setText(export ? R.string.title_setup_export : R.string.title_setup_import);
if (savedInstanceState != null) {
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
etPassword2.getEditText().setText(savedInstanceState.getString("fair:password2"));
}
etPassword2.setVisibility(export ? View.VISIBLE : View.GONE);
tvImportGmail.setVisibility(
export || Build.VERSION.SDK_INT < Build.VERSION_CODES.O
? View.GONE : View.VISIBLE);
grpExport.setVisibility(export ? View.VISIBLE : View.GONE);
grpImport.setVisibility(export ? View.GONE : View.VISIBLE);
return new AlertDialog.Builder(getContext())
return new AlertDialog.Builder(context)
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
@ -1359,17 +1342,55 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
String password1 = etPassword1.getEditText().getText().toString();
String password2 = etPassword2.getEditText().getText().toString();
if (!BuildConfig.DEBUG && TextUtils.isEmpty(password1))
ToastEx.makeText(getContext(), R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
else {
if (!export || password1.equals(password2)) {
if (password1.equals(password2)) {
((ActivitySetup) getActivity()).password = password1;
getActivity().startActivityForResult(
Helper.getChooser(getContext(),
export ? getIntentExport() : getIntentImport()),
export ? REQUEST_EXPORT : REQUEST_IMPORT);
Helper.getChooser(context, getIntentExport()), REQUEST_EXPORT);
} else
ToastEx.makeText(getContext(), R.string.title_setup_password_different, Toast.LENGTH_LONG).show();
ToastEx.makeText(context, R.string.title_setup_password_different, Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
public static class FragmentDialogImport extends FragmentDialogBase {
private TextInputLayout etPassword1;
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putString("fair:password1", etPassword1.getEditText().getText().toString());
super.onSaveInstanceState(outState);
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Context context = getContext();
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_import, null);
etPassword1 = dview.findViewById(R.id.tilPassword1);
if (savedInstanceState != null)
etPassword1.getEditText().setText(savedInstanceState.getString("fair:password1"));
return new AlertDialog.Builder(context)
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String password1 = etPassword1.getEditText().getText().toString();
if (TextUtils.isEmpty(password1) && !BuildConfig.DEBUG)
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
else {
((ActivitySetup) getActivity()).password = password1;
getActivity().startActivityForResult(
Helper.getChooser(context, getIntentImport()), REQUEST_IMPORT);
}
}
})

@ -82,40 +82,5 @@
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword2" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvImportHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_import_do"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvExportHint" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvImportGmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_import_gmail"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImportHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpExport"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvExportHint" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpImport"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvImportHint" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_setup_import"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvEncrypted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_setup_export_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilPassword1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvEncrypted"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="password"
android:hint="@string/title_setup_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:textAppearance="@style/TextAppearance.AppCompat.Medium">
<requestFocus />
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
<eu.faircode.email.FixedTextView
android:id="@+id/tvImportHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_import_do"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword1" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvImportGmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_import_gmail"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImportHint" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
Loading…
Cancel
Save