mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 02:05:36 +00:00
Reordered message menu
This commit is contained in:
parent
d4d63fb0a9
commit
1b8c531419
3 changed files with 159 additions and 155 deletions
|
@ -3,11 +3,15 @@
|
|||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<compositeConfiguration>
|
||||
<compositeBuild compositeDefinitionSource="SCRIPT" />
|
||||
</compositeConfiguration>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/colorpicker" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
|
|
|
@ -2120,6 +2120,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
.show();
|
||||
}
|
||||
|
||||
private void onMenuDecrypt(ActionData data) {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(
|
||||
new Intent(ActivityView.ACTION_DECRYPT)
|
||||
.putExtra("id", data.message.id));
|
||||
}
|
||||
|
||||
private void onMenuCreateRule(ActionData data) {
|
||||
Intent rule = new Intent(ActivityView.ACTION_EDIT_RULE);
|
||||
rule.putExtra("account", data.message.account);
|
||||
|
@ -2133,6 +2140,137 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
lbm.sendBroadcast(rule);
|
||||
}
|
||||
|
||||
private void onMenuManageKeywords(ActionData data) {
|
||||
if (!Helper.isPro(context)) {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("message", data.message);
|
||||
|
||||
new SimpleTask<EntityFolder>() {
|
||||
@Override
|
||||
protected EntityFolder onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
return DB.getInstance(context).folder().getFolder(message.folder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(final Bundle args, EntityFolder folder) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
|
||||
List<String> keywords = Arrays.asList(message.keywords);
|
||||
|
||||
final List<String> items = new ArrayList<>(keywords);
|
||||
for (String keyword : folder.keywords)
|
||||
if (!items.contains(keyword))
|
||||
items.add(keyword);
|
||||
|
||||
Collections.sort(items);
|
||||
|
||||
final boolean selected[] = new boolean[items.size()];
|
||||
final boolean dirty[] = new boolean[items.size()];
|
||||
for (int i = 0; i < selected.length; i++) {
|
||||
selected[i] = keywords.contains(items.get(i));
|
||||
dirty[i] = false;
|
||||
}
|
||||
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
.setTitle(R.string.title_manage_keywords)
|
||||
.setMultiChoiceItems(items.toArray(new String[0]), selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
dirty[which] = true;
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
args.putStringArray("keywords", items.toArray(new String[0]));
|
||||
args.putBooleanArray("selected", selected);
|
||||
args.putBooleanArray("dirty", dirty);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
String[] keywords = args.getStringArray("keywords");
|
||||
boolean[] selected = args.getBooleanArray("selected");
|
||||
boolean[] dirty = args.getBooleanArray("dirty");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
for (int i = 0; i < selected.length; i++)
|
||||
if (dirty[i])
|
||||
EntityOperation.queue(context, db, message, EntityOperation.KEYWORD, keywords[i], selected[i]);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keywords:managa");
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.title_add, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_keyword, null);
|
||||
final EditText etKeyword = view.findViewById(R.id.etKeyword);
|
||||
etKeyword.setText(null);
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String keyword = Helper.sanitizeKeyword(etKeyword.getText().toString());
|
||||
if (!TextUtils.isEmpty(keyword)) {
|
||||
args.putString("keyword", keyword);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
String keyword = args.getString("keyword");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityOperation.queue(context, db, message, EntityOperation.KEYWORD, keyword, true);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keyword:add");
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keywords");
|
||||
}
|
||||
|
||||
private void onMenuShare(ActionData data) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", data.message.id);
|
||||
|
@ -2340,144 +2478,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
}
|
||||
|
||||
private void onMenuManageKeywords(ActionData data) {
|
||||
if (!Helper.isPro(context)) {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("message", data.message);
|
||||
|
||||
new SimpleTask<EntityFolder>() {
|
||||
@Override
|
||||
protected EntityFolder onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
return DB.getInstance(context).folder().getFolder(message.folder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(final Bundle args, EntityFolder folder) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
|
||||
List<String> keywords = Arrays.asList(message.keywords);
|
||||
|
||||
final List<String> items = new ArrayList<>(keywords);
|
||||
for (String keyword : folder.keywords)
|
||||
if (!items.contains(keyword))
|
||||
items.add(keyword);
|
||||
|
||||
Collections.sort(items);
|
||||
|
||||
final boolean selected[] = new boolean[items.size()];
|
||||
final boolean dirty[] = new boolean[items.size()];
|
||||
for (int i = 0; i < selected.length; i++) {
|
||||
selected[i] = keywords.contains(items.get(i));
|
||||
dirty[i] = false;
|
||||
}
|
||||
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
.setTitle(R.string.title_manage_keywords)
|
||||
.setMultiChoiceItems(items.toArray(new String[0]), selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
dirty[which] = true;
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
args.putStringArray("keywords", items.toArray(new String[0]));
|
||||
args.putBooleanArray("selected", selected);
|
||||
args.putBooleanArray("dirty", dirty);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
String[] keywords = args.getStringArray("keywords");
|
||||
boolean[] selected = args.getBooleanArray("selected");
|
||||
boolean[] dirty = args.getBooleanArray("dirty");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
for (int i = 0; i < selected.length; i++)
|
||||
if (dirty[i])
|
||||
EntityOperation.queue(context, db, message, EntityOperation.KEYWORD, keywords[i], selected[i]);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keywords:managa");
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.title_add, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_keyword, null);
|
||||
final EditText etKeyword = view.findViewById(R.id.etKeyword);
|
||||
etKeyword.setText(null);
|
||||
new DialogBuilderLifecycle(context, owner)
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String keyword = Helper.sanitizeKeyword(etKeyword.getText().toString());
|
||||
if (!TextUtils.isEmpty(keyword)) {
|
||||
args.putString("keyword", keyword);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
EntityMessage message = (EntityMessage) args.getSerializable("message");
|
||||
String keyword = args.getString("keyword");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityOperation.queue(context, db, message, EntityOperation.KEYWORD, keyword, true);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keyword:add");
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(context, owner, ex);
|
||||
}
|
||||
}.execute(context, owner, args, "message:keywords");
|
||||
}
|
||||
|
||||
private void onMenuDecrypt(ActionData data) {
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(
|
||||
new Intent(ActivityView.ACTION_DECRYPT)
|
||||
.putExtra("id", data.message.id));
|
||||
}
|
||||
|
||||
private void onActionMore(final ActionData data) {
|
||||
boolean show_headers = properties.getValue("headers", data.message.id);
|
||||
|
||||
|
@ -2536,9 +2536,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
case R.id.menu_junk:
|
||||
onMenuJunk(data);
|
||||
return true;
|
||||
case R.id.menu_decrypt:
|
||||
onMenuDecrypt(data);
|
||||
return true;
|
||||
case R.id.menu_create_rule:
|
||||
onMenuCreateRule(data);
|
||||
return true;
|
||||
case R.id.menu_manage_keywords:
|
||||
onMenuManageKeywords(data);
|
||||
return true;
|
||||
case R.id.menu_share:
|
||||
onMenuShare(data);
|
||||
return true;
|
||||
|
@ -2551,12 +2557,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
case R.id.menu_raw:
|
||||
onMenuRaw(data);
|
||||
return true;
|
||||
case R.id.menu_manage_keywords:
|
||||
onMenuManageKeywords(data);
|
||||
return true;
|
||||
case R.id.menu_decrypt:
|
||||
onMenuDecrypt(data);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,18 @@
|
|||
android:id="@+id/menu_junk"
|
||||
android:title="@string/title_spam" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_decrypt"
|
||||
android:title="@string/title_decrypt" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_create_rule"
|
||||
android:title="@string/title_create_rule" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_manage_keywords"
|
||||
android:title="@string/title_manage_keywords" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_share"
|
||||
android:title="@string/title_share" />
|
||||
|
@ -44,12 +52,4 @@
|
|||
<item
|
||||
android:id="@+id/menu_raw"
|
||||
android:title="@string/title_raw_download" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_manage_keywords"
|
||||
android:title="@string/title_manage_keywords" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_decrypt"
|
||||
android:title="@string/title_decrypt" />
|
||||
</menu>
|
||||
|
|
Loading…
Reference in a new issue