ContourDatabase

com.j0h1.contour.database

## Class ContourDatabase

- java.lang.Object
- - com.j0h1.contour.database.ContourDatabase

-     public class ContourDatabase
      extends java.lang.Object

  This class contains all methods to access or modify data of the local SQLite database.
  Author:
    Johannes Riedmann

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static java.lang.String` | `DATABASE_NAME`
    `private static int` | `DATABASE_VERSION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ContourDatabase(Context context)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `deletePathsForDrawing(int imageId)` Deletes all paths assigned to a drawing.
    `void` | `deletePlayer()` Deletes the locally persisted player.
    `void` | `discardSession()` Wipes all data from the local database, except for the player data.
    `Player` | `findPlayer()` Retrieve the locally persisted player.
    `java.util.ArrayList<ImagePojo>` | `getCurrentCustomImageData()` Returns the image data of a custom session.
    `double` | `getCurrentScore()` Returns the sum of the locally persisted score images.
    `java.lang.Integer` | `getCurrentTrackId()` Returns the trackId of the current track session.
    `java.util.ArrayList<ImagePojo>` | `getDrawings()` Returns all drawings persisted locally.
    `Image` | `getImageAtPosition(int position)` Returns an edge image at a specific position.
    `int` | `getImageCount()` Returns the total amount of edge images stores in the local database.
    `Image` | `getLastImage()` Returns the latest image that has no drawing assigned to it, which is the last image that the user had opened in the game.
    `java.util.ArrayList<CustomPath>` | `getPathListForImage(int imageId)` Returns a list of CustomPath objects (= serializable Path objects) for a given image.
    `int` | `getRecentScreenOrientation()` Returns the recent screen orientation of the session.
    `java.util.ArrayList<ImagePojo>` | `getScoreImages()` Returns all score images persisted locally.
    `int` | `getSessionCount()` This method is meant to check if there is currently an ongoing session.
    `int` | `persistDrawing(int imageId, Bitmap drawing)` Stores a drawing in the local database.
    `void` | `persistPlayer(Player player)` Persists a player locally.
    `void` | `persistScoreImage(int drawingId, double score, Bitmap scoreImage)` Stores a score image in the local database.
    `void` | `startCustomSession(int playerId, Image edgeImage, byte[] originalData)` Creates a local custom session and stores the edge image, as well as the original image data locally.
    `void` | `startTrackSession(int playerId, int trackId, java.util.List<ImagePojo> edgeImages)` Creates a local track session and stores all edge images of a given track.
    `void` | `updateDrawing(int imageId, java.util.ArrayList<CustomPath> paths)` Updates a user drawing, represented by a list of paths, for an image with the given imageId.
    `void` | `updateRecentScreenOrientation(int orientation)` Updates the recent screen orientation of the session.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DATABASE_NAME

          private static final java.lang.String DATABASE_NAME

      See Also:
        Constant Field Values

    - #### DATABASE_VERSION

          private static final int DATABASE_VERSION

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ContourDatabase

          public ContourDatabase(Context context)

  - ### Method Detail

    - #### startTrackSession

          public void startTrackSession(int playerId,
                                        int trackId,
                                        java.util.List<ImagePojo> edgeImages)

      Creates a local track session and stores all edge images of a given track.
      Parameters:
        `playerId` - ID if player that starts the session.
        `trackId` - ID of track that is assigned to the session.
        `edgeImages` - Edge images of the given track.

    - #### startCustomSession

          public void startCustomSession(int playerId,
                                         Image edgeImage,
                                         byte[] originalData)

      Creates a local custom session and stores the edge image, as well as the original image data locally.
      Parameters:
        `playerId` - ID of player that starts the session.
        `edgeImage` - Generated edge image data.
        `originalData` - Original image data of the selected image.

    - #### getSessionCount

          public int getSessionCount()

      This method is meant to check if there is currently an ongoing session.
      Returns:
        Amount of sessions currently persisted in the local database. This should be either 0 or 1, because the database is always cleaned up after a session is finished or discarded.

    - #### getImageCount

          public int getImageCount()

      Returns the total amount of edge images stores in the local database.
      Returns:
        Amount of edge images in local database.

    - #### getCurrentScore

          public double getCurrentScore()

      Returns the sum of the locally persisted score images. This is equal to the currently reached score in an ongoing session.
      Returns:
        Sum of scores assigned to score images.

    - #### getImageAtPosition

          public Image getImageAtPosition(int position)

      Returns an edge image at a specific position.
      Parameters:
        `position` - Position of edge image in the current track (or custom session).
      Returns:
        Edge image at the given position.

    - #### getCurrentCustomImageData

          public java.util.ArrayList<ImagePojo> getCurrentCustomImageData()

      Returns the image data of a custom session.
      Returns:
        Image data of current custom session.

    - #### getLastImage

          public Image getLastImage()

      Returns the latest image that has no drawing assigned to it, which is the last image that the user had opened in the game. If the drawing session was already over as the user closed the application, null is returned.
      Returns:
        Last image with no drawing assigned.

    - #### getPathListForImage

          public java.util.ArrayList<CustomPath> getPathListForImage(int imageId)

      Returns a list of CustomPath objects (= serializable Path objects) for a given image.
      Parameters:
        `imageId` - ImageId to get paths from.
      Returns:
        List of CustomPath object persisted for the image with the given imageId.

    - #### updateDrawing

          public void updateDrawing(int imageId,
                                    java.util.ArrayList<CustomPath> paths)

      Updates a user drawing, represented by a list of paths, for an image with the given imageId.
      Parameters:
        `imageId` - ImageId of the image, whose drawing gets updated.
        `paths` - Updated drawing information, stored in a list of serializable Path objects.

    - #### deletePathsForDrawing

          public void deletePathsForDrawing(int imageId)

      Deletes all paths assigned to a drawing.
      Parameters:
        `imageId` - ImageId, the drawing is associated with.

    - #### persistDrawing

          public int persistDrawing(int imageId,
                                    Bitmap drawing)

      Stores a drawing in the local database.
      Parameters:
        `imageId` - ImageId of the image that needs to be persisted.
        `drawing` - Drawing data as Bitmap objects that needs to be persisted.
      Returns:
        Generated drawingId.

    - #### persistScoreImage

          public void persistScoreImage(int drawingId,
                                        double score,
                                        Bitmap scoreImage)

      Stores a score image in the local database.
      Parameters:
        `drawingId` - ID of the drawing the score image is assigned to.
        `score` - Score that was achieved for the drawing.
        `scoreImage` - Score image data as Bitmap objects that needs to be persisted.

    - #### discardSession

          public void discardSession()

      Wipes all data from the local database, except for the player data. That means session data, image data that belongs to this session and path data that is assigned to a specific drawing.

    - #### getCurrentTrackId

          public java.lang.Integer getCurrentTrackId()

      Returns the trackId of the current track session.
      Returns:
        TrackId of current track in drawing session.

    - #### getDrawings

          public java.util.ArrayList<ImagePojo> getDrawings()

      Returns all drawings persisted locally. Image data gets base64 encoded.
      Returns:
        List of drawings for the current session.

    - #### getScoreImages

          public java.util.ArrayList<ImagePojo> getScoreImages()

      Returns all score images persisted locally. Image data gets base64 encoded.
      Returns:
        List of score images for the current session.

    - #### findPlayer

          public Player findPlayer()

      Retrieve the locally persisted player. Only one player can be persisted locally at one time.
      Returns:
        Player objects that represents the locally persisted player.

    - #### persistPlayer

          public void persistPlayer(Player player)

      Persists a player locally.
      Parameters:
        `player` - Player to be persisted locally.

    - #### deletePlayer

          public void deletePlayer()

      Deletes the locally persisted player.

    - #### updateRecentScreenOrientation

          public void updateRecentScreenOrientation(int orientation)

      Updates the recent screen orientation of the session.
      Parameters:
        `orientation` - 1 = portrait mode; 2 = landscape mode

    - #### getRecentScreenOrientation

          public int getRecentScreenOrientation()

      Returns the recent screen orientation of the session.
      Returns:
        1 = portrait mode, 2 = landscape mode