package info.richardjones.mnemonicrevisionhelper.app;

import android.content.Intent;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.*;
import info.richardjones.mnemonicrevisionhelper.app.loader.*;

import java.util.ArrayList;
import java.util.List;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class EntryPoint extends AppCompatActivity {

/*
    private AdView mAdView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in
        // values/strings.xml.
        mAdView = (AdView) findViewById(R.id.ad_view);

        // Create an ad request. Check your logcat output for the hashed device ID to
        // get test ads on a physical device. e.g.
        // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device."
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();

        // Start loading the ad in the background.
        mAdView.loadAd(adRequest);
    }
    */
/*
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, 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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

     Called when leaving the activity
        @Override
    public void onPause() {
        if (mAdView != null) {
            mAdView.pause();
        }
        super.onPause();
    }

     Called when returning to the activity
    @Override
    public void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

    Called before the activity is destroyed
    @Override
    public void onDestroy() {
        if (mAdView != null) {
            mAdView.destroy();
        }
        super.onDestroy();
    }
*/



    private AdView mAdView;

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

        setContentView(R.layout.main_page);

        mAdView = (AdView) findViewById(R.id.ad_view);

        AdRequest adRequest = new AdRequest.Builder()
//                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();

        mAdView.loadAd(adRequest);

        final ListView listview = (ListView) findViewById(R.id.listview);

        final MnemonicResultsArrayAdapter adapter = new MnemonicResultsArrayAdapter(this, loadData());
        listview.setAdapter(adapter);

        final EditText userInput = (EditText) findViewById(R.id.mnemonic_input);
        userInput.addTextChangedListener(new MnemonicInputTextListener(adapter));
    }


    private List<MatchingMnemonic> loadData() {
        List<MatchingMnemonic> res = new ArrayList();
        new HardCodedMnemonicSloganMapLoader().load(res);
        new HardCodedMnemonicSongMap1Loader().load(res);
        new HardCodedMnemonicSongMap2Loader().load(res);
        new HardCodedMnemonicSongMap3Loader().load(res);
        new HardCodedMnemonicSongMap4Loader().load(res);

        return res;
    }

    @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_entry_point, 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_about) {
            DialogFragment newFragment = new AboutBoxDialogFragment();
            newFragment.show(getSupportFragmentManager(), "ABOUT_KEY");
            return true;
        }

        if (id == R.id.action_setting) {
            Intent intent = new Intent(EntryPoint.this, SettingsActivity.class);
            startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    //Called when leaving the activity
    @Override
    public void onPause() {
        if (mAdView != null) {
            mAdView.pause();
        }
        super.onPause();
    }

    // Called when returning to the activity
    @Override
    public void onResume() {
        super.onResume();
        if (mAdView != null) {
            mAdView.resume();
        }
    }

    // Called before the activity is destroyed
    @Override
    public void onDestroy() {
        if (mAdView != null) {
            mAdView.destroy();
        }
        super.onDestroy();
    }



}

@@ -541,2099 +541,8 @@
  %7B%0A%0A
-/*%0A    private AdView mAdView;%0A    @Override%0A    protected void onCreate(Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A        setContentView(R.layout.activity_my);%0A%0A        // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in%0A        // values/strings.xml.%0A        mAdView = (AdView) findViewById(R.id.ad_view);%0A%0A        // Create an ad request. Check your logcat output for the hashed device ID to%0A        // get test ads on a physical device. e.g.%0A        // %22Use AdRequest.Builder.addTestDevice(%22ABCDEF012345%22) to get test ads on this device.%22%0A        AdRequest adRequest = new AdRequest.Builder()%0A                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)%0A                .build();%0A%0A        // Start loading the ad in the background.%0A        mAdView.loadAd(adRequest);%0A    %7D%0A    */%0A/*%0A    @Override%0A    public boolean onCreateOptionsMenu(Menu menu) %7B%0A        // Inflate the menu; this adds items to the action bar if it is present.%0A        getMenuInflater().inflate(R.menu.my, menu);%0A        return true;%0A    %7D%0A%0A    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        // Handle action bar item clicks here. The action bar will%0A        // automatically handle clicks on the Home/Up button, so long%0A        // as you specify a parent activity in AndroidManifest.xml.%0A        int id = item.getItemId();%0A        if (id == R.id.action_settings) %7B%0A            return true;%0A        %7D%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A%0A     Called when leaving the activity%0A        @Override%0A    public void onPause() %7B%0A        if (mAdView != null) %7B%0A            mAdView.pause();%0A        %7D%0A        super.onPause();%0A    %7D%0A%0A     Called when returning to the activity%0A    @Override%0A    public void onResume() %7B%0A        super.onResume();%0A        if (mAdView != null) %7B%0A            mAdView.resume();%0A        %7D%0A    %7D%0A%0A    Called before the activity is destroyed%0A    @Override%0A    public void onDestroy() %7B%0A        if (mAdView != null) %7B%0A            mAdView.destroy();%0A        %7D%0A        super.onDestroy();%0A    %7D%0A*/%0A%0A%0A%0A
     
@@ -1350,17 +1350,16 @@
 %0A    %7D%0A%0A
-%0A
     priv
@@ -1836,89 +1836,8 @@
 ) %7B%0A
-        // Inflate the menu; this adds items to the action bar if it is present.%0A
     
@@ -2010,287 +2010,35 @@
     
-// Handle action bar item clicks here. The action bar will%0A        // automatically handle clicks on the Home/Up button, so long%0A        // as you specify a parent activity in AndroidManifest.xml.%0A        int id = item.getItemId();%0A%0A        //noinspection SimplifiableIfStatement
+int id = item.getItemId();%0A
 %0A   
@@ -2506,47 +2506,8 @@
  %7D%0A%0A
-    //Called when leaving the activity%0A
     
@@ -2650,53 +2650,8 @@
  %7D%0A%0A
-    // Called when returning to the activity%0A
     
@@ -2797,55 +2797,8 @@
  %7D%0A%0A
-    // Called before the activity is destroyed%0A
     
@@ -2946,9 +2946,5 @@
   %7D%0A
-%0A%0A%0A%7D%0A
+%7D

remove commented out code