Use set importance submenu instead of dialog

pull/174/head
M66B 5 years ago
parent 439b1b741f
commit c47686a403

@ -92,7 +92,6 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
@ -3292,6 +3291,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_flag_color:
onMenuColoredStar(message);
return true;
case R.id.menu_set_importance_low:
onMenuSetImportance(message, EntityMessage.PRIORITIY_LOW);
return true;
case R.id.menu_set_importance_normal:
onMenuSetImportance(message, EntityMessage.PRIORITIY_NORMAL);
return true;
case R.id.menu_set_importance_high:
onMenuSetImportance(message, EntityMessage.PRIORITIY_HIGH);
return true;
case R.id.menu_copy:
onActionMove(message, true);
return true;
@ -3304,9 +3312,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_create_rule:
onMenuCreateRule(message);
return true;
case R.id.menu_set_importance:
onMenuSetImportance(message);
return true;
case R.id.menu_manage_keywords:
onMenuManageKeywords(message);
return true;
@ -3566,6 +3571,32 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
fragment.show(parentFragment.getParentFragmentManager(), "message:color");
}
private void onMenuSetImportance(TupleMessageEx message, int importance) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putInt("importance", importance);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
Integer importance = args.getInt("importance");
if (EntityMessage.PRIORITIY_NORMAL.equals(importance))
importance = null;
DB db = DB.getInstance(context);
db.message().setMessageImportance(id, importance);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "importance:set");
}
private void onMenuDelete(final TupleMessageEx message) {
Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete));
@ -3634,17 +3665,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
lbm.sendBroadcast(rule);
}
private void onMenuSetImportance(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
if (message.importance != null)
args.putInt("importance", message.importance);
FragmentDialogSetImportance fragment = new FragmentDialogSetImportance();
fragment.setArguments(args);
fragment.show(parentFragment.getParentFragmentManager(), "keyword:importance");
}
private void onMenuManageKeywords(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
@ -4995,50 +5015,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
}
public static class FragmentDialogSetImportance extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
int importance = getArguments().getInt("importance", EntityMessage.PRIORITIY_NORMAL);
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_importance, null);
final Spinner spImportance = view.findViewById(R.id.spImportance);
spImportance.setSelection(importance);
return new AlertDialog.Builder(getContext())
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = getArguments();
args.putInt("importance", spImportance.getSelectedItemPosition());
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
Integer importance = args.getInt("importance");
if (EntityMessage.PRIORITIY_NORMAL.equals(importance))
importance = null;
DB db = DB.getInstance(context);
db.message().setMessageImportance(id, importance);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(getContext(), getViewLifecycleOwner(), args, "importance: set");
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
public static class FragmentDialogKeywordManage extends FragmentDialogBase {
@NonNull
@Override

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_rule_importance"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/spImportance"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:entries="@array/priorityNames"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -16,6 +16,22 @@
android:id="@+id/menu_flag_color"
android:title="@string/title_flag_color" />
<item
android:id="@+id/menu_set_importance"
android:title="@string/title_set_importance">
<menu>
<item
android:id="@+id/menu_set_importance_low"
android:title="@string/title_importance_low" />
<item
android:id="@+id/menu_set_importance_normal"
android:title="@string/title_importance_normal" />
<item
android:id="@+id/menu_set_importance_high"
android:title="@string/title_importance_high" />
</menu>
</item>
<item
android:id="@+id/menu_copy"
android:title="@string/title_copy" />
@ -32,10 +48,6 @@
android:id="@+id/menu_create_rule"
android:title="@string/title_create_rule" />
<item
android:id="@+id/menu_set_importance"
android:title="@string/title_rule_importance" />
<item
android:id="@+id/menu_manage_keywords"
android:title="@string/title_manage_keywords" />

@ -633,6 +633,10 @@
<string name="title_flag">Add star</string>
<string name="title_flag_color">Colored star &#8230;</string>
<string name="title_unflag">Remove star</string>
<string name="title_set_importance">Set importance</string>
<string name="title_importance_low">Low</string>
<string name="title_importance_normal">Normal</string>
<string name="title_importance_high">High</string>
<string name="title_forward">Forward</string>
<string name="title_new_message">New message</string>
<string name="title_editasnew">Edit as new</string>

Loading…
Cancel
Save