Fixes, improvements

This commit is contained in:
M66B 2018-09-23 04:28:13 +00:00
parent 0a525ba91f
commit e3f76b07b2
5 changed files with 38 additions and 27 deletions

View File

@ -743,12 +743,14 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
try {
db.beginTransaction();
if (!message.content)
EntityOperation.queue(db, message, EntityOperation.BODY);
if (!EntityFolder.OUTBOX.equals(message.folderType)) {
if (!message.content)
EntityOperation.queue(db, message, EntityOperation.BODY);
if (!message.threaded) {
db.message().setMessageUiSeen(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true);
if (!message.threaded) {
db.message().setMessageUiSeen(message.id, true);
EntityOperation.queue(db, message, EntityOperation.SEEN, true);
}
}
db.setTransactionSuccessful();

View File

@ -263,8 +263,10 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
final TupleMessageEx message = getItem(pos);
PopupMenu popupMenu = new PopupMenu(context, itemView);
popupMenu.getMenu().add(Menu.NONE, action_flag, 1, message.ui_flagged ? R.string.title_unflag : R.string.title_flag);
popupMenu.getMenu().add(Menu.NONE, action_seen, 2, message.ui_seen ? R.string.title_unseen : R.string.title_seen);
if (!EntityFolder.OUTBOX.equals(message.folderType)) {
popupMenu.getMenu().add(Menu.NONE, action_flag, 1, message.ui_flagged ? R.string.title_unflag : R.string.title_flag);
popupMenu.getMenu().add(Menu.NONE, action_seen, 2, message.ui_seen ? R.string.title_unseen : R.string.title_seen);
}
if (EntityFolder.TRASH.equals(message.folderType))
popupMenu.getMenu().add(Menu.NONE, action_delete, 3, R.string.title_delete);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -355,7 +357,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
}
});
popupMenu.show();
if (popupMenu.getMenu().hasVisibleItems())
popupMenu.show();
return true;
}

View File

@ -55,7 +55,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private long fid;
private String search;
private int pageSize;
private Handler mainHandler;
private Handler handler;
private IBoundaryCallbackMessages intf;
private ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
@ -65,6 +65,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
private int index;
private boolean searching = false;
private int loaded = 0;
private boolean destroyed = false;
interface IBoundaryCallbackMessages {
void onLoading();
@ -79,13 +80,14 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
this.fid = folder;
this.search = search;
this.pageSize = pageSize;
this.mainHandler = new Handler(_context.getMainLooper());
this.handler = new Handler();
this.intf = intf;
owner.getLifecycle().addObserver(new GenericLifecycleObserver() {
@Override
public void onStateChanged(LifecycleOwner source, Lifecycle.Event event) {
if (event == Lifecycle.Event.ON_DESTROY)
if (event == Lifecycle.Event.ON_DESTROY) {
destroyed = true;
executor.submit(new Runnable() {
@Override
public void run() {
@ -104,6 +106,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
}
}
});
}
}
});
}
@ -134,16 +137,18 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
public void run() {
try {
searching = true;
mainHandler.post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
intf.onLoading();
if (!destroyed)
intf.onLoading();
}
});
DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolder(fid);
if (folder.account == null) // outbox
return;
EntityAccount account = db.account().getAccount(folder.account);
if (imessages == null) {
@ -221,24 +226,25 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
}
}
mainHandler.post(new Runnable() {
@Override
public void run() {
intf.onLoaded();
}
});
Log.i(Helper.TAG, "Boundary done");
} catch (final Throwable ex) {
Log.e(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
mainHandler.post(new Runnable() {
handler.post(new Runnable() {
@Override
public void run() {
intf.onError(context, ex);
if (!destroyed)
intf.onError(context, ex);
}
});
} finally {
searching = false;
handler.post(new Runnable() {
@Override
public void run() {
if (!destroyed)
intf.onLoaded();
}
});
}
}
});

View File

@ -32,5 +32,7 @@ public class DialogBuilderLifecycle extends AlertDialog.Builder implements Lifec
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
dialog.dismiss();
owner = null;
dialog = null;
}
}

View File

@ -667,7 +667,7 @@ public class FragmentMessages extends FragmentEx {
case FOLDER:
if (searchCallback == null)
searchCallback = new BoundaryCallbackMessages(
getContext(), FragmentMessages.this,
getContext(), this,
folder, null, REMOTE_PAGE_SIZE,
new BoundaryCallbackMessages.IBoundaryCallbackMessages() {
@Override
@ -682,7 +682,6 @@ public class FragmentMessages extends FragmentEx {
@Override
public void onError(Context context, Throwable ex) {
pbWait.setVisibility(View.GONE);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
.setPositiveButton(android.R.string.cancel, null)
@ -710,7 +709,7 @@ public class FragmentMessages extends FragmentEx {
} else {
if (searchCallback == null)
searchCallback = new BoundaryCallbackMessages(
getContext(), FragmentMessages.this,
getContext(), this,
folder, search, REMOTE_PAGE_SIZE,
new BoundaryCallbackMessages.IBoundaryCallbackMessages() {
@Override
@ -728,7 +727,6 @@ public class FragmentMessages extends FragmentEx {
@Override
public void onError(Context context, Throwable ex) {
pbWait.setVisibility(View.GONE);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
.setPositiveButton(android.R.string.cancel, null)