|
|
@ -26,6 +26,8 @@ import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.text.format.DateUtils;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ImageView;
|
|
|
@ -39,6 +41,7 @@ import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
@ -70,6 +73,9 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|
|
|
TextView tvError;
|
|
|
|
TextView tvError;
|
|
|
|
ProgressBar pbLoading;
|
|
|
|
ProgressBar pbLoading;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int action_seen = 1;
|
|
|
|
|
|
|
|
private static final int action_flag = 2;
|
|
|
|
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
|
|
|
@ -207,40 +213,59 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
TupleMessageEx message = getItem(pos);
|
|
|
|
final TupleMessageEx message = getItem(pos);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
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);
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
public boolean onMenuItemClick(MenuItem target) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
args.putLong("id", message.id);
|
|
|
|
try {
|
|
|
|
args.putInt("action", target.getItemId());
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
@Override
|
|
|
|
for (EntityMessage tmessage : db.message().getMessageByThread(message.account, message.thread)) {
|
|
|
|
protected Void onLoad(Context context, Bundle args) {
|
|
|
|
db.message().setMessageUiSeen(tmessage.id, !message.ui_seen);
|
|
|
|
long id = args.getLong("id");
|
|
|
|
EntityOperation.queue(db, tmessage, EntityOperation.SEEN, !tmessage.ui_seen);
|
|
|
|
int action = args.getInt("action");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
|
|
|
|
for (EntityMessage tmessage : db.message().getMessageByThread(message.account, message.thread))
|
|
|
|
|
|
|
|
if (action == action_flag) {
|
|
|
|
|
|
|
|
db.message().setMessageUiFlagged(tmessage.id, !message.ui_flagged);
|
|
|
|
|
|
|
|
EntityOperation.queue(db, tmessage, EntityOperation.FLAG, !tmessage.ui_flagged);
|
|
|
|
|
|
|
|
} else if (action == action_seen) {
|
|
|
|
|
|
|
|
db.message().setMessageUiSeen(tmessage.id, !message.ui_seen);
|
|
|
|
|
|
|
|
EntityOperation.queue(db, tmessage, EntityOperation.SEEN, !tmessage.ui_seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
db.endTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
@Override
|
|
|
|
} finally {
|
|
|
|
public void onException(Bundle args, Throwable ex) {
|
|
|
|
db.endTransaction();
|
|
|
|
Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
EntityOperation.process(context);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
popupMenu.show();
|
|
|
|
public void onException(Bundle args, Throwable ex) {
|
|
|
|
|
|
|
|
Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}.load(context, owner, args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|