{"action":"created","comment":{"url":"https://api.github.com/repos/framgia/RSS_2/pulls/comments/57172402","id":57172402,"diff_hunk":"@@ -0,0 +1,373 @@\n+package framgia.vn.readrss.controller;\n+\n+import android.app.Activity;\n+import android.content.ContentValues;\n+import android.database.Cursor;\n+import android.database.sqlite.SQLiteDatabase;\n+import android.util.Log;\n+import android.widget.Toast;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Locale;\n+\n+import framgia.vn.readrss.models.Category;\n+import framgia.vn.readrss.models.Data;\n+import framgia.vn.readrss.models.Informations;\n+import framgia.vn.readrss.models.ListData;\n+\n+/**\n+ * Created by FRAMGIA\\nguyen.huy.quyet on 18/03/2016.\n+ */\n+public class Database {\n+    Activity context;\n+    Cursor cursor = null;\n+\n+    public Database(Activity context) {\n+        this.context = context;\n+    }\n+//    private SQLiteDatabase database = null;\n+\n+    private boolean isDatabaseExists(SQLiteDatabase database, String tableName) {\n+        Cursor cursor = database.rawQuery(\"Select DISTINCT tbl_name from sqlite_master where tbl_name = '\" + tableName + \"'\", null);\n+        if (cursor != null) {\n+            if (cursor.getCount() > 0) {\n+                cursor.close();\n+                return true;\n+            }\n+            cursor.close();\n+        }\n+        return false;\n+    }\n+\n+    public void insertDataBase(SQLiteDatabase database) {\n+        try {\n+            if (database != null) {\n+                if (!isDatabaseExists(database, \"tblPost\")) {\n+                    /**\n+                     * ko ton tai bang => tao moi CSDL trong\n+                     * bat dau tao moi cac bang\n+                     */\n+                    database.setLocale(Locale.getDefault());\n+                    database.setVersion(1);\n+                    /**\n+                     * Create table category\n+                     */\n+                    String sqlCategory = \"create table tblCategory (\" +\n+                            \"id integer primary key autoincrement,\" +\n+                            \"name)\";\n+                    database.execSQL(sqlCategory);\n+                    Toast.makeText(context, \"Insert tblCategory success !\", Toast.LENGTH_SHORT).show();\n+\n+                    /**\n+                     * Create table tblInformation\n+                     */\n+                    String sqlInformations = \"create table tblInformation (\" +\n+                            \"id integer primary key autoincrement, \" +\n+                            \"title text, \" +\n+                            \"link text, \" +\n+                            \"description text, \" +\n+                            \"image text, \" +\n+                            \"language text, \" +\n+                            \"copyright text, \" +\n+                            \"ttl text, \" +\n+                            \"lastBuildDate text,\" +\n+                            \"generator text, \" +\n+                            \"atom text)\";\n+                    database.execSQL(sqlInformations);\n+                    Toast.makeText(context, \"Insert tblInformation success !\", Toast.LENGTH_SHORT).show();\n+\n+                    /**\n+                     * Create table tblPost\n+                     */\n+                    String sqlPost = \"create table tblPost (\" +\n+                            \"id integer primary key autoincrement, \" +\n+                            \"title text, \" +\n+                            \"description text, \" +\n+                            \"link text, \" +\n+                            \"guid text, \" +\n+                            \"pubDate text, \" +\n+                            \"category text, \" +\n+                            \"author text, \" +\n+                            \"enclosure text)\";\n+                    database.execSQL(sqlPost);\n+                    Toast.makeText(context, \"Insert tblPost success !\", Toast.LENGTH_SHORT).show();\n+\n+                    /**\n+                     * Create table tblTimeUpdate\n+                     */\n+                    String sqlTimeUpdate = \" create table tblTimeUpdate (\" +\n+                            \"time datetime)\";\n+                    database.execSQL(sqlTimeUpdate);\n+                    Toast.makeText(context, \"Insert tblTimeUpdate success !\", Toast.LENGTH_SHORT).show();\n+\n+                    /**\n+                     * Create table tblCategoryPost\n+                     */\n+                    String sqlCategory_post = \"create table tblCategoryPost(\" +\n+                            \"id_post integer not null constraint id_post references tblPost(id) on delete cascade,\" +\n+                            \"id_category integer not null constraint id_category references tblCategory(id) on delete cascade,\" +\n+                            \"category_primary integer)\";\n+\n+                    database.execSQL(sqlCategory_post);\n+                    Toast.makeText(context, \"Insert tblCategoryPost success !\", Toast.LENGTH_SHORT).show();\n+                    Category category = new Category();\n+                    ContentValues values = new ContentValues();\n+                    for (Category category1 : category.getCategoryArrayList()) {\n+                        values.put(\"name\", category1.getName());\n+                        long check = database.insert(\"tblCategory\", null, values);\n+                        if (check == -1) {\n+                            Toast.makeText(context, \"Error insert data Category\", Toast.LENGTH_SHORT).show();\n+                            delete_Database(database);\n+                            break;\n+                        } else\n+                            values.clear();\n+\n+                    }\n+                    Toast.makeText(context, \"Insert database CategoryPost success !\", Toast.LENGTH_SHORT).show();\n+                    Toast.makeText(context, \"Insert database success !\", Toast.LENGTH_LONG).show();\n+                }   // End if (!isDatabaseExists(database, \"tblPost\"))\n+                database.close();\n+            }   // End if(database != null)\n+        } catch (Exception ex) {\n+            Log.d(\"error\", ex.toString());\n+            delete_Database(database);\n+        }\n+    }\n+\n+    public void delete_Database(SQLiteDatabase database) {\n+        String msg = \"\";\n+        if (context.deleteDatabase(\"readRss.db\")) {\n+            msg = \" Delete data success !\";\n+        } else\n+            msg = \" Delete data error !\";\n+        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();\n+    }\n+\n+//    public void insertOrUpdateDataPost(SQLiteDatabase sqLiteDatabase, ArrayList<Data> data) {\n+//        if (checkDataPost(sqLiteDatabase)) {\n+//            updateDataPost(sqLiteDatabase, data);","path":"app/src/main/java/framgia/vn/readrss/controller/Database.java","position":149,"original_position":149,"commit_id":"9a92b75da32756cfb183fd620dd9d87a87ee24a4","original_commit_id":"9a92b75da32756cfb183fd620dd9d87a87ee24a4","user":{"login":"nvmanh","id":2127662,"avatar_url":"https://avatars.githubusercontent.com/u/2127662?v=3","gravatar_id":"","url":"https://api.github.com/users/nvmanh","html_url":"https://github.com/nvmanh","followers_url":"https://api.github.com/users/nvmanh/followers","following_url":"https://api.github.com/users/nvmanh/following{/other_user}","gists_url":"https://api.github.com/users/nvmanh/gists{/gist_id}","starred_url":"https://api.github.com/users/nvmanh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvmanh/subscriptions","organizations_url":"https://api.github.com/users/nvmanh/orgs","repos_url":"https://api.github.com/users/nvmanh/repos","events_url":"https://api.github.com/users/nvmanh/events{/privacy}","received_events_url":"https://api.github.com/users/nvmanh/received_events","type":"User","site_admin":false},"body":"ko dùng nữa thì remove đi em cho gọn code","created_at":"2016-03-23T14:52:31Z","updated_at":"2016-03-23T14:52:31Z","html_url":"https://github.com/framgia/RSS_2/pull/3#discussion_r57172402","pull_request_url":"https://api.github.com/repos/framgia/RSS_2/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/comments/57172402"},"html":{"href":"https://github.com/framgia/RSS_2/pull/3#discussion_r57172402"},"pull_request":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/framgia/RSS_2/pulls/3","id":63851940,"html_url":"https://github.com/framgia/RSS_2/pull/3","diff_url":"https://github.com/framgia/RSS_2/pull/3.diff","patch_url":"https://github.com/framgia/RSS_2/pull/3.patch","issue_url":"https://api.github.com/repos/framgia/RSS_2/issues/3","number":3,"state":"open","locked":false,"title":"CREATE Fragment, Controller, Database","user":{"login":"huyquyet","id":14154998,"avatar_url":"https://avatars.githubusercontent.com/u/14154998?v=3","gravatar_id":"","url":"https://api.github.com/users/huyquyet","html_url":"https://github.com/huyquyet","followers_url":"https://api.github.com/users/huyquyet/followers","following_url":"https://api.github.com/users/huyquyet/following{/other_user}","gists_url":"https://api.github.com/users/huyquyet/gists{/gist_id}","starred_url":"https://api.github.com/users/huyquyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huyquyet/subscriptions","organizations_url":"https://api.github.com/users/huyquyet/orgs","repos_url":"https://api.github.com/users/huyquyet/repos","events_url":"https://api.github.com/users/huyquyet/events{/privacy}","received_events_url":"https://api.github.com/users/huyquyet/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-23T09:23:29Z","updated_at":"2016-03-23T14:52:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d351ff232ad597131ba9a754840e88c46b8c7772","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/framgia/RSS_2/pulls/3/commits","review_comments_url":"https://api.github.com/repos/framgia/RSS_2/pulls/3/comments","review_comment_url":"https://api.github.com/repos/framgia/RSS_2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/framgia/RSS_2/issues/3/comments","statuses_url":"https://api.github.com/repos/framgia/RSS_2/statuses/9a92b75da32756cfb183fd620dd9d87a87ee24a4","head":{"label":"huyquyet:init_project","ref":"init_project","sha":"9a92b75da32756cfb183fd620dd9d87a87ee24a4","user":{"login":"huyquyet","id":14154998,"avatar_url":"https://avatars.githubusercontent.com/u/14154998?v=3","gravatar_id":"","url":"https://api.github.com/users/huyquyet","html_url":"https://github.com/huyquyet","followers_url":"https://api.github.com/users/huyquyet/followers","following_url":"https://api.github.com/users/huyquyet/following{/other_user}","gists_url":"https://api.github.com/users/huyquyet/gists{/gist_id}","starred_url":"https://api.github.com/users/huyquyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huyquyet/subscriptions","organizations_url":"https://api.github.com/users/huyquyet/orgs","repos_url":"https://api.github.com/users/huyquyet/repos","events_url":"https://api.github.com/users/huyquyet/events{/privacy}","received_events_url":"https://api.github.com/users/huyquyet/received_events","type":"User","site_admin":false},"repo":{"id":54180130,"name":"RSS_2","full_name":"huyquyet/RSS_2","owner":{"login":"huyquyet","id":14154998,"avatar_url":"https://avatars.githubusercontent.com/u/14154998?v=3","gravatar_id":"","url":"https://api.github.com/users/huyquyet","html_url":"https://github.com/huyquyet","followers_url":"https://api.github.com/users/huyquyet/followers","following_url":"https://api.github.com/users/huyquyet/following{/other_user}","gists_url":"https://api.github.com/users/huyquyet/gists{/gist_id}","starred_url":"https://api.github.com/users/huyquyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huyquyet/subscriptions","organizations_url":"https://api.github.com/users/huyquyet/orgs","repos_url":"https://api.github.com/users/huyquyet/repos","events_url":"https://api.github.com/users/huyquyet/events{/privacy}","received_events_url":"https://api.github.com/users/huyquyet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/huyquyet/RSS_2","description":"RSS feed (training)","fork":true,"url":"https://api.github.com/repos/huyquyet/RSS_2","forks_url":"https://api.github.com/repos/huyquyet/RSS_2/forks","keys_url":"https://api.github.com/repos/huyquyet/RSS_2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/huyquyet/RSS_2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/huyquyet/RSS_2/teams","hooks_url":"https://api.github.com/repos/huyquyet/RSS_2/hooks","issue_events_url":"https://api.github.com/repos/huyquyet/RSS_2/issues/events{/number}","events_url":"https://api.github.com/repos/huyquyet/RSS_2/events","assignees_url":"https://api.github.com/repos/huyquyet/RSS_2/assignees{/user}","branches_url":"https://api.github.com/repos/huyquyet/RSS_2/branches{/branch}","tags_url":"https://api.github.com/repos/huyquyet/RSS_2/tags","blobs_url":"https://api.github.com/repos/huyquyet/RSS_2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/huyquyet/RSS_2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/huyquyet/RSS_2/git/refs{/sha}","trees_url":"https://api.github.com/repos/huyquyet/RSS_2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/huyquyet/RSS_2/statuses/{sha}","languages_url":"https://api.github.com/repos/huyquyet/RSS_2/languages","stargazers_url":"https://api.github.com/repos/huyquyet/RSS_2/stargazers","contributors_url":"https://api.github.com/repos/huyquyet/RSS_2/contributors","subscribers_url":"https://api.github.com/repos/huyquyet/RSS_2/subscribers","subscription_url":"https://api.github.com/repos/huyquyet/RSS_2/subscription","commits_url":"https://api.github.com/repos/huyquyet/RSS_2/commits{/sha}","git_commits_url":"https://api.github.com/repos/huyquyet/RSS_2/git/commits{/sha}","comments_url":"https://api.github.com/repos/huyquyet/RSS_2/comments{/number}","issue_comment_url":"https://api.github.com/repos/huyquyet/RSS_2/issues/comments{/number}","contents_url":"https://api.github.com/repos/huyquyet/RSS_2/contents/{+path}","compare_url":"https://api.github.com/repos/huyquyet/RSS_2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/huyquyet/RSS_2/merges","archive_url":"https://api.github.com/repos/huyquyet/RSS_2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/huyquyet/RSS_2/downloads","issues_url":"https://api.github.com/repos/huyquyet/RSS_2/issues{/number}","pulls_url":"https://api.github.com/repos/huyquyet/RSS_2/pulls{/number}","milestones_url":"https://api.github.com/repos/huyquyet/RSS_2/milestones{/number}","notifications_url":"https://api.github.com/repos/huyquyet/RSS_2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/huyquyet/RSS_2/labels{/name}","releases_url":"https://api.github.com/repos/huyquyet/RSS_2/releases{/id}","deployments_url":"https://api.github.com/repos/huyquyet/RSS_2/deployments","created_at":"2016-03-18T06:46:58Z","updated_at":"2016-03-16T03:57:49Z","pushed_at":"2016-03-23T09:28:10Z","git_url":"git://github.com/huyquyet/RSS_2.git","ssh_url":"git@github.com:huyquyet/RSS_2.git","clone_url":"https://github.com/huyquyet/RSS_2.git","svn_url":"https://github.com/huyquyet/RSS_2","homepage":null,"size":183,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"framgia:master","ref":"master","sha":"b95cdb4977915dc4e46fef80707213487fa3eed6","user":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","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":53999487,"name":"RSS_2","full_name":"framgia/RSS_2","owner":{"login":"framgia","id":2322183,"avatar_url":"https://avatars.githubusercontent.com/u/2322183?v=3","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/RSS_2","description":"RSS feed (training)","fork":false,"url":"https://api.github.com/repos/framgia/RSS_2","forks_url":"https://api.github.com/repos/framgia/RSS_2/forks","keys_url":"https://api.github.com/repos/framgia/RSS_2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framgia/RSS_2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framgia/RSS_2/teams","hooks_url":"https://api.github.com/repos/framgia/RSS_2/hooks","issue_events_url":"https://api.github.com/repos/framgia/RSS_2/issues/events{/number}","events_url":"https://api.github.com/repos/framgia/RSS_2/events","assignees_url":"https://api.github.com/repos/framgia/RSS_2/assignees{/user}","branches_url":"https://api.github.com/repos/framgia/RSS_2/branches{/branch}","tags_url":"https://api.github.com/repos/framgia/RSS_2/tags","blobs_url":"https://api.github.com/repos/framgia/RSS_2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framgia/RSS_2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framgia/RSS_2/git/refs{/sha}","trees_url":"https://api.github.com/repos/framgia/RSS_2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framgia/RSS_2/statuses/{sha}","languages_url":"https://api.github.com/repos/framgia/RSS_2/languages","stargazers_url":"https://api.github.com/repos/framgia/RSS_2/stargazers","contributors_url":"https://api.github.com/repos/framgia/RSS_2/contributors","subscribers_url":"https://api.github.com/repos/framgia/RSS_2/subscribers","subscription_url":"https://api.github.com/repos/framgia/RSS_2/subscription","commits_url":"https://api.github.com/repos/framgia/RSS_2/commits{/sha}","git_commits_url":"https://api.github.com/repos/framgia/RSS_2/git/commits{/sha}","comments_url":"https://api.github.com/repos/framgia/RSS_2/comments{/number}","issue_comment_url":"https://api.github.com/repos/framgia/RSS_2/issues/comments{/number}","contents_url":"https://api.github.com/repos/framgia/RSS_2/contents/{+path}","compare_url":"https://api.github.com/repos/framgia/RSS_2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framgia/RSS_2/merges","archive_url":"https://api.github.com/repos/framgia/RSS_2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framgia/RSS_2/downloads","issues_url":"https://api.github.com/repos/framgia/RSS_2/issues{/number}","pulls_url":"https://api.github.com/repos/framgia/RSS_2/pulls{/number}","milestones_url":"https://api.github.com/repos/framgia/RSS_2/milestones{/number}","notifications_url":"https://api.github.com/repos/framgia/RSS_2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framgia/RSS_2/labels{/name}","releases_url":"https://api.github.com/repos/framgia/RSS_2/releases{/id}","deployments_url":"https://api.github.com/repos/framgia/RSS_2/deployments","created_at":"2016-03-16T03:57:49Z","updated_at":"2016-03-23T03:52:46Z","pushed_at":"2016-03-23T09:28:10Z","git_url":"git://github.com/framgia/RSS_2.git","ssh_url":"git@github.com:framgia/RSS_2.git","clone_url":"https://github.com/framgia/RSS_2.git","svn_url":"https://github.com/framgia/RSS_2","homepage":null,"size":109,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/3"},"html":{"href":"https://github.com/framgia/RSS_2/pull/3"},"issue":{"href":"https://api.github.com/repos/framgia/RSS_2/issues/3"},"comments":{"href":"https://api.github.com/repos/framgia/RSS_2/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/framgia/RSS_2/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/framgia/RSS_2/statuses/9a92b75da32756cfb183fd620dd9d87a87ee24a4"}}}}