package anabalica.github.io.meowletters;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


/**
 * This is the Game Over activity. When there are no more free spots for letters to appear, the
 * game ends.
 *
 * @author Ana Balica
 */
public class GameOverActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_over);
        Intent intent = getIntent();
        String score = intent.getStringExtra(GameActivity.SCORE);

        TextView finalScore = (TextView) findViewById(R.id.finalScore);
        finalScore.setText("Score " + score);
    }


    @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_game_over, 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) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * Launch menu on 'Back' press
     */
    public void onBackPressed() {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.startActivity(intent);
    }

    /**
     * Start a new game
     */
    public void startNewGame(View view) {
        Intent intent = new Intent(this, GameActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.startActivity(intent);
    }
}

@@ -87,22 +87,107 @@
 content.
-Intent
+ContentValues;%0Aimport android.content.Intent;%0Aimport android.database.sqlite.SQLiteDatabase
 ;%0Aimport
@@ -321,16 +321,151 @@
 tView;%0A%0A
+import anabalica.github.io.meowletters.storage.HighscoresContract;%0Aimport anabalica.github.io.meowletters.storage.HighscoresDbHelper;%0A%0A
 %0A/**%0A * 
@@ -1035,24 +1035,108 @@
  %22 + score);
+%0A%0A        int points = Integer.parseInt(score);%0A        insertNewHighscrore(points);
 %0A    %7D%0A%0A%0A   
@@ -2418,32 +2418,32 @@
 VITY_NEW_TASK);%0A
-
         this.sta
@@ -2467,11 +2467,830 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Insert into the database highscores table a new entry. Games that have accumulated 0 points,%0A     * are not inserted.%0A     *%0A     * @param score int amount of game points%0A     */%0A    private void insertNewHighscrore(int score) %7B%0A        if (score %3E 0) %7B%0A            HighscoresDbHelper highscoresDbHelper = new HighscoresDbHelper(this);%0A            SQLiteDatabase db = highscoresDbHelper.getWritableDatabase();%0A%0A            ContentValues values = new ContentValues();%0A            values.put(HighscoresContract.HighscoreEntry.COLUMN_NAME_USERNAME, %22dummy username%22);%0A            values.put(HighscoresContract.HighscoreEntry.COLUMN_NAME_SCORE, score);%0A%0A            db.insert(HighscoresContract.HighscoreEntry.TABLE_NAME, null, values);%0A            System.out.println(%22Inserted the entry%22);%0A        %7D%0A    %7D
 %0A%7D%0A

store game score on game over