mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 19:34:15 +01:00
Show send state/errors
This commit is contained in:
@@ -54,6 +54,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
ImageView ivSync;
|
||||
TextView tvUser;
|
||||
TextView tvHost;
|
||||
ImageView ivState;
|
||||
TextView tvAccount;
|
||||
TextView tvError;
|
||||
|
||||
@@ -66,6 +67,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
ivSync = itemView.findViewById(R.id.ivSync);
|
||||
tvUser = itemView.findViewById(R.id.tvUser);
|
||||
tvHost = itemView.findViewById(R.id.tvHost);
|
||||
ivState = itemView.findViewById(R.id.ivState);
|
||||
tvAccount = itemView.findViewById(R.id.tvAccount);
|
||||
tvError = itemView.findViewById(R.id.tvError);
|
||||
}
|
||||
@@ -85,7 +87,17 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
|
||||
tvUser.setText(identity.email);
|
||||
tvHost.setText(String.format("%s:%d", identity.host, identity.port));
|
||||
tvAccount.setText(identity.accountName);
|
||||
tvError.setVisibility(View.GONE);
|
||||
|
||||
if ("connected".equals(identity.state))
|
||||
ivState.setImageResource(R.drawable.baseline_cloud_24);
|
||||
else if ("connecting".equals(identity.state))
|
||||
ivState.setImageResource(R.drawable.baseline_cloud_queue_24);
|
||||
else
|
||||
ivState.setImageResource(R.drawable.baseline_cloud_off_24);
|
||||
ivState.setVisibility(identity.synchronize ? View.VISIBLE : View.INVISIBLE);
|
||||
|
||||
tvError.setText(identity.error);
|
||||
tvError.setVisibility(identity.error == null ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class DB extends RoomDatabase {
|
||||
|
||||
private static DB sInstance;
|
||||
|
||||
private static final String DB_NAME = "fairemail.db";
|
||||
private static final String DB_NAME = "fairemail";
|
||||
|
||||
public static synchronized DB getInstance(Context context) {
|
||||
if (sInstance == null)
|
||||
|
||||
@@ -51,6 +51,12 @@ public interface DaoIdentity {
|
||||
@Update
|
||||
void updateIdentity(EntityIdentity identity);
|
||||
|
||||
@Query("UPDATE identity SET state = :state WHERE id = :id")
|
||||
int setIdentityState(long id, String state);
|
||||
|
||||
@Query("UPDATE identity SET error = :error WHERE id = :id")
|
||||
int setIdentityError(long id, String error);
|
||||
|
||||
@Query("UPDATE identity SET `primary` = 0")
|
||||
void resetPrimary();
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ public class EntityAccount {
|
||||
this.password.equals(other.password) &&
|
||||
this.primary.equals(other.primary) &&
|
||||
this.synchronize.equals(other.synchronize) &&
|
||||
(this.seen_until == null ? other.seen_until == null : this.seen_until.equals(other.seen_until)) &&
|
||||
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
|
||||
(this.error == null ? other.error == null : this.error.equals(other.error)));
|
||||
} else
|
||||
|
||||
@@ -62,6 +62,8 @@ public class EntityIdentity {
|
||||
public Boolean primary;
|
||||
@NonNull
|
||||
public Boolean synchronize;
|
||||
public String state;
|
||||
public String error;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -77,7 +79,9 @@ public class EntityIdentity {
|
||||
this.user.equals(other.user) &&
|
||||
this.password.equals(other.password) &&
|
||||
this.primary.equals(other.primary) &&
|
||||
this.synchronize.equals(other.synchronize));
|
||||
this.synchronize.equals(other.synchronize) &&
|
||||
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
|
||||
(this.error == null ? other.error == null : this.error.equals(other.error)));
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -435,6 +435,9 @@ public class FragmentAccount extends FragmentEx {
|
||||
account.synchronize = synchronize;
|
||||
account.primary = (account.synchronize && args.getBoolean("primary"));
|
||||
|
||||
if (!synchronize)
|
||||
account.error = null;
|
||||
|
||||
if (account.primary)
|
||||
db.account().resetPrimary();
|
||||
|
||||
@@ -443,9 +446,6 @@ public class FragmentAccount extends FragmentEx {
|
||||
else
|
||||
account.id = db.account().insertAccount(account);
|
||||
|
||||
if (!synchronize)
|
||||
db.account().setAccountError(account.id, null);
|
||||
|
||||
List<EntityFolder> folders = new ArrayList<>();
|
||||
|
||||
EntityFolder inbox = new EntityFolder();
|
||||
@@ -479,7 +479,7 @@ public class FragmentAccount extends FragmentEx {
|
||||
}
|
||||
|
||||
for (EntityFolder folder : folders) {
|
||||
db.folder().setFolderUser(folder.account, folder.type);
|
||||
db.folder().setFolderUser(account.id, folder.type);
|
||||
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
|
||||
if (existing == null) {
|
||||
folder.account = account.id;
|
||||
|
||||
@@ -276,6 +276,9 @@ public class FragmentIdentity extends FragmentEx {
|
||||
identity.synchronize = synchronize;
|
||||
identity.primary = (identity.synchronize && args.getBoolean("primary"));
|
||||
|
||||
if (!identity.synchronize)
|
||||
identity.error = null;
|
||||
|
||||
if (identity.primary)
|
||||
db.identity().resetPrimary();
|
||||
|
||||
|
||||
@@ -978,7 +978,10 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
Transport itransport = isession.getTransport(ident.starttls ? "smtp" : "smtps");
|
||||
try {
|
||||
// Connect transport
|
||||
db.identity().setIdentityState(ident.id, "connecting");
|
||||
itransport.connect(ident.host, ident.port, ident.user, ident.password);
|
||||
db.identity().setIdentityState(ident.id, "connected");
|
||||
db.identity().setIdentityError(ident.id, null);
|
||||
|
||||
// Send message
|
||||
Address[] to = imessage.getAllRecipients();
|
||||
@@ -1013,8 +1016,15 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
} catch (MessagingException ex) {
|
||||
db.identity().setIdentityError(ident.id, Helper.formatThrowable(ex));
|
||||
throw ex;
|
||||
} finally {
|
||||
itransport.close();
|
||||
try {
|
||||
itransport.close();
|
||||
} finally {
|
||||
db.identity().setIdentityState(ident.id, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user