Browse Source

chaquopy license working + extended MailServerCredentials Class + start python instance on app startup + beautify mail server credentials editor dialog incl. icons / setting assumed text inputs

Noah Vogt 3 years ago
parent
commit
c070401c5e

+ 1 - 1
.gitignore

@@ -1,7 +1,7 @@
 *.iml
 /.idea
 .gradle
-/local.properties
+local.properties
 /.idea/caches
 /.idea/libraries
 /.idea/modules.xml

+ 12 - 1
app/src/main/java/com/noahvogt/miniprojekt/MailServerCredentials.java

@@ -7,8 +7,17 @@ public class MailServerCredentials {
     private String mPassword;
     private int mImapPort;
     private String mName;
+    private String mSignature;
 
-    public MailServerCredentials(String name, String username, String password, String imapHost, String smtpHost, int imapPort) {
+    public String getImapHost () {return this.mImapHost;}
+    public String getSmtpHost () {return this.mSmtpHost;}
+    public String getUsername () {return this.mUsername;}
+    public String getPassword () {return this.mPassword;}
+    public int getImapPort () {return this.mImapPort;}
+    public String getName () {return this.mName;}
+    public String getSignature () {return this.mSignature;}
+
+    public MailServerCredentials(String name, String username, String password, String imapHost, String smtpHost, int imapPort, String signature) {
         mName = name;
         mUsername = username;
         mPassword = password;
@@ -16,5 +25,7 @@ public class MailServerCredentials {
         mImapHost = imapHost;
         mImapPort = imapPort;
         mSmtpHost = smtpHost;
+
+        mSignature = signature;
     }
 }

+ 27 - 8
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -178,6 +178,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
             }
         });
+
+        /* start python instance right on startup */
+        if (! Python.isStarted()) {
+            Python.start(new AndroidPlatform(this));
+        }
     }
 
 
@@ -236,29 +241,43 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     /* better leave empty to avoid any listener disambiguity */
     public void onClick(View view) { }
 
-    public void changeMailServerSettingsDialog() {
+    public void changeMailServerSettingsDialog(String name, String email, String password) {
         // define View window
         AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
         final View changeMailServerSettingsView = getLayoutInflater().inflate(R.layout.mail_credentials_customizer, null);
 
-        // open View window
+        EditText incomingServerObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_incoming_server_text);
+        EditText outgoingServerObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_outgoing_server_text);
+        EditText incomingPortObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_incoming_port_text);
+        EditText outgoingPortObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_outgoing_port_text);
+        EditText serverUsernameObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_username_text);
+        EditText passwordObject = (EditText) changeMailServerSettingsView.findViewById(R.id.custom_mail_server_password_text);
+
+        incomingServerObject.setText(MailFunctions.getImapHostFromEmail(email));
+        outgoingServerObject.setText(MailFunctions.getSmtpHostFromEmail(email));
+        incomingPortObject.setText("993");
+        outgoingPortObject.setText("587");
+        serverUsernameObject.setText(email);
+        passwordObject.setText(password);
+
+        /* open View window */
         dialogBuilder.setView(changeMailServerSettingsView);
         dialog = dialogBuilder.create();
         dialog.show();
     }
 
-    public void askForChangeMailServerSettingsDialog() {
-        // define View window
+    public void askForChangeMailServerSettingsDialog(String name, String email, String password) {
+        /* define View window */
         AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
 
-        // open View window
+        /* open View window */
         dialogBuilder.setTitle("failed to connect :(");
         dialogBuilder
                 .setMessage("Do you want to further customize your mail server settings?")
                 .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         /*if this button is clicked, close the whole fragment */
-                        changeMailServerSettingsDialog();
+                        changeMailServerSettingsDialog(name, email, password);
                     }
                 })
                 .setNegativeButton("No",new DialogInterface.OnClickListener() {
@@ -365,14 +384,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
                     Gson gson = new Gson();
                     MailServerCredentials newMailServerCredentials = new MailServerCredentials(
-                            name, password, email, MailFunctions.getImapHostFromEmail(email), MailFunctions.getSmtpHostFromEmail(email), 993);
+                            name, password, email, MailFunctions.getImapHostFromEmail(email), MailFunctions.getSmtpHostFromEmail(email), 993, "");
                     String newCredentialsJson = gson.toJson(newMailServerCredentials);
                     System.out.println(newCredentialsJson);
                     credentialsEditor.putString("data", newCredentialsJson);
                     credentialsEditor.apply();
 
                 } else {
-                    askForChangeMailServerSettingsDialog();
+                    askForChangeMailServerSettingsDialog(name, email, password);
                 }
             }
         });

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

@@ -119,7 +119,7 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
                     dismiss();
                 }
                 else {
-                    /* setup dialog */
+                    /* setup dialog for saving draft message */
                     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                     alertDialogBuilder.setTitle("Warning");
                     alertDialogBuilder

+ 10 - 0
app/src/main/res/drawable/ic_baseline_call_made_24.xml

@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal">
+  <path
+      android:fillColor="@android:color/white"
+      android:pathData="M9,5v2h6.59L4,18.59 5.41,20 17,8.41V15h2V5z"/>
+</vector>

+ 11 - 0
app/src/main/res/drawable/ic_baseline_call_received_24.xml

@@ -0,0 +1,11 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24"
+    android:tint="?attr/colorControlNormal"
+    android:autoMirrored="true">
+  <path
+      android:fillColor="@android:color/white"
+      android:pathData="M20,5.41L18.59,4 7,15.59V9H5v10h10v-2H8.41z"/>
+</vector>

+ 78 - 2
app/src/main/res/layout/mail_credentials_customizer.xml

@@ -27,19 +27,24 @@
         app:layout_constraintTop_toTopOf="parent" />
 
     <ScrollView
+        android:id="@+id/scrollView2"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_marginTop="128dp"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textView3">
+        app:layout_constraintTop_toBottomOf="@+id/textView3"
+        >
 
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
-            android:orientation="vertical">
+            android:orientation="vertical"
+            android:layout_marginBottom="100dp"
+            >
 
             <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                 android:id="@+id/custom_mail_server_incoming_server_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -50,6 +55,7 @@
                 android:layout_marginRight="32dp"
 
                 android:hint="Incoming Server"
+                app:startIconDrawable="@drawable/ic_baseline_call_received_24"
 
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
@@ -62,6 +68,7 @@
             </com.google.android.material.textfield.TextInputLayout>
 
             <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                 android:id="@+id/custom_mail_server_outgoing_server_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -72,6 +79,7 @@
                 android:layout_marginRight="32dp"
 
                 android:hint="Outgoing Server"
+                app:startIconDrawable="@drawable/ic_baseline_call_made_24"
 
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
@@ -84,6 +92,7 @@
             </com.google.android.material.textfield.TextInputLayout>
 
             <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                 android:id="@+id/custom_mail_server_incoming_port_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -94,6 +103,7 @@
                 android:layout_marginRight="32dp"
 
                 android:hint="Incoming Port"
+                app:startIconDrawable="@drawable/ic_baseline_call_received_24"
 
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
@@ -106,6 +116,7 @@
             </com.google.android.material.textfield.TextInputLayout>
 
             <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                 android:id="@+id/custom_mail_server_outgoing_port_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -116,6 +127,7 @@
                 android:layout_marginRight="32dp"
 
                 android:hint="Outgoing Port"
+                app:startIconDrawable="@drawable/ic_baseline_call_made_24"
 
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
@@ -128,6 +140,7 @@
             </com.google.android.material.textfield.TextInputLayout>
 
             <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                 android:id="@+id/custom_mail_server_username_layout"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
@@ -138,6 +151,7 @@
                 android:layout_marginRight="32dp"
 
                 android:hint="Server Username"
+                app:startIconDrawable="@drawable/ic_mail_outline"
 
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
@@ -145,10 +159,72 @@
 
                 <com.google.android.material.textfield.TextInputEditText
                     android:id="@+id/custom_mail_server_username_text"
+                    android:inputType="textEmailAddress"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content" />
             </com.google.android.material.textfield.TextInputLayout>
 
+            <com.google.android.material.textfield.TextInputLayout
+                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
+                android:id="@+id/custom_mail_server_password_layout"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="32dp"
+                android:layout_marginLeft="32dp"
+                android:layout_marginTop="32dp"
+                android:layout_marginEnd="32dp"
+                android:layout_marginRight="32dp"
+
+                android:hint="Server Password"
+                app:startIconDrawable="@drawable/ic_lock"
+
+                android:paddingBottom="50dp"
+
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toBottomOf="@+id/custom_mail_server_username_layout">
+
+                <com.google.android.material.textfield.TextInputEditText
+                    android:id="@+id/custom_mail_server_password_text"
+                    android:inputType="textPassword"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content" />
+            </com.google.android.material.textfield.TextInputLayout>
+
+            <RelativeLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+
+                <Button
+                    android:id="@+id/cancelCustomizeButton"
+
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+
+                    android:layout_alignParentLeft="true"
+                    android:layout_centerVertical="true"
+                    android:layout_marginStart="42dp"
+                    android:layout_marginLeft="42dp"
+                    android:text="Save" />
+
+                <Button
+                    android:id="@+id/saveCustomizeButton"
+
+                    android:layout_marginEnd="42dp"
+                    android:layout_marginRight="42dp"
+
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_alignBottom="@+id/cancelCustomizeButton"
+                    android:layout_alignParentRight="true"
+                    android:text="Cancel" />
+
+            </RelativeLayout>
+
         </LinearLayout>
+
+
     </ScrollView>
+
+
 </androidx.constraintlayout.widget.ConstraintLayout>

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

@@ -84,9 +84,7 @@
 
         <com.google.android.material.textfield.TextInputEditText
             android:id="@id/popup_material_name_asking_text"
-
             android:inputType="textPersonName"
-
             android:layout_width="match_parent"
             android:layout_height="wrap_content" />
     </com.google.android.material.textfield.TextInputLayout>