Bladeren bron

added beautiful canceling alert dialog box with buttons that do not work

Noah Vogt 4 jaren geleden
bovenliggende
commit
ebec45b2bc

+ 67 - 3
app/src/main/java/com/noahvogt/miniprojekt/messageCreateFragment.java

@@ -5,20 +5,27 @@ import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.PopupMenu;
 import android.widget.Toast;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.DialogFragment;
 
+import com.google.android.material.snackbar.Snackbar;
 
 public class messageCreateFragment extends DialogFragment implements PopupMenu.OnMenuItemClickListener {
 
     static messageCreateFragment newInstance() {
         return new messageCreateFragment();
     }
+    private AlertDialog dialog;
+
+
 
     // set theming style
     @Override
@@ -27,23 +34,80 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
         setStyle(DialogFragment.STYLE_NORMAL, R.style.messageCreateTheme);
     }
 
-    // set layout
+
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+        // set and inflate layout
         View view = inflater.inflate(R.layout.message_create_fragment, container, false);
+
+        // init vars
+
         ImageButton closeButton = view.findViewById(R.id.create_message_close_button);
         ImageButton sendButton = view.findViewById(R.id.create_message_send_button);
         ImageButton dotButton = view.findViewById(R.id.create_message_dots_button);
         ImageButton attachButton = view.findViewById(R.id.create_message_attach_button);
 
+        EditText sendingAddressObject = (EditText) view.findViewById(R.id.create_message_sending_address_text);
+        EditText receivingAddressObject = (EditText) view.findViewById(R.id.create_message_receiving_address_text);
+        EditText subjectObject = (EditText) view.findViewById(R.id.create_message_subject_text);
+        EditText messageBodyObject = (EditText) view.findViewById(R.id.create_message_body_text);
+
+        // get string vars, MAYBE NOT HERE
+        String sendingAddress = sendingAddressObject.getText().toString();
+        String receivingAddress = receivingAddressObject.getText().toString();
+        String subject = subjectObject.getText().toString();
+        String messageBody = messageBodyObject.getText().toString();
+
         // TODO: add cc + bcc functionality
 
+        // button listeners
+
         closeButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                // TODO: alert user when pressing this button in case input fields are not empty
-                dismiss();
+                String subject = subjectObject.getText().toString();
+                String messageBody = messageBodyObject.getText().toString();
+                if (subject.isEmpty() && messageBody.isEmpty()) {
+                    dismiss();
+                }
+                else {
+                    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);
+
+                    final boolean[] wantsToCancel = new boolean[1]; // do we really need an array here? stupid java
+
+
+/*
+                    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
+                }
+
             }
         });
 

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

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

+ 22 - 1
app/src/main/res/layout/message_create_fragment.xml

@@ -124,9 +124,30 @@
             android:inputType="textEmailAddress"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:hint="Sending Mail Address" />
+            android:hint="From (Email)" />
     </com.google.android.material.textfield.TextInputLayout>
 
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+                android:id="@+id/create_message_receiving_address_layout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+
+                android:layout_marginStart="12dp"
+                android:layout_marginLeft="12dp"
+                android:layout_marginTop="12dp"
+                android:layout_marginEnd="12dp"
+                android:layout_marginRight="12dp"
+                android:layout_marginBottom="12dp">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/create_message_receiving_address_text"
+                    android:inputType="textEmailAddress"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:hint="To (Email)" />
+            </com.google.android.material.textfield.TextInputLayout>
+
     <com.google.android.material.textfield.TextInputLayout
         style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
         android:id="@+id/create_message_subject_layout"

+ 2 - 3
app/src/main/res/layout/popup.xml

@@ -22,7 +22,6 @@
         app:layout_constraintVertical_bias="0.068" />
 
 
-
     <Button
         android:id="@+id/saveButton"
         android:layout_width="wrap_content"
@@ -32,7 +31,7 @@
         android:layout_marginLeft="16dp"
 
         android:layout_marginTop="16dp"
-        android:layout_marginBottom="32dp"
+        android:layout_marginBottom="16dp"
         android:text="Save"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
@@ -51,7 +50,7 @@
         android:layout_marginEnd="16dp"
 
         android:layout_marginRight="16dp"
-        android:layout_marginBottom="32dp"
+        android:layout_marginBottom="16dp"
         android:text="Cancel"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"

BIN
app/src/main/res/mipmap-hdpi/ic_red_warning.png


BIN
app/src/main/res/mipmap-mdpi/ic_red_warning.png


BIN
app/src/main/res/mipmap-xhdpi/ic_red_warning.png


BIN
app/src/main/res/mipmap-xxhdpi/ic_red_warning.png


BIN
app/src/main/res/mipmap-xxxhdpi/ic_red_warning.png