Kaynağa Gözat

added a window for creating messages using DialogFragment + general cleanup

Noah Vogt 4 yıl önce
ebeveyn
işleme
5f7253c7bc

+ 1 - 0
app/build.gradle

@@ -40,6 +40,7 @@ dependencies {
     implementation 'androidx.navigation:navigation-ui:2.2.2'
     implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
     implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
+    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
     testImplementation 'junit:junit:4.+'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

+ 25 - 60
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -1,31 +1,29 @@
 package com.noahvogt.miniprojekt;
 
-import android.annotation.SuppressLint;
 import android.os.Bundle;
-import android.view.View;
 import android.view.Menu;
-import android.webkit.WebHistoryItem;
+import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
-import android.widget.TextView;
+import android.widget.ImageButton;
 import android.widget.Toast;
 
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import com.google.android.material.snackbar.Snackbar;
-import com.google.android.material.navigation.NavigationView;
-
 import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+import androidx.drawerlayout.widget.DrawerLayout;
+import androidx.fragment.app.DialogFragment;
 import androidx.navigation.NavController;
 import androidx.navigation.Navigation;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.NavigationUI;
-import androidx.drawerlayout.widget.DrawerLayout;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
+
+import com.google.android.material.navigation.NavigationView;
+import com.google.android.material.snackbar.Snackbar;
+
+import static com.noahvogt.miniprojekt.R.id.drawer_layout;
 
 // regex utils for email string validation
-import android.util.Patterns;
-import java.util.regex.Pattern;
 
 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 
@@ -38,7 +36,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     private Button newemail_save_button, newemail_cancel_button; // may not be private
     private Button add_email_button;
 
+    private ImageButton message_create_button;
 
+    // empty descriptor
     public MainActivity() {
     }
 
@@ -66,7 +66,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                         .setAction("Action", null).show();
             }
         });*/
-        DrawerLayout drawer = findViewById(R.id.drawer_layout);
+        DrawerLayout drawer = findViewById(drawer_layout);
         NavigationView navigationView = findViewById(R.id.nav_view);
         // Passing each menu ID as a set of Ids because each
         // menu should be considered as top level destinations.
@@ -77,6 +77,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupWithNavController(navigationView, navController);
+
+        message_create_button = (ImageButton) findViewById(R.id.messageButton);
+        message_create_button.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                DialogFragment dialog = messageCreateFragment.newInstance();
+                dialog.show(getSupportFragmentManager(), "tag");
+            }
+        });
+
     }
 
     @Override
@@ -125,7 +135,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                 String email = newemail_email.getText().toString();
                 String password = newemail_password.getText().toString();
 
-                if (!validateEmail() | !validateName() | !validatePassword()) {
+                if (!mailFunctions.validateEmail(newemail_email) | !mailFunctions.validateName(newemail_name) | !mailFunctions.validatePassword(newemail_password)) {
                     return;
                 }
 
@@ -149,51 +159,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
     }
 
-    // TODO: resolve password endIcon conflict
-    private boolean validateName() {
-        String name = newemail_name.getText().toString().trim();
-
-        if (name.isEmpty()) {
-            newemail_name.setError("Field can't be empty");
-            return false;
-        } else if (name.length() > 50) {
-            newemail_name.setError("Name too long");
-            return false;
-        } else {
-            newemail_name.setError(null);
-            return true;
-        }
-    }
-
-    // TODO: resolve password endIcon conflict
-    private boolean validateEmail() {
-        String email = newemail_email.getText().toString().trim();
-
-        if (email.isEmpty()) {
-            newemail_email.setError("Field can't be empty");
-            return false;
-        } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
-            newemail_email.setError("Please enter a valid email address");
-            return false;
-        } else {
-            newemail_email.setError(null);
-            return true;
-        }
-    }
-
-    // TODO: resolve password endIcon conflicts
-    private boolean validatePassword() {
-        String password = newemail_password.getText().toString().trim();
-
-        if (password.isEmpty()) {
-            newemail_password.setError("Field can't be empty");
-            return false;
-        } else {
-            newemail_password.setError(null);
-            return true;
-        }
-    }
-
     // show debug output in  specific view
     private void showSnackbar(View View, String text) {
         Snackbar.make(View, text, Snackbar.LENGTH_LONG)

+ 52 - 0
app/src/main/java/com/noahvogt/miniprojekt/mailFunctions.java

@@ -0,0 +1,52 @@
+package com.noahvogt.miniprojekt;
+
+import android.util.Patterns;
+import android.widget.EditText;
+
+public class mailFunctions {
+
+    // TODO: resolve password endIcon conflict
+    public static boolean validateName(EditText emailName) {
+        String name = emailName.getText().toString().trim();
+
+        if (name.isEmpty()) {
+            emailName.setError("Field can't be empty");
+            return false;
+        } else if (name.length() > 50) {
+            emailName.setError("Name too long");
+            return false;
+        } else {
+            emailName.setError(null);
+            return true;
+        }
+    }
+
+    // TODO: resolve password endIcon conflict
+    public static boolean validateEmail(EditText emailAddress) {
+        String email = emailAddress.getText().toString().trim();
+
+        if (email.isEmpty()) {
+            emailAddress.setError("Field can't be empty");
+            return false;
+        } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
+            emailAddress.setError("Please enter a valid email address");
+            return false;
+        } else {
+            emailAddress.setError(null);
+            return true;
+        }
+    }
+
+    // TODO: resolve password endIcon conflicts
+    public static boolean validatePassword(EditText emailPassword) {
+        String password = emailPassword.getText().toString().trim();
+
+        if (password.isEmpty()) {
+            emailPassword.setError("Field can't be empty");
+            return false;
+        } else {
+            emailPassword.setError(null);
+            return true;
+        }
+    }
+}

+ 58 - 0
app/src/main/java/com/noahvogt/miniprojekt/messageCreateFragment.java

@@ -0,0 +1,58 @@
+package com.noahvogt.miniprojekt;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.DialogFragment;
+
+import com.noahvogt.miniprojekt.debuggingFeatures;
+
+public class messageCreateFragment extends DialogFragment {
+
+    static messageCreateFragment newInstance() {
+        return new messageCreateFragment();
+    }
+
+    // set theming style
+    @Override
+    public void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setStyle(DialogFragment.STYLE_NORMAL, R.style.messageCreateTheme);
+    }
+
+    // set layout
+    @Nullable
+    @Override
+    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+        View view = inflater.inflate(R.layout.message_create_fragment, container, false);
+        ImageButton close = view.findViewById(R.id.create_message_close_button);
+        TextView action = view.findViewById(R.id.create_message_send_button);
+
+        close.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                dismiss();
+            }
+        });
+        action.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                // TODO: implement sending functionality
+                dismiss();
+            }
+        });
+
+        return view;
+    }
+
+    public interface Callback {
+        void onActionClick(String name);
+    }
+
+}

+ 1 - 1
app/src/main/res/layout/content_main.xml

@@ -31,7 +31,7 @@
         app:layout_constraintEnd_toEndOf="parent">
 
         <ImageButton
-            android:id="@+id/imageButton2"
+            android:id="@+id/messageButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
 

+ 109 - 0
app/src/main/res/layout/message_create_fragment.xml

@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout 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"
+    android:id="@+id/messageFragment"
+    android:orientation="vertical"
+    tools:context=".ui.messageCreateFragment">
+
+    <androidx.cardview.widget.CardView
+        android:id="@+id/cardView"
+        android:layout_width="match_parent"
+        android:layout_height="?attr/actionBarSize"
+        app:cardBackgroundColor="#5e35b1">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+        <ImageButton
+            android:id="@+id/create_message_close_button"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="8dp"
+            android:layout_marginStart="8dp"
+            android:background="?attr/selectableItemBackgroundBorderless"
+            android:padding="8dp"
+            android:src="@mipmap/ic_close_purple" />
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginLeft="8dp"
+            android:layout_marginStart="8dp"
+            android:layout_toRightOf="@id/create_message_close_button"
+            android:layout_toEndOf="@+id/create_message_close_button"
+            android:text="Create Message"
+            android:textColor="@android:color/white"
+            android:textSize="20sp" />
+
+        <TextView
+            android:id="@+id/create_message_send_button"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
+            android:layout_centerVertical="true"
+            android:layout_marginRight="8dp"
+            android:layout_marginEnd="8dp"
+            android:background="?attr/selectableItemBackground"
+            android:padding="8dp"
+            android:text="SEND"
+            android:textColor="@android:color/white" />
+
+    </RelativeLayout>
+    </androidx.cardview.widget.CardView>
+
+
+
+
+    <com.google.android.material.textfield.TextInputLayout
+        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+        android:id="@+id/create_message_sending_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_sending_address_text"
+            android:inputType="textEmailAddress"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="Sending Mail Address" />
+    </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"
+        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"
+
+        app:layout_constraintTop_toBottomOf="@+id/create_message_sending_address_layout"
+        tools:layout_editor_absoluteX="1dp">
+
+        <com.google.android.material.textfield.TextInputEditText
+            android:id="@+id/create_message_subject_text"
+            android:inputType="textEmailSubject"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:hint="Subject" />
+    </com.google.android.material.textfield.TextInputLayout>
+
+</LinearLayout>

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


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


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


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


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


+ 1 - 1
app/src/main/res/values/strings.xml

@@ -14,4 +14,4 @@
     <string name="your_email_address_filler">Your Email Address</string>
     <string name="your_full_name_filler">Your Full Name</string>
 
-</resources>
+</resources>

+ 5 - 0
app/src/main/res/values/style.xml

@@ -12,4 +12,9 @@
         <item name="errorTextColor">@color/error_red</item>
         <item name="color">@color/error_red</item>
     </style>
+
+    <style name="messageCreateTheme" parent="Theme.MaterialComponents.Light.DialogWhenLarge">
+        <item name="android:windowNoTitle">true</item>
+        <item name="android:windowAnimationStyle">@style/Theme.AppCompat.Dialog</item>
+    </style>
 </resources>