Ver Fonte

further working on account management frontend + make mailFunctions checkConnection function more verbose when catching an error

Noah Vogt há 3 anos atrás
pai
commit
1fbfe4a021

+ 59 - 10
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -66,6 +66,7 @@ import com.google.gson.Gson;
 
 
 import static com.noahvogt.miniprojekt.R.id.drawer_layout;
+import static com.noahvogt.miniprojekt.R.id.exitButton;
 
 import org.w3c.dom.Text;
 
@@ -111,16 +112,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
 
-        /* define button listeners */
-
-
-
-        /*creates account manager by clicking on profile */
+        /* show account manager when clicking on profile */
         View accountView = findViewById(R.id.accountView);
         accountView.setOnClickListener(new View.OnClickListener() {
             @Override
-            public void onClick(View v) {
-                /* define View window */
+            public void onClick(View onClickView) {
+                /* define dialog */
                 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
                 final View accountManagerView = getLayoutInflater().inflate(R.layout.account_manager, null);
 
@@ -128,15 +125,67 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                         (AutoCompleteTextView) accountManagerView.findViewById(R.id.accountSelectorTextView);
 
                 /* get string data for drop down menu */
-                String[] dummyMails = getResources().getStringArray(R.array.dummy_emails);
+                SharedPreferences credReader = getSharedPreferences("Credentials", Context.MODE_PRIVATE);
+                String currentUser = credReader.getString("currentUser", "");
+                SharedPreferences.Editor credEditor = credReader.edit();
+
+                TextView showCurrentUserObject = (TextView) accountManagerView.findViewById(R.id.showCurrentUser);
+                Button switchAccountObject = (Button) accountManagerView.findViewById(R.id.switchToAccountButton);
+                Button deleteAccountObject = (Button) accountManagerView.findViewById(R.id.deleteAccountButton);
+                Button changeServerSettingsObject = (Button) accountManagerView.findViewById(R.id.changeServerSettingsButton);
+                Button exit = (Button) accountManagerView.findViewById(R.id.exitButton);
+
+                showCurrentUserObject.setText(String.format("current user:\n%s", currentUser));
+
+
+                Gson gson = new Gson();
+
+                String jsonCredData = credReader.getString("data", "");
+                Type credentialsType = new TypeToken<ArrayList<MailServerCredentials>>() {
+                }.getType();
+                ArrayList<MailServerCredentials> currentUsersCredentials = gson.fromJson(jsonCredData, credentialsType);
+                String[] userArray = new String[0];
+                if (!currentUsersCredentials.isEmpty()) {
+                    userArray = new String[currentUsersCredentials.size()];
+                    for (int i = 0; i < currentUsersCredentials.size(); i++) {
+                        userArray[i] = currentUsersCredentials.get(i).getUsername();
+                    }
+                }
+
+                //String[] dummyMails = getResources().getStringArray(R.array.dummy_emails);
                 ArrayAdapter<String> dropDownAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.dropdown_item,
-                        R.id.textViewDropDownItem, dummyMails);
+                        R.id.textViewDropDownItem, userArray);
                 accountSelectorObject.setAdapter(dropDownAdapter);
 
-                /* open View window */
+                /* open dialog */
                 dialogBuilder.setView(accountManagerView);
                 dialog = dialogBuilder.create();
                 dialog.show();
+
+                switchAccountObject.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View view) {
+                        Gson gson = new Gson();
+
+                        String userInput = accountSelectorObject.getText().toString();
+                        String jsonCredData = credReader.getString("data", "");
+                        Type credentialsType = new TypeToken<ArrayList<MailServerCredentials>>() {
+                        }.getType();
+                        ArrayList<MailServerCredentials> currentUsersCredentials = gson.fromJson(jsonCredData, credentialsType);
+
+                        System.out.println(userInput);
+                        for (int i = 0; i < currentUsersCredentials.size(); i++) {
+                            if (currentUsersCredentials.get(i).getUsername().equals(userInput)) {
+                                credEditor.putString("currentUser", userInput);
+                                showCurrentUserObject.setText(String.format("current user:\n%s", userInput));
+                                showToast("switched account");
+                                break;
+                            }
+                        }
+                    }
+                });
+
+                exit.setOnClickListener(v -> dialog.dismiss());
             }
         });
 

+ 4 - 0
app/src/main/python/mailFunctions.py

@@ -47,6 +47,10 @@ def checkConnection(host, username, password, port):
         connection.logout()
         return True
     except Exception as e:
+        print("host: " + host)
+        print("username: " + username)
+        print("password: " + password)
+        print("port: " + str(port))
         print(str(e))
         return False
 

+ 66 - 2
app/src/main/res/layout/account_manager.xml

@@ -6,6 +6,7 @@
     android:layout_height="match_parent">
 
     <com.google.android.material.textfield.TextInputLayout
+        android:id="@+id/accountSelectorLayout"
         style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
@@ -16,7 +17,8 @@
         android:layout_marginRight="32dp"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent">
+        app:layout_constraintTop_toTopOf="parent"
+        app:startIconDrawable="@drawable/ic_mail_outline">
 
         <AutoCompleteTextView
             android:id="@+id/accountSelectorTextView"
@@ -24,8 +26,70 @@
             android:layout_height="match_parent"
             android:layout_weight="1"
             android:inputType="none"
-            android:text="AutoCompleteTextView" />
+            android:text="select Account" />
 
 
     </com.google.android.material.textfield.TextInputLayout>
+
+    <TextView
+        android:id="@+id/showCurrentUser"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="Current User: "
+        android:textColor="@color/black"
+        android:textSize="14sp"
+        android:textStyle="bold"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/accountSelectorLayout"/>
+
+    <Button
+        android:id="@+id/deleteAccountButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="delete account"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/showCurrentUser" />
+
+    <Button
+        android:id="@+id/switchToAccountButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="switch to account"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/deleteAccountButton" />
+
+    <Button
+        android:id="@+id/changeServerSettingsButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="change server settings"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/switchToAccountButton" />
+
+    <Button
+        android:id="@+id/exitButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:layout_marginBottom="16dp"
+        android:paddingBottom="16dp"
+        android:text="exit"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/changeServerSettingsButton" />
+
+
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 10 - 0
app/src/main/res/layout/dropdown_item.xml

@@ -0,0 +1,10 @@
+<TextView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/textViewDropDownItem"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:padding="12dp"
+    android:textColor="@color/black"
+    android:textStyle="bold"
+    android:textSize="16sp"
+    android:text="TextView"/>