Added dialog to set importance

pull/172/head
M66B 5 years ago
parent 51eb9aaaef
commit 5897302e5d

@ -92,6 +92,7 @@ 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;
@ -3303,6 +3304,9 @@ 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;
@ -3630,6 +3634,17 @@ 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);
@ -4980,6 +4995,50 @@ 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

@ -0,0 +1,33 @@
<?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>

@ -32,6 +32,10 @@
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" />

Loading…
Cancel
Save