Browse Source

added database but the messages are in every folder the same, and to emailwriter there are

Simon Hammer 3 years ago
parent
commit
f5e168286b
26 changed files with 651 additions and 290 deletions
  1. 15 4
      app/build.gradle
  2. 82 0
      app/schemas/com.noahvogt.miniprojekt.ui.DataBase.EmailRoomDatabase/1.json
  3. 1 0
      app/src/main/AndroidManifest.xml
  4. 69 20
      app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java
  5. 54 0
      app/src/main/java/com/noahvogt/miniprojekt/NewDraftMessageActivity.java
  6. 46 6
      app/src/main/java/com/noahvogt/miniprojekt/messageCreateFragment.java
  7. 0 44
      app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/Data.java
  8. 39 0
      app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/EmailRepository.java
  9. 79 0
      app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/EmailRoomDatabase.java
  10. 58 31
      app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/Message.java
  11. 49 0
      app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/MessageDao.java
  12. 3 3
      app/src/main/java/com/noahvogt/miniprojekt/ui/gallery/GalleryFragment.java
  13. 37 101
      app/src/main/java/com/noahvogt/miniprojekt/ui/home/CustomAdapter.java
  14. 3 2
      app/src/main/java/com/noahvogt/miniprojekt/ui/home/HomeFragment.java
  15. 12 11
      app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/DraftFragment.java
  16. 30 0
      app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/DraftViewModel.java
  17. 42 0
      app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/EmailViewHolder.java
  18. 0 19
      app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/SlideshowViewModel.java
  19. 10 0
      app/src/main/res/drawable/ic_baseline_add_24.xml
  20. 9 1
      app/src/main/res/layout/activity_main.xml
  21. 6 24
      app/src/main/res/layout/content_main.xml
  22. 2 2
      app/src/main/res/layout/fragment_home.xml
  23. 1 1
      app/src/main/res/layout/fragment_slideshow.xml
  24. 1 1
      app/src/main/res/navigation/mobile_navigation.xml
  25. 3 19
      app/src/main/res/values/strings.xml
  26. 0 1
      build.gradle

+ 15 - 4
app/build.gradle

@@ -17,6 +17,12 @@ android {
         versionName "1.0"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+        javaCompileOptions {
+            annotationProcessorOptions {
+                arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
+            }
+        }
     }
 
     buildTypes {
@@ -33,10 +39,6 @@ android {
 
 dependencies {
 
-    //implementation 'com.android.support:cardview-v7:28.0.0'
-    //implementation 'com.android.support:appcompat-v7:28.0.0'
-    //implementation 'com.android.support:appcompat-v7:18.0.+'
-
     implementation 'androidx.appcompat:appcompat:1.2.0'
     implementation 'com.google.android.material:material:1.3.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
@@ -45,8 +47,17 @@ dependencies {
 
     implementation 'androidx.navigation:navigation-fragment:2.3.5'
     implementation 'androidx.navigation:navigation-ui:2.3.5'
+
+    /* Room components */
+    implementation 'androidx.room:room-runtime:2.3.0'
+    annotationProcessor 'androidx.room:room-compiler:2.3.0'
+    androidTestImplementation 'androidx.room:room-testing:2.3.0'
+
+    /* lifecycle components */
     implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
     implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
+    implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
+
     implementation 'androidx.recyclerview:recyclerview:1.2.0'
 
     testImplementation 'junit:junit:4.+'

+ 82 - 0
app/schemas/com.noahvogt.miniprojekt.ui.DataBase.EmailRoomDatabase/1.json

@@ -0,0 +1,82 @@
+{
+  "formatVersion": 1,
+  "database": {
+    "version": 1,
+    "identityHash": "34face9405a190ae787e2fa2e498cbd7",
+    "entities": [
+      {
+        "tableName": "message_table",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `to` TEXT NOT NULL, `cc` TEXT, `bcc` TEXT, `fromEmail` TEXT NOT NULL, `date` TEXT NOT NULL, `subject` TEXT, `textContent` TEXT, `seen` INTEGER NOT NULL)",
+        "fields": [
+          {
+            "fieldPath": "id",
+            "columnName": "id",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mTo",
+            "columnName": "to",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mCc",
+            "columnName": "cc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mBcc",
+            "columnName": "bcc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mFrom",
+            "columnName": "fromEmail",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mDate",
+            "columnName": "date",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mSubject",
+            "columnName": "subject",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mTextContent",
+            "columnName": "textContent",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mSeen",
+            "columnName": "seen",
+            "affinity": "INTEGER",
+            "notNull": true
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "id"
+          ],
+          "autoGenerate": true
+        },
+        "indices": [],
+        "foreignKeys": []
+      }
+    ],
+    "views": [],
+    "setupQueries": [
+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '34face9405a190ae787e2fa2e498cbd7')"
+    ]
+  }
+}

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -9,6 +9,7 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="true"
         android:theme="@style/Theme.MiniProjekt">
+        <activity android:name=".NewDraftMessageActivity"></activity>
         <activity
             android:name=".MainActivity"
             android:label="@string/app_name"

+ 69 - 20
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -1,12 +1,12 @@
 package com.noahvogt.miniprojekt;
 
+import android.content.Intent;
 import android.os.Bundle;
 
 import android.view.Menu;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
-import android.widget.ImageButton;
 import android.widget.Toast;
 
 import androidx.appcompat.app.AlertDialog;
@@ -15,36 +15,37 @@ import androidx.appcompat.widget.Toolbar;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.DialogFragment;
 
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
 import com.noahvogt.miniprojekt.ui.DataBase.Message;
 import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
 
+import androidx.lifecycle.ViewModelProvider;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 
-import java.util.ArrayList;
-
 
 import com.google.android.material.navigation.NavigationView;
 
-
 import androidx.navigation.NavController;
 import androidx.navigation.Navigation;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.NavigationUI;
 
-
 import com.google.android.material.snackbar.Snackbar;
+import com.noahvogt.miniprojekt.ui.slideshow.DraftViewModel;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import static com.noahvogt.miniprojekt.R.id.drawer_layout;
 
 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 
-
-
-
     private AppBarConfiguration mAppBarConfiguration;
 
-    protected ArrayList<Message> data;
+    public static final int NEW_WORD_ACTIVITY_REQUEST_CODE = 1;
+    public static DraftViewModel mEmailViewModel;
+    public static int View;
 
     private AlertDialog dialog;
 
@@ -71,15 +72,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
             }
         });
 
-        ImageButton message_create_button = (ImageButton) findViewById(R.id.messageButton);
-        message_create_button.setOnClickListener(new View.OnClickListener() {
+        /*creates accountmanager by clicking on profil */
+        View accountView = findViewById(R.id.accountView);
+        accountView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                DialogFragment dialog = messageCreateFragment.newInstance();
-                dialog.show(getSupportFragmentManager(), "tag");
+                createNewEmailDialog();
             }
         });
-
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
@@ -95,19 +95,68 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupWithNavController(navigationView, navController);
 
-        //initDataset();
+
         // Lookup the recyclerview in activity layout
         RecyclerView recyclerView = findViewById(R.id.recyclerView);
-        // Initialize contacts
-        data = CustomAdapter.createEmailList(20);
-        // Create adapter passing in the sample user data
-        CustomAdapter adapter = new CustomAdapter(data);
-        // Attach the adapter to the recyclerview to populate items
+        final CustomAdapter adapter = new CustomAdapter(new CustomAdapter.EmailDiff());
+        /* Attach the adapter to the recyclerview to populate items */
         recyclerView.setAdapter(adapter);
         recyclerView.setLayoutManager(new LinearLayoutManager(this));
+
+        if (View != 1 && View != -1) {
+            mEmailViewModel = new ViewModelProvider(this).get(DraftViewModel.class);
+
+            mEmailViewModel.getDraftMessage().observe(this, messages -> {
+                /* Update the cached copy of the messages in the adapter*/
+                adapter.submitList(messages);
+            });
+        }
+
+        /* Start email Writer*/
+        FloatingActionButton message_create_button = 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");
+
+                Intent intent = new Intent(MainActivity.this, NewDraftMessageActivity.class);
+                startActivityForResult(intent, NEW_WORD_ACTIVITY_REQUEST_CODE);
+            }
+        });
     }
 
 
+        /* gets the data from the Email writer and adds it to the Database i think*/
+        public void onActivityResult(int requestCode, int resultCode, Intent data) {
+            super.onActivityResult(requestCode, resultCode, data);
+
+            /* Creates class for the Date when Email is written */
+            Date dNow = new Date();
+            SimpleDateFormat ft =
+                    new SimpleDateFormat("dd.MM.yy");
+
+            if (requestCode == NEW_WORD_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
+                Message word = new Message(
+                        data.getStringExtra(NewDraftMessageActivity.EXTRA_TO),
+                        null,
+                        null,
+                        data.getStringExtra(NewDraftMessageActivity.EXTRA_FROM),
+                        ft.format(dNow),
+                        data.getStringExtra(NewDraftMessageActivity.EXTRA_SUBJECT),
+                        data.getStringExtra(NewDraftMessageActivity.EXTRA_MESSAGE), false);
+                mEmailViewModel.insert(word);
+            } else {
+                Toast.makeText(
+                        getApplicationContext(),
+                        R.string.empty_not_saved,
+                        Toast.LENGTH_LONG).show();
+            }
+
+
+        }
+
+
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {

+ 54 - 0
app/src/main/java/com/noahvogt/miniprojekt/NewDraftMessageActivity.java

@@ -0,0 +1,54 @@
+package com.noahvogt.miniprojekt;
+
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.widget.EditText;
+import android.widget.ImageButton;
+
+public class NewDraftMessageActivity extends AppCompatActivity {
+
+    public static final String EXTRA_TO = "com.example.android.namelistsql.NAME";
+    public static final String EXTRA_FROM = "com.example.android.namelistsql.FROM";
+    public static final String EXTRA_SUBJECT = "com.example.android.namelistsql.SUBJECT";
+    public static final String EXTRA_MESSAGE = "com.example.android.namelistsql.MESSAGE";
+    public static final String EXTRA_DATE = "com.example.android.namelistsql.DATE";
+
+    private EditText sendingAddressObject;
+    private EditText receivingAddressObject;
+    private EditText subjectObject;
+    private EditText messageBodyObject;
+
+    @Override
+    public void onCreate(Bundle savedInstanceState){
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.message_create_fragment);
+
+        sendingAddressObject = findViewById(R.id.create_message_sending_address_text);
+        receivingAddressObject = findViewById(R.id.create_message_receiving_address_text);
+        subjectObject = findViewById(R.id.create_message_subject_text);
+        messageBodyObject = findViewById(R.id.create_message_body_text);
+
+        final ImageButton button = findViewById(R.id.create_message_send_button);
+        button.setOnClickListener(view -> {
+            Intent replyIntent = new Intent();
+            if (TextUtils.isEmpty(sendingAddressObject.getText())) {
+                setResult(RESULT_CANCELED, replyIntent);
+            } else {
+                String from = sendingAddressObject.getText().toString();
+                String to = receivingAddressObject.getText().toString();
+                String subject = subjectObject.getText().toString();
+                String message = messageBodyObject.getText().toString();
+                replyIntent.putExtra(EXTRA_FROM, from);
+                replyIntent.putExtra(EXTRA_TO, to);
+                replyIntent.putExtra(EXTRA_SUBJECT, subject);
+                replyIntent.putExtra(EXTRA_MESSAGE, message);
+                setResult(RESULT_OK, replyIntent);
+            }
+            finish();
+        });
+    }
+}

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

@@ -1,7 +1,11 @@
 package com.noahvogt.miniprojekt;
 
+import android.app.Activity;
+
 import android.content.DialogInterface;
+import android.content.Intent;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.View;
@@ -18,6 +22,22 @@ import androidx.fragment.app.DialogFragment;
 
 public class messageCreateFragment extends DialogFragment implements PopupMenu.OnMenuItemClickListener {
 
+    public static final String EXTRA_TO = "com.example.android.namelistsql.NAME";
+    public static final String EXTRA_FROM = "com.example.android.namelistsql.FROM";
+    public static final String EXTRA_SUBJECT = "com.example.android.namelistsql.SUBJECT";
+    public static final String EXTRA_MESSAGE = "com.example.android.namelistsql.MESSAGE";
+    public static final String EXTRA_DATE = "com.example.android.namelistsql.DATE";
+
+    private EditText sendingAddressObject;
+    private EditText receivingAddressObject;
+    private EditText subjectObject;
+    private EditText messageBodyObject;
+
+    public static final int RESULT_CANCELED = 0;
+    public static final int RESULT_OK = -1;
+
+    Activity activity = new Activity();
+
     static messageCreateFragment newInstance() {
         return new messageCreateFragment();
     }
@@ -42,21 +62,41 @@ public class messageCreateFragment extends DialogFragment implements PopupMenu.O
         // init vars
 
         ImageButton closeButton = view.findViewById(R.id.create_message_close_button);
-        ImageButton sendButton = view.findViewById(R.id.create_message_send_button);
+        final 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);
+         sendingAddressObject = (EditText) view.findViewById(R.id.create_message_sending_address_text);
+         receivingAddressObject = (EditText) view.findViewById(R.id.create_message_receiving_address_text);
+         subjectObject = (EditText) view.findViewById(R.id.create_message_subject_text);
+         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 subject = subjectObject.getText().toString();
         String messageBody = messageBodyObject.getText().toString();
 
+
+        /* dosen't wotk cause Activity is not extendet and used as variable */
+        sendButton.setOnClickListener(View -> {
+            Intent replyIntent = new Intent();
+            if (TextUtils.isEmpty(sendingAddressObject.getText())) {
+                activity.setResult(RESULT_CANCELED, replyIntent);
+            } else {
+                String from = sendingAddressObject.getText().toString();
+                String to = receivingAddressObject.getText().toString();
+                String subject = subjectObject.getText().toString();
+                String message = messageBodyObject.getText().toString();
+                replyIntent.putExtra(EXTRA_FROM, from);
+                replyIntent.putExtra(EXTRA_TO, to);
+                replyIntent.putExtra(EXTRA_SUBJECT, subject);
+                replyIntent.putExtra(EXTRA_MESSAGE, message);
+                activity.setResult(RESULT_OK, replyIntent);
+            }
+            activity.finish();
+        });
+
         // TODO: add cc + bcc functionality
 
         // button listeners

+ 0 - 44
app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/Data.java

@@ -1,44 +0,0 @@
-package com.noahvogt.miniprojekt.ui.DataBase;
-
-import java.util.ArrayList;
-
-public class Data {
-    private String mName;
-    private String mdate;
-    private String mBetreff;
-    private String mBegin;
-
-
-    public Data(String name, String date, String begin, String betreff) {
-        mName = name;
-        mdate = date;
-        mBegin = begin;
-        mBetreff = betreff;
-
-
-    }
-
-    public String getName() {
-        return mName;
-    }
-    public String getDate(){return mdate;}
-    public String getBetreff(){return mBetreff;}
-    public String getBegin(){return mBegin;}
-
-
-
-
-
-    public static ArrayList<Data> createMailList(int numItems) {
-        ArrayList<Data> contacts = new ArrayList<Data>();
-
-        int lastContactId = 0;
-
-        for (int i = 1; i <= numItems; i++) {
-            contacts.add(new Data("Person " + ++lastContactId, "14.04.2021", "This email begins with..",
-                    "My Betreff is no that god"));
-        }
-
-        return contacts;
-    }
-}

+ 39 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/EmailRepository.java

@@ -0,0 +1,39 @@
+package com.noahvogt.miniprojekt.ui.DataBase;
+
+import android.app.Application;
+
+import androidx.lifecycle.LiveData;
+
+import java.util.List;
+
+public class EmailRepository {
+
+    private MessageDao messageDao;
+    private LiveData<List<Message>> mAllMessage;
+
+    // Note that in order to unit test the WordRepository, you have to remove the Application
+    // dependency. This adds complexity and much more code, and this sample is not about testing.
+    // See the BasicSample in the android-architecture-components repository at
+    // https://github.com/googlesamples
+    /*get all messages sorted by date out of Database*/
+    public EmailRepository(Application application) {
+        EmailRoomDatabase db = EmailRoomDatabase.getDatabase(application);
+        messageDao = db.messageDao();
+        mAllMessage = messageDao.getDateMessages();
+    }
+
+    // Room executes all queries on a separate thread.
+    // Observed LiveData will notify the observer when the data has changed.
+    /* returns all messages sorted by date */
+    public LiveData<List<Message>> getDraftMessages() {
+        return mAllMessage;
+    }
+
+    // You must call this on a non-UI thread or your app will throw an exception. Room ensures
+    // that you're not doing any long running operations on the main thread, blocking the UI.
+    public void insert(Message message) {
+        EmailRoomDatabase.databaseWriteExecutor.execute(() -> {
+            messageDao.insert(message);
+        });
+    }
+}

+ 79 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/EmailRoomDatabase.java

@@ -0,0 +1,79 @@
+package com.noahvogt.miniprojekt.ui.DataBase;
+
+import android.content.Context;
+
+import androidx.annotation.NonNull;
+import androidx.room.Database;
+import androidx.room.Room;
+import androidx.room.RoomDatabase;
+import androidx.room.migration.Migration;
+import androidx.sqlite.db.SupportSQLiteDatabase;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Database(entities = {Message.class}, version = 1, exportSchema = true)
+public abstract class EmailRoomDatabase extends RoomDatabase{
+
+    public abstract MessageDao messageDao();
+
+    /* the INSTANCE can be used ba different threads at the same time */
+    private static volatile EmailRoomDatabase INSTANCE;
+
+    /* tells room the schema is changed from the version tha is istallend in device
+     * is not used */
+    static final Migration MIGRATION_2_3 = new Migration(2, 3) {
+        @Override
+        public void migrate(SupportSQLiteDatabase database) {
+            database.execSQL("ALTER TABLE word_table "
+                    + "ADD COLUMN last_update INTEGER ");
+        }
+    };
+
+    /* creating 4 threads */
+    private static final int NUMBER_OF_THREADS = 4;
+    static final ExecutorService databaseWriteExecutor =
+            Executors.newFixedThreadPool(NUMBER_OF_THREADS);
+
+    static EmailRoomDatabase getDatabase(final Context context) {
+        if (INSTANCE == null) {
+            /* synchronize all threads of WordRoomDatabase */
+            synchronized (EmailRoomDatabase.class) {
+                if (INSTANCE == null) {
+                    /* passes the interface in the Room and deletes old data/schema from device*/
+                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
+                            EmailRoomDatabase.class, "message_database")
+                            .addCallback(sRoomDatabaseCallback)
+                            .fallbackToDestructiveMigration()
+                            .build();
+                }
+            }
+        }
+        return INSTANCE;
+    }
+
+    private static RoomDatabase.Callback sRoomDatabaseCallback = new RoomDatabase.Callback() {
+        @Override
+        public void onCreate(@NonNull SupportSQLiteDatabase db) {
+            super.onCreate(db);
+
+            // If you want to keep data through app restarts,
+            // comment out the following block
+            databaseWriteExecutor.execute(() -> {
+                // Populate the database in the background.
+                // If you want to start with more words, just add them.
+                MessageDao dao = INSTANCE.messageDao();
+                dao.deleteAll();
+
+                Message word = new Message("Simon", null, null,
+                        "Noah", "28.8.21", "testing", "I want to try it",
+                        true);
+                dao.insert(word);
+
+            });
+        }
+    };
+
+}
+
+

+ 58 - 31
app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/Message.java

@@ -1,57 +1,84 @@
 package com.noahvogt.miniprojekt.ui.DataBase;
 
-public class Message {
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+import androidx.room.PrimaryKey;
 
-    private int id = 0;
-    private int account = 0;
-    private String to ;
-    private String cc;
-    private String bcc; //blind carpet copy, not see who sees mails
-    private String from;
-    private String date;
-    private String betreff;
-    private int attachment = 0;
-    private boolean seen = true;
+/* @Embedded to express entitys together
+ *  https://developer.android.com/training/data-storage/room/relationships
+ * to learn more */
 
-    public int getId(){return id;}
+@Entity(tableName = "message_table")
+public class Message {
 
-    public int getAccount(){return account;}
+    @PrimaryKey (autoGenerate = true)
+    public int id;
 
-    public String getTo(){return to;}
+    /* name of Columm */
+    @NonNull
+    @ColumnInfo(name = "to")
+    private String mTo ;
 
-    public String getCc(){return cc;}
 
-    public String getBcc(){return bcc;}
+    @ColumnInfo(name = "cc")
+    private String mCc;
 
-    public  String getFrom(){return from;}
+    @ColumnInfo(name = "bcc")
+    private String mBcc; //blind carpet copy, not see who sees mails
 
-    public String getDate(){return date;}
+    @NonNull
+    @ColumnInfo(name = "fromEmail")
+    private String mFrom;
 
-    public String getBetreff(){return betreff;}
+    @NonNull
+    @ColumnInfo(name = "date")
+    private String mDate;
 
-    public int getAttachment(){return attachment;}
+    @ColumnInfo(name = "subject")
+    private String mSubject;
 
-    public boolean getSeen(){return seen;}
+    @ColumnInfo(name = "textContent")
+    private String mTextContent;
 
-    public void setId(int i){id = i;}
+    @ColumnInfo(name = "seen")
+    private boolean mSeen;
 
-    public void setAccount(int i){account = i;}
+    public String getTo(){return this.mTo;}
 
-    public void setTo(String s){to = s;}
+    public String getFrom(){return this.mFrom;}
 
-    public void setCc(String s){cc = s;}
+    public String getCc(){return this.mCc;}
 
-    public void setBcc(String s){bcc = s;}
+    public String getBcc(){return this.mBcc;}
 
-    public void setFrom(String s){from = s;}
+    public String getDate(){return this.mDate;}
 
-    public void setDate(String s){date = s;}
+    public String getSubject(){return this.mSubject;}
 
-    public void setBetreff(String s){betreff = s;}
+    public String getTextContent(){return this.mTextContent;}
 
-    public void setAttachment(int i){ attachment = i;}
+    public int getId(){return this.id;}
 
-    public void setSeen(boolean b){seen = b;}
+    public boolean isSeen() {return this.mSeen;}
 
+    public Message(
+            @NonNull String to,
+            String cc,
+            String bcc,
+            @NonNull String from,
+            @NonNull String date,
+            String subject,
+            String textContent,
+            @NonNull boolean seen) {
+        this.mTo = to;
+        this.mFrom = from;
+        this.mCc = cc;
+        this.mBcc = bcc;
+        this.mDate = date;
+        this.mSubject = subject;
+        this.mTextContent = textContent;
+        this.mSeen = seen;
+    }
 
 }

+ 49 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/DataBase/MessageDao.java

@@ -0,0 +1,49 @@
+package com.noahvogt.miniprojekt.ui.DataBase;
+
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+
+import java.util.List;
+
+@Dao
+public interface MessageDao {
+
+    /*
+
+    WordDao is an interface; DAOs must either be interfaces or abstract classes.
+    The @Dao annotation identifies it as a DAO class for Room.
+    void insert(Word word); Declares a method to insert one word:
+    The @Insert annotation is a special DAO method annotation where you don't have to provide any SQL! (There are also @Delete and @Update annotations for deleting and updating rows, but you are not using them in this app.)
+    onConflict = OnConflictStrategy.IGNORE: The selected on conflict strategy ignores a new word if it's exactly the same as one already in the list. To know more about the available conflict strategies, check out the documentation.
+    deleteAll(): declares a method to delete all the words.
+    There is no convenience annotation for deleting multiple entities, so it's annotated with the generic @Query.
+    @Query("DELETE FROM word_table"): @Query requires that you provide a SQL query as a string parameter to the annotation.
+    List<Word> getAlphabetizedWords(): A method to get all the words and have it return a List of Words.
+    @Query("SELECT * FROM word_table ORDER BY word ASC"): Returns a list of words sorted in ascending order.
+
+     */
+
+    // allowing the insert of the same word multiple times by passing a
+    // conflict resolution strategy
+    @Insert(onConflict = OnConflictStrategy.IGNORE)
+    void insert(Message message);
+
+    @Query("DELETE FROM message_table")
+    void deleteAll();
+
+    @Query("SELECT * FROM message_table")
+    LiveData<List<Message>> getAllMessages();
+
+    @Query("SELECT * FROM message_table ORDER BY date ASC")
+    LiveData<List<Message>> getDateMessages();
+
+    /* selects just from, subject and date from word_table */
+
+    /* @Query("SELECT fromEmail, date, subject, textContent FROM message_table")
+    LiveData<List<Message>> getRecyclerviewData();
+     */
+
+}

+ 3 - 3
app/src/main/java/com/noahvogt/miniprojekt/ui/gallery/GalleryFragment.java

@@ -12,19 +12,19 @@ import androidx.fragment.app.Fragment;
 import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModelProvider;
 
+import com.noahvogt.miniprojekt.MainActivity;
 import com.noahvogt.miniprojekt.R;
 import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
 
 public class GalleryFragment extends Fragment {
 
     private GalleryViewModel galleryViewModel;
-
-
+    private String Sent;
 
     public View onCreateView(@NonNull LayoutInflater inflater,
                              ViewGroup container, Bundle savedInstanceState) {
 
-        CustomAdapter.setInbox(30);
+        MainActivity.View = 1;
 
         galleryViewModel =
                 new ViewModelProvider(this).get(GalleryViewModel.class);

+ 37 - 101
app/src/main/java/com/noahvogt/miniprojekt/ui/home/CustomAdapter.java

@@ -1,57 +1,53 @@
 package com.noahvogt.miniprojekt.ui.home;
 
 
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
+import android.os.Build;
 import android.view.ViewGroup;
-import android.widget.TextView;
 
 
-import androidx.appcompat.view.menu.MenuWrapperICS;
-import androidx.recyclerview.widget.RecyclerView;
+import androidx.annotation.NonNull;
+import androidx.annotation.RequiresApi;
+import androidx.recyclerview.widget.DiffUtil;
+import androidx.recyclerview.widget.ListAdapter;
 
-import com.noahvogt.miniprojekt.R;
-import com.noahvogt.miniprojekt.ui.DataBase.Data;
 import com.noahvogt.miniprojekt.ui.DataBase.Message;
-import com.noahvogt.miniprojekt.ui.gallery.GalleryFragment;
+import com.noahvogt.miniprojekt.ui.slideshow.EmailViewHolder;
 
-import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Objects;
 
-public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
+public class CustomAdapter extends ListAdapter<Message, EmailViewHolder> {
 
-    public static Message message = new Message();
 
-    private static ArrayList<Message> current = new ArrayList<Message>();
 
-    private List<Message> localDataSet;
+    public CustomAdapter(@NonNull DiffUtil.ItemCallback<Message> diffCallback) {
+        super(diffCallback);
+    }
 
-    /**
-     * Provide a reference to the type of views that you are using
-     * (custom ViewHolder).
-     */
-    public class ViewHolder extends RecyclerView.ViewHolder {
-        private TextView name;
-        private TextView betreff;
-        private TextView date;
-        private TextView begin;
-
-        public ViewHolder(View view) {
-            super(view);
-            // Define click listener for the ViewHolder's View
-
-            name = (TextView) view.findViewById(R.id.textView);
-            betreff = (TextView) view.findViewById(R.id.betreff);
-            date = (TextView) view.findViewById(R.id.date);
-            begin = (TextView) view.findViewById(R.id.begin);
+    @Override
+    public EmailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+        return EmailViewHolder.create(parent);
+    }
+
+    @Override
+    public void onBindViewHolder(EmailViewHolder holder, int position) {
+        Message current = getItem(position);
+        holder.bind(current.getFrom(),current.getSubject(), current.getDate() ,current.getTextContent());
+
+    }
+
+    public static class EmailDiff extends DiffUtil.ItemCallback<Message> {
+
+        @Override
+        public boolean areItemsTheSame(@NonNull Message oldItem, @NonNull Message newItem) {
+            return oldItem == newItem;
         }
 
-        //public TextView getTextView() {
-            //return textView;
-        //}
+        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
+        @Override
+        public boolean areContentsTheSame(@NonNull Message oldItem, @NonNull Message newItem) {
+            return Objects.equals(oldItem.getId(), newItem.getId());
+        }
     }
 
     /**
@@ -60,80 +56,18 @@ public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder
      * @param dataSet String[] containing the data to populate views to be used
      * by RecyclerView.
      */
-    public CustomAdapter(List<Message> dataSet) {
-        localDataSet = dataSet;
-    }
 
-    // Create new views (invoked by the layout manager)
-    @NotNull
-    @Override
-    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
-        // Create a new view, which defines the UI of the list item
-        //View view = LayoutInflater.from(viewGroup.getContext())
-                //.inflate(R.layout.text_row_item, viewGroup, false);
-
-        Context context = viewGroup.getContext();
-        LayoutInflater inflater = LayoutInflater.from(context);
 
-        // Inflate the custom layout
-        View contactView = inflater.inflate(R.layout.fragment_home, viewGroup, false); //fragment_home is just for no errors idk if it is the right file
+    // Create new views (invoked by the layout manager)
 
-        // Return a new holder instance
-        ViewHolder view = new ViewHolder(contactView);
-        return view;
-    }
 
     // Replace the contents of a view (invoked by the layout manager)
-    @Override
-    public void onBindViewHolder(ViewHolder viewHolder, int position) {
-
-        // Get element from your dataset at this position and replace the
-        // contents of the view with that element
-        //viewHolder.getTextView().setText(localDataSet[position]);
-        // Get the data model based on position
-        Message contact = localDataSet.get(position);
-
-        // Set item views based on your views and data model
-        TextView nameView = viewHolder.name;
-        TextView betreffView = viewHolder.betreff;
-        TextView dateView = viewHolder.date;
-        TextView beginView = viewHolder.begin;
 
-        nameView.setText(contact.getFrom());
-        betreffView.setText(contact.getBetreff());
-        dateView.setText(contact.getDate());
-
-           
-
-    }
 
     // Return the size of your dataset (invoked by the layout manager)
-    @Override
-    public int getItemCount() {
-        return localDataSet.size();
-    }
-
 
 
-    //to set the content of the Sentfolder by changing the adapter
-    public static void setSent(int numItems){
-
-            message.setId(1);
-            message.setBetreff("Hi");
-            message.setFrom("jeffry");
-            message.setDate("Today");
-
-            current.add(message.getId(),message);
-
-            message.setId(2);
-            message.setBetreff("test");
-            message.setFrom("Simon");
-            message.setDate("23.8.august");
-
-            current.add(message.getId(), message);
-
-
-    }
+    /*
 
     //to set the content of the Inboxfolder
     public static void setInbox(int numItems){
@@ -187,5 +121,7 @@ public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder
         return CustomAdapter.current;
 
     }
+
+     */
 }
 

+ 3 - 2
app/src/main/java/com/noahvogt/miniprojekt/ui/home/HomeFragment.java

@@ -13,16 +13,17 @@ import androidx.fragment.app.Fragment;
 import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModelProvider;
 
+import com.noahvogt.miniprojekt.MainActivity;
 import com.noahvogt.miniprojekt.R;
 
 public class HomeFragment extends Fragment {
 
     private HomeViewModel homeViewModel;
+    private static String Inbox;
 
     public View onCreateView(@NonNull LayoutInflater inflater,
                              ViewGroup container, Bundle savedInstanceState) {
-
-        CustomAdapter.setSent(20);
+        MainActivity.View = -1;
 
         homeViewModel =
                 new ViewModelProvider(this).get(HomeViewModel.class);

+ 12 - 11
app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/SlideshowFragment.java → app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/DraftFragment.java

@@ -13,23 +13,19 @@ import androidx.lifecycle.Observer;
 import androidx.lifecycle.ViewModelProvider;
 
 import com.noahvogt.miniprojekt.R;
-import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
-
-public class SlideshowFragment extends Fragment {
-
-    private SlideshowViewModel slideshowViewModel;
 
+public class DraftFragment extends Fragment {
+/*
+    private DraftViewModel draftViewModel;
 
     public View onCreateView(@NonNull LayoutInflater inflater,
                              ViewGroup container, Bundle savedInstanceState) {
 
-        CustomAdapter.setDraft(10);
-
-        slideshowViewModel =
-                new ViewModelProvider(this).get(SlideshowViewModel.class);
+        draftViewModel =
+                new ViewModelProvider(this).get(DraftViewModel.class);
         View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
         final TextView textView = root.findViewById(R.id.text_slideshow);
-        slideshowViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
+        draftViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
             @Override
             public void onChanged(@Nullable String s) {
                 textView.setText(s);
@@ -37,4 +33,9 @@ public class SlideshowFragment extends Fragment {
         });
         return root;
     }
-}
+
+
+ */
+
+}
+

+ 30 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/DraftViewModel.java

@@ -0,0 +1,30 @@
+package com.noahvogt.miniprojekt.ui.slideshow;
+
+import android.app.Application;
+
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.AndroidViewModel;
+
+import com.noahvogt.miniprojekt.MainActivity;
+import com.noahvogt.miniprojekt.ui.DataBase.EmailRepository;
+import com.noahvogt.miniprojekt.ui.DataBase.Message;
+
+import java.util.List;
+
+public class DraftViewModel extends AndroidViewModel {
+
+    private EmailRepository mEmailRepository;
+
+    private final LiveData<List<Message>> mDraftMessage;
+
+    public DraftViewModel(Application application) {
+        super(application);
+        mEmailRepository = new EmailRepository(application);
+        mDraftMessage = mEmailRepository.getDraftMessages();
+    }
+
+    public LiveData<List<Message>> getDraftMessage(){return mDraftMessage;}
+
+    public void insert(Message message){mEmailRepository.insert(message);}
+
+}

+ 42 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/EmailViewHolder.java

@@ -0,0 +1,42 @@
+package com.noahvogt.miniprojekt.ui.slideshow;
+
+import android.provider.Telephony;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.noahvogt.miniprojekt.MainActivity;
+import com.noahvogt.miniprojekt.R;
+import androidx.recyclerview.widget.RecyclerView;
+
+/* adds the content to the View of RecyclerView*/
+public class EmailViewHolder extends RecyclerView.ViewHolder {
+    private final TextView fromItemView;
+    private final TextView subjectItemView;
+    private final TextView dateItemView;
+    private final TextView messageItemView;
+
+    private EmailViewHolder(View itemView) {
+        super(itemView);
+        fromItemView = itemView.findViewById(R.id.textView);
+        subjectItemView = itemView.findViewById(R.id.subject);
+        dateItemView = itemView.findViewById(R.id.date);
+        messageItemView = itemView.findViewById(R.id.message);
+    }
+
+    public void bind(String from, String subject, String date, String message) {
+        fromItemView.setText(from);
+        subjectItemView.setText(subject);
+        dateItemView.setText(date);
+        messageItemView.setText(message);
+    }
+
+    public static EmailViewHolder create(ViewGroup parent) {
+        View view = LayoutInflater.from(parent.getContext())
+                .inflate(R.layout.fragment_home, parent, false);
+        return new EmailViewHolder(view);
+    }
+}
+
+

+ 0 - 19
app/src/main/java/com/noahvogt/miniprojekt/ui/slideshow/SlideshowViewModel.java

@@ -1,19 +0,0 @@
-package com.noahvogt.miniprojekt.ui.slideshow;
-
-import androidx.lifecycle.LiveData;
-import androidx.lifecycle.MutableLiveData;
-import androidx.lifecycle.ViewModel;
-
-public class SlideshowViewModel extends ViewModel {
-
-    private MutableLiveData<String> mText;
-
-    public SlideshowViewModel() {
-        mText = new MutableLiveData<>();
-        mText.setValue("This is slideshow fragment");
-    }
-
-    public LiveData<String> getText() {
-        return mText;
-    }
-}

+ 10 - 0
app/src/main/res/drawable/ic_baseline_add_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="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
+</vector>

+ 9 - 1
app/src/main/res/layout/activity_main.xml

@@ -19,13 +19,14 @@
 
     </androidx.recyclerview.widget.RecyclerView>
 
+
+
     <include
         layout="@layout/app_bar_main"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="20dp"
         android:paddingRight="20dp" />
-
     <com.google.android.material.navigation.NavigationView
         android:id="@+id/nav_view"
         android:layout_width="wrap_content"
@@ -35,6 +36,11 @@
         app:headerLayout="@layout/nav_header_main"
         app:menu="@menu/activity_main_drawer" >
 
+        <View
+            android:id="@+id/accountView"
+            android:layout_width="match_parent"
+            android:layout_height="@dimen/nav_header_height"/>
+
         <Button
             android:id="@+id/addEmailButton"
             android:layout_width="wrap_content"
@@ -50,4 +56,6 @@
 
 
 
+
+
 </androidx.drawerlayout.widget.DrawerLayout>

+ 6 - 24
app/src/main/res/layout/content_main.xml

@@ -18,33 +18,15 @@
         app:layout_constraintTop_toTopOf="parent"
         app:navGraph="@navigation/mobile_navigation" />
 
-    <LinearLayout
-        android:id="@+id/container"
-        android:layout_width="96dp"
-        android:layout_height="96dp"
-
-        android:layout_marginEnd="16dp"
-        android:layout_marginRight="16dp"
-        android:layout_marginBottom="16dp"
-
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent">
-
-        <ImageButton
+        <com.google.android.material.floatingactionbutton.FloatingActionButton
             android:id="@+id/messageButton"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:layout_margin="16dp"
+            android:contentDescription="@string/write_email"
+            android:src="@drawable/ic_baseline_add_24"/>
 
-            android:paddingLeft="18dp"
-            android:paddingRight="18dp"
-            android:paddingTop="18dp"
-            android:paddingBottom="18dp"
-            android:scaleType="fitXY"
-
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:srcCompat="@drawable/mail_write_icon"
-            tools:ignore="VectorDrawableCompat" />
-    </LinearLayout>
 
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 2
app/src/main/res/layout/fragment_home.xml

@@ -17,7 +17,7 @@
         android:textSize="25dp"/>
 
     <TextView
-        android:id="@+id/begin"
+        android:id="@+id/message"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_row="2"
@@ -27,7 +27,7 @@
 
 
     <TextView
-        android:id="@+id/betreff"
+        android:id="@+id/subject"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_row="1"

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

@@ -4,7 +4,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    tools:context=".ui.slideshow.SlideshowFragment">
+    tools:context=".ui.slideshow.DraftFragment">
 
     <TextView
         android:id="@+id/text_slideshow"

+ 1 - 1
app/src/main/res/navigation/mobile_navigation.xml

@@ -19,7 +19,7 @@
 
     <fragment
         android:id="@+id/nav_slideshow"
-        android:name="com.noahvogt.miniprojekt.ui.slideshow.SlideshowFragment"
+        android:name="com.noahvogt.miniprojekt.ui.slideshow.DraftFragment"
         android:label="@string/drawer_drafts"
         tools:layout="@layout/fragment_slideshow" />
 </navigation>

+ 3 - 19
app/src/main/res/values/strings.xml

@@ -14,30 +14,14 @@
     <string name="your_email_address_filler">Your Email Address</string>
     <string name="your_full_name_filler">Your Full Name</string>
 
-
-
-
     <string name="Sender">Absender</string>
     <string name="Betreff">Betreff</string>
     <string name="Beginn">E-mail Beginn</string>
     <string name="date">22. Apr.</string>
 
-    <!-- Add in flower names  -->
-    <string-array name="flower_array">
-        <item>Lily</item>
-        <item>Poppy</item>
-        <item>Sunflower</item>
-        <item>Freesia</item>
-        <item>Daisy</item>
-        <item>Rose</item>
-        <item>Daffodil</item>
-        <item>Lavender</item>
-        <item>Peony</item>
-        <item>Lilac</item>
-        <item>Dahlia</item>
-        <item>Tulip</item>
-        <item>Dandelion</item>
-    </string-array>
+    <string name="write_email">Write a Email</string>
+    <string name="empty_not_saved">Email not saved because it was empty.</string>
+
 
 </resources>
 

+ 0 - 1
build.gradle

@@ -6,7 +6,6 @@ buildscript {
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:4.2.2'
-
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
     }