Add identity after save account

pull/156/head
M66B 6 years ago
parent 7b277737f5
commit cc268a655a

@ -63,6 +63,7 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
@ -134,6 +135,7 @@ public class FragmentAccount extends FragmentBase {
private Spinner spLeft;
private Spinner spRight;
private CheckBox cbIdentity;
private Button btnSave;
private ContentLoadingProgressBar pbSave;
private TextView tvError;
@ -211,6 +213,7 @@ public class FragmentAccount extends FragmentBase {
spLeft = view.findViewById(R.id.spLeft);
spRight = view.findViewById(R.id.spRight);
cbIdentity = view.findViewById(R.id.cbIdentity);
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
tvError = view.findViewById(R.id.tvError);
@ -264,6 +267,7 @@ public class FragmentAccount extends FragmentBase {
etPrefix.setText(provider.prefix);
grpFolders.setVisibility(View.GONE);
cbIdentity.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
}
@ -457,6 +461,7 @@ public class FragmentAccount extends FragmentBase {
btnCheck.setVisibility(View.GONE);
pbCheck.setVisibility(View.GONE);
cbIdentity.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
tvError.setVisibility(View.GONE);
@ -703,6 +708,7 @@ public class FragmentAccount extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
grpFolders.setVisibility(View.GONE);
cbIdentity.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)
@ -775,7 +781,7 @@ public class FragmentAccount extends FragmentBase {
args.putSerializable("left", left);
args.putSerializable("right", right);
new SimpleTask<Void>() {
new SimpleTask<Long>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
@ -794,7 +800,7 @@ public class FragmentAccount extends FragmentBase {
}
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
protected Long onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
int auth_type = args.getInt("auth_type");
@ -1053,12 +1059,18 @@ public class FragmentAccount extends FragmentBase {
nm.cancel("receive", account.id.intValue());
}
return null;
return account.id;
}
@Override
protected void onExecuted(Bundle args, Void data) {
protected void onExecuted(Bundle args, Long id) {
getFragmentManager().popBackStack();
if (cbIdentity.isChecked()) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivitySetup.ACTION_EDIT_IDENTITY)
.putExtra("account", id));
}
}
@Override
@ -1155,6 +1167,8 @@ public class FragmentAccount extends FragmentBase {
cbBrowse.setChecked(account == null ? true : account.browse);
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
cbIdentity.setChecked(account == null);
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);
new SimpleTask<EntityAccount>() {
@ -1451,6 +1465,7 @@ public class FragmentAccount extends FragmentBase {
}
grpFolders.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE);
cbIdentity.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE);
btnSave.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE);
}

@ -121,6 +121,7 @@ public class FragmentIdentity extends FragmentBase {
private Group grpAdvanced;
private long id = -1;
private long account = -1;
private boolean saving = false;
private int auth_type = Helper.AUTH_TYPE_PASSWORD;
private int color = Color.TRANSPARENT;
@ -133,6 +134,7 @@ public class FragmentIdentity extends FragmentBase {
// Get arguments
Bundle args = getArguments();
id = args.getLong("id", -1);
account = args.getLong("account", -1);
}
@Override
@ -879,7 +881,7 @@ public class FragmentIdentity extends FragmentBase {
spAccount.setSelection(0);
for (int pos = 0; pos < accounts.size(); pos++) {
EntityAccount account = accounts.get(pos);
if (account.id.equals((identity == null ? -1 : identity.account))) {
if (account.id.equals(identity == null ? FragmentIdentity.this.account : identity.account)) {
spAccount.setTag(pos);
spAccount.setSelection(pos);
// OAuth token could be updated

@ -672,6 +672,15 @@
<!-- save -->
<CheckBox
android:id="@+id/cbIdentity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_setup_identity"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spRight" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
@ -680,7 +689,7 @@
android:tag="disable"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spRight" />
app:layout_constraintTop_toBottomOf="@id/cbIdentity" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbSave"

@ -309,6 +309,7 @@
<string name="title_no_sync">Synchronization errors since %1$s</string>
<string name="title_identity_required">An identity is required to send messages</string>
<string name="title_drafts_required">A drafts folder is required to send messages</string>
<string name="title_account_setup_identity">Add an identity after saving this account</string>
<string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_edit_html">Edit as HTML</string>

Loading…
Cancel
Save