package net.devrand.kihon.kihonweather;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import net.devrand.kihon.kihonweather.event.FabEvent;

import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;

public class WeatherActivity extends AppCompatActivity {

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

        Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = ButterKnife.findById(this, R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().post(new FabEvent());
            }
        });

        FrameLayout frame = ButterKnife.findById(this, R.id.main_fragment);
        Fragment fragment = new WeatherActivityFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(frame.getId(), 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_weather, 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();

        switch (id) {
            case R.id.action_settings:
                startActivity(new Intent(this, SettingsActivity.class));
                return true;
            case R.id.action_forecast:
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                return true;
            case R.id.action_stations:
                return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

@@ -633,16 +633,52 @@
 vity %7B%0A%0A
+    FrameLayout fragmentContainer;%0A%0A
     @Ove
@@ -1242,25 +1242,25 @@
     
-F
+f
 ra
+g
 me
-Layout frame
+ntContainer
  = B
@@ -1482,18 +1482,30 @@
 .add(fra
+g
 me
+ntContainer
 .getId()
@@ -2305,157 +2305,439 @@
     
-FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();%0A                return true;%0A            case R.id.action_stations:
+getSupportFragmentManager().popBackStack();%0A                return true;%0A            case R.id.action_stations:%0A                Fragment fragment = new StationSelectionFragment();%0A                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();%0A                transaction.replace(fragmentContainer.getId(), fragment)%0A                        .addToBackStack(null)%0A                        .commit();
 %0A   

use fragment transactions