mirror of https://github.com/M66B/FairEmail.git
Allow moving rules to another folder
This commit is contained in:
parent
8a09282b09
commit
4a0972f282
|
@ -185,7 +185,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||||
.setCheckable(true).setChecked(rule.enabled);
|
.setCheckable(true).setChecked(rule.enabled);
|
||||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_execute, 2, R.string.title_rule_execute)
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_execute, 2, R.string.title_rule_execute)
|
||||||
.setEnabled(ActivityBilling.isPro(context));
|
.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() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -199,6 +200,10 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||||
onActionExecute();
|
onActionExecute();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.string.title_move_to_folder:
|
||||||
|
onActionMove();
|
||||||
|
return true;
|
||||||
|
|
||||||
case R.string.title_copy:
|
case R.string.title_copy:
|
||||||
onActionCopy();
|
onActionCopy();
|
||||||
return true;
|
return true;
|
||||||
|
@ -286,6 +291,19 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||||
}.execute(context, owner, args, "rule:execute");
|
}.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() {
|
private void onActionCopy() {
|
||||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||||
lbm.sendBroadcast(
|
lbm.sendBroadcast(
|
||||||
|
|
|
@ -59,6 +59,9 @@ public interface DaoRule {
|
||||||
@Update
|
@Update
|
||||||
int updateRule(EntityRule rule);
|
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")
|
@Query("UPDATE rule SET enabled = :enabled WHERE id = :id")
|
||||||
int setRuleEnabled(long id, boolean enabled);
|
int setRuleEnabled(long id, boolean enabled);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ package eu.faircode.email;
|
||||||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -41,6 +43,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.app.Activity.RESULT_OK;
|
||||||
|
|
||||||
public class FragmentRules extends FragmentBase {
|
public class FragmentRules extends FragmentBase {
|
||||||
private long account;
|
private long account;
|
||||||
private long folder;
|
private long folder;
|
||||||
|
@ -54,6 +58,8 @@ public class FragmentRules extends FragmentBase {
|
||||||
|
|
||||||
private AdapterRule adapter;
|
private AdapterRule adapter;
|
||||||
|
|
||||||
|
static final int REQUEST_MOVE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue