/**
 * MIT License
 * <p>
 * Copyright (c) 2016 Midhun Harikumar
 * <p>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p>
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * <p>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.ae.apps.tripmeter.activities;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;

import com.ae.apps.common.activities.ToolBarBaseActivity;
import com.ae.apps.tripmeter.R;
import com.ae.apps.tripmeter.fragments.FuelCalcFragment;
import com.ae.apps.tripmeter.fragments.FuelPricesFragment;
import com.ae.apps.tripmeter.fragments.TripExpensesFragment;

/**
 * The Main Activity
 */
public class MainActivity extends ToolBarBaseActivity implements FuelPricesFragment.OnFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Implementing BottomNavigationView
        BottomNavigationView navigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
        navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                updateDisplayedFragment(item.getItemId());
                return false;
            }
        });

        updateDisplayedFragment(R.id.action_trip_calc);

        /*
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
         */
    }

    @Override
    protected int getToolbarResourceId() {
        return R.id.toolbar;
    }

    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_main;
    }

    /**
     * Update the fragment
     * @param itemId id of the menu
     */
    private void updateDisplayedFragment(int itemId) {
        Fragment fragment = null;
        switch (itemId) {
            case R.id.action_trip_calc:
                fragment = FuelCalcFragment.newInstance();
                break;
            // Both items below point to coming soon fragments
            case R.id.action_fuel_price:
                fragment = FuelPricesFragment.newInstance("", "");
                break;
            case R.id.action_trip_expenses:
                fragment = TripExpensesFragment.newInstance();
                break;
        }

        final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fragment_container, fragment).commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }
        if (id == R.id.action_about) {
            startActivity(new Intent(this, AboutActivity.class));
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}

@@ -3376,16 +3376,120 @@
 = null;%0A
+        final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();%0A
         
@@ -3597,32 +3597,111 @@
 .newInstance();%0A
+                setToolbarTitle(getResources().getString(R.string.menu_calc));%0A
                 
@@ -3878,16 +3878,101 @@
 %22, %22%22);%0A
+                setToolbarTitle(getResources().getString(R.string.menu_fuel_price));%0A
         
@@ -4113,129 +4113,113 @@
     
-break;%0A        %7D%0A%0A        final FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
+setToolbarTitle(getResources().getString(R.string.menu_trip_expenses));%0A                break;%0A        %7D%0A
 %0A   

set toolbar title