Show operation errors

This commit is contained in:
M66B 2018-12-01 15:13:57 +01:00
parent 30628f15f8
commit 6a81e064bf
7 changed files with 1197 additions and 7 deletions

File diff suppressed because it is too large Load Diff

View File

@ -51,11 +51,12 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
private DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.LONG);
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
View itemView;
TextView tvMessage;
TextView tvName;
TextView tvArgs;
TextView tvTime;
private View itemView;
private TextView tvMessage;
private TextView tvName;
private TextView tvArgs;
private TextView tvTime;
private TextView tvError;
ViewHolder(View itemView) {
super(itemView);
@ -65,6 +66,7 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
tvName = itemView.findViewById(R.id.tvName);
tvArgs = itemView.findViewById(R.id.tvArgs);
tvTime = itemView.findViewById(R.id.tvTime);
tvError = itemView.findViewById(R.id.tvError);
}
private void wire() {
@ -82,6 +84,8 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
tvName.setText(operation.name);
tvArgs.setText(operation.args);
tvTime.setText(df.format(new Date(operation.created)));
tvError.setText(operation.error);
tvError.setVisibility(operation.error == null ? View.GONE : View.VISIBLE);
}
@Override

View File

@ -46,7 +46,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 10,
version = 11,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -192,6 +192,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("CREATE INDEX `index_message_ui_browsed` ON `message` (`ui_browsed`)");
}
})
.addMigrations(new Migration(10, 11) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `operation` ADD COLUMN `error` TEXT");
}
})
.build();
}

View File

@ -40,6 +40,9 @@ public interface DaoOperation {
@Query("SELECT COUNT(id) FROM operation WHERE folder = :folder")
int getOperationCount(long folder);
@Query("UPDATE operation SET error = :error WHERE id = :id")
int setOperationError(long id, String error);
@Insert
long insertOperation(EntityOperation operation);

View File

@ -64,6 +64,7 @@ public class EntityOperation {
public String args;
@NonNull
public Long created;
public String error;
public static final String ADD = "add";
public static final String MOVE = "move";
@ -138,7 +139,8 @@ public class EntityOperation {
this.message.equals(other.message) &&
this.name.equals(other.name) &&
this.args.equals(other.args) &&
this.created.equals(other.created));
this.created.equals(other.created) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
} else
return false;
}

View File

@ -1335,6 +1335,7 @@ public class ServiceSynchronize extends LifecycleService {
if (message == null)
throw new MessageRemovedException();
db.operation().setOperationError(op.id, null);
db.message().setMessageError(message.id, null);
if (message.uid == null &&
@ -1388,6 +1389,7 @@ public class ServiceSynchronize extends LifecycleService {
// TODO: SMTP response codes: https://www.ietf.org/rfc/rfc821.txt
reportError(null, folder.name, ex);
db.operation().setOperationError(op.id, Helper.formatThrowable(ex));
if (message != null &&
!(ex instanceof MessageRemovedException) &&
!(ex instanceof FolderClosedException) &&

View File

@ -48,4 +48,22 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="tvMessage,tvName,tvArgs,tvTime" />
<TextView
android:id="@+id/tvError"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:text="error"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintEnd_toStartOf="@id/tvTime"
app:layout_constraintStart_toStartOf="@id/tvName"
app:layout_constraintTop_toBottomOf="@id/barrier" />
</androidx.constraintlayout.widget.ConstraintLayout>