|
@@ -1,6 +1,7 @@
|
|
|
package com.noahvogt.miniprojekt;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
import android.content.SharedPreferences;
|
|
|
import android.os.Bundle;
|
|
@@ -17,6 +18,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
import androidx.fragment.app.DialogFragment;
|
|
|
|
|
|
|
|
|
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
import com.noahvogt.miniprojekt.ui.DataBase.Message;
|
|
|
import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
|
|
@@ -43,8 +45,14 @@ import com.noahvogt.miniprojekt.ui.show.MessageShowFragment;
|
|
|
import com.noahvogt.miniprojekt.ui.slideshow.EmailViewModel;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import com.google.gson.Gson;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
import static com.noahvogt.miniprojekt.R.id.drawer_layout;
|
|
|
|
|
@@ -59,7 +67,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
private AlertDialog dialog;
|
|
|
private EditText newemail_name, newemail_email, newemail_password; /* may not be private */
|
|
|
|
|
|
- SharedPreferences preferences;
|
|
|
+ SharedPreferences preferences, mailServerCredentials;
|
|
|
|
|
|
/* empty descriptor */
|
|
|
public MainActivity() {}
|
|
@@ -108,6 +116,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
/* invoke preferences */
|
|
|
preferences = getSharedPreferences("UserPreferences", Context.MODE_PRIVATE);
|
|
|
+ mailServerCredentials = getSharedPreferences("Credentials", Context.MODE_PRIVATE);
|
|
|
|
|
|
/* invoke toolbar */
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
@@ -227,7 +236,40 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
/* better leave empty to avoid any listener disambiguity */
|
|
|
public void onClick(View view) { }
|
|
|
|
|
|
+ public void changeMailServerSettingsDialog() {
|
|
|
+ // define View window
|
|
|
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
+ final View changeMailServerSettingsView = getLayoutInflater().inflate(R.layout.mail_credentials_customizer, null);
|
|
|
|
|
|
+ // open View window
|
|
|
+ dialogBuilder.setView(changeMailServerSettingsView);
|
|
|
+ dialog = dialogBuilder.create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void askForChangeMailServerSettingsDialog() {
|
|
|
+ // define View window
|
|
|
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
+
|
|
|
+ // 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();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .setNegativeButton("No",new DialogInterface.OnClickListener() {
|
|
|
+ public void onClick(DialogInterface dialog,int id) {
|
|
|
+ /* if this button is clicked, close the hole fragment */
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dialog = dialogBuilder.create();
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
|
|
|
public void createNewEmailDialog(){
|
|
|
/* define View window */
|
|
@@ -251,6 +293,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
dialog.show();
|
|
|
|
|
|
SharedPreferences.Editor preferencesEditor = preferences.edit();
|
|
|
+ SharedPreferences.Editor credentialsEditor = mailServerCredentials.edit();
|
|
|
|
|
|
if (! Python.isStarted()) {
|
|
|
Python.start(new AndroidPlatform(this));
|
|
@@ -272,18 +315,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
|
|
|
/* connect to mail server and print various debugging output */
|
|
|
showToast("Probe Connection ...");
|
|
|
- if (MailFunctions.canConnect(name, email, password) == Boolean.TRUE) {
|
|
|
+ if (MailFunctions.canConnect(MailFunctions.getImapHostFromEmail(email), email, password) == Boolean.TRUE) {
|
|
|
showToast("was able to connect");
|
|
|
- List l = MailFunctions.listMailboxes(MailFunctions.getIMAPConnection(name, email, password));
|
|
|
+ List l = MailFunctions.listMailboxes(MailFunctions.getIMAPConnection(MailFunctions.getImapHostFromEmail(email), email, password));
|
|
|
for (int i = 0; i < l.size(); i++) {
|
|
|
showToast(l.get(i).toString());
|
|
|
// TODO: select right folder to store, Synchronization
|
|
|
/*gives list of Message Objects/dictionaries */
|
|
|
- List p = MailFunctions.fetchMailsFromBox(MailFunctions.getIMAPConnection(name, email, password), l.get(i).toString(), "list");
|
|
|
+ /*List p = MailFunctions.fetchMailsFromBox(MailFunctions.getIMAPConnection(name, email, password), l.get(i).toString(), "list");
|
|
|
System.out.println(l.get(i).toString());
|
|
|
- System.out.println(p);
|
|
|
+ System.out.println(p);*/
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/*Message word = new Message(
|
|
|
messageCreateFragment.replyIntent.getStringExtra(messageCreateFragment.EXTRA_TO),
|
|
|
null,
|
|
@@ -296,23 +340,44 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|
|
mEmailViewModel.insert(word);
|
|
|
|
|
|
*/
|
|
|
+
|
|
|
+
|
|
|
preferencesEditor.putString("name", name);
|
|
|
preferencesEditor.putString("email", email);
|
|
|
preferencesEditor.putString("password", password);
|
|
|
preferencesEditor.apply();
|
|
|
- } else {
|
|
|
- showToast("failed to connect");
|
|
|
|
|
|
- /* show all strings the user gave, this will later be stored to a secure database and checked for validation */
|
|
|
- showToast(name);
|
|
|
- showToast(email);
|
|
|
- showToast(password);
|
|
|
- }
|
|
|
+ /* ArrayList<String> newUserSettings = new ArrayList<String>();
|
|
|
+ newUserSettings.add(name);
|
|
|
+ newUserSettings.add(email);
|
|
|
+ newUserSettings.add(password);
|
|
|
+ System.out.println("newUserSettings: " + newUserSettings);
|
|
|
|
|
|
|
|
|
+ //Retrieve the values
|
|
|
+ Set<String> oldSet = mailServerCredentials.getStringSet("UserSettings", null);
|
|
|
+
|
|
|
+ //Set the values
|
|
|
+ Set<String> newSet = new HashSet<String>();
|
|
|
+ newSet.addAll(newUserSettings);
|
|
|
+ credentialsEditor.putStringSet("UserSettings", newSet);
|
|
|
+ credentialsEditor.commit();*/
|
|
|
+
|
|
|
+ Gson gson = new Gson();
|
|
|
+ MailServerCredentials newMailServerCredentials = new MailServerCredentials(
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+
|
|
|
newemail_cancel_button.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|