@@ -0,0 +1,3300 @@
+package eu.redray.trevie.database;%0A%0Aimport android.content.Context;%0Aimport android.database.sqlite.SQLiteDatabase;%0Aimport android.database.sqlite.SQLiteOpenHelper;%0A%0Aimport eu.redray.trevie.database.MoviesContract.MoviesEntry;%0Aimport eu.redray.trevie.database.MoviesContract.TrailersEntry;%0Aimport eu.redray.trevie.database.MoviesContract.ReviewsEntry;%0A%0A/**%0A * Manages a local database for movies data.%0A */%0Apublic class MoviesDbHelper extends SQLiteOpenHelper %7B%0A%0A    // If you change the database schema, you must increment the database version.%0A    private static final int DATABASE_VERSION = 1;%0A%0A    static final String DATABASE_NAME = %22movies.db%22;%0A%0A    public MoviesDbHelper(Context context) %7B%0A        super(context, DATABASE_NAME, null, DATABASE_VERSION);%0A    %7D%0A%0A    @Override%0A    public void onCreate(SQLiteDatabase sqLiteDatabase) %7B%0A        // Create Movies table%0A        final String SQL_CREATE_MOVIES_TABLE = %22CREATE TABLE %22 + MoviesEntry.TABLE_NAME + %22 (%22 +%0A                // Movie ID fetched from TheMovieDB%0A                MoviesEntry._ID + %22 INTEGER PRIMARY KEY,%22 +%0A                MoviesEntry.COLUMN_TITLE + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_RELEASE_DATE + %22 TEXT NOT NULL,%22 +%0A                MoviesEntry.COLUMN_AVG_RATING + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_SYNOPSIS + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_POSTER_PATH + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_RUNTIME + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_GENRES + %22 TEXT NOT NULL, %22 +%0A                MoviesEntry.COLUMN_COUNTRIES + %22 TEXT NOT NULL)%22;%0A%0A        sqLiteDatabase.execSQL(SQL_CREATE_MOVIES_TABLE);%0A%0A        // Create trailers table%0A        final String SQL_CREATE_TRAILERS_TABLE = %22CREATE TABLE %22 + TrailersEntry.TABLE_NAME + %22 (%22 +%0A                TrailersEntry._ID + %22 INTEGER PRIMARY KEY AUTOINCREMENT, %22 +%0A                // The id of a movie associated with this trailer%0A                TrailersEntry.COLUMN_MOVIE_KEY + %22 INTEGER NOT NULL, %22 +%0A                TrailersEntry.COLUMN_URL + %22 TEXT UNIQUE NOT NULL, %22 +%0A                // Set up the location column as a foreign key to location table.%0A                %22 FOREIGN KEY (%22 + TrailersEntry.COLUMN_MOVIE_KEY + %22) REFERENCES %22 +%0A                MoviesEntry.TABLE_NAME + %22 (%22 + MoviesEntry._ID +%0A                %22));%22;%0A%0A        sqLiteDatabase.execSQL(SQL_CREATE_TRAILERS_TABLE);%0A%0A        // Create reviews table%0A        final String SQL_CREATE_REVIEWS_TABLE = %22CREATE TABLE %22 + ReviewsEntry.TABLE_NAME + %22 (%22 +%0A                ReviewsEntry._ID + %22 INTEGER PRIMARY KEY AUTOINCREMENT, %22 +%0A                // The id of a movie associated with this trailer%0A                ReviewsEntry.COLUMN_MOVIE_KEY + %22 INTEGER NOT NULL, %22 +%0A                ReviewsEntry.COLUMN_REVIEW + %22 TEXT UNIQUE NOT NULL, %22 +%0A                // Set up the location column as a foreign key to location table.%0A                %22 FOREIGN KEY (%22 + ReviewsEntry.COLUMN_MOVIE_KEY + %22) REFERENCES %22 +%0A                MoviesEntry.TABLE_NAME + %22 (%22 + MoviesEntry._ID +%0A                %22));%22;%0A%0A        sqLiteDatabase.execSQL(SQL_CREATE_REVIEWS_TABLE);%0A    %7D%0A%0A    @Override%0A    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) %7B%0A        onCreate(sqLiteDatabase);%0A    %7D%0A%7D%0A%0A

Add database helper class