mirror of https://github.com/M66B/FairEmail.git
Edit account primacy
This commit is contained in:
parent
f29cbd1f0e
commit
ef25812bfe
|
@ -26,6 +26,7 @@ import android.content.DialogInterface;
|
|||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -38,14 +39,20 @@ public class FragmentDialogEditName extends FragmentDialogBase {
|
|||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edit_name, null);
|
||||
final EditText etName = view.findViewById(R.id.etName);
|
||||
etName.setText(getArguments().getString("name"));
|
||||
final CheckBox cbPrimary = view.findViewById(R.id.cbPrimary);
|
||||
|
||||
Bundle args = getArguments();
|
||||
etName.setText(args.getString("name"));
|
||||
cbPrimary.setChecked(args.getBoolean("primary"));
|
||||
cbPrimary.setVisibility(args.containsKey("primary") ? View.VISIBLE : View.GONE);
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getArguments().putString("name", etName.getText().toString());
|
||||
args.putString("name", etName.getText().toString());
|
||||
args.putBoolean("primary", cbPrimary.isChecked());
|
||||
sendResult(RESULT_OK);
|
||||
}
|
||||
})
|
||||
|
|
|
@ -862,6 +862,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
return;
|
||||
|
||||
args.putString("name", account.name);
|
||||
args.putBoolean("primary", account.primary);
|
||||
|
||||
FragmentDialogEditName fragment = new FragmentDialogEditName();
|
||||
fragment.setArguments(args);
|
||||
|
@ -1352,12 +1353,28 @@ public class FragmentFolders extends FragmentBase {
|
|||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
String name = args.getString("name");
|
||||
boolean primary = args.getBoolean("primary");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
return null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.account().setAccountName(id, name);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityAccount account = db.account().getAccount(id);
|
||||
if (account == null)
|
||||
return null;
|
||||
|
||||
db.account().setAccountName(account.id, name);
|
||||
if (primary)
|
||||
db.account().resetPrimary();
|
||||
db.account().setAccountPrimary(account.id, primary);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -32,4 +32,15 @@
|
|||
|
||||
<requestFocus />
|
||||
</eu.faircode.email.EditTextPlain>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_primary"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/etName" />
|
||||
|
||||
</eu.faircode.email.ConstraintLayoutEx>
|
Loading…
Reference in New Issue