{"action":"created","comment":{"url":"https://api.github.com/repos/fossasia/open-event-android/pulls/comments/124982163","pull_request_review_id":47326073,"id":124982163,"diff_hunk":"@@ -30,47 +39,110 @@\n \n     private static final int READ_TIMEOUT_MILLIS = 50 * 1000; // 20s\n \n+    private static final String CACHE_CONTROL = \"Cache-Control\";\n+\n     private static OpenEventAPI openEventAPI;\n     private static FacebookGraphAPI facebookGraphAPI;\n \n+    private static OkHttpClient.Builder okHttpClientBuilder;\n     private static Retrofit.Builder retrofitBuilder;\n \n     static {\n-        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient().newBuilder()\n+        okHttpClientBuilder = new OkHttpClient().newBuilder()\n                 .connectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)\n                 .readTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);\n \n         if (BuildConfig.DEBUG)\n             okHttpClientBuilder.addNetworkInterceptor(new StethoInterceptor());\n \n-        OkHttpClient okHttpClient = okHttpClientBuilder.addInterceptor(new HttpLoggingInterceptor()\n-                .setLevel(HttpLoggingInterceptor.Level.BASIC))\n-                .build();\n-\n         retrofitBuilder = new Retrofit.Builder()\n-                .addConverterFactory(JacksonConverterFactory.create(new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)))\n-                .client(okHttpClient);\n+                .addConverterFactory(JacksonConverterFactory.create(new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)));\n     }\n \n     public static OpenEventAPI getOpenEventAPI() {\n-        if (openEventAPI == null)\n+        if (openEventAPI == null) {\n+            OkHttpClient okHttpClient = okHttpClientBuilder.addInterceptor(new HttpLoggingInterceptor()\n+                    .setLevel(HttpLoggingInterceptor.Level.BASIC))\n+                    .build();\n+\n+            retrofitBuilder.client(okHttpClient);\n+\n             openEventAPI = retrofitBuilder\n                     .baseUrl(Urls.BASE_URL)\n                     .build()\n                     .create(OpenEventAPI.class);\n+        }\n \n         return openEventAPI;\n     }\n \n     public static FacebookGraphAPI getFacebookGraphAPI() {\n-        if (facebookGraphAPI == null)\n+        if (facebookGraphAPI == null) {\n+            OkHttpClient okHttpClient = okHttpClientBuilder.addInterceptor(new HttpLoggingInterceptor()\n+                    .setLevel(HttpLoggingInterceptor.Level.BASIC))\n+                    .addInterceptor(provideOfflineCacheInterceptor())\n+                    .addNetworkInterceptor(provideCacheInterceptor())\n+                    .cache(provideCache())\n+                    .build();\n+\n+\n+            retrofitBuilder.client(okHttpClient);\n+\n             facebookGraphAPI = retrofitBuilder\n                     .baseUrl(Urls.FACEBOOK_BASE_URL)\n                     .addCallAdapterFactory(RxJava2CallAdapterFactory.create())\n                     .build()\n                     .create(FacebookGraphAPI.class);\n+        }\n \n         return facebookGraphAPI;\n     }\n \n+    private static Cache provideCache() {\n+        Cache cache = null;\n+        try {\n+            cache = new Cache(new File( OpenEventApp.getAppContext().getCacheDir(), \"facebook-feed-cache\"),\n+                    10 * 1024 * 1024 ); // 10 MB\n+        }\n+        catch (Exception e) {\n+            Timber.e(e, \"Could not create Cache!\");\n+        }\n+        return cache;\n+    }\n+\n+    private static Interceptor provideCacheInterceptor () {\n+        return chain -> {\n+            Response response = chain.proceed( chain.request() );\n+\n+            // re-write response header to force use of cache\n+            CacheControl cacheControl = new CacheControl.Builder()\n+                    .maxAge(2, TimeUnit.MINUTES)\n+                    .build();\n+\n+            return response.newBuilder()\n+                    .removeHeader(\"Pragma\")\n+                    .header(CACHE_CONTROL, cacheControl.toString())\n+                    .build();\n+        };\n+    }\n+\n+    private static Interceptor provideOfflineCacheInterceptor() {\n+        return chain -> {\n+            Request request = chain.request();\n+\n+            if (!NetworkUtils.haveNetworkConnection(OpenEventApp.getAppContext())) {","path":"android/app/src/main/java/org/fossasia/openevent/api/APIClient.java","position":130,"original_position":130,"commit_id":"76f75a58cd5d4dc38fb018ddff08ad4dbec0bd41","original_commit_id":"76f75a58cd5d4dc38fb018ddff08ad4dbec0bd41","user":{"login":"iamareebjamal","id":3874064,"avatar_url":"https://avatars3.githubusercontent.com/u/3874064?v=3","gravatar_id":"","url":"https://api.github.com/users/iamareebjamal","html_url":"https://github.com/iamareebjamal","followers_url":"https://api.github.com/users/iamareebjamal/followers","following_url":"https://api.github.com/users/iamareebjamal/following{/other_user}","gists_url":"https://api.github.com/users/iamareebjamal/gists{/gist_id}","starred_url":"https://api.github.com/users/iamareebjamal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iamareebjamal/subscriptions","organizations_url":"https://api.github.com/users/iamareebjamal/orgs","repos_url":"https://api.github.com/users/iamareebjamal/repos","events_url":"https://api.github.com/users/iamareebjamal/events{/privacy}","received_events_url":"https://api.github.com/users/iamareebjamal/received_events","type":"User","site_admin":false},"body":"Why does this need to be dynamic?","created_at":"2017-06-30T07:49:27Z","updated_at":"2017-06-30T07:49:27Z","html_url":"https://github.com/fossasia/open-event-android/pull/1750#discussion_r124982163","pull_request_url":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750","_links":{"self":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/comments/124982163"},"html":{"href":"https://github.com/fossasia/open-event-android/pull/1750#discussion_r124982163"},"pull_request":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750"}}},"pull_request":{"url":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750","id":128191858,"html_url":"https://github.com/fossasia/open-event-android/pull/1750","diff_url":"https://github.com/fossasia/open-event-android/pull/1750.diff","patch_url":"https://github.com/fossasia/open-event-android/pull/1750.patch","issue_url":"https://api.github.com/repos/fossasia/open-event-android/issues/1750","number":1750,"state":"open","locked":false,"title":"Implement caching in the livefeed","user":{"login":"rohanagarwal94","id":13241256,"avatar_url":"https://avatars0.githubusercontent.com/u/13241256?v=3","gravatar_id":"","url":"https://api.github.com/users/rohanagarwal94","html_url":"https://github.com/rohanagarwal94","followers_url":"https://api.github.com/users/rohanagarwal94/followers","following_url":"https://api.github.com/users/rohanagarwal94/following{/other_user}","gists_url":"https://api.github.com/users/rohanagarwal94/gists{/gist_id}","starred_url":"https://api.github.com/users/rohanagarwal94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohanagarwal94/subscriptions","organizations_url":"https://api.github.com/users/rohanagarwal94/orgs","repos_url":"https://api.github.com/users/rohanagarwal94/repos","events_url":"https://api.github.com/users/rohanagarwal94/events{/privacy}","received_events_url":"https://api.github.com/users/rohanagarwal94/received_events","type":"User","site_admin":false},"body":"Fixes #1735\r\n\r\nThis will implement caching in the live feed and solve app crash in the global search.","created_at":"2017-06-29T16:14:40Z","updated_at":"2017-06-30T07:49:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24609eee6da44bd17d4fa9b189d1142d22ccb453","assignee":{"login":"rohanagarwal94","id":13241256,"avatar_url":"https://avatars0.githubusercontent.com/u/13241256?v=3","gravatar_id":"","url":"https://api.github.com/users/rohanagarwal94","html_url":"https://github.com/rohanagarwal94","followers_url":"https://api.github.com/users/rohanagarwal94/followers","following_url":"https://api.github.com/users/rohanagarwal94/following{/other_user}","gists_url":"https://api.github.com/users/rohanagarwal94/gists{/gist_id}","starred_url":"https://api.github.com/users/rohanagarwal94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohanagarwal94/subscriptions","organizations_url":"https://api.github.com/users/rohanagarwal94/orgs","repos_url":"https://api.github.com/users/rohanagarwal94/repos","events_url":"https://api.github.com/users/rohanagarwal94/events{/privacy}","received_events_url":"https://api.github.com/users/rohanagarwal94/received_events","type":"User","site_admin":false},"assignees":[{"login":"rohanagarwal94","id":13241256,"avatar_url":"https://avatars0.githubusercontent.com/u/13241256?v=3","gravatar_id":"","url":"https://api.github.com/users/rohanagarwal94","html_url":"https://github.com/rohanagarwal94","followers_url":"https://api.github.com/users/rohanagarwal94/followers","following_url":"https://api.github.com/users/rohanagarwal94/following{/other_user}","gists_url":"https://api.github.com/users/rohanagarwal94/gists{/gist_id}","starred_url":"https://api.github.com/users/rohanagarwal94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohanagarwal94/subscriptions","organizations_url":"https://api.github.com/users/rohanagarwal94/orgs","repos_url":"https://api.github.com/users/rohanagarwal94/repos","events_url":"https://api.github.com/users/rohanagarwal94/events{/privacy}","received_events_url":"https://api.github.com/users/rohanagarwal94/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750/commits","review_comments_url":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750/comments","review_comment_url":"https://api.github.com/repos/fossasia/open-event-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/fossasia/open-event-android/issues/1750/comments","statuses_url":"https://api.github.com/repos/fossasia/open-event-android/statuses/76f75a58cd5d4dc38fb018ddff08ad4dbec0bd41","head":{"label":"rohanagarwal94:feedcaching","ref":"feedcaching","sha":"76f75a58cd5d4dc38fb018ddff08ad4dbec0bd41","user":{"login":"rohanagarwal94","id":13241256,"avatar_url":"https://avatars0.githubusercontent.com/u/13241256?v=3","gravatar_id":"","url":"https://api.github.com/users/rohanagarwal94","html_url":"https://github.com/rohanagarwal94","followers_url":"https://api.github.com/users/rohanagarwal94/followers","following_url":"https://api.github.com/users/rohanagarwal94/following{/other_user}","gists_url":"https://api.github.com/users/rohanagarwal94/gists{/gist_id}","starred_url":"https://api.github.com/users/rohanagarwal94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohanagarwal94/subscriptions","organizations_url":"https://api.github.com/users/rohanagarwal94/orgs","repos_url":"https://api.github.com/users/rohanagarwal94/repos","events_url":"https://api.github.com/users/rohanagarwal94/events{/privacy}","received_events_url":"https://api.github.com/users/rohanagarwal94/received_events","type":"User","site_admin":false},"repo":{"id":62865510,"name":"open-event-android","full_name":"rohanagarwal94/open-event-android","owner":{"login":"rohanagarwal94","id":13241256,"avatar_url":"https://avatars0.githubusercontent.com/u/13241256?v=3","gravatar_id":"","url":"https://api.github.com/users/rohanagarwal94","html_url":"https://github.com/rohanagarwal94","followers_url":"https://api.github.com/users/rohanagarwal94/followers","following_url":"https://api.github.com/users/rohanagarwal94/following{/other_user}","gists_url":"https://api.github.com/users/rohanagarwal94/gists{/gist_id}","starred_url":"https://api.github.com/users/rohanagarwal94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohanagarwal94/subscriptions","organizations_url":"https://api.github.com/users/rohanagarwal94/orgs","repos_url":"https://api.github.com/users/rohanagarwal94/repos","events_url":"https://api.github.com/users/rohanagarwal94/events{/privacy}","received_events_url":"https://api.github.com/users/rohanagarwal94/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rohanagarwal94/open-event-android","description":"The Open Event Android Client","fork":true,"url":"https://api.github.com/repos/rohanagarwal94/open-event-android","forks_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/forks","keys_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/teams","hooks_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/hooks","issue_events_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/issues/events{/number}","events_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/events","assignees_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/assignees{/user}","branches_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/branches{/branch}","tags_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/tags","blobs_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/statuses/{sha}","languages_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/languages","stargazers_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/stargazers","contributors_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/contributors","subscribers_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/subscribers","subscription_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/subscription","commits_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/contents/{+path}","compare_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/merges","archive_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/downloads","issues_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/issues{/number}","pulls_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/pulls{/number}","milestones_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/milestones{/number}","notifications_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/labels{/name}","releases_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/releases{/id}","deployments_url":"https://api.github.com/repos/rohanagarwal94/open-event-android/deployments","created_at":"2016-07-08T06:47:50Z","updated_at":"2016-07-08T06:47:52Z","pushed_at":"2017-06-30T04:34:18Z","git_url":"git://github.com/rohanagarwal94/open-event-android.git","ssh_url":"git@github.com:rohanagarwal94/open-event-android.git","clone_url":"https://github.com/rohanagarwal94/open-event-android.git","svn_url":"https://github.com/rohanagarwal94/open-event-android","homepage":null,"size":295429,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"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":"fossasia:development","ref":"development","sha":"7273f58643e106b0d50c7f5143f197f66bc3c6f7","user":{"login":"fossasia","id":6295529,"avatar_url":"https://avatars0.githubusercontent.com/u/6295529?v=3","gravatar_id":"","url":"https://api.github.com/users/fossasia","html_url":"https://github.com/fossasia","followers_url":"https://api.github.com/users/fossasia/followers","following_url":"https://api.github.com/users/fossasia/following{/other_user}","gists_url":"https://api.github.com/users/fossasia/gists{/gist_id}","starred_url":"https://api.github.com/users/fossasia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fossasia/subscriptions","organizations_url":"https://api.github.com/users/fossasia/orgs","repos_url":"https://api.github.com/users/fossasia/repos","events_url":"https://api.github.com/users/fossasia/events{/privacy}","received_events_url":"https://api.github.com/users/fossasia/received_events","type":"Organization","site_admin":false},"repo":{"id":35269607,"name":"open-event-android","full_name":"fossasia/open-event-android","owner":{"login":"fossasia","id":6295529,"avatar_url":"https://avatars0.githubusercontent.com/u/6295529?v=3","gravatar_id":"","url":"https://api.github.com/users/fossasia","html_url":"https://github.com/fossasia","followers_url":"https://api.github.com/users/fossasia/followers","following_url":"https://api.github.com/users/fossasia/following{/other_user}","gists_url":"https://api.github.com/users/fossasia/gists{/gist_id}","starred_url":"https://api.github.com/users/fossasia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fossasia/subscriptions","organizations_url":"https://api.github.com/users/fossasia/orgs","repos_url":"https://api.github.com/users/fossasia/repos","events_url":"https://api.github.com/users/fossasia/events{/privacy}","received_events_url":"https://api.github.com/users/fossasia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/fossasia/open-event-android","description":"Open Event Android App Generator https://github.com/fossasia/open-event-android/raw/apk/sample-apk-development.apk http://droidgen.eventyay.com","fork":false,"url":"https://api.github.com/repos/fossasia/open-event-android","forks_url":"https://api.github.com/repos/fossasia/open-event-android/forks","keys_url":"https://api.github.com/repos/fossasia/open-event-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fossasia/open-event-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fossasia/open-event-android/teams","hooks_url":"https://api.github.com/repos/fossasia/open-event-android/hooks","issue_events_url":"https://api.github.com/repos/fossasia/open-event-android/issues/events{/number}","events_url":"https://api.github.com/repos/fossasia/open-event-android/events","assignees_url":"https://api.github.com/repos/fossasia/open-event-android/assignees{/user}","branches_url":"https://api.github.com/repos/fossasia/open-event-android/branches{/branch}","tags_url":"https://api.github.com/repos/fossasia/open-event-android/tags","blobs_url":"https://api.github.com/repos/fossasia/open-event-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fossasia/open-event-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fossasia/open-event-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/fossasia/open-event-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fossasia/open-event-android/statuses/{sha}","languages_url":"https://api.github.com/repos/fossasia/open-event-android/languages","stargazers_url":"https://api.github.com/repos/fossasia/open-event-android/stargazers","contributors_url":"https://api.github.com/repos/fossasia/open-event-android/contributors","subscribers_url":"https://api.github.com/repos/fossasia/open-event-android/subscribers","subscription_url":"https://api.github.com/repos/fossasia/open-event-android/subscription","commits_url":"https://api.github.com/repos/fossasia/open-event-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/fossasia/open-event-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/fossasia/open-event-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/fossasia/open-event-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/fossasia/open-event-android/contents/{+path}","compare_url":"https://api.github.com/repos/fossasia/open-event-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fossasia/open-event-android/merges","archive_url":"https://api.github.com/repos/fossasia/open-event-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fossasia/open-event-android/downloads","issues_url":"https://api.github.com/repos/fossasia/open-event-android/issues{/number}","pulls_url":"https://api.github.com/repos/fossasia/open-event-android/pulls{/number}","milestones_url":"https://api.github.com/repos/fossasia/open-event-android/milestones{/number}","notifications_url":"https://api.github.com/repos/fossasia/open-event-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fossasia/open-event-android/labels{/name}","releases_url":"https://api.github.com/repos/fossasia/open-event-android/releases{/id}","deployments_url":"https://api.github.com/repos/fossasia/open-event-android/deployments","created_at":"2015-05-08T09:04:11Z","updated_at":"2017-06-25T13:47:15Z","pushed_at":"2017-06-30T06:44:43Z","git_url":"git://github.com/fossasia/open-event-android.git","ssh_url":"git@github.com:fossasia/open-event-android.git","clone_url":"https://github.com/fossasia/open-event-android.git","svn_url":"https://github.com/fossasia/open-event-android","homepage":"","size":103863,"stargazers_count":310,"watchers_count":310,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":335,"mirror_url":null,"open_issues_count":30,"forks":335,"open_issues":30,"watchers":310,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750"},"html":{"href":"https://github.com/fossasia/open-event-android/pull/1750"},"issue":{"href":"https://api.github.com/repos/fossasia/open-event-android/issues/1750"},"comments":{"href":"https://api.github.com/repos/fossasia/open-event-android/issues/1750/comments"},"review_comments":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750/comments"},"review_comment":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/fossasia/open-event-android/pulls/1750/commits"},"statuses":{"href":"https://api.github.com/repos/fossasia/open-event-android/statuses/76f75a58cd5d4dc38fb018ddff08ad4dbec0bd41"}}}}
{"actor":{"display_login":"iamareebjamal"}}