package com.upmoon.alex.campchamptrivia;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class HighScoreActivity extends AppCompatActivity {

    private int[] mHighScores = new int[10];

    private int mPlayerScore, mQuizID;

    private static final String TAG = "HIGH SCORE ACTIVITY";

    private static final String EXTRA_QUIZ_NUMBER =
            "com.upmoon.alex.campchamptrivia.quiz_number";

    private static final String PLAYER_SCORE =
            "com.upmoon.alex.campchamptrivia.player_score";

    private Button mShareScore;

    public static Intent newIntent(Context packageContext, int quizNum, int newScore){
        Intent i = new Intent(packageContext, QuizActivity.class);
        i.putExtra(EXTRA_QUIZ_NUMBER,quizNum);
        i.putExtra(PLAYER_SCORE, newScore);
        return i;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_high_score);
        Log.d(TAG, "HighScoreActivity onCreate() called");

        mShareScore = (Button) findViewById(R.id.shareButton);

        mPlayerScore = Integer.parseInt(PLAYER_SCORE);

        mQuizID = Integer.parseInt(EXTRA_QUIZ_NUMBER);




        mShareScore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String mShareMessage = "I just scored a " + Integer.toString(mPlayerScore) + " on quiz " + Integer.toString(mQuizID) + " in CampChampTrivia!";
                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("text/plain"); // might be text, sound, whatever
                share.putExtra(Intent.EXTRA_STREAM, mShareMessage);
                startActivity(Intent.createChooser(share, "share"));
            }
        });
    }

    private int[] getExistingHighScores() {
        int[] highScores = new int[10];

        // Load high scores from memory.

        return highScores;
    }

    private void setNewHighScore(int[] scores) {
        for (int i = 0; i < 10; i++) {
            // write scores[i] to memory.
        }
        return;
    }
}

@@ -255,16 +255,147 @@
 utton;%0A%0A
+import java.io.BufferedReader;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.InputStreamReader;%0A%0A
 public c
@@ -1522,16 +1522,63 @@
 MBER);%0A%0A
+        mHighScores = getExistingHighScores();%0A
 %0A%0A%0A     
@@ -2183,130 +2183,1312 @@
     
-private int%5B%5D getExistingHighScores() %7B%0A        int%5B%5D highScores = new int%5B10%5D;%0A%0A        // Load high scores from memory.%0A
+@Override%0A    protected void onStop() %7B%0A        super.onStop();%0A        Log.d(TAG, %22onStop() called%22);%0A        setHighScores(mHighScores);%0A    %7D%0A%0A    private int%5B%5D getExistingHighScores() %7B%0A        int%5B%5D highScores = new int%5B10%5D;%0A        FileInputStream fis;%0A%0A        // High scores are stored in a file highScores.txt%0A        String FILENAME = %22highScores%22;%0A%0A        // Try to open highScores.txt in a FileInputStream%0A        try %7B%0A            fis = openFileInput(FILENAME);%0A%0A            if(fis != null) %7B%0A                InputStreamReader inputStreamReader = new InputStreamReader(fis);%0A                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);%0A                String receptacle = %22%22;%0A%0A                // Load high scores from memory.%0A                for (int i = 0; i %3C 10; i++) %7B%0A                    if((receptacle = bufferedReader.readLine()) != null) %7B%0A                        highScores%5Bi%5D = Integer.parseInt(receptacle);%0A                    %7D else %7B%0A                        highScores%5Bi%5D = 0;%0A                    %7D%0A                %7D%0A%0A                // Close inputFileStream%0A                fis.close();%0A            %7D%0A        %7D catch (Exception exception) %7B%0A            Log.d(TAG, %22Error: Unable to open file, FILENAME%22);%0A        %7D%0A%0A        // Return highScores array
 %0A   
@@ -3542,11 +3542,8 @@
  set
-New
 High
@@ -3547,16 +3547,17 @@
 ighScore
+s
 (int%5B%5D s
@@ -3561,24 +3561,54 @@
 %5D scores) %7B%0A
+        FileOutputStream fos;%0A
         for 

Implement getExistingHighScores()