package com.example.android.sunshine.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    private static final String LOG_TAG = "MainActivity";
    private static final String DETAILFRAGMENT_TAG = "DFTAG";

    private String mLocation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mLocation = Utility.getPreferredLocation(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        String changedLocation = Utility.getPreferredLocation(this);
        if (changedLocation != null && !changedLocation.equals(mLocation)) {
            ForecastFragment forecastFragment = (ForecastFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.fragment_forecast);
            if (forecastFragment != null) {
                forecastFragment.onLocationChanged();
            }
            mLocation = changedLocation;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.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) {
            // Launch SettingsActivity
            Intent settingsIntent = new Intent(this, SettingsActivity.class);
            startActivity(settingsIntent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    // TODO: 11/4/16 showLocationOnMap() and onOptionsItemSelected contents to be moved in MainActivity like in course.
}

@@ -374,16 +374,54 @@
 %22DFTAG%22;
+%0A    private boolean mTwoPane = false;
 %0A%0A    pr
@@ -659,24 +659,836 @@
 ation(this);
+%0A%0A        if (findViewById(R.id.weather_detail_container) != null) %7B%0A            // The detail container view will be present only in the large-screen layouts%0A            // (res/layout-sw600dp). If this view is present, then the activity should be%0A            // in two-pane mode.%0A            mTwoPane = true;%0A            // In two-pane mode, show the detail view in this activity by%0A            // adding or replacing the detail fragment using a%0A            // fragment transaction.%0A            if (savedInstanceState == null) %7B%0A                getSupportFragmentManager().beginTransaction()%0A                        .replace(R.id.weather_detail_container, new DetailFragment(),%0A                                DETAILFRAGMENT_TAG).commit();%0A            %7D%0A        %7D else %7B%0A            mTwoPane = false;%0A        %7D
 %0A    %7D%0A%0A    
@@ -3033,11 +3033,62 @@
  course.
+ Perhaps we don't need to do it. Think then decide.
 %0A%7D%0A

Add condition to check whether it's a one-pane or two-pane layout. Launch the details fragment if it's a two pane layout.