package cecelia.moodcookie;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;

import cecelia.moodcookie.db.NoteDatabaseHelper;
import cecelia.moodcookie.types.Mood;
import cecelia.moodcookie.types.Note;

public class MainActivity extends AppCompatActivity {

    NoteDatabaseHelper dbHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.dbHelper = new NoteDatabaseHelper(this);

        // read notes from the database
        ArrayList<Note> notes = dbHelper.getAllNotes();

        for (Note note : notes) {
            Log.d("Main Activity", note.getText());
        }

        startHomepageFragment();

    }

    public void startDisplayPageFragment() {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder, new DisplayPageFragment(), "CURRENT_FRAGMENT");
        fragmentTransaction.commit();
    }

    public void startHomepageFragment() {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder, new HomepageFragment(), "CURRENT_FRAGMENT");
        fragmentTransaction.commit();
    }

    public void startConfirmationPageFragment() {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment_holder, new ConfirmationPageFragment(), "CURRENT_FRAGMENT");
        fragmentTransaction.commit();
    }

}

@@ -22,16 +22,45 @@
 ookie;%0A%0A
+import android.app.Fragment;%0A
 import a
@@ -471,16 +471,53 @@
 Helper;%0A
+    FragmentManager fragmentManager;%0A
     @Ove
@@ -725,16 +725,69 @@
 r(this);
+%0A        this.fragmentManager = getFragmentManager();
 %0A%0A      
@@ -1012,37 +1012,38 @@
 );%0A%0A    %7D%0A%0A    p
-ublic
+rivate
  void startDispl
@@ -1041,48 +1041,25 @@
 tart
-DisplayPageFragment() %7B%0A        
+Fragment(
 Fragment
 Mana
@@ -1046,39 +1046,32 @@
 ragment(Fragment
-Manager
  fragmentManager
@@ -1067,39 +1067,11 @@
 ment
-Manager = getFragmentManager();
+) %7B
 %0A   
@@ -1109,32 +1109,37 @@
 ntTransaction = 
+this.
 fragmentManager.
@@ -1220,33 +1220,16 @@
 er, 
-new DisplayPageF
+f
 ragment
-()
 , %22C
@@ -1309,29 +1309,32 @@
 c void start
-Homep
+DisplayP
 ageFragment(
@@ -1349,53 +1349,45 @@
     
-FragmentManager fragmentManager = 
+startFragment(new DisplayPa
 ge
-t
 Fragment
 Mana
@@ -1386,599 +1386,218 @@
 ment
-Manager
 (
+)
 );%0A    
+%7D%0A%0A
     
-FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();%0A        fragmentTransaction.replace(R.id.fragment_holder, new HomepageFragment(), %22CURRENT_FRAGMENT%22);%0A        fragmentTransaction.commit();%0A    %7D%0A%0A    public void startConfirmationPageFragment() %7B%0A        FragmentManager fragmentManager = getFragmentManager();%0A        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();%0A        fragmentTransaction.replace(R.id.fragment_holder, new ConfirmationPageFragment(), %22CURRENT_FRAGMENT%22);%0A        fragmentTransaction.commit(
+public void startHomepageFragment() %7B%0A        startFragment(new HomepageFragment());%0A    %7D%0A%0A    public void startConfirmationPageFragment() %7B%0A        startFragment(new ConfirmationPageFragment()
 );%0A 

make the fragment manager code in the mainactivity more concise