<commit_before>/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package us.theparamountgroup.android.inventory;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.LoaderManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NavUtils;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.theparamountgroup.android.inventory.R;

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import us.theparamountgroup.android.inventory.data.ShellContract;

/**
 * Allows user to create a new shell or edit an existing one.
 */
public class EditorActivity extends AppCompatActivity implements
        LoaderManager.LoaderCallbacks<Cursor> {

    public static final String LOG_TAG = EditorActivity.class.getSimpleName();
    private static final int PICK_IMAGE_REQUEST = 0;
    private static final int REQUEST_IMAGE_CAPTURE = 1;
    // private static final String CAMERA_DIR = "/dcim/";
    private static final int MY_PERMISSIONS_REQUEST = 2;
    /**
     * Identifier for the shell data loader
     */
    private static final int EXISTING_SHELL_LOADER = 0;
    /**
     * constants for image requests
     */
// a static variable to get a reference of our application context
    public static Context contextOfApplication;
    String mCurrentPhotoPath;
    /**
     * Content URI for the existing shell (null if it's a new shell)
     */
    private Uri mCurrentShellUri;
    /**
     * EditText field to enter the shell's name
     */
    private EditText mNameEditText;
    /**
     * EditText field to enter the shell's color
     */
    private EditText mColorEditText;
    /**
     * EditText field to enter if the shell has a hole
     */
    private Spinner mHoleSpinner;
    /**
     * EditText field to enter the type shell
     */
    private Spinner mTypeSpinner;
    /**
     * If the shell has hole. The possible valid values are in the ShellContract.java file:
     * {@link ShellContract.ShellEntry#HOLE_UNKNOWN}, {@link ShellContract.ShellEntry#HOLE}, or
     * {@link ShellContract.ShellEntry#NO_HOLE}.
     */
    private int mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
    /**
     * Type of Shell. The possible valid values are in the ShellContract.java file:
     * {@link ShellContract.ShellEntry#TYPE_SCALLOP}, {@link ShellContract.ShellEntry#TYPE_JINGLE},
     * {@link ShellContract.ShellEntry#TYPE_SLIPPER},{@link ShellContract.ShellEntry#TYPE_SHARD}.
     */
    private int mType = ShellContract.ShellEntry.TYPE_SCALLOP;
    /**
     * Boolean flag that keeps track of whether the shell has been edited (true) or not (false)
     */
    private boolean mShellHasChanged = false;
    private ImageView mImageView;
    private Button mButtonTakePicture;
    private Uri mUri;
    private Bitmap mBitmap;
    private boolean isGalleryPicture = false;
    /**
     * OnTouchListener that listens for any user touches on a View, implying that they are modifying
     * the view, and we change the mShellHasChanged boolean to true.
     */
    private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mShellHasChanged = true;
            return false;
        }
    };

    public static Context getContextOfApplication() {
        return contextOfApplication;
    }

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

        contextOfApplication = getApplicationContext();
        setContentView(R.layout.activity_editor);

        // Examine the intent that was used to launch this activity,
        // in order to figure out if we're creating a new shell or editing an existing one.
        Intent intent = getIntent();
        mCurrentShellUri = intent.getData();

        // If the intent DOES NOT contain a shell content URI, then we know that we are
        // creating a new shell.
        if (mCurrentShellUri == null) {
            // This is a new shell, so change the app bar to say "Add a Shell"
            setTitle(getString(R.string.editor_activity_title_new_pet));

            // Invalidate the options menu, so the "Delete" menu option can be hidden.
            // (It doesn't make sense to delete a shell that hasn't been created yet.)
            invalidateOptionsMenu();
        } else {
            // Otherwise this is an existing shell, so change app bar to say "Edit Shell"
            setTitle(getString(R.string.editor_activity_title_edit_pet));

            // Initialize a loader to read the shell data from the database
            // and display the current values in the editor
            getLoaderManager().initLoader(EXISTING_SHELL_LOADER, null, this);
        }

        // Find all relevant views that we will need to read user input from
        mNameEditText = (EditText) findViewById(R.id.edit_shell_name);
        mColorEditText = (EditText) findViewById(R.id.edit_shell_color);

        mHoleSpinner = (Spinner) findViewById(R.id.spinner_hole);
        mTypeSpinner = (Spinner) findViewById(R.id.spinner_type);

        // Setup OnTouchListeners on all the input fields, so we can determine if the user
        // has touched or modified them. This will let us know if there are unsaved changes
        // or not, if the user tries to leave the editor without saving.
        mNameEditText.setOnTouchListener(mTouchListener);
        mColorEditText.setOnTouchListener(mTouchListener);
        mHoleSpinner.setOnTouchListener(mTouchListener);
        mTypeSpinner.setOnTouchListener(mTouchListener);

/*      The view tree observer can be used to get notifications when global events, like layout, happen.
*       The returned ViewTreeObserver observer is not guaranteed to remain valid for the lifetime of this View.
*/
        mImageView = (ImageView) findViewById(R.id.image);
        ViewTreeObserver viewTreeObserver = mImageView.getViewTreeObserver();
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Log.i(LOG_TAG, " in onGlobalLayout trying to get image to appear");
                mImageView.setImageResource(R.drawable.ic_empty_shelter);
                mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
               // mImageView.setImageBitmap(getBitmapFromUri(mUri));
            }
        });
        mButtonTakePicture = (Button) findViewById(R.id.take_photo);
        mButtonTakePicture.setEnabled(false);

        requestPermissions();
        setupHoleSpinner();
        setupTypeSpinner();
    }

    /**
     * Setup the dropdown spinner that allows the user to select if the shell has a hole.
     */
    private void setupHoleSpinner() {
        // Create adapter for spinner. The list options are from the String array it will use
        // the spinner will use the default layout
        ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this,
                R.array.array_hole_options, android.R.layout.simple_spinner_item);

        // Specify dropdown layout style - simple list view with 1 item per line
        genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

        // Apply the adapter to the spinner
        mHoleSpinner.setAdapter(genderSpinnerAdapter);

        // Set the integer mSelected to the constant values
        mHoleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String selection = (String) parent.getItemAtPosition(position);
                if (!TextUtils.isEmpty(selection)) {
                    if (selection.equals(getString(R.string.no_hole))) {
                        mHole = ShellContract.ShellEntry.HOLE;
                    } else if (selection.equals(getString(R.string.hole))) {
                        mHole = ShellContract.ShellEntry.NO_HOLE;
                    } else {
                        mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
                    }
                }
            }

            // Because AdapterView is an abstract class, onNothingSelected must be defined
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
            }
        });
    }

    /**
     * Setup the dropdown spinner that allows the user to select the type of shell.
     */
    private void setupTypeSpinner() {
        // Create adapter for spinner. The list options are from the String array it will use
        // the spinner will use the default layout
        ArrayAdapter typeSpinnerAdapter = ArrayAdapter.createFromResource(this,
                R.array.array_type_options, android.R.layout.simple_spinner_item);

        // Specify dropdown layout style - simple list view with 1 item per line
        typeSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

        // Apply the adapter to the spinner
        mTypeSpinner.setAdapter(typeSpinnerAdapter);

        // Set the integer mSelected to the constant values
        mTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String selection = (String) parent.getItemAtPosition(position);
                if (!TextUtils.isEmpty(selection)) {
                    if (selection.equals(getString(R.string.type_scallop))) {
                        mType = ShellContract.ShellEntry.TYPE_SCALLOP;
                    } else if (selection.equals(getString(R.string.type_jingle))) {
                        mType = ShellContract.ShellEntry.TYPE_JINGLE;
                    } else if (selection.equals(getString(R.string.type_slipper))) {
                        mType = ShellContract.ShellEntry.TYPE_SLIPPER;
                    } else {

                        mType = ShellContract.ShellEntry.TYPE_SHARD;
                        Log.i(LOG_TAG, " In type spinner and assigned mType to shard: " + mType);
                    }
                }
            }

            // Because AdapterView is an abstract class, onNothingSelected must be defined
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                mType = ShellContract.ShellEntry.TYPE_SCALLOP;
            }
        });
    }

    /**
     * Get user input from editor and save pet into database.
     */
    private void saveShell() {
        Log.i(LOG_TAG, " in saveShell: ");
        // Read from input fields
        // Use trim to eliminate leading or trailing white space
        String nameString = mNameEditText.getText().toString().trim();
        String colorString = mColorEditText.getText().toString().trim();
        String photoString;


        // Check if this is supposed to be a new shell
        // and check if all the fields in the editor are blank
        if (mCurrentShellUri == null &&
                TextUtils.isEmpty(nameString) && TextUtils.isEmpty(colorString) && mHole == ShellContract.ShellEntry.HOLE_UNKNOWN) {
            // Since no fields were modified, we can return early without creating a new shell.
            // No need to create ContentValues and no need to do any ContentProvider operations.
            return;
        }
        if (mUri != null) {
            Log.i(LOG_TAG, " Lets see what mUri has for us: " + mUri);
            photoString = mUri.toString();
            Log.i(LOG_TAG, " Lets see what photoString has for us: " + photoString);
        } else {
            photoString = "";
        }
        Log.i(LOG_TAG, " Lets see what photoString has for us after if: " + photoString);
        // Create a ContentValues object where column names are the keys,
        // and pet attributes from the editor are the values.
        ContentValues values = new ContentValues();
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_NAME, nameString);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_COLOR, colorString);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_HOLE, mHole);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_TYPE, mType);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_PHOTO, photoString);


        // Determine if this is a new or existing shell by checking if mCurrentShellUri is null or not
        if (mCurrentShellUri == null) {
            // This is a NEW shell, so insert a new shell into the provider,
            // returning the content URI for the new shell.
            Uri newUri = getContentResolver().insert(ShellContract.ShellEntry.CONTENT_URI, values);

            // Show a toast message depending on whether or not the insertion was successful.
            if (newUri == null) {
                // If the new content URI is null, then there was an error with insertion.
                Toast.makeText(this, getString(R.string.editor_insert_pet_failed),
                        Toast.LENGTH_SHORT).show();
            } else {
                // Otherwise, the insertion was successful and we can display a toast.<commit_msg>Working version full function. Working on getting a thumbnail.<commit_after>/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package us.theparamountgroup.android.inventory;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.LoaderManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NavUtils;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.theparamountgroup.android.inventory.R;

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import us.theparamountgroup.android.inventory.data.ShellContract;

/**
 * Allows user to create a new shell or edit an existing one.
 */
public class EditorActivity extends AppCompatActivity implements
        LoaderManager.LoaderCallbacks<Cursor> {

    public static final String LOG_TAG = EditorActivity.class.getSimpleName();
    private static final int PICK_IMAGE_REQUEST = 0;
    private static final int REQUEST_IMAGE_CAPTURE = 1;
    // private static final String CAMERA_DIR = "/dcim/";
    private static final int MY_PERMISSIONS_REQUEST = 2;
    /**
     * Identifier for the shell data loader
     */
    private static final int EXISTING_SHELL_LOADER = 0;
    /**
     * constants for image requests
     */
// a static variable to get a reference of our application context
    public static Context contextOfApplication;
    String mCurrentPhotoPath;
    /**
     * Content URI for the existing shell (null if it's a new shell)
     */
    private Uri mCurrentShellUri;
    /**
     * EditText field to enter the shell's name
     */
    private EditText mNameEditText;
    /**
     * EditText field to enter the shell's color
     */
    private EditText mColorEditText;
    /**
     * EditText field to enter if the shell has a hole
     */
    private Spinner mHoleSpinner;
    /**
     * EditText field to enter the type shell
     */
    private Spinner mTypeSpinner;
    /**
     * If the shell has hole. The possible valid values are in the ShellContract.java file:
     * {@link ShellContract.ShellEntry#HOLE_UNKNOWN}, {@link ShellContract.ShellEntry#HOLE}, or
     * {@link ShellContract.ShellEntry#NO_HOLE}.
     */
    private int mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
    /**
     * Type of Shell. The possible valid values are in the ShellContract.java file:
     * {@link ShellContract.ShellEntry#TYPE_SCALLOP}, {@link ShellContract.ShellEntry#TYPE_JINGLE},
     * {@link ShellContract.ShellEntry#TYPE_SLIPPER},{@link ShellContract.ShellEntry#TYPE_SHARD}.
     */
    private int mType = ShellContract.ShellEntry.TYPE_SCALLOP;
    /**
     * Boolean flag that keeps track of whether the shell has been edited (true) or not (false)
     */
    private boolean mShellHasChanged = false;
    private ImageView mImageView;
    private Button mButtonTakePicture;
    private Uri mUri;
    private Bitmap mBitmap;
    private boolean isGalleryPicture = false;
    /**
     * OnTouchListener that listens for any user touches on a View, implying that they are modifying
     * the view, and we change the mShellHasChanged boolean to true.
     */
    private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mShellHasChanged = true;
            return false;
        }
    };

    public static Context getContextOfApplication() {
        return contextOfApplication;
    }

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

        contextOfApplication = getApplicationContext();
        setContentView(R.layout.activity_editor);

        // Examine the intent that was used to launch this activity,
        // in order to figure out if we're creating a new shell or editing an existing one.
        Intent intent = getIntent();
        mCurrentShellUri = intent.getData();

        // If the intent DOES NOT contain a shell content URI, then we know that we are
        // creating a new shell.
        if (mCurrentShellUri == null) {
            // This is a new shell, so change the app bar to say "Add a Shell"
            setTitle(getString(R.string.editor_activity_title_new_pet));

            // Invalidate the options menu, so the "Delete" menu option can be hidden.
            // (It doesn't make sense to delete a shell that hasn't been created yet.)
            invalidateOptionsMenu();
        } else {
            // Otherwise this is an existing shell, so change app bar to say "Edit Shell"
            setTitle(getString(R.string.editor_activity_title_edit_pet));

            // Initialize a loader to read the shell data from the database
            // and display the current values in the editor
            getLoaderManager().initLoader(EXISTING_SHELL_LOADER, null, this);
        }

        // Find all relevant views that we will need to read user input from
        mNameEditText = (EditText) findViewById(R.id.edit_shell_name);
        mColorEditText = (EditText) findViewById(R.id.edit_shell_color);

        mHoleSpinner = (Spinner) findViewById(R.id.spinner_hole);
        mTypeSpinner = (Spinner) findViewById(R.id.spinner_type);

        // Setup OnTouchListeners on all the input fields, so we can determine if the user
        // has touched or modified them. This will let us know if there are unsaved changes
        // or not, if the user tries to leave the editor without saving.
        mNameEditText.setOnTouchListener(mTouchListener);
        mColorEditText.setOnTouchListener(mTouchListener);
        mHoleSpinner.setOnTouchListener(mTouchListener);
        mTypeSpinner.setOnTouchListener(mTouchListener);

/*      The view tree observer can be used to get notifications when global events, like layout, happen.
*       The returned ViewTreeObserver observer is not guaranteed to remain valid for the lifetime of this View.
*/
        mImageView = (ImageView) findViewById(R.id.image);
        ViewTreeObserver viewTreeObserver = mImageView.getViewTreeObserver();
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Log.i(LOG_TAG, " in onGlobalLayout trying to get image to appear");
                mImageView.setImageResource(R.drawable.ic_empty_shelter);
                mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
               // mImageView.setImageBitmap(getBitmapFromUri(mUri));
            }
        });
        mButtonTakePicture = (Button) findViewById(R.id.take_photo);
        mButtonTakePicture.setEnabled(false);

        requestPermissions();
        setupHoleSpinner();
        setupTypeSpinner();
    }

    /**
     * Setup the dropdown spinner that allows the user to select if the shell has a hole.
     */
    private void setupHoleSpinner() {
        // Create adapter for spinner. The list options are from the String array it will use
        // the spinner will use the default layout
        ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this,
                R.array.array_hole_options, android.R.layout.simple_spinner_item);

        // Specify dropdown layout style - simple list view with 1 item per line
        genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

        // Apply the adapter to the spinner
        mHoleSpinner.setAdapter(genderSpinnerAdapter);

        // Set the integer mSelected to the constant values
        mHoleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String selection = (String) parent.getItemAtPosition(position);
                if (!TextUtils.isEmpty(selection)) {
                    if (selection.equals(getString(R.string.no_hole))) {
                        mHole = ShellContract.ShellEntry.HOLE;
                    } else if (selection.equals(getString(R.string.hole))) {
                        mHole = ShellContract.ShellEntry.NO_HOLE;
                    } else {
                        mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
                    }
                }
            }

            // Because AdapterView is an abstract class, onNothingSelected must be defined
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                mHole = ShellContract.ShellEntry.HOLE_UNKNOWN;
            }
        });
    }

    /**
     * Setup the dropdown spinner that allows the user to select the type of shell.
     */
    private void setupTypeSpinner() {
        // Create adapter for spinner. The list options are from the String array it will use
        // the spinner will use the default layout
        ArrayAdapter typeSpinnerAdapter = ArrayAdapter.createFromResource(this,
                R.array.array_type_options, android.R.layout.simple_spinner_item);

        // Specify dropdown layout style - simple list view with 1 item per line
        typeSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

        // Apply the adapter to the spinner
        mTypeSpinner.setAdapter(typeSpinnerAdapter);

        // Set the integer mSelected to the constant values
        mTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String selection = (String) parent.getItemAtPosition(position);
                if (!TextUtils.isEmpty(selection)) {
                    if (selection.equals(getString(R.string.type_scallop))) {
                        mType = ShellContract.ShellEntry.TYPE_SCALLOP;
                    } else if (selection.equals(getString(R.string.type_jingle))) {
                        mType = ShellContract.ShellEntry.TYPE_JINGLE;
                    } else if (selection.equals(getString(R.string.type_slipper))) {
                        mType = ShellContract.ShellEntry.TYPE_SLIPPER;
                    } else {

                        mType = ShellContract.ShellEntry.TYPE_SHARD;
                        Log.i(LOG_TAG, " In type spinner and assigned mType to shard: " + mType);
                    }
                }
            }

            // Because AdapterView is an abstract class, onNothingSelected must be defined
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                mType = ShellContract.ShellEntry.TYPE_SCALLOP;
            }
        });
    }

    /**
     * Get user input from editor and save pet into database.
     */
    private void saveShell() {
        Log.i(LOG_TAG, " in saveShell: ");
        // Read from input fields
        // Use trim to eliminate leading or trailing white space
        String nameString = mNameEditText.getText().toString().trim();
        String colorString = mColorEditText.getText().toString().trim();
        String photoString;


        // Check if this is supposed to be a new shell
        // and check if all the fields in the editor are blank
        if (mCurrentShellUri == null &&
                TextUtils.isEmpty(nameString) && TextUtils.isEmpty(colorString) && mHole == ShellContract.ShellEntry.HOLE_UNKNOWN) {
            // Since no fields were modified, we can return early without creating a new shell.
            // No need to create ContentValues and no need to do any ContentProvider operations.
            return;
        }
        if (mUri != null) {
            Log.i(LOG_TAG, "in Save shell Lets see what mUri has for us: " + mUri);
            photoString = mUri.toString();
            Log.i(LOG_TAG, " Lets see what photoString has for us: " + photoString);
        } else {
            photoString = "";
        }
        Log.i(LOG_TAG, " Lets see what photoString has for us after if: " + photoString);
        // Create a ContentValues object where column names are the keys,
        // and pet attributes from the editor are the values.
        ContentValues values = new ContentValues();
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_NAME, nameString);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_COLOR, colorString);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_HOLE, mHole);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_TYPE, mType);
        values.put(ShellContract.ShellEntry.COLUMN_SHELL_PHOTO, photoString);


        // Determine if this is a new or existing shell by checking if mCurrentShellUri is null or not
        if (mCurrentShellUri == null) {
            // This is a NEW shell, so insert a new shell into the provider,
            // returning the content URI for the new shell.
            Uri newUri = getContentResolver().insert(ShellContract.ShellEntry.CONTENT_URI, values);

            // Show a toast message depending on whether or not the insertion was successful.
            if (newUri == null) {
                // If the new content URI is null, then there was an error with insertion.
                Toast.makeText(this, getString(R.string.editor_insert_pet_failed),
                        Toast.LENGTH_SHORT).show();
            } else {
                // Otherwise, the insertion was successful and we can display a toast.
{'fraction_non_alphanumeric': 0.0773240087088474, 'fraction_numerical': 0.0013854984495612589, 'mean_word_length': 2.6318437762070204, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3525568', 'n_tokens_mistral': 7918, 'n_tokens_neox': 7700, 'n_words': 2484}