// Path: sqliteDBDemo/app/src/main/java/edu/cs4730/sqlitedbdemo/db/mySQLiteHelper.java
// public class mySQLiteHelper extends SupportSQLiteOpenHelper.Callback {
// 
//     private static final String TAG = "mySQLiteHelper";
// 
//     //column names for the table.
//     public static final String KEY_NAME = "Name";
//     public static final String KEY_SCORE = "Score";
//     public static final String KEY_ROWID = "_id";   //required field for the cursorAdapter
// 
//     public static final String DATABASE_NAME = "myScore.db";
//     public static final String TABLE_NAME = "HighScore";
//     private static final int DATABASE_VERSION = 2;
// 
//     // Database creation sql statement
//     private static final String DATABASE_CREATE =
//         "CREATE TABLE " + TABLE_NAME + " (" +
//             KEY_ROWID + " integer PRIMARY KEY autoincrement," +  //this line is required for the cursorAdapter.
//             KEY_NAME + " TEXT, " +
//             KEY_SCORE + " INTEGER );";
// 
//     //required constructor with the super.
//     public mySQLiteHelper() {
//         super(DATABASE_VERSION);
//     }
// 
//     @Override
//     public void onCreate(SupportSQLiteDatabase db) {
//         //NOTE only called when the database is initial created!
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
//         //Called when the database version changes, Remember the constant from above.
//         Log.w(TAG, "Upgrading database from version " + oldVersion
//             + " to "
//             + newVersion + ", which will destroy all old data");
//         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
//         onCreate(db);
//     }
// 
// }


import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import edu.cs4730.sqlitedbdemo.db.mySQLiteHelper;
package edu.cs4730.sqlitedbdemo;



/**
 * this adapter is very similar to the adapters used for listview, except a ViewHolder is required
 * see http://developer.android.com/training/improving-layouts/smooth-scrolling.html
 * except instead having to implement a ViewHolder, it is implemented within
 * the adapter.
 */

public class myAdapter extends RecyclerView.Adapter<myAdapter.ViewHolder> {

    private Cursor mCursor;
    private int rowLayout;
    private Context mContext;

    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView myName, myScore;


        public ViewHolder(View itemView) {
            super(itemView);
            myName = itemView.findViewById(R.id.name);
            myScore = itemView.findViewById(R.id.score);
        }
    }

    //constructor
    public myAdapter(Cursor c, int rowLayout, Context context) {
        this.mCursor = c;
        this.rowLayout = rowLayout;
        this.mContext = context;
    }

    // Create new views (invoked by the layout manager)
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(v);
    }

    // Replace the contents of a view (invoked by the layout manager)
    @SuppressLint("Range")
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        //this assumes it's not called with a null mCursor, since i means there is a data.
        mCursor.moveToPosition(i);
        viewHolder.myName.setText(
// Path: sqliteDBDemo/app/src/main/java/edu/cs4730/sqlitedbdemo/db/mySQLiteHelper.java
// public class mySQLiteHelper extends SupportSQLiteOpenHelper.Callback {
// 
//     private static final String TAG = "mySQLiteHelper";
// 
//     //column names for the table.
//     public static final String KEY_NAME = "Name";
//     public static final String KEY_SCORE = "Score";
//     public static final String KEY_ROWID = "_id";   //required field for the cursorAdapter
// 
//     public static final String DATABASE_NAME = "myScore.db";
//     public static final String TABLE_NAME = "HighScore";
//     private static final int DATABASE_VERSION = 2;
// 
//     // Database creation sql statement
//     private static final String DATABASE_CREATE =
//         "CREATE TABLE " + TABLE_NAME + " (" +
//             KEY_ROWID + " integer PRIMARY KEY autoincrement," +  //this line is required for the cursorAdapter.
//             KEY_NAME + " TEXT, " +
//             KEY_SCORE + " INTEGER );";
// 
//     //required constructor with the super.
//     public mySQLiteHelper() {
//         super(DATABASE_VERSION);
//     }
// 
//     @Override
//     public void onCreate(SupportSQLiteDatabase db) {
//         //NOTE only called when the database is initial created!
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
//         //Called when the database version changes, Remember the constant from above.
//         Log.w(TAG, "Upgrading database from version " + oldVersion
//             + " to "
//             + newVersion + ", which will destroy all old data");
//         db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
//         onCreate(db);
//     }
// 
// }


// Path: sqliteDBDemo/app/src/main/java/edu/cs4730/sqlitedbdemo/myAdapter.java
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import edu.cs4730.sqlitedbdemo.db.mySQLiteHelper;

package edu.cs4730.sqlitedbdemo;



/**
 * this adapter is very similar to the adapters used for listview, except a ViewHolder is required
 * see http://developer.android.com/training/improving-layouts/smooth-scrolling.html
 * except instead having to implement a ViewHolder, it is implemented within
 * the adapter.
 */

public class myAdapter extends RecyclerView.Adapter<myAdapter.ViewHolder> {

    private Cursor mCursor;
    private int rowLayout;
    private Context mContext;

    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView myName, myScore;


        public ViewHolder(View itemView) {
            super(itemView);
            myName = itemView.findViewById(R.id.name);
            myScore = itemView.findViewById(R.id.score);
        }
    }

    //constructor
    public myAdapter(Cursor c, int rowLayout, Context context) {
        this.mCursor = c;
        this.rowLayout = rowLayout;
        this.mContext = context;
    }

    // Create new views (invoked by the layout manager)
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(rowLayout, viewGroup, false);
        return new ViewHolder(v);
    }

    // Replace the contents of a view (invoked by the layout manager)
    @SuppressLint("Range")
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        //this assumes it's not called with a null mCursor, since i means there is a data.
        mCursor.moveToPosition(i);
        viewHolder.myName.setText(
            mCursor.getString(mCursor.getColumnIndex(mySQLiteHelper.KEY_NAME))