mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 22:51:02 +00:00
Show warning icons in nav menu on errors
This commit is contained in:
parent
441fa79c46
commit
65dcbc7464
6 changed files with 57 additions and 36 deletions
|
@ -381,8 +381,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
db.operation().liveStats().observe(this, new Observer<TupleOperationStats>() {
|
||||
@Override
|
||||
public void onChanged(TupleOperationStats stats) {
|
||||
navOperations.setIcon(stats == null || stats.errors == null || stats.errors == 0
|
||||
? R.drawable.baseline_list_24 : R.drawable.baseline_warning_24);
|
||||
navOperations.setWarning(stats != null && stats.errors != null && stats.errors > 0);
|
||||
navOperations.setCount(stats == null ? 0 : stats.pending);
|
||||
madapter.notifyDataSetChanged();
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
|
|||
private View view;
|
||||
private ImageView ivItem;
|
||||
private TextView tvItem;
|
||||
private ImageView ivWarning;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -59,6 +60,7 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
|
|||
view = itemView.findViewById(R.id.clItem);
|
||||
ivItem = itemView.findViewById(R.id.ivItem);
|
||||
tvItem = itemView.findViewById(R.id.tvItem);
|
||||
ivWarning = itemView.findViewById(R.id.ivWarning);
|
||||
}
|
||||
|
||||
private void wire() {
|
||||
|
@ -70,12 +72,9 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
|
|||
}
|
||||
|
||||
private void bindTo(TupleAccountEx account) {
|
||||
if (account.error == null)
|
||||
ivItem.setImageResource("connected".equals(account.state)
|
||||
? account.primary ? R.drawable.baseline_folder_special_24 : R.drawable.baseline_folder_24
|
||||
: R.drawable.baseline_folder_open_24);
|
||||
else
|
||||
ivItem.setImageResource(R.drawable.baseline_warning_24);
|
||||
ivItem.setImageResource("connected".equals(account.state)
|
||||
? account.primary ? R.drawable.baseline_folder_special_24 : R.drawable.baseline_folder_24
|
||||
: R.drawable.baseline_folder_open_24);
|
||||
|
||||
if (account.color == null)
|
||||
ivItem.clearColorFilter();
|
||||
|
@ -90,6 +89,8 @@ public class AdapterNavAccount extends RecyclerView.Adapter<AdapterNavAccount.Vi
|
|||
|
||||
tvItem.setTextColor(Helper.resolveColor(context,
|
||||
account.unseen == 0 ? android.R.attr.textColorSecondary : R.attr.colorUnread));
|
||||
|
||||
ivWarning.setVisibility(account.error == null ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,6 +56,7 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
|
|||
private View view;
|
||||
private ImageView ivItem;
|
||||
private TextView tvItem;
|
||||
private ImageView ivWarning;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -63,6 +64,7 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
|
|||
view = itemView.findViewById(R.id.clItem);
|
||||
ivItem = itemView.findViewById(R.id.ivItem);
|
||||
tvItem = itemView.findViewById(R.id.tvItem);
|
||||
ivWarning = itemView.findViewById(R.id.ivWarning);
|
||||
}
|
||||
|
||||
private void wire() {
|
||||
|
@ -74,31 +76,28 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
|
|||
}
|
||||
|
||||
private void bindTo(TupleFolderNav folder) {
|
||||
if (folder.error == null)
|
||||
if (EntityFolder.OUTBOX.equals(folder.type)) {
|
||||
if ("syncing".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_compare_arrows_24);
|
||||
else
|
||||
ivItem.setImageResource(R.drawable.baseline_send_24);
|
||||
if (EntityFolder.OUTBOX.equals(folder.type)) {
|
||||
if ("syncing".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_compare_arrows_24);
|
||||
else
|
||||
ivItem.setImageResource(R.drawable.baseline_send_24);
|
||||
|
||||
ivItem.clearColorFilter();
|
||||
} else {
|
||||
if ("syncing".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_compare_arrows_24);
|
||||
else if ("downloading".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_cloud_download_24);
|
||||
else
|
||||
ivItem.setImageResource("connected".equals(folder.state)
|
||||
? R.drawable.baseline_folder_24
|
||||
: R.drawable.baseline_folder_open_24);
|
||||
|
||||
if (folder.color == null)
|
||||
ivItem.clearColorFilter();
|
||||
} else {
|
||||
if ("syncing".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_compare_arrows_24);
|
||||
else if ("downloading".equals(folder.sync_state))
|
||||
ivItem.setImageResource(R.drawable.baseline_cloud_download_24);
|
||||
else
|
||||
ivItem.setImageResource("connected".equals(folder.state)
|
||||
? R.drawable.baseline_folder_24
|
||||
: R.drawable.baseline_folder_open_24);
|
||||
|
||||
if (folder.color == null)
|
||||
ivItem.clearColorFilter();
|
||||
else
|
||||
ivItem.setColorFilter(folder.color);
|
||||
}
|
||||
else
|
||||
ivItem.setImageResource(R.drawable.baseline_warning_24);
|
||||
else
|
||||
ivItem.setColorFilter(folder.color);
|
||||
}
|
||||
|
||||
int count = (EntityFolder.OUTBOX.equals(folder.type) ? folder.operations : folder.unseen);
|
||||
|
||||
|
@ -110,6 +109,8 @@ public class AdapterNavFolder extends RecyclerView.Adapter<AdapterNavFolder.View
|
|||
|
||||
tvItem.setTextColor(Helper.resolveColor(context,
|
||||
count == 0 ? android.R.attr.textColorSecondary : R.attr.colorUnread));
|
||||
|
||||
ivWarning.setVisibility(folder.error == null ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,6 +50,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
private View view;
|
||||
private ImageView ivItem;
|
||||
private TextView tvItem;
|
||||
private ImageView ivWarning;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -57,6 +58,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
view = itemView.findViewById(R.id.clItem);
|
||||
ivItem = itemView.findViewById(R.id.ivItem);
|
||||
tvItem = itemView.findViewById(R.id.tvItem);
|
||||
ivWarning = itemView.findViewById(R.id.ivWarning);
|
||||
}
|
||||
|
||||
private void wire() {
|
||||
|
@ -80,6 +82,8 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
|
||||
tvItem.setTextColor(Helper.resolveColor(context,
|
||||
menu.getCount() == null ? android.R.attr.textColorSecondary : R.attr.colorUnread));
|
||||
|
||||
ivWarning.setVisibility(menu.hasWarning() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ public class NavMenuItem {
|
|||
private int icon;
|
||||
private int title;
|
||||
private Integer count = null;
|
||||
private boolean warning = false;
|
||||
private boolean separated = false;
|
||||
private Runnable click;
|
||||
private Runnable longClick;
|
||||
|
@ -40,16 +41,16 @@ public class NavMenuItem {
|
|||
this.longClick = longClick;
|
||||
}
|
||||
|
||||
void setIcon(int icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
void setCount(Integer count) {
|
||||
if (count != null && count == 0)
|
||||
count = null;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
void setWarning(boolean warning) {
|
||||
this.warning = warning;
|
||||
}
|
||||
|
||||
NavMenuItem setSeparated() {
|
||||
this.separated = true;
|
||||
return this;
|
||||
|
@ -71,6 +72,10 @@ public class NavMenuItem {
|
|||
return this.separated;
|
||||
}
|
||||
|
||||
boolean hasWarning() {
|
||||
return this.warning;
|
||||
}
|
||||
|
||||
void onClick() {
|
||||
click.run();
|
||||
}
|
||||
|
|
|
@ -34,8 +34,19 @@
|
|||
android:text="Nav item"
|
||||
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivWarning"
|
||||
app:layout_constraintStart_toEndOf="@id/ivItem"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivWarning"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:src="@drawable/baseline_warning_24"
|
||||
android:tint="?colorWarning"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in a new issue