Small improvements

pull/50/head
M66B 7 years ago
parent 33ad41020a
commit 106e518960

@ -44,6 +44,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; 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<List<EntityAccount>>() { DB.getInstance(this).account().liveAccounts().observe(this, new Observer<List<EntityAccount>>() {
@Override @Override
public void onChanged(@Nullable List<EntityAccount> accounts) { public void onChanged(@Nullable List<EntityAccount> accounts) {
if (accounts == null)
accounts = new ArrayList<>();
ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(ActivityView.this, R.layout.item_drawer); ArrayAdapterDrawer drawerArray = new ArrayAdapterDrawer(ActivityView.this, R.layout.item_drawer);
if (accounts != null) { final Collator collator = Collator.getInstance(Locale.getDefault());
final Collator collator = Collator.getInstance(Locale.getDefault()); collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(accounts, new Comparator<EntityAccount>() { Collections.sort(accounts, new Comparator<EntityAccount>() {
@Override @Override
public int compare(EntityAccount a1, EntityAccount a2) { public int compare(EntityAccount a1, EntityAccount a2) {
return collator.compare(a1.name, a2.name); return collator.compare(a1.name, a2.name);
} }
}); });
for (EntityAccount account : accounts) for (EntityAccount account : accounts)
drawerArray.add(new DrawerItem(-1, R.drawable.baseline_folder_24, account.name, account.id)); 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)); drawerArray.add(new DrawerItem(ActivityView.this, R.drawable.baseline_settings_applications_24, R.string.menu_setup));

@ -27,6 +27,7 @@ import android.widget.ProgressBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -93,8 +94,10 @@ public class FragmentAccounts extends FragmentEx {
DB.getInstance(getContext()).account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() { DB.getInstance(getContext()).account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
@Override @Override
public void onChanged(@Nullable List<EntityAccount> accounts) { public void onChanged(@Nullable List<EntityAccount> accounts) {
if (accounts != null) if (accounts == null)
adapter.set(accounts); accounts = new ArrayList<>();
adapter.set(accounts);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);

@ -703,8 +703,11 @@ public class FragmentCompose extends FragmentEx {
new Observer<List<EntityAttachment>>() { new Observer<List<EntityAttachment>>() {
@Override @Override
public void onChanged(@Nullable List<EntityAttachment> attachments) { public void onChanged(@Nullable List<EntityAttachment> attachments) {
adapter.set(attachments == null ? new ArrayList<EntityAttachment>() : attachments); if (attachments == null)
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE); attachments = new ArrayList<>();
adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
} }
}); });

@ -27,6 +27,7 @@ import android.widget.ProgressBar;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -93,8 +94,7 @@ public class FragmentIdentities extends FragmentEx {
DB.getInstance(getContext()).identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() { DB.getInstance(getContext()).identity().liveIdentities().observe(getViewLifecycleOwner(), new Observer<List<TupleIdentityEx>>() {
@Override @Override
public void onChanged(@Nullable List<TupleIdentityEx> identities) { public void onChanged(@Nullable List<TupleIdentityEx> identities) {
if (identities != null) adapter.set(identities == null ? new ArrayList<TupleIdentityEx>() : identities);
adapter.set(identities);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);

@ -41,6 +41,7 @@ import android.widget.Toast;
import com.google.android.material.textfield.TextInputLayout; import com.google.android.material.textfield.TextInputLayout;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -389,7 +390,7 @@ public class FragmentIdentity extends FragmentEx {
@Override @Override
public void onChanged(List<EntityAccount> accounts) { public void onChanged(List<EntityAccount> accounts) {
if (accounts == null) if (accounts == null)
return; accounts = new ArrayList<>();
EntityAccount unselected = new EntityAccount(); EntityAccount unselected = new EntityAccount();
unselected.id = -1L; unselected.id = -1L;

@ -47,6 +47,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.text.Collator; import java.text.Collator;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; 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).removeObservers(getViewLifecycleOwner());
db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() { db.folder().liveFolders(message.account).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
@Override @Override
public void onChanged(@Nullable final List<TupleFolderEx> folders) { public void onChanged(@Nullable List<TupleFolderEx> folders) {
if (folders == null)
folders = new ArrayList<>();
boolean inInbox = EntityFolder.INBOX.equals(message.folderType); boolean inInbox = EntityFolder.INBOX.equals(message.folderType);
boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType); boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType);
boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType); boolean inArchive = EntityFolder.ARCHIVE.equals(message.folderType);
@ -345,9 +349,11 @@ public class FragmentMessage extends FragmentEx {
new Observer<List<EntityAttachment>>() { new Observer<List<EntityAttachment>>() {
@Override @Override
public void onChanged(@Nullable List<EntityAttachment> attachments) { public void onChanged(@Nullable List<EntityAttachment> attachments) {
if (attachments != null) if (attachments == null)
adapter.set(attachments); attachments = new ArrayList<>();
grpAttachments.setVisibility(attachments != null && attachments.size() > 0 ? View.VISIBLE : View.GONE);
adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
} }
}); });

@ -25,6 +25,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -75,8 +76,10 @@ public class FragmentOperations extends FragmentEx {
DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer<List<EntityOperation>>() { DB.getInstance(getContext()).operation().liveOperations().observe(getViewLifecycleOwner(), new Observer<List<EntityOperation>>() {
@Override @Override
public void onChanged(@Nullable List<EntityOperation> operations) { public void onChanged(@Nullable List<EntityOperation> operations) {
if (operations != null) if (operations == null)
adapter.set(operations); operations = new ArrayList<>();
adapter.set(operations);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);

@ -141,9 +141,6 @@ public class ServiceSynchronize extends LifecycleService {
@Override @Override
public void onChanged(@Nullable TupleAccountStats stats) { public void onChanged(@Nullable TupleAccountStats stats) {
if (stats == null)
return;
NotificationManager nm = getSystemService(NotificationManager.class); NotificationManager nm = getSystemService(NotificationManager.class);
nm.notify(NOTIFICATION_SYNCHRONIZE, nm.notify(NOTIFICATION_SYNCHRONIZE,
getNotificationService(stats.accounts, stats.operations, stats.unsent).build()); getNotificationService(stats.accounts, stats.operations, stats.unsent).build());
@ -189,7 +186,7 @@ public class ServiceSynchronize extends LifecycleService {
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onLoad(Context context, Bundle args) throws Throwable { protected Void onLoad(Context context, Bundle args) {
long time = args.getLong("time"); long time = args.getLong("time");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -352,6 +349,7 @@ public class ServiceSynchronize extends LifecycleService {
@Override @Override
public void notification(StoreEvent e) { public void notification(StoreEvent e) {
Log.i(Helper.TAG, account.name + " event: " + e.getMessage()); Log.i(Helper.TAG, account.name + " event: " + e.getMessage());
db.account().setAccountError(account.id, e.getMessage());
} }
}); });
istore.addFolderListener(new FolderAdapter() { istore.addFolderListener(new FolderAdapter() {
@ -410,7 +408,12 @@ public class ServiceSynchronize extends LifecycleService {
monitorFolder(account, folder, fstore, ifolder, state); 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) { } catch (IllegalStateException ex) {
// Happens when syncing message
// This operation is not allowed on a closed folder // This operation is not allowed on a closed folder
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex)); Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));

Loading…
Cancel
Save