{"action":"created","comment":{"url":"https://api.github.com/repos/framgia/moviedb_12/pulls/comments/174005274","pull_request_review_id":103285327,"id":174005274,"diff_hunk":"@@ -0,0 +1,112 @@\n+package com.training.vungoctuan.moviedb.data.source.local;\n+\n+import android.content.ContentValues;\n+import android.content.Context;\n+import android.database.Cursor;\n+import android.database.sqlite.SQLiteDatabase;\n+import android.database.sqlite.SQLiteOpenHelper;\n+\n+import com.training.vungoctuan.moviedb.data.model.Movie;\n+import com.training.vungoctuan.moviedb.util.Constant.MoviesDataBase;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+/**\n+ * Created by vungoctuan on 3/12/18.\n+ */\n+public class MoviesDatabaseHelper extends SQLiteOpenHelper {\n+    private static MoviesDatabaseHelper sInstance;\n+\n+    public static MoviesDatabaseHelper getInstance(Context context) {\n+        if (sInstance == null) {\n+            sInstance = new MoviesDatabaseHelper(context);\n+        }\n+        return sInstance;\n+    }\n+\n+    private MoviesDatabaseHelper(Context context) {\n+        super(context, MoviesDataBase.DATABASE_NAME, null, MoviesDataBase.DATABASE_VERSION);\n+    }\n+\n+    @Override\n+    public void onCreate(SQLiteDatabase sqLiteDatabase) {\n+        sqLiteDatabase.execSQL(MoviesDataBase.QUERY_CREATE_MOVIES);\n+    }\n+\n+    @Override\n+    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {\n+        if (oldVersion != newVersion) {\n+            sqLiteDatabase.execSQL(\n+                MoviesDataBase.QUERY_DROP_TABLE_IF_EXISTS + MoviesDataBase.TABLE_FAVOURITE_MOVIES);\n+            onCreate(sqLiteDatabase);\n+        }\n+    }\n+\n+    List<Movie> getAllMovies() throws Exception {\n+        List<Movie> movies = new ArrayList<>();\n+        String selectAllQuery =\n+            String.format(MoviesDataBase.QUERY_SELECT_ALL_FROM,\n+                MoviesDataBase.TABLE_FAVOURITE_MOVIES);\n+        SQLiteDatabase db = getReadableDatabase();\n+        Cursor cursor = db.rawQuery(selectAllQuery, null);\n+        try {\n+            if (cursor.moveToNext()) {\n+                do {\n+                    Movie movie = new Movie();\n+                    movie.setId(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_ID)));\n+                    movie.setTitle(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_TITLE)));\n+                    movie.setVoteAverage(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_VOTE_AVERAGE)));\n+                    movie.setPosterPath(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_POSTER_PATH)));\n+                    movie.setBackdropPath(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_BACKDROP_PATH)));\n+                    movie.setOverview(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_OVERVIEW)));\n+                    movie.setReleaseDate(cursor.getString(\n+                        cursor.getColumnIndex(MoviesDataBase.KEY_MOVIES_RELEASE_DATE)));\n+                    movies.add(movie);\n+                } while (cursor.moveToNext());\n+            }\n+        } finally {\n+            if (cursor != null && !cursor.isClosed()) {\n+                cursor.close();\n+            }\n+        }\n+        return movies;\n+    }\n+\n+    void addMovies(Movie movie) throws Exception {\n+        SQLiteDatabase db = getWritableDatabase();\n+        db.beginTransaction();\n+        try {\n+            ContentValues values = new ContentValues();\n+            values.put(MoviesDataBase.KEY_MOVIES_ID, movie.getId());\n+            values.put(MoviesDataBase.KEY_MOVIES_TITLE, movie.getTitle());\n+            values.put(MoviesDataBase.KEY_MOVIES_VOTE_AVERAGE, movie.getVoteAverage());\n+            values.put(MoviesDataBase.KEY_MOVIES_POSTER_PATH, movie.getPosterPath());\n+            values.put(MoviesDataBase.KEY_MOVIES_BACKDROP_PATH, movie.getBackdropPath());\n+            values.put(MoviesDataBase.KEY_MOVIES_OVERVIEW, movie.getOverview());\n+            values.put(MoviesDataBase.KEY_MOVIES_RELEASE_DATE, movie.getReleaseDate());\n+            db.insertOrThrow(MoviesDataBase.TABLE_FAVOURITE_MOVIES, null, values);\n+            db.setTransactionSuccessful();\n+        } finally {\n+            db.endTransaction();\n+        }\n+    }\n+\n+    void deleteMovies(Movie movie) throws Exception {\n+        SQLiteDatabase db = getWritableDatabase();\n+        db.beginTransaction();\n+        try {\n+            String selection = MoviesDataBase.KEY_MOVIES_ID + MoviesDataBase.QUERY_WHERE;\n+            String[] selectionArgs = {movie.getId()};\n+            db.delete(MoviesDataBase.TABLE_FAVOURITE_MOVIES, selection, selectionArgs);\n+        } finally {\n+            db.endTransaction();","path":"app/src/main/java/com/training/vungoctuan/moviedb/data/source/local/MoviesDatabaseHelper.java","position":109,"original_position":109,"commit_id":"93a20a7a8bd543b625402aeb4876b0d666ac0bdd","original_commit_id":"93a20a7a8bd543b625402aeb4876b0d666ac0bdd","user":{"login":"DoanVanToan","id":21195010,"avatar_url":"https://avatars3.githubusercontent.com/u/21195010?v=4","gravatar_id":"","url":"https://api.github.com/users/DoanVanToan","html_url":"https://github.com/DoanVanToan","followers_url":"https://api.github.com/users/DoanVanToan/followers","following_url":"https://api.github.com/users/DoanVanToan/following{/other_user}","gists_url":"https://api.github.com/users/DoanVanToan/gists{/gist_id}","starred_url":"https://api.github.com/users/DoanVanToan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DoanVanToan/subscriptions","organizations_url":"https://api.github.com/users/DoanVanToan/orgs","repos_url":"https://api.github.com/users/DoanVanToan/repos","events_url":"https://api.github.com/users/DoanVanToan/events{/privacy}","received_events_url":"https://api.github.com/users/DoanVanToan/received_events","type":"User","site_admin":false},"body":"tương tự ","created_at":"2018-03-13T03:04:01Z","updated_at":"2018-03-13T03:05:10Z","html_url":"https://github.com/framgia/moviedb_12/pull/20#discussion_r174005274","pull_request_url":"https://api.github.com/repos/framgia/moviedb_12/pulls/20","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/comments/174005274"},"html":{"href":"https://github.com/framgia/moviedb_12/pull/20#discussion_r174005274"},"pull_request":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/20"}}},"pull_request":{"url":"https://api.github.com/repos/framgia/moviedb_12/pulls/20","id":174540680,"html_url":"https://github.com/framgia/moviedb_12/pull/20","diff_url":"https://github.com/framgia/moviedb_12/pull/20.diff","patch_url":"https://github.com/framgia/moviedb_12/pull/20.patch","issue_url":"https://api.github.com/repos/framgia/moviedb_12/issues/20","number":20,"state":"open","locked":false,"title":"Init SQlite and Repository","user":{"login":"TuanTuanTu","id":8645458,"avatar_url":"https://avatars0.githubusercontent.com/u/8645458?v=4","gravatar_id":"","url":"https://api.github.com/users/TuanTuanTu","html_url":"https://github.com/TuanTuanTu","followers_url":"https://api.github.com/users/TuanTuanTu/followers","following_url":"https://api.github.com/users/TuanTuanTu/following{/other_user}","gists_url":"https://api.github.com/users/TuanTuanTu/gists{/gist_id}","starred_url":"https://api.github.com/users/TuanTuanTu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuanTuanTu/subscriptions","organizations_url":"https://api.github.com/users/TuanTuanTu/orgs","repos_url":"https://api.github.com/users/TuanTuanTu/repos","events_url":"https://api.github.com/users/TuanTuanTu/events{/privacy}","received_events_url":"https://api.github.com/users/TuanTuanTu/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-03-13T02:08:51Z","updated_at":"2018-03-13T03:05:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e1c85f36569a1e17aa85dbf011a91eb4bcf37be","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/framgia/moviedb_12/pulls/20/commits","review_comments_url":"https://api.github.com/repos/framgia/moviedb_12/pulls/20/comments","review_comment_url":"https://api.github.com/repos/framgia/moviedb_12/pulls/comments{/number}","comments_url":"https://api.github.com/repos/framgia/moviedb_12/issues/20/comments","statuses_url":"https://api.github.com/repos/framgia/moviedb_12/statuses/93a20a7a8bd543b625402aeb4876b0d666ac0bdd","head":{"label":"TuanTuanTu:favourite-system/01","ref":"favourite-system/01","sha":"93a20a7a8bd543b625402aeb4876b0d666ac0bdd","user":{"login":"TuanTuanTu","id":8645458,"avatar_url":"https://avatars0.githubusercontent.com/u/8645458?v=4","gravatar_id":"","url":"https://api.github.com/users/TuanTuanTu","html_url":"https://github.com/TuanTuanTu","followers_url":"https://api.github.com/users/TuanTuanTu/followers","following_url":"https://api.github.com/users/TuanTuanTu/following{/other_user}","gists_url":"https://api.github.com/users/TuanTuanTu/gists{/gist_id}","starred_url":"https://api.github.com/users/TuanTuanTu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuanTuanTu/subscriptions","organizations_url":"https://api.github.com/users/TuanTuanTu/orgs","repos_url":"https://api.github.com/users/TuanTuanTu/repos","events_url":"https://api.github.com/users/TuanTuanTu/events{/privacy}","received_events_url":"https://api.github.com/users/TuanTuanTu/received_events","type":"User","site_admin":false},"repo":{"id":123209587,"name":"moviedb_12","full_name":"TuanTuanTu/moviedb_12","owner":{"login":"TuanTuanTu","id":8645458,"avatar_url":"https://avatars0.githubusercontent.com/u/8645458?v=4","gravatar_id":"","url":"https://api.github.com/users/TuanTuanTu","html_url":"https://github.com/TuanTuanTu","followers_url":"https://api.github.com/users/TuanTuanTu/followers","following_url":"https://api.github.com/users/TuanTuanTu/following{/other_user}","gists_url":"https://api.github.com/users/TuanTuanTu/gists{/gist_id}","starred_url":"https://api.github.com/users/TuanTuanTu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TuanTuanTu/subscriptions","organizations_url":"https://api.github.com/users/TuanTuanTu/orgs","repos_url":"https://api.github.com/users/TuanTuanTu/repos","events_url":"https://api.github.com/users/TuanTuanTu/events{/privacy}","received_events_url":"https://api.github.com/users/TuanTuanTu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TuanTuanTu/moviedb_12","description":"moviedb_12 (Training)","fork":true,"url":"https://api.github.com/repos/TuanTuanTu/moviedb_12","forks_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/forks","keys_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/teams","hooks_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/hooks","issue_events_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/issues/events{/number}","events_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/events","assignees_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/assignees{/user}","branches_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/branches{/branch}","tags_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/tags","blobs_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/git/refs{/sha}","trees_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/statuses/{sha}","languages_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/languages","stargazers_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/stargazers","contributors_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/contributors","subscribers_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/subscribers","subscription_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/subscription","commits_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/commits{/sha}","git_commits_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/git/commits{/sha}","comments_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/comments{/number}","issue_comment_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/issues/comments{/number}","contents_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/contents/{+path}","compare_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/merges","archive_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/downloads","issues_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/issues{/number}","pulls_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/pulls{/number}","milestones_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/milestones{/number}","notifications_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/labels{/name}","releases_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/releases{/id}","deployments_url":"https://api.github.com/repos/TuanTuanTu/moviedb_12/deployments","created_at":"2018-02-28T01:12:45Z","updated_at":"2018-02-28T01:10:09Z","pushed_at":"2018-03-13T02:58:16Z","git_url":"git://github.com/TuanTuanTu/moviedb_12.git","ssh_url":"git@github.com:TuanTuanTu/moviedb_12.git","clone_url":"https://github.com/TuanTuanTu/moviedb_12.git","svn_url":"https://github.com/TuanTuanTu/moviedb_12","homepage":null,"size":462,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"framgia:develop","ref":"develop","sha":"daafd9919a7f400e067af81d9e33453a0fc1aa41","user":{"login":"framgia","id":2322183,"avatar_url":"https://avatars3.githubusercontent.com/u/2322183?v=4","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"repo":{"id":123209337,"name":"moviedb_12","full_name":"framgia/moviedb_12","owner":{"login":"framgia","id":2322183,"avatar_url":"https://avatars3.githubusercontent.com/u/2322183?v=4","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/framgia/moviedb_12","description":"moviedb_12 (Training)","fork":false,"url":"https://api.github.com/repos/framgia/moviedb_12","forks_url":"https://api.github.com/repos/framgia/moviedb_12/forks","keys_url":"https://api.github.com/repos/framgia/moviedb_12/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framgia/moviedb_12/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framgia/moviedb_12/teams","hooks_url":"https://api.github.com/repos/framgia/moviedb_12/hooks","issue_events_url":"https://api.github.com/repos/framgia/moviedb_12/issues/events{/number}","events_url":"https://api.github.com/repos/framgia/moviedb_12/events","assignees_url":"https://api.github.com/repos/framgia/moviedb_12/assignees{/user}","branches_url":"https://api.github.com/repos/framgia/moviedb_12/branches{/branch}","tags_url":"https://api.github.com/repos/framgia/moviedb_12/tags","blobs_url":"https://api.github.com/repos/framgia/moviedb_12/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framgia/moviedb_12/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framgia/moviedb_12/git/refs{/sha}","trees_url":"https://api.github.com/repos/framgia/moviedb_12/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framgia/moviedb_12/statuses/{sha}","languages_url":"https://api.github.com/repos/framgia/moviedb_12/languages","stargazers_url":"https://api.github.com/repos/framgia/moviedb_12/stargazers","contributors_url":"https://api.github.com/repos/framgia/moviedb_12/contributors","subscribers_url":"https://api.github.com/repos/framgia/moviedb_12/subscribers","subscription_url":"https://api.github.com/repos/framgia/moviedb_12/subscription","commits_url":"https://api.github.com/repos/framgia/moviedb_12/commits{/sha}","git_commits_url":"https://api.github.com/repos/framgia/moviedb_12/git/commits{/sha}","comments_url":"https://api.github.com/repos/framgia/moviedb_12/comments{/number}","issue_comment_url":"https://api.github.com/repos/framgia/moviedb_12/issues/comments{/number}","contents_url":"https://api.github.com/repos/framgia/moviedb_12/contents/{+path}","compare_url":"https://api.github.com/repos/framgia/moviedb_12/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framgia/moviedb_12/merges","archive_url":"https://api.github.com/repos/framgia/moviedb_12/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framgia/moviedb_12/downloads","issues_url":"https://api.github.com/repos/framgia/moviedb_12/issues{/number}","pulls_url":"https://api.github.com/repos/framgia/moviedb_12/pulls{/number}","milestones_url":"https://api.github.com/repos/framgia/moviedb_12/milestones{/number}","notifications_url":"https://api.github.com/repos/framgia/moviedb_12/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framgia/moviedb_12/labels{/name}","releases_url":"https://api.github.com/repos/framgia/moviedb_12/releases{/id}","deployments_url":"https://api.github.com/repos/framgia/moviedb_12/deployments","created_at":"2018-02-28T01:10:09Z","updated_at":"2018-03-13T03:03:22Z","pushed_at":"2018-03-13T02:58:17Z","git_url":"git://github.com/framgia/moviedb_12.git","ssh_url":"git@github.com:framgia/moviedb_12.git","clone_url":"https://github.com/framgia/moviedb_12.git","svn_url":"https://github.com/framgia/moviedb_12","homepage":null,"size":462,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":1,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/20"},"html":{"href":"https://github.com/framgia/moviedb_12/pull/20"},"issue":{"href":"https://api.github.com/repos/framgia/moviedb_12/issues/20"},"comments":{"href":"https://api.github.com/repos/framgia/moviedb_12/issues/20/comments"},"review_comments":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/20/comments"},"review_comment":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/framgia/moviedb_12/pulls/20/commits"},"statuses":{"href":"https://api.github.com/repos/framgia/moviedb_12/statuses/93a20a7a8bd543b625402aeb4876b0d666ac0bdd"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"DoanVanToan"}}