瀏覽代碼

merged bugfixing, it works but is not fully completed

Simon Hammer 4 年之前
父節點
當前提交
e8142a6c93

+ 1 - 0
.gitignore

@@ -8,6 +8,7 @@
 /.idea/workspace.xml
 /.idea/workspace.xml
 /.idea/navEditor.xml
 /.idea/navEditor.xml
 /.idea/assetWizardSettings.xml
 /.idea/assetWizardSettings.xml
+/.idea
 .DS_Store
 .DS_Store
 /build
 /build
 /captures
 /captures

+ 12 - 4
app/build.gradle

@@ -33,14 +33,22 @@ android {
 
 
 dependencies {
 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 'androidx.appcompat:appcompat:1.2.0'
     implementation 'com.google.android.material:material:1.3.0'
     implementation 'com.google.android.material:material:1.3.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
-    implementation 'androidx.navigation:navigation-fragment:2.2.2'
-    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'
     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
+
+    implementation 'androidx.navigation:navigation-fragment:2.3.5'
+    implementation 'androidx.navigation:navigation-ui:2.3.5'
+    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
+    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
+    implementation 'androidx.recyclerview:recyclerview:1.2.0'
+
     testImplementation 'junit:junit:4.+'
     testImplementation 'junit:junit:4.+'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

+ 45 - 0
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -1,6 +1,7 @@
 package com.noahvogt.miniprojekt;
 package com.noahvogt.miniprojekt;
 
 
 import android.os.Bundle;
 import android.os.Bundle;
+
 import android.view.Menu;
 import android.view.Menu;
 import android.view.View;
 import android.view.View;
 import android.widget.Button;
 import android.widget.Button;
@@ -13,11 +14,31 @@ import androidx.appcompat.app.AppCompatActivity;
 import androidx.appcompat.widget.Toolbar;
 import androidx.appcompat.widget.Toolbar;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.drawerlayout.widget.DrawerLayout;
 import androidx.fragment.app.DialogFragment;
 import androidx.fragment.app.DialogFragment;
+
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.noahvogt.miniprojekt.ui.home.CustomAdapter;
+import com.noahvogt.miniprojekt.ui.home.Data;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
+import java.util.ArrayList;
+
+
+import com.google.android.material.navigation.NavigationView;
+
+
 import androidx.navigation.NavController;
 import androidx.navigation.NavController;
 import androidx.navigation.Navigation;
 import androidx.navigation.Navigation;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.AppBarConfiguration;
 import androidx.navigation.ui.NavigationUI;
 import androidx.navigation.ui.NavigationUI;
 
 
+
 import com.google.android.material.navigation.NavigationView;
 import com.google.android.material.navigation.NavigationView;
 import com.google.android.material.snackbar.Snackbar;
 import com.google.android.material.snackbar.Snackbar;
 
 
@@ -27,6 +48,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
 
     private AppBarConfiguration mAppBarConfiguration;
     private AppBarConfiguration mAppBarConfiguration;
 
 
+    //imported by simon 2.may from RecyclerView Programm, changed to 23.may Simon to ArrayList<Data>...
+    protected ArrayList<Data> data;
+
     private AlertDialog dialog;
     private AlertDialog dialog;
 
 
     private EditText newemail_name, newemail_email, newemail_password; // may not be private
     private EditText newemail_name, newemail_email, newemail_password; // may not be private
@@ -35,6 +59,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     public MainActivity() {
     public MainActivity() {
     }
     }
 
 
+
+
+
+
+
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
@@ -73,8 +102,21 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
         NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
         NavigationUI.setupWithNavController(navigationView, navController);
         NavigationUI.setupWithNavController(navigationView, navController);
+
+        //initDataset();
+        // Lookup the recyclerview in activity layou
+        RecyclerView recyclerView = findViewById(R.id.recyclerView);
+        // Initialize contacts
+        data = Data.createContactsList(20);
+        // Create adapter passing in the sample user data
+        CustomAdapter adapter = new CustomAdapter(data);
+        // Attach the adapter to the recyclerview to populate items
+        recyclerView.setAdapter(adapter);
+        recyclerView.setLayoutManager(new LinearLayoutManager(this));
     }
     }
 
 
+
+
     @Override
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         // Inflate the menu; this adds items to the action bar if it is present.
@@ -89,6 +131,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
                 || super.onSupportNavigateUp();
                 || super.onSupportNavigateUp();
     }
     }
 
 
+
     // better leave empty to avoid any listener disambiguity
     // better leave empty to avoid any listener disambiguity
     public void onClick(View view) {}
     public void onClick(View view) {}
 
 
@@ -156,4 +199,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     private void showToast(String text) {
     private void showToast(String text) {
         Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
         Toast.makeText(MainActivity.this, text, Toast.LENGTH_SHORT).show();
     }
     }
+
+
 }
 }

+ 107 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/home/CustomAdapter.java

@@ -0,0 +1,107 @@
+package com.noahvogt.miniprojekt.ui.home;
+
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.TextView;
+
+
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.noahvogt.miniprojekt.R;
+
+import org.w3c.dom.Text;
+
+import java.util.List;
+
+public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> {
+
+    private List<Data> localDataSet;
+
+    /**
+     * 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);
+        }
+
+        //public TextView getTextView() {
+            //return textView;
+        //}
+    }
+
+    /**
+     * Initialize the dataset of the Adapter.
+     *
+     * @param dataSet String[] containing the data to populate views to be used
+     * by RecyclerView.
+     */
+    public CustomAdapter(List<Data> dataSet) {
+        localDataSet = dataSet;
+    }
+
+    // Create new views (invoked by the layout manager)
+    @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
+
+        // 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
+        Data 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.getName());
+        betreffView.setText(contact.getBetreff());
+        dateView.setText(contact.getDate());
+        beginView.setText(contact.getBegin());
+
+
+    }
+
+    // Return the size of your dataset (invoked by the layout manager)
+    @Override
+    public int getItemCount() {
+        return localDataSet.size();
+    }
+}
+

+ 42 - 0
app/src/main/java/com/noahvogt/miniprojekt/ui/home/Data.java

@@ -0,0 +1,42 @@
+package com.noahvogt.miniprojekt.ui.home;
+
+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;}
+
+
+
+    private static int lastContactId = 0;
+
+    public static ArrayList<Data> createContactsList(int numContacts) {
+        ArrayList<Data> contacts = new ArrayList<Data>();
+
+        for (int i = 1; i <= numContacts; i++) {
+            contacts.add(new Data("Person " + ++lastContactId, "14.04.2021", "This email begins with..",
+                    "My Betreff is no that god"));
+        }
+
+        return contacts;
+    }
+}

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

@@ -6,6 +6,7 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewGroup;
 import android.widget.TextView;
 import android.widget.TextView;
 
 
+
 import androidx.annotation.NonNull;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.annotation.Nullable;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.Fragment;
@@ -23,7 +24,7 @@ public class HomeFragment extends Fragment {
         homeViewModel =
         homeViewModel =
                 new ViewModelProvider(this).get(HomeViewModel.class);
                 new ViewModelProvider(this).get(HomeViewModel.class);
         View root = inflater.inflate(R.layout.fragment_home, container, false);
         View root = inflater.inflate(R.layout.fragment_home, container, false);
-        final TextView textView = root.findViewById(R.id.text_home);
+        final TextView textView = root.findViewById(R.id.textView);
         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
         homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
             @Override
             @Override
             public void onChanged(@Nullable String s) {
             public void onChanged(@Nullable String s) {

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

@@ -6,7 +6,18 @@
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"
     android:fitsSystemWindows="true"
-    tools:openDrawer="start">
+    tools:openDrawer="start"
+    tools:context=".MainActivity">
+
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:paddingTop="50dp"
+        app:layoutManager="androidx.recyclerview.widget.GridLayoutManager">
+
+    </androidx.recyclerview.widget.RecyclerView>
 
 
     <include
     <include
         layout="@layout/app_bar_main"
         layout="@layout/app_bar_main"
@@ -36,4 +47,7 @@
             android:paddingRight="10dp"
             android:paddingRight="10dp"
             android:text="Add Email" />
             android:text="Add Email" />
     </com.google.android.material.navigation.NavigationView>
     </com.google.android.material.navigation.NavigationView>
+
+
+
 </androidx.drawerlayout.widget.DrawerLayout>
 </androidx.drawerlayout.widget.DrawerLayout>

+ 44 - 17
app/src/main/res/layout/fragment_home.xml

@@ -1,23 +1,50 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout 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"
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".ui.home.HomeFragment">
+    android:layout_height="wrap_content"
+    android:paddingLeft="16dp"
+    android:paddingTop="16dp"
+    android:paddingRight="16dp"
+    android:layout_gravity="top">
 
 
+    <!-- Add in TextView to display flower name   -->
     <TextView
     <TextView
-        android:id="@+id/text_home"
-        android:layout_width="match_parent"
+        android:id="@+id/textView"
+        android:layout_column="0"
+        android:layout_row="0"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:layout_gravity="center_horizontal"
-        android:textAlignment="center"
+        android:layout_width="wrap_content"
+        android:textSize="25dp"/>
+
+    <TextView
+        android:id="@+id/begin"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_row="2"
+        android:layout_column="0"
+        android:textSize="20sp"
+        android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
+
+
+    <TextView
+        android:id="@+id/betreff"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_row="1"
+        android:layout_column="0"
         android:textSize="20sp"
         android:textSize="20sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-</androidx.constraintlayout.widget.ConstraintLayout>
+        android:textAppearance="@style/TextAppearance.AppCompat.Body1"
+        android:textColor="@color/colorBetreff" />
+
+
+    <TextView
+        android:id="@+id/date"
+        android:textSize="20dp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_row="0"
+        android:layout_column="3"
+        android:gravity="left" />
+
+
+</GridLayout>

+ 8 - 0
app/src/main/res/values/colors.xml

@@ -7,5 +7,13 @@
     <color name="teal_700">#FF018786</color>
     <color name="teal_700">#FF018786</color>
     <color name="black">#FF000000</color>
     <color name="black">#FF000000</color>
     <color name="white">#FFFFFFFF</color>
     <color name="white">#FFFFFFFF</color>
+
     <color name="error_red">#ff7400</color>
     <color name="error_red">#ff7400</color>
+
+
+    <color name="colorPrimary">#6200EE</color>
+    <color name="colorPrimaryDark">#3700B3</color>
+    <color name="colorAccent">#03DAC5</color>
+    <color name="colorBetreff">#3EC143</color>
+
 </resources>
 </resources>

+ 3 - 0
app/src/main/res/values/dimens.xml

@@ -5,4 +5,7 @@
     <dimen name="nav_header_vertical_spacing">8dp</dimen>
     <dimen name="nav_header_vertical_spacing">8dp</dimen>
     <dimen name="nav_header_height">176dp</dimen>
     <dimen name="nav_header_height">176dp</dimen>
     <dimen name="fab_margin">16dp</dimen>
     <dimen name="fab_margin">16dp</dimen>
+
+    <dimen name="list_item_height">45dp</dimen>
+    <dimen name="margin_medium">30dp</dimen>
 </resources>
 </resources>

+ 26 - 0
app/src/main/res/values/strings.xml

@@ -14,4 +14,30 @@
     <string name="your_email_address_filler">Your Email Address</string>
     <string name="your_email_address_filler">Your Email Address</string>
     <string name="your_full_name_filler">Your Full Name</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>
+
 </resources>
 </resources>
+