Эх сурвалжийг харах

now definitely use simpler, less intrusive cancel alert dialog

Noah Vogt 4 жил өмнө
parent
commit
de9f44dc7d

+ 7 - 54
app/src/main/java/com/noahvogt/miniprojekt/messageCreateFragment.java

@@ -69,83 +69,36 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
             public void onClick(View v) {
             public void onClick(View v) {
                 String subject = subjectObject.getText().toString();
                 String subject = subjectObject.getText().toString();
                 String messageBody = messageBodyObject.getText().toString();
                 String messageBody = messageBodyObject.getText().toString();
+
+                // give alert dialog box to user in case input fields are not empty
+
                 if (subject.isEmpty() && messageBody.isEmpty()) {
                 if (subject.isEmpty() && messageBody.isEmpty()) {
                     dismiss();
                     dismiss();
                 }
                 }
                 else {
                 else {
-
-                    final boolean[] wantsToCancel = new boolean[1]; // do we really need an array here? stupid java
-                    /*
-                    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
-                    final View cancelAlertPopupView = getLayoutInflater().inflate(R.layout.closing_alert, null);
-
-                    // open View window
-                    dialogBuilder.setView(cancelAlertPopupView);
-                    dialog = dialogBuilder.create();
-                    dialog.show();
-
-                    Button yesButton = (Button) view.findViewById(R.id.closing_alert_yes_button);
-                    Button noButton = (Button) view.findViewById(R.id.closing_alert_no_button);
-
-
-
-
-
-                    yesButton.setOnClickListener(new View.OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            //wantsToCancel[0] = true;
-                            dialog.dismiss();
-                        }
-                    });
-                    noButton.setOnClickListener(new View.OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            //wantsToCancel[0] = false;
-                            dialog.dismiss();
-                        }
-                    });
-
-                    if (wantsToCancel[0]) {
-                        dismiss();
-                    }*/
-                    // TODO: alert user when pressing this button in case input fields are not empty
-
+                    // setup dialog
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
-
-                    // set title
                     alertDialogBuilder.setTitle("Warning");
                     alertDialogBuilder.setTitle("Warning");
-
-                    // set dialog message
                     alertDialogBuilder
                     alertDialogBuilder
                             .setMessage("Do you really want to cancel?")
                             .setMessage("Do you really want to cancel?")
                             .setCancelable(false)
                             .setCancelable(false)
                             .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                             .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog, int id) {
                                 public void onClick(DialogInterface dialog, int id) {
-                                    // if this button is clicked, close
-                                    // current activity
-                                    wantsToCancel[0] = true;
+                                    // if this button is clicked, close the whole fragment
                                     dismiss();
                                     dismiss();
                                 }
                                 }
                             })
                             })
                             .setNegativeButton("No",new DialogInterface.OnClickListener() {
                             .setNegativeButton("No",new DialogInterface.OnClickListener() {
                                 public void onClick(DialogInterface dialog,int id) {
                                 public void onClick(DialogInterface dialog,int id) {
-                                    // if this button is clicked, just close
-                                    // the dialog box and do nothing
-                                    wantsToCancel[0] = false;
+                                    // if this button is clicked, just close the dialog box
                                     dialog.cancel();
                                     dialog.cancel();
                                 }
                                 }
                             });
                             });
 
 
-                    // create alert dialog
+                    // create + show alert dialog
                     AlertDialog alertDialog = alertDialogBuilder.create();
                     AlertDialog alertDialog = alertDialogBuilder.create();
-
-                    // show it
                     alertDialog.show();
                     alertDialog.show();
                 }
                 }
-
-
-
             }
             }
         });
         });
 
 

+ 0 - 56
app/src/main/res/layout/closing_alert.xml

@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <ImageView
-        android:id="@+id/imageView2"
-        android:layout_width="133dp"
-        android:layout_height="148dp"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent"
-        app:srcCompat="@mipmap/ic_red_warning" />
-
-    <TextView
-        android:id="@+id/textView2"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:textSize="32sp"
-        android:textColor="#000000"
-        android:text="Warning:\n Do you really want to cancel?"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/imageView2" />
-
-    <Button
-        android:id="@+id/closing_alert_yes_button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-
-        android:layout_marginTop="132dp"
-        android:layout_marginBottom="16dp"
-        android:text="Yes"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toEndOf="@+id/closing_alert_no_button"
-        app:layout_constraintTop_toBottomOf="@+id/imageView2"
-        tools:ignore="MissingConstraints" />
-
-    <Button
-        android:id="@+id/closing_alert_no_button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginTop="132dp"
-        android:layout_marginBottom="16dp"
-        android:text="No"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toStartOf="@+id/closing_alert_yes_button"
-        app:layout_constraintStart_toStartOf="parent"
-
-        app:layout_constraintTop_toBottomOf="@+id/imageView2"
-        tools:ignore="MissingConstraints" />
-</androidx.constraintlayout.widget.ConstraintLayout>