Allow moving rules to another folder

This commit is contained in:
M66B 2019-09-08 09:54:03 +02:00
parent 8a09282b09
commit 4a0972f282
3 changed files with 63 additions and 1 deletions

View File

@ -185,7 +185,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
.setCheckable(true).setChecked(rule.enabled);
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_execute, 2, R.string.title_rule_execute)
.setEnabled(ActivityBilling.isPro(context));
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 3, R.string.title_copy);
popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_folder, 3, R.string.title_move_to_folder);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -199,6 +200,10 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
onActionExecute();
return true;
case R.string.title_move_to_folder:
onActionMove();
return true;
case R.string.title_copy:
onActionCopy();
return true;
@ -286,6 +291,19 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
}.execute(context, owner, args, "rule:execute");
}
private void onActionMove() {
Bundle args = new Bundle();
args.putString("title", context.getString(R.string.title_move_to_folder));
args.putLong("account", rule.account);
args.putLongArray("disabled", new long[]{rule.folder});
args.putLong("rule", rule.id);
FragmentDialogFolder fragment = new FragmentDialogFolder();
fragment.setArguments(args);
fragment.setTargetFragment(parentFragment, FragmentRules.REQUEST_MOVE);
fragment.show(parentFragment.getFragmentManager(), "rule:move");
}
private void onActionCopy() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(

View File

@ -59,6 +59,9 @@ public interface DaoRule {
@Update
int updateRule(EntityRule rule);
@Query("UPDATE rule SET folder = :folder WHERE id = :id")
int setRuleFolder(long id, long folder);
@Query("UPDATE rule SET enabled = :enabled WHERE id = :id")
int setRuleEnabled(long id, boolean enabled);

View File

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -41,6 +43,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import static android.app.Activity.RESULT_OK;
public class FragmentRules extends FragmentBase {
private long account;
private long folder;
@ -54,6 +58,8 @@ public class FragmentRules extends FragmentBase {
private AdapterRule adapter;
static final int REQUEST_MOVE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -140,4 +146,39 @@ public class FragmentRules extends FragmentBase {
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_MOVE:
if (resultCode == RESULT_OK && data != null)
onMove(data.getBundleExtra("args"));
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onMove(Bundle args) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("rule");
long folder = args.getLong("folder");
DB db = DB.getInstance(context);
db.rule().setRuleFolder(id, folder);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
}
}.execute(this, args, "rule:move");
}
}