package com.example.kraft_300.bottomnavigationaddsubmultdiv;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {

    private FrameLayout content = null;
    private android.app.FragmentManager fragmentManager = getFragmentManager();
    private Fragment lastfragment = null;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        content = (FrameLayout) findViewById(R.id.content);
    }


    private void InsertFragment(Fragment  fragment) {
        FragmentTransaction fragTrans =  fragmentManager.beginTransaction();
        fragTrans.add(R.id.content, fragment);
        if (lastfragment!=null) {
            fragTrans.remove(lastfragment);
        }
        fragTrans.addToBackStack(null);
        fragTrans.commit();
        lastfragment = fragment;
    } // InsertFragement

    public void bnAdd_Click(View view) {
        InsertFragment(new AddFragment());
    }

    public void bnSub_Click(View view) {
        InsertFragment(new SubFragment());
    }

    public void bnMult_Click(View view) {
        InsertFragment(new MultFragment());
    }

    public void bnDiv_Click(View view) {
        InsertFragment(new DivFragment());
    }

    public void bnSqr_Click(View view) {
        InsertFragment(new SqrFragment());
    }
}
