|
|
|
@ -21,22 +21,23 @@ package eu.faircode.email;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
|
import androidx.lifecycle.LifecycleObserver;
|
|
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
|
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
|
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
@ -53,8 +54,6 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
private LifecycleOwner owner;
|
|
|
|
|
private LayoutInflater inflater;
|
|
|
|
|
|
|
|
|
|
private boolean debug;
|
|
|
|
|
|
|
|
|
|
private List<TupleOperationEx> items = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
|
|
|
@ -65,6 +64,8 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
private TextView tvTime;
|
|
|
|
|
private TextView tvError;
|
|
|
|
|
|
|
|
|
|
private TwoStateOwner powner = new TwoStateOwner(owner, "OperationPopup");
|
|
|
|
|
|
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
|
@ -78,13 +79,11 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
|
|
|
|
|
private void wire() {
|
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
|
if (BuildConfig.DEBUG || debug)
|
|
|
|
|
view.setOnLongClickListener(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void unwire() {
|
|
|
|
|
view.setOnClickListener(null);
|
|
|
|
|
if (BuildConfig.DEBUG || debug)
|
|
|
|
|
view.setOnLongClickListener(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -183,22 +182,40 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TupleOperationEx operation = items.get(pos);
|
|
|
|
|
final TupleOperationEx operation = items.get(pos);
|
|
|
|
|
if (operation == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 1, R.string.title_delete);
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.string.title_delete:
|
|
|
|
|
onActionDelete();
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onActionDelete() {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putLong("id", operation.id);
|
|
|
|
|
args.putLong("folder", operation.folder);
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
|
@Override
|
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
long folder = args.getLong("folder");
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
db.operation().deleteOperation(id);
|
|
|
|
|
db.folder().setFolderError(folder, null);
|
|
|
|
|
EntityOperation operation = db.operation().getOperation(id);
|
|
|
|
|
if (operation == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
db.operation().deleteOperation(operation.id);
|
|
|
|
|
db.folder().setFolderError(operation.folder, null);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -207,6 +224,10 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
Helper.unexpectedError(parentFragment.getFragmentManager(), ex);
|
|
|
|
|
}
|
|
|
|
|
}.execute(context, owner, args, "operation:delete");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
popupMenu.show();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -218,9 +239,6 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
this.owner = parentFragment.getViewLifecycleOwner();
|
|
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
this.debug = prefs.getBoolean("debug", false);
|
|
|
|
|
|
|
|
|
|
setHasStableIds(true);
|
|
|
|
|
|
|
|
|
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
|
|
@ -313,6 +331,11 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
|
|
|
|
|
return new ViewHolder(inflater.inflate(R.layout.item_operation, parent, false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onViewRecycled(@NonNull ViewHolder holder) {
|
|
|
|
|
holder.powner.recreate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
|
|
|
holder.unwire();
|
|
|
|
|