diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 0ce504ff..934a6c9f 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -44,6 +44,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.text.Collator; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -131,22 +132,23 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack DB.getInstance(this).account().liveAccounts().observe(this, new Observer>() { @Override public void onChanged(@Nullable List accounts) { + if (accounts == null) + accounts = new ArrayList<>(); + ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(ActivityView.this, R.layout.item_drawer); - if (accounts != null) { - final Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc + final Collator collator = Collator.getInstance(Locale.getDefault()); + collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc - Collections.sort(accounts, new Comparator() { - @Override - public int compare(EntityAccount a1, EntityAccount a2) { - return collator.compare(a1.name, a2.name); - } - }); + Collections.sort(accounts, new Comparator() { + @Override + public int compare(EntityAccount a1, EntityAccount a2) { + return collator.compare(a1.name, a2.name); + } + }); - for (EntityAccount account : accounts) - drawerArray.add(new DrawerItem(-1, R.drawable.baseline_folder_24, account.name, account.id)); - } + for (EntityAccount account : accounts) + drawerArray.add(new DrawerItem(-1, R.drawable.baseline_folder_24, account.name, account.id)); drawerArray.add(new DrawerItem(ActivityView.this, R.drawable.baseline_settings_applications_24, R.string.menu_setup)); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccounts.java b/app/src/main/java/eu/faircode/email/FragmentAccounts.java index 7f038840..20bd075a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccounts.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccounts.java @@ -27,6 +27,7 @@ import android.widget.ProgressBar; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; @@ -93,8 +94,10 @@ public class FragmentAccounts extends FragmentEx { DB.getInstance(getContext()).account().liveAccounts().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List accounts) { - if (accounts != null) - adapter.set(accounts); + if (accounts == null) + accounts = new ArrayList<>(); + + adapter.set(accounts); pbWait.setVisibility(View.GONE); grpReady.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index e826ebcd..8d83385c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -703,8 +703,11 @@ public class FragmentCompose extends FragmentEx { new Observer>() { @Override public void onChanged(@Nullable List attachments) { - adapter.set(attachments == null ? new ArrayList() : attachments); - grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE); + if (attachments == null) + attachments = new ArrayList<>(); + + adapter.set(attachments); + grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE); } }); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentities.java b/app/src/main/java/eu/faircode/email/FragmentIdentities.java index 69b7d325..f509ef75 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentities.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentities.java @@ -27,6 +27,7 @@ import android.widget.ProgressBar; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; @@ -93,8 +94,7 @@ public class FragmentIdentities extends FragmentEx { DB.getInstance(getContext()).identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List identities) { - if (identities != null) - adapter.set(identities); + adapter.set(identities == null ? new ArrayList() : identities); pbWait.setVisibility(View.GONE); grpReady.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index cf5fec33..72b1de09 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -41,6 +41,7 @@ import android.widget.Toast; import com.google.android.material.textfield.TextInputLayout; +import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -389,7 +390,7 @@ public class FragmentIdentity extends FragmentEx { @Override public void onChanged(List accounts) { if (accounts == null) - return; + accounts = new ArrayList<>(); EntityAccount unselected = new EntityAccount(); unselected.id = -1L; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 10c682b0..558560cb 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -47,6 +47,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; import java.text.Collator; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -291,7 +292,10 @@ public class FragmentMessage extends FragmentEx { db.folder().liveFolders(message.account).removeObservers(getViewLifecycleOwner()); db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer>() { @Override - public void onChanged(@Nullable final List folders) { + public void onChanged(@Nullable List folders) { + if (folders == null) + folders = new ArrayList<>(); + boolean inInbox = EntityFolder.INBOX.equals(message.folderType); boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType); boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); @@ -345,9 +349,11 @@ public class FragmentMessage extends FragmentEx { new Observer>() { @Override public void onChanged(@Nullable List attachments) { - if (attachments != null) - adapter.set(attachments); - grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE); + if (attachments == null) + attachments = new ArrayList<>(); + + adapter.set(attachments); + grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE); } }); diff --git a/app/src/main/java/eu/faircode/email/FragmentOperations.java b/app/src/main/java/eu/faircode/email/FragmentOperations.java index edab0859..f988eb19 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOperations.java +++ b/app/src/main/java/eu/faircode/email/FragmentOperations.java @@ -25,6 +25,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ProgressBar; +import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; @@ -75,8 +76,10 @@ public class FragmentOperations extends FragmentEx { DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer>() { @Override public void onChanged(@Nullable List operations) { - if (operations != null) - adapter.set(operations); + if (operations == null) + operations = new ArrayList<>(); + + adapter.set(operations); pbWait.setVisibility(View.GONE); grpReady.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 108ca718..7333c00e 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -141,9 +141,6 @@ public class ServiceSynchronize extends LifecycleService { @Override public void onChanged(@Nullable TupleAccountStats stats) { - if (stats == null) - return; - NotificationManager nm = getSystemService(NotificationManager.class); nm.notify(NOTIFICATION_SYNCHRONIZE, getNotificationService(stats.accounts, stats.operations, stats.unsent).build()); @@ -189,7 +186,7 @@ public class ServiceSynchronize extends LifecycleService { new SimpleTask() { @Override - protected Void onLoad(Context context, Bundle args) throws Throwable { + protected Void onLoad(Context context, Bundle args) { long time = args.getLong("time"); DB db = DB.getInstance(context); @@ -352,6 +349,7 @@ public class ServiceSynchronize extends LifecycleService { @Override public void notification(StoreEvent e) { Log.i(Helper.TAG, account.name + " event: " + e.getMessage()); + db.account().setAccountError(account.id, e.getMessage()); } }); istore.addFolderListener(new FolderAdapter() { @@ -410,7 +408,12 @@ public class ServiceSynchronize extends LifecycleService { monitorFolder(account, folder, fstore, ifolder, state); + } catch (FolderClosedException ex) { + // Happens when no connectivity + Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); + } catch (IllegalStateException ex) { + // Happens when syncing message // This operation is not allowed on a closed folder Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));