├── .github └── FUNDING.yml ├── .gradle ├── 4.4 │ ├── fileChanges │ │ └── last-build.bin │ ├── fileHashes │ │ ├── fileHashes.bin │ │ └── fileHashes.lock │ └── taskHistory │ │ ├── taskHistory.bin │ │ └── taskHistory.lock └── buildOutputCleanup │ ├── buildOutputCleanup.lock │ ├── cache.properties │ └── outputFiles.bin ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── libraries │ ├── Gradle__android_arch_core_common_1_1_1_jar.xml │ ├── Gradle__android_arch_core_runtime_1_1_1.xml │ ├── Gradle__android_arch_lifecycle_common_1_1_1_jar.xml │ ├── Gradle__android_arch_lifecycle_extensions_1_1_1.xml │ ├── Gradle__android_arch_lifecycle_livedata_1_1_1.xml │ ├── Gradle__android_arch_lifecycle_livedata_core_1_1_1.xml │ ├── Gradle__android_arch_lifecycle_runtime_1_1_1.xml │ ├── Gradle__android_arch_lifecycle_viewmodel_1_1_1.xml │ ├── Gradle__android_arch_paging_common_1_0_0_jar.xml │ ├── Gradle__android_arch_paging_runtime_1_0_0.xml │ ├── Gradle__com_android_support_animated_vector_drawable_28_0_0.xml │ ├── Gradle__com_android_support_appcompat_v7_28_0_0.xml │ ├── Gradle__com_android_support_asynclayoutinflater_28_0_0.xml │ ├── Gradle__com_android_support_cardview_v7_28_0_0.xml │ ├── Gradle__com_android_support_collections_28_0_0_jar.xml │ ├── Gradle__com_android_support_constraint_constraint_layout_1_1_3.xml │ ├── Gradle__com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml │ ├── Gradle__com_android_support_coordinatorlayout_28_0_0.xml │ ├── Gradle__com_android_support_cursoradapter_28_0_0.xml │ ├── Gradle__com_android_support_customview_28_0_0.xml │ ├── Gradle__com_android_support_design_28_0_0.xml │ ├── Gradle__com_android_support_documentfile_28_0_0.xml │ ├── Gradle__com_android_support_drawerlayout_28_0_0.xml │ ├── Gradle__com_android_support_exifinterface_27_1_0.xml │ ├── Gradle__com_android_support_interpolator_28_0_0.xml │ ├── Gradle__com_android_support_loader_28_0_0.xml │ ├── Gradle__com_android_support_localbroadcastmanager_28_0_0.xml │ ├── Gradle__com_android_support_print_28_0_0.xml │ ├── Gradle__com_android_support_recyclerview_v7_28_0_0.xml │ ├── Gradle__com_android_support_slidingpanelayout_28_0_0.xml │ ├── Gradle__com_android_support_support_annotations_28_0_0_jar.xml │ ├── Gradle__com_android_support_support_compat_28_0_0.xml │ ├── Gradle__com_android_support_support_core_ui_28_0_0.xml │ ├── Gradle__com_android_support_support_core_utils_28_0_0.xml │ ├── Gradle__com_android_support_support_fragment_28_0_0.xml │ ├── Gradle__com_android_support_support_vector_drawable_28_0_0.xml │ ├── Gradle__com_android_support_swiperefreshlayout_28_0_0.xml │ ├── Gradle__com_android_support_test_espresso_espresso_core_3_0_2.xml │ ├── Gradle__com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml │ ├── Gradle__com_android_support_test_monitor_1_0_2.xml │ ├── Gradle__com_android_support_test_runner_1_0_2.xml │ ├── Gradle__com_android_support_transition_28_0_0.xml │ ├── Gradle__com_android_support_versionedparcelable_28_0_0.xml │ ├── Gradle__com_android_support_viewpager_28_0_0.xml │ ├── Gradle__com_facebook_shimmer_shimmer_0_1_0.xml │ ├── Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml │ ├── Gradle__com_google_code_gson_gson_2_6_2_jar.xml │ ├── Gradle__com_jakewharton_android_repackaged_dalvik_dx_1_jar.xml │ ├── Gradle__com_jakewharton_android_repackaged_libcore_dex_2_jar.xml │ ├── Gradle__com_makeramen_roundedimageview_2_3_0.xml │ ├── Gradle__com_squareup_javawriter_2_1_1_jar.xml │ ├── Gradle__com_squareup_okhttp3_logging_interceptor_3_8_0_jar.xml │ ├── Gradle__com_squareup_okhttp3_okhttp_3_10_0_jar.xml │ ├── Gradle__com_squareup_okio_okio_1_14_0_jar.xml │ ├── Gradle__com_squareup_picasso_picasso_2_71828.xml │ ├── Gradle__com_squareup_retrofit2_converter_gson_2_0_2_jar.xml │ ├── Gradle__com_squareup_retrofit2_retrofit_2_0_2_jar.xml │ ├── Gradle__javax_inject_javax_inject_1_jar.xml │ ├── Gradle__junit_junit_4_12_jar.xml │ ├── Gradle__net_bytebuddy_byte_buddy_1_6_11_jar.xml │ ├── Gradle__net_bytebuddy_byte_buddy_agent_1_6_11_jar.xml │ ├── Gradle__net_bytebuddy_byte_buddy_android_1_6_5_jar.xml │ ├── Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml │ ├── Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml │ ├── Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml │ ├── Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml │ ├── Gradle__org_mockito_mockito_android_2_7_22_jar.xml │ ├── Gradle__org_mockito_mockito_core_2_7_22_jar.xml │ └── Gradle__org_objenesis_objenesis_2_5_jar.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── vcs.xml └── workspace.xml ├── MySample.iml ├── PagingLibrary.iml ├── PagingLibraryExample.iml ├── README.md ├── ViewModalSample.iml ├── android-paging-library-sample.iml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── paging │ │ └── com │ │ └── mysample │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── paging │ │ │ └── com │ │ │ └── mysample │ │ │ ├── FullImageActivity.java │ │ │ ├── Util │ │ │ ├── AppNetworkStatus.java │ │ │ ├── ErrorCode.java │ │ │ └── NetworkStatus.java │ │ │ ├── homescreen │ │ │ ├── ImageServices.java │ │ │ ├── ItemAdapter.java │ │ │ ├── ItemDataSource.java │ │ │ ├── ItemDataSourceFactory.java │ │ │ ├── ItemViewModel.java │ │ │ ├── MainActivity.java │ │ │ └── RetrofitClient.java │ │ │ └── pojo │ │ │ ├── IMResponse.java │ │ │ └── Image.java │ └── res │ │ ├── drawable-hdpi │ │ └── ic_action_name.png │ │ ├── drawable-mdpi │ │ └── ic_action_name.png │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xhdpi │ │ └── ic_action_name.png │ │ ├── drawable-xxhdpi │ │ └── ic_action_name.png │ │ ├── drawable │ │ ├── circle.xml │ │ ├── comments.xml │ │ ├── ic_launcher_background.xml │ │ ├── images.png │ │ ├── like.xml │ │ ├── shimmer_background.xml │ │ ├── transparent_box.xml │ │ └── wifi_off.png │ │ ├── layout │ │ ├── activity_full_image.xml │ │ ├── activity_main.xml │ │ ├── image_layout.xml │ │ ├── place_holder.xml │ │ └── retry_no_connection_layout.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── raw │ │ └── gif.gif │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── paging │ └── com │ └── mysample │ ├── ExampleUnitTest.java │ ├── ImageRepositoryTest.java │ └── MainPresenterTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gradle/4.4/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/4.4/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/4.4/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/4.4/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/4.4/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /.gradle/4.4/taskHistory/taskHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/4.4/taskHistory/taskHistory.bin -------------------------------------------------------------------------------- /.gradle/4.4/taskHistory/taskHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/4.4/taskHistory/taskHistory.lock -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Sun Dec 16 18:14:41 IST 2018 2 | gradle.version=4.4 3 | -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_core_common_1_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_core_runtime_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_common_1_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_extensions_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_livedata_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_livedata_core_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_runtime_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_lifecycle_viewmodel_1_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_paging_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__android_arch_paging_runtime_1_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_animated_vector_drawable_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_appcompat_v7_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_asynclayoutinflater_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_cardview_v7_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_collections_28_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_constraint_constraint_layout_1_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_constraint_constraint_layout_solver_1_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_coordinatorlayout_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_cursoradapter_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_customview_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_design_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_documentfile_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_drawerlayout_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_exifinterface_27_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_interpolator_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_loader_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_localbroadcastmanager_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_print_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_recyclerview_v7_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_slidingpanelayout_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_annotations_28_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_compat_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_core_ui_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_core_utils_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_fragment_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_support_vector_drawable_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_swiperefreshlayout_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_test_espresso_espresso_core_3_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_test_espresso_espresso_idling_resource_3_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_test_monitor_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_test_runner_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_transition_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_versionedparcelable_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_android_support_viewpager_28_0_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_facebook_shimmer_shimmer_0_1_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_google_code_findbugs_jsr305_2_0_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_google_code_gson_gson_2_6_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_jakewharton_android_repackaged_dalvik_dx_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_jakewharton_android_repackaged_libcore_dex_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_makeramen_roundedimageview_2_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_javawriter_2_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_okhttp3_logging_interceptor_3_8_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_3_10_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_okio_okio_1_14_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_picasso_picasso_2_71828.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_retrofit2_converter_gson_2_0_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__com_squareup_retrofit2_retrofit_2_0_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__javax_inject_javax_inject_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__junit_junit_4_12_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__net_bytebuddy_byte_buddy_1_6_11_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__net_bytebuddy_byte_buddy_agent_1_6_11_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__net_bytebuddy_byte_buddy_android_1_6_5_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__net_sf_kxml_kxml2_2_3_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_hamcrest_hamcrest_integration_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_hamcrest_hamcrest_library_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_mockito_mockito_android_2_7_22_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_mockito_mockito_core_2_7_22_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/Gradle__org_objenesis_objenesis_2_5_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /MySample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PagingLibrary.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PagingLibraryExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # android-paging-library-sample 2 | ### A sample application to describe new way of paging in recyclerView using paging library. 3 | Here is Android Paging Library sample application for you. Android Paging Library is an important component of Android Jetpack. 4 | 5 | Many app displays a large set of data to the users, for example consider the Amazon App, it shows you the list of products, and the app has too many products, but it do not loads all the product at once, it shows you some products, as soon as you reaches the last item of the product list it loads more products. This is called paging. 6 | 7 | 8 | 9 | #### Why use Paging? 10 | 11 | Assume you have more than 1000 items for your list that you are fetching from a backend server. Here are the cons if you are fetching everything at once. 12 | 13 | #### Disadvantages of not using Paging 14 | 15 | User do not see all the items at once, but you are fetching everything at once, so it will consume more bandwidth uselessly. 16 | Creating a large List at once uses more system resources resulting in a lagging app and bad user experience. 17 | Advantages of using Paging 18 | 19 | You will only load a small chunk from your large data set, it will consume less bandwidth. 20 | The app will use less resources resulting in a smooth app and nice user experience. 21 | Android Paging Library 22 | 23 | Android paging library is a component of android jetpack. Remember it is not available by default so we need to add it. It helps us to load data gradually and gracefully in our application’s RecyclerView. 24 | 25 | In this Android Paging Library Tutorial I will not tell you about the theoretical things about the library. Because to know this thing you can visit the official documentation. Instead of discussing the theoretical bla bla bla we will learn implementing the library in our application, as the official documentation might confuse you. 26 | 27 | #### Pre-Requisites 28 | 29 | Before moving ahead, you should go through these tutorials first, as we are going to use these things. 30 | 31 | Using Retrofit in Android: Complete Retrofit Playlist from Scratch. 32 | We will use the Retrofit Library to fetch the data from backend API. The above tutorial discusses about Retrofit and Building API from scratch. So you can check the sereis. 33 | RecyclerView: RecyclerView Tutorial. 34 | We will load the items in a RecyclerView after fetching it from server. 35 | Android ViewModel: Android ViewModel Tutorial. 36 | This is another component from Android Jetpack. It helps us to store UI related data in a more efficient way. 37 | -------------------------------------------------------------------------------- /ViewModalSample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /android-paging-library-sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.jdsports.com.mysample" 7 | minSdkVersion 21 8 | targetSdkVersion 28 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | //noinspection GradleCompatible 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 26 | 27 | // retrofit, gson 28 | implementation 'com.google.code.gson:gson:2.6.2' 29 | //implementation 'com.squareup.retrofit2:retrofit:2.0.2' 30 | implementation 'com.squareup.retrofit2:converter-gson:2.0.2' 31 | 32 | implementation 'com.android.support:recyclerview-v7:+' 33 | implementation 'com.squareup.picasso:picasso:2.71828' 34 | implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0' 35 | // implementation 'com.squareup.okhttp3:okhttp:3.8.0' 36 | implementation 'com.squareup.retrofit2:retrofit:2.0.0-beta3' 37 | implementation 'com.squareup.okhttp3:okhttp:3.0.0-RC1' 38 | // Shimmer effects 39 | implementation 'com.facebook.shimmer:shimmer:0.1.0@aar' 40 | //noinspection GradleCompatible 41 | implementation 'com.android.support:cardview-v7:23.3.+' 42 | implementation 'com.android.support:design:28.0.0' 43 | implementation 'com.makeramen:roundedimageview:2.3.0' 44 | 45 | implementation 'android.arch.paging:runtime:1.0.0' 46 | implementation 'android.arch.lifecycle:extensions:1.1.1' 47 | 48 | testImplementation 'junit:junit:4.12' 49 | 50 | // required if you want to use Mockito for unit tests 51 | testImplementation 'org.mockito:mockito-core:2.7.22' 52 | // required if you want to use Mockito for Android tests 53 | androidTestImplementation 'org.mockito:mockito-android:2.7.22' 54 | 55 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 56 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 57 | } 58 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/paging/com/mysample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.jdsports.com.mysample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/FullImageActivity.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.widget.ImageView; 7 | 8 | import com.squareup.picasso.Picasso; 9 | 10 | public class FullImageActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_full_image); 16 | 17 | Intent intent = getIntent(); 18 | String url = intent.getStringExtra("imageUrl"); 19 | if (!url.isEmpty()) { 20 | ImageView imageView = findViewById(R.id.image); 21 | Picasso.get() 22 | .load(url) 23 | .placeholder(R.drawable.shimmer_background) 24 | .into(imageView); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/Util/AppNetworkStatus.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.Util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | public class AppNetworkStatus implements NetworkStatus { 8 | 9 | private Context context; 10 | 11 | public AppNetworkStatus(Context context) { 12 | this.context = context; 13 | } 14 | 15 | @Override 16 | public boolean isOnline() { 17 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 18 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 19 | if (networkInfo != null && networkInfo.isConnected()) { 20 | // Device is online 21 | return true; 22 | } else { 23 | // Device is not online 24 | return false; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/Util/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.Util; 2 | 3 | public class ErrorCode { 4 | 5 | /** 6 | * common network error, when device is offline 7 | * check_internet 8 | */ 9 | public static final int NETWORK_ERROR = 100; 10 | public static final int CONNECTION_PROBLEM = 200; 11 | 12 | public static final int NO_RESULT = 300; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/Util/NetworkStatus.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.Util; 2 | 3 | public interface NetworkStatus { 4 | 5 | boolean isOnline(); 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/ImageServices.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import com.paging.com.mysample.pojo.IMResponse; 4 | 5 | import retrofit2.Call; 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Query; 8 | 9 | public interface ImageServices { 10 | 11 | @GET("api/") 12 | Call getAllImages(@Query("key") String apiKey, @Query("page") int page, @Query("per_page") String perPage); 13 | 14 | @GET("api/") 15 | Call searchImages(@Query("key") String apiKey, @Query("q") String searchQuery); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/ItemAdapter.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import android.arch.paging.PagedListAdapter; 4 | import android.content.Context; 5 | import android.graphics.Color; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.util.DiffUtil; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | 15 | import com.paging.com.mysample.R; 16 | import com.paging.com.mysample.pojo.Image; 17 | import com.makeramen.roundedimageview.RoundedTransformationBuilder; 18 | import com.squareup.picasso.Picasso; 19 | import com.squareup.picasso.Transformation; 20 | 21 | public class ItemAdapter extends PagedListAdapter { 22 | 23 | private static DiffUtil.ItemCallback DIFF_CALLBACK = 24 | new DiffUtil.ItemCallback() { 25 | @Override 26 | public boolean areItemsTheSame(Image oldItem, Image newItem) { 27 | return oldItem.getId() == newItem.getId(); 28 | } 29 | 30 | @Override 31 | public boolean areContentsTheSame(Image oldItem, Image newItem) { 32 | return oldItem.equals(newItem); 33 | } 34 | }; 35 | private Context mCtx; 36 | 37 | public ItemAdapter(Context mCtx) { 38 | super(DIFF_CALLBACK); 39 | this.mCtx = mCtx; 40 | } 41 | 42 | @NonNull 43 | @Override 44 | public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 45 | View view = LayoutInflater.from(mCtx).inflate(R.layout.image_layout, parent, false); 46 | return new ItemViewHolder(view); 47 | } 48 | 49 | @Override 50 | public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) { 51 | final Image image = getItem(position); 52 | holder.userName.setText(image.getUser().toString()); 53 | holder.like.setText(image.getLikes().toString()); 54 | holder.comments.setText(image.getComments().toString()); 55 | 56 | Picasso.get() 57 | .load(image.getLargeImageURL()) 58 | .placeholder(R.drawable.shimmer_background) 59 | .into(holder.image); 60 | 61 | Transformation transformation = new RoundedTransformationBuilder() 62 | .borderColor(Color.BLACK) 63 | .borderWidthDp(1) 64 | .cornerRadiusDp(30) 65 | .oval(false) 66 | .build(); 67 | 68 | if (!image.getUserImageURL().isEmpty()) { 69 | Picasso.get() 70 | .load(image.getUserImageURL()) 71 | .fit() 72 | .transform(transformation) 73 | .into(holder.userImage); 74 | } 75 | } 76 | 77 | class ItemViewHolder extends RecyclerView.ViewHolder { 78 | 79 | TextView userName, like, comments; 80 | ImageView image, userImage; 81 | 82 | public ItemViewHolder(View view) { 83 | super(view); 84 | image = view.findViewById(R.id.image); 85 | userImage = view.findViewById(R.id.user_image); 86 | userName = view.findViewById(R.id.user); 87 | like = view.findViewById(R.id.like); 88 | comments = view.findViewById(R.id.comments); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/ItemDataSource.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import android.arch.paging.PageKeyedDataSource; 4 | import android.support.annotation.NonNull; 5 | 6 | import com.paging.com.mysample.pojo.IMResponse; 7 | import com.paging.com.mysample.pojo.Image; 8 | 9 | import retrofit2.Call; 10 | import retrofit2.Callback; 11 | import retrofit2.Response; 12 | 13 | 14 | public class ItemDataSource extends PageKeyedDataSource { 15 | 16 | public static final int PAGE_SIZE = 50; 17 | private static final int FIRST_PAGE = 1; 18 | private final String API_KEY = "8439361-5e1e53a0e1b58baa26ab398f7"; 19 | 20 | @Override 21 | public void loadInitial(@NonNull LoadInitialParams params, @NonNull final LoadInitialCallback callback) { 22 | 23 | RetrofitClient.getInstance() 24 | .getApi().getAllImages(API_KEY, FIRST_PAGE, "3") 25 | .enqueue(new Callback() { 26 | @Override 27 | public void onResponse(Call call, Response response) { 28 | if (response.body() != null) { 29 | callback.onResult(response.body().getImages(), null, FIRST_PAGE + 1); 30 | } 31 | } 32 | 33 | @Override 34 | public void onFailure(Call call, Throwable t) { 35 | 36 | } 37 | }); 38 | } 39 | 40 | @Override 41 | public void loadBefore(@NonNull final LoadParams params, @NonNull final LoadCallback callback) { 42 | RetrofitClient.getInstance() 43 | .getApi().getAllImages(API_KEY, params.key, "3") 44 | .enqueue(new Callback() { 45 | @Override 46 | public void onResponse(Call call, Response response) { 47 | Integer adjacentKey = (params.key > 1) ? params.key - 1 : null; 48 | if (response.body() != null) { 49 | callback.onResult(response.body().getImages(), adjacentKey); 50 | } 51 | } 52 | 53 | @Override 54 | public void onFailure(Call call, Throwable t) { 55 | 56 | } 57 | }); 58 | } 59 | 60 | @Override 61 | public void loadAfter(@NonNull final LoadParams params, @NonNull final LoadCallback callback) { 62 | RetrofitClient.getInstance() 63 | .getApi() 64 | .getAllImages(API_KEY, params.key, "3") 65 | .enqueue(new Callback() { 66 | @Override 67 | public void onResponse(Call call, Response response) { 68 | if (response.body() != null && true) { 69 | callback.onResult(response.body().getImages(), params.key + 1); 70 | } 71 | } 72 | 73 | @Override 74 | public void onFailure(Call call, Throwable t) { 75 | 76 | } 77 | }); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/ItemDataSourceFactory.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import android.arch.lifecycle.MutableLiveData; 4 | import android.arch.paging.DataSource; 5 | import android.arch.paging.PageKeyedDataSource; 6 | 7 | import com.paging.com.mysample.pojo.Image; 8 | 9 | public class ItemDataSourceFactory extends DataSource.Factory { 10 | 11 | private MutableLiveData> itemLiveDataSource = new MutableLiveData<>(); 12 | 13 | 14 | @Override 15 | public DataSource create() { 16 | ItemDataSource itemDataSource = new ItemDataSource(); 17 | itemLiveDataSource.postValue(itemDataSource); 18 | return itemDataSource; 19 | } 20 | 21 | public MutableLiveData> getItemLiveDataSource() { 22 | return itemLiveDataSource; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/ItemViewModel.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import android.arch.lifecycle.LiveData; 4 | import android.arch.lifecycle.ViewModel; 5 | import android.arch.paging.LivePagedListBuilder; 6 | import android.arch.paging.PageKeyedDataSource; 7 | import android.arch.paging.PagedList; 8 | 9 | import com.paging.com.mysample.pojo.Image; 10 | 11 | public class ItemViewModel extends ViewModel { 12 | 13 | public LiveData> itemPagedList; 14 | public LiveData> liveDataSource; 15 | 16 | public ItemViewModel() { 17 | ItemDataSourceFactory itemDataSourceFactory = new ItemDataSourceFactory(); 18 | liveDataSource = itemDataSourceFactory.getItemLiveDataSource(); 19 | 20 | PagedList.Config pagedListConfig = 21 | (new PagedList.Config.Builder()) 22 | .setEnablePlaceholders(false) 23 | .setPageSize(ItemDataSource.PAGE_SIZE).build(); 24 | 25 | itemPagedList = (new LivePagedListBuilder(itemDataSourceFactory, pagedListConfig)) 26 | .build(); 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import android.arch.lifecycle.Observer; 4 | import android.arch.lifecycle.ViewModelProviders; 5 | import android.arch.paging.PagedList; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | import android.support.annotation.Nullable; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.Menu; 14 | import android.view.MenuInflater; 15 | import android.view.View; 16 | import android.widget.FrameLayout; 17 | 18 | import com.facebook.shimmer.ShimmerFrameLayout; 19 | import com.paging.com.mysample.R; 20 | import com.paging.com.mysample.pojo.Image; 21 | 22 | public class MainActivity extends AppCompatActivity { 23 | 24 | private ShimmerFrameLayout shimmerViewContainer; 25 | private ItemAdapter adapter; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_main); 31 | setUpUI(); 32 | final RecyclerView recyclerView = findViewById(R.id.image_list); 33 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 34 | recyclerView.setHasFixedSize(true); 35 | ItemViewModel itemViewModel = ViewModelProviders.of(this).get(ItemViewModel.class); 36 | 37 | adapter = new ItemAdapter(this); 38 | showLoadingIndicator(true); 39 | itemViewModel.itemPagedList.observe(this, new Observer>() { 40 | @Override 41 | public void onChanged(@Nullable final PagedList items) { 42 | 43 | if (shimmerViewContainer.getVisibility() == View.VISIBLE) { 44 | showLoadingIndicator(false); 45 | } 46 | recyclerView.setVisibility(View.VISIBLE); 47 | adapter.submitList(items); 48 | 49 | } 50 | }); 51 | 52 | recyclerView.setAdapter(adapter); 53 | } 54 | 55 | @Override 56 | public boolean onCreateOptionsMenu(Menu menu) { 57 | MenuInflater inflater = getMenuInflater(); 58 | // Inflate menu to add items to action bar if it is present. 59 | inflater.inflate(R.menu.menu_main, menu); 60 | return true; 61 | } 62 | 63 | public void showLoadingIndicator(boolean active) { 64 | if (active) { 65 | shimmerViewContainer.setVisibility(View.VISIBLE); 66 | shimmerViewContainer.startShimmerAnimation(); 67 | } else { 68 | 69 | Handler handler = new Handler(); 70 | handler.postDelayed(new Runnable() { 71 | @Override 72 | public void run() { 73 | shimmerViewContainer.stopShimmerAnimation(); 74 | shimmerViewContainer.setVisibility(View.GONE); 75 | } 76 | }, 2000); 77 | 78 | } 79 | } 80 | 81 | public void setUpUI() { 82 | Toolbar toolbar = findViewById(R.id.tabanim_toolbar); 83 | toolbar.setTitle(getResources().getString(R.string.app_name)); 84 | setSupportActionBar(toolbar); 85 | shimmerViewContainer = findViewById(R.id.shimmer_view_container); 86 | } 87 | 88 | @Override 89 | public void onResume() { 90 | super.onResume(); 91 | shimmerViewContainer.startShimmerAnimation(); 92 | } 93 | 94 | @Override 95 | protected void onPause() { 96 | shimmerViewContainer.stopShimmerAnimation(); 97 | super.onPause(); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/homescreen/RetrofitClient.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.homescreen; 2 | 3 | import retrofit2.Retrofit; 4 | import retrofit2.converter.gson.GsonConverterFactory; 5 | 6 | public class RetrofitClient { 7 | 8 | private static final String BASE_URL = "https://pixabay.com/"; 9 | private static RetrofitClient mInstance; 10 | private Retrofit retrofit; 11 | 12 | 13 | private RetrofitClient() { 14 | retrofit = new Retrofit.Builder() 15 | .baseUrl(BASE_URL) 16 | .addConverterFactory(GsonConverterFactory.create()) 17 | .build(); 18 | } 19 | 20 | public static synchronized RetrofitClient getInstance() { 21 | if (mInstance == null) { 22 | mInstance = new RetrofitClient(); 23 | } 24 | return mInstance; 25 | } 26 | 27 | public ImageServices getApi() { 28 | return retrofit.create(ImageServices.class); 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/pojo/IMResponse.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.pojo; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.List; 7 | 8 | public class IMResponse { 9 | 10 | @SerializedName("totalHits") 11 | @Expose 12 | private Integer totalHits; 13 | @SerializedName("hits") 14 | @Expose 15 | private List images = null; 16 | @SerializedName("total") 17 | @Expose 18 | private Integer total; 19 | 20 | public Integer getTotalHits() { 21 | return totalHits; 22 | } 23 | 24 | public void setTotalHits(Integer totalHits) { 25 | this.totalHits = totalHits; 26 | } 27 | 28 | public List getImages() { 29 | return images; 30 | } 31 | 32 | public void setImages(List images) { 33 | this.images = images; 34 | } 35 | 36 | public Integer getTotal() { 37 | return total; 38 | } 39 | 40 | public void setTotal(Integer total) { 41 | this.total = total; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/paging/com/mysample/pojo/Image.java: -------------------------------------------------------------------------------- 1 | package com.paging.com.mysample.pojo; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | public class Image { 7 | 8 | @SerializedName("largeImageURL") 9 | @Expose 10 | private String largeImageURL; 11 | @SerializedName("webformatHeight") 12 | @Expose 13 | private Integer webformatHeight; 14 | @SerializedName("webformatWidth") 15 | @Expose 16 | private Integer webformatWidth; 17 | @SerializedName("likes") 18 | @Expose 19 | private Integer likes; 20 | @SerializedName("imageWidth") 21 | @Expose 22 | private Integer imageWidth; 23 | @SerializedName("id") 24 | @Expose 25 | private Integer id; 26 | @SerializedName("user_id") 27 | @Expose 28 | private Integer userId; 29 | @SerializedName("views") 30 | @Expose 31 | private Integer views; 32 | @SerializedName("comments") 33 | @Expose 34 | private Integer comments; 35 | @SerializedName("pageURL") 36 | @Expose 37 | private String pageURL; 38 | @SerializedName("imageHeight") 39 | @Expose 40 | private Integer imageHeight; 41 | @SerializedName("webformatURL") 42 | @Expose 43 | private String webformatURL; 44 | @SerializedName("type") 45 | @Expose 46 | private String type; 47 | @SerializedName("previewHeight") 48 | @Expose 49 | private Integer previewHeight; 50 | @SerializedName("tags") 51 | @Expose 52 | private String tags; 53 | @SerializedName("downloads") 54 | @Expose 55 | private Integer downloads; 56 | @SerializedName("user") 57 | @Expose 58 | private String user; 59 | @SerializedName("favorites") 60 | @Expose 61 | private Integer favorites; 62 | @SerializedName("imageSize") 63 | @Expose 64 | private Integer imageSize; 65 | @SerializedName("previewWidth") 66 | @Expose 67 | private Integer previewWidth; 68 | @SerializedName("userImageURL") 69 | @Expose 70 | private String userImageURL; 71 | @SerializedName("previewURL") 72 | @Expose 73 | private String previewURL; 74 | 75 | public String getLargeImageURL() { 76 | return largeImageURL; 77 | } 78 | 79 | public void setLargeImageURL(String largeImageURL) { 80 | this.largeImageURL = largeImageURL; 81 | } 82 | 83 | public Integer getWebformatHeight() { 84 | return webformatHeight; 85 | } 86 | 87 | public void setWebformatHeight(Integer webformatHeight) { 88 | this.webformatHeight = webformatHeight; 89 | } 90 | 91 | public Integer getWebformatWidth() { 92 | return webformatWidth; 93 | } 94 | 95 | public void setWebformatWidth(Integer webformatWidth) { 96 | this.webformatWidth = webformatWidth; 97 | } 98 | 99 | public Integer getLikes() { 100 | return likes; 101 | } 102 | 103 | public void setLikes(Integer likes) { 104 | this.likes = likes; 105 | } 106 | 107 | public Integer getImageWidth() { 108 | return imageWidth; 109 | } 110 | 111 | public void setImageWidth(Integer imageWidth) { 112 | this.imageWidth = imageWidth; 113 | } 114 | 115 | public Integer getId() { 116 | return id; 117 | } 118 | 119 | public void setId(Integer id) { 120 | this.id = id; 121 | } 122 | 123 | public Integer getUserId() { 124 | return userId; 125 | } 126 | 127 | public void setUserId(Integer userId) { 128 | this.userId = userId; 129 | } 130 | 131 | public Integer getViews() { 132 | return views; 133 | } 134 | 135 | public void setViews(Integer views) { 136 | this.views = views; 137 | } 138 | 139 | public Integer getComments() { 140 | return comments; 141 | } 142 | 143 | public void setComments(Integer comments) { 144 | this.comments = comments; 145 | } 146 | 147 | public String getPageURL() { 148 | return pageURL; 149 | } 150 | 151 | public void setPageURL(String pageURL) { 152 | this.pageURL = pageURL; 153 | } 154 | 155 | public Integer getImageHeight() { 156 | return imageHeight; 157 | } 158 | 159 | public void setImageHeight(Integer imageHeight) { 160 | this.imageHeight = imageHeight; 161 | } 162 | 163 | public String getWebformatURL() { 164 | return webformatURL; 165 | } 166 | 167 | public void setWebformatURL(String webformatURL) { 168 | this.webformatURL = webformatURL; 169 | } 170 | 171 | public String getType() { 172 | return type; 173 | } 174 | 175 | public void setType(String type) { 176 | this.type = type; 177 | } 178 | 179 | public Integer getPreviewHeight() { 180 | return previewHeight; 181 | } 182 | 183 | public void setPreviewHeight(Integer previewHeight) { 184 | this.previewHeight = previewHeight; 185 | } 186 | 187 | public String getTags() { 188 | return tags; 189 | } 190 | 191 | public void setTags(String tags) { 192 | this.tags = tags; 193 | } 194 | 195 | public Integer getDownloads() { 196 | return downloads; 197 | } 198 | 199 | public void setDownloads(Integer downloads) { 200 | this.downloads = downloads; 201 | } 202 | 203 | public String getUser() { 204 | return user; 205 | } 206 | 207 | public void setUser(String user) { 208 | this.user = user; 209 | } 210 | 211 | public Integer getFavorites() { 212 | return favorites; 213 | } 214 | 215 | public void setFavorites(Integer favorites) { 216 | this.favorites = favorites; 217 | } 218 | 219 | public Integer getImageSize() { 220 | return imageSize; 221 | } 222 | 223 | public void setImageSize(Integer imageSize) { 224 | this.imageSize = imageSize; 225 | } 226 | 227 | public Integer getPreviewWidth() { 228 | return previewWidth; 229 | } 230 | 231 | public void setPreviewWidth(Integer previewWidth) { 232 | this.previewWidth = previewWidth; 233 | } 234 | 235 | public String getUserImageURL() { 236 | return userImageURL; 237 | } 238 | 239 | public void setUserImageURL(String userImageURL) { 240 | this.userImageURL = userImageURL; 241 | } 242 | 243 | public String getPreviewURL() { 244 | return previewURL; 245 | } 246 | 247 | public void setPreviewURL(String previewURL) { 248 | this.previewURL = previewURL; 249 | } 250 | 251 | } 252 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable-hdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable-mdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable-xhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_name.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable-xxhdpi/ic_action_name.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/comments.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable/images.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/like.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shimmer_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/transparent_box.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/wifi_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rkandoroidrepo/android-paging-library-sample/33bd3932229b4aa2c2d94b2827b0c43701feaa2c/app/src/main/res/drawable/wifi_off.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_full_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 19 | 20 | 21 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | 50 | 51 | 52 | 53 | 61 | 62 | 63 | 64 | 65 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /app/src/main/res/layout/image_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 | 26 | 27 | 33 | 34 | 35 | 40 | 41 | 54 | 55 | 63 | 64 | 72 | 73 | 79 | 80 | 90 | 91 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/res/layout/place_holder.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 23 | 24 | 31 | 32 | 40 | 41 | 45 | 46 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/retry_no_connection_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 14 | 15 | 20 | 21 | 30 | 31 | 38 | 39 |