Browse Source

Show send state/errors

main
M66B 6 years ago
parent
commit
ab485f8d43
10 changed files with 73 additions and 13 deletions
  1. +15
    -3
      app/schemas/eu.faircode.email.DB/1.json
  2. +13
    -1
      app/src/main/java/eu/faircode/email/AdapterIdentity.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/DB.java
  4. +6
    -0
      app/src/main/java/eu/faircode/email/DaoIdentity.java
  5. +1
    -0
      app/src/main/java/eu/faircode/email/EntityAccount.java
  6. +5
    -1
      app/src/main/java/eu/faircode/email/EntityIdentity.java
  7. +4
    -4
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  8. +3
    -0
      app/src/main/java/eu/faircode/email/FragmentIdentity.java
  9. +11
    -1
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  10. +14
    -2
      app/src/main/res/layout/item_identity.xml

+ 15
- 3
app/schemas/eu.faircode.email.DB/1.json View File

@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "6213f410bff60ef85d8608f09052327d",
"identityHash": "23016f9b3ae09175ada077c837687ab6",
"entities": [
{
"tableName": "identity",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `email` TEXT NOT NULL, `replyto` TEXT, `account` INTEGER NOT NULL, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `starttls` INTEGER NOT NULL, `user` TEXT NOT NULL, `password` TEXT NOT NULL, `primary` INTEGER NOT NULL, `synchronize` INTEGER NOT NULL, FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `email` TEXT NOT NULL, `replyto` TEXT, `account` INTEGER NOT NULL, `host` TEXT NOT NULL, `port` INTEGER NOT NULL, `starttls` INTEGER NOT NULL, `user` TEXT NOT NULL, `password` TEXT NOT NULL, `primary` INTEGER NOT NULL, `synchronize` INTEGER NOT NULL, `state` TEXT, `error` TEXT, FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@ -79,6 +79,18 @@
"columnName": "synchronize",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "state",
"columnName": "state",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "error",
"columnName": "error",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
@ -770,7 +782,7 @@
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"6213f410bff60ef85d8608f09052327d\")"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"23016f9b3ae09175ada077c837687ab6\")"
]
}
}

+ 13
- 1
app/src/main/java/eu/faircode/email/AdapterIdentity.java View File

@ -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


+ 1
- 1
app/src/main/java/eu/faircode/email/DB.java View File

@ -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)


+ 6
- 0
app/src/main/java/eu/faircode/email/DaoIdentity.java View File

@ -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();


+ 1
- 0
app/src/main/java/eu/faircode/email/EntityAccount.java View File

@ -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


+ 5
- 1
app/src/main/java/eu/faircode/email/EntityIdentity.java View File

@ -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;
}


+ 4
- 4
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -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;


+ 3
- 0
app/src/main/java/eu/faircode/email/FragmentIdentity.java View File

@ -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();


+ 11
- 1
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -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);
}
}
}


+ 14
- 2
app/src/main/res/layout/item_identity.xml View File

@ -50,6 +50,16 @@
app:layout_constraintStart_toEndOf="@+id/ivPrimary"
app:layout_constraintTop_toBottomOf="@id/ivSync" />
<ImageView
android:id="@+id/ivState"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_cloud_off_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
<TextView
android:id="@+id/tvHost"
android:layout_width="0dp"
@ -59,9 +69,10 @@
android:maxLines="1"
android:text="host"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/ivState"
app:layout_constraintEnd_toStartOf="@+id/tvAccount"
app:layout_constraintStart_toEndOf="@+id/ivPrimary"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
app:layout_constraintTop_toTopOf="@id/ivState" />
<TextView
android:id="@+id/tvAccount"
@ -72,9 +83,10 @@
android:text="account"
android:textAlignment="textEnd"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/ivState"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvHost"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
app:layout_constraintTop_toTopOf="@id/ivState" />
<TextView
android:id="@+id/tvError"


Loading…
Cancel
Save