├── .gitignore ├── LICENCE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── packtpub │ │ └── apps │ │ └── rxjava_essentials │ │ ├── App.java │ │ ├── MainActivity.java │ │ ├── ScrimInsetsFrameLayout.java │ │ ├── Utils.java │ │ ├── apps │ │ ├── AppInfo.java │ │ ├── AppInfoRich.java │ │ ├── ApplicationAdapter.java │ │ └── ApplicationsList.java │ │ ├── chapter4 │ │ ├── DistinctExampleFragment.java │ │ ├── FilterExampleFragment.java │ │ └── TakeExampleFragment.java │ │ ├── chapter5 │ │ ├── GroupByExampleFragment.java │ │ ├── MapExampleFragment.java │ │ └── ScanExampleFragment.java │ │ ├── chapter6 │ │ ├── AndThenWhenExampleFragment.java │ │ ├── CombineLatestExampleFragment.java │ │ ├── JoinExampleFragment.java │ │ ├── MergeExampleFragment.java │ │ └── ZipExampleFragment.java │ │ ├── chapter7 │ │ ├── LongTaskFragment.java │ │ ├── NetworkTaskFragment.java │ │ └── SharedPreferencesListFragment.java │ │ ├── chapter8 │ │ ├── SoActivity.java │ │ ├── SoAdapter.java │ │ └── api │ │ │ ├── openweathermap │ │ │ ├── OpenWeatherMapApiManager.java │ │ │ ├── OpenWeatherMapService.java │ │ │ └── models │ │ │ │ ├── Clouds.java │ │ │ │ ├── Coord.java │ │ │ │ ├── Main.java │ │ │ │ ├── Sys.java │ │ │ │ ├── Weather.java │ │ │ │ ├── WeatherResponse.java │ │ │ │ └── Wind.java │ │ │ └── stackexchange │ │ │ ├── SeApiManager.java │ │ │ ├── StackExchangeService.java │ │ │ └── models │ │ │ ├── BadgeCounts.java │ │ │ ├── User.java │ │ │ └── UsersResponse.java │ │ ├── example1 │ │ └── FirstExampleFragment.java │ │ ├── example2 │ │ └── SecondExampleFragment.java │ │ ├── example3 │ │ └── ThirdExampleFragment.java │ │ └── navigation_drawer │ │ ├── NavigationDrawerAdapter.java │ │ ├── NavigationDrawerCallbacks.java │ │ ├── NavigationDrawerFragment.java │ │ └── NavigationItem.java │ └── res │ ├── drawable-hdpi │ ├── ic_action_android.png │ ├── ic_action_filter.png │ ├── ic_action_playback_schuffle.png │ ├── ic_action_process_save.png │ ├── ic_action_wizard.png │ └── ic_menu_check.png │ ├── drawable-mdpi │ ├── ic_action_android.png │ ├── ic_action_filter.png │ ├── ic_action_playback_schuffle.png │ ├── ic_action_process_save.png │ ├── ic_action_wizard.png │ └── ic_menu_check.png │ ├── drawable-xhdpi │ ├── bg_bt_raise.9.png │ ├── bg_bt_raise_color.9.png │ ├── ic_action_android.png │ ├── ic_action_filter.png │ ├── ic_action_playback_schuffle.png │ ├── ic_action_process_save.png │ ├── ic_action_wizard.png │ └── ic_menu_check.png │ ├── drawable-xxhdpi │ ├── ic_action_android.png │ ├── ic_action_filter.png │ ├── ic_action_playback_schuffle.png │ ├── ic_action_process_save.png │ ├── ic_action_wizard.png │ ├── ic_menu_check.png │ └── packt_logo.png │ ├── drawable │ ├── button_rect_list_normal.xml │ ├── button_rect_list_secondary.xml │ ├── button_round.xml │ ├── color_tpi.xml │ ├── round.xml │ ├── round_touch.xml │ └── transparent_pixel.png │ ├── layout │ ├── activity_main.xml │ ├── activity_so.xml │ ├── applications_list_item.xml │ ├── drawer_row.xml │ ├── fragment_download.xml │ ├── fragment_example.xml │ ├── fragment_item_grid.xml │ ├── fragment_item_list.xml │ ├── fragment_navigation_drawer.xml │ ├── so_list_item.xml │ └── toolbar_default.xml │ ├── menu │ ├── main.xml │ └── menu_so.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-large │ └── refs.xml │ ├── values-sw600dp │ └── refs.xml │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ ├── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── refs.xml │ ├── strings.xml │ ├── styles.xml │ └── styles_material.xml │ └── xml │ └── fab_icon_states.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── drawer_bellow.gif ├── drawer_over_toolbar.gif ├── playstore_style.gif └── screenshot1.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea/ 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | com_crashlytics_export_strings.xml 10 | crashlytics-build.properties 11 | captures/ -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RxJava Essentials code samples 2 | 3 | These are the [RxJava Essentials](https://www.packtpub.com/application-development/rxjava-essentials) code samples modified to use the latest build tools and with minor code formatting modifications. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'me.tatarka.retrolambda' 2 | apply plugin: 'com.android.application' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.0" 7 | 8 | defaultConfig { 9 | applicationId "com.packtpub.apps.rxjava_essentials" 10 | minSdkVersion 16 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | compileOptions { 24 | sourceCompatibility JavaVersion.VERSION_1_8 25 | targetCompatibility JavaVersion.VERSION_1_8 26 | } 27 | 28 | lintOptions { 29 | disable 'InvalidPackage' 30 | abortOnError false 31 | } 32 | 33 | packagingOptions { 34 | exclude 'META-INF/services/javax.annotation.processing.Processor' 35 | } 36 | } 37 | 38 | repositories { 39 | jcenter() 40 | maven { url "https://github.com/alter-ego/advanced-android-logger/raw/develop/releases/" } 41 | } 42 | 43 | dependencies { 44 | compile fileTree(dir: 'libs', include: ['*.jar']) 45 | compile 'com.android.support:support-v4:23.0.0' 46 | compile "com.android.support:appcompat-v7:23.0.0" 47 | compile 'com.android.support:recyclerview-v7:23.0.0' 48 | compile 'com.android.support:cardview-v7:23.0.0' 49 | 50 | compile 'com.alterego:advancedandroidlogger:1.0.3@aar' 51 | 52 | provided 'org.projectlombok:lombok:1.16.6' 53 | compile 'com.jakewharton:butterknife:6.1.0' 54 | 55 | compile 'io.reactivex:rxandroid:0.24.0' 56 | compile 'io.reactivex:rxjava-joins:0.22.0' 57 | 58 | compile 'com.google.guava:guava:18.0' 59 | compile 'com.google.code.gson:gson:2.3.1' 60 | 61 | compile 'com.github.lzyzsd:circleprogress:1.1.0@aar' 62 | compile 'com.github.rey5137:material:1.0.0' 63 | 64 | compile 'com.squareup.retrofit:retrofit:1.9.0' 65 | compile 'com.squareup.okhttp:okhttp:2.4.0' 66 | 67 | compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' 68 | } 69 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Development\Android\android-studio\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 28 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/App.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import com.alterego.advancedandroidlogger.implementations.DetailedAndroidLogger; 6 | import com.alterego.advancedandroidlogger.interfaces.IAndroidLogger; 7 | import com.nostra13.universalimageloader.core.DisplayImageOptions; 8 | import com.nostra13.universalimageloader.core.ImageLoader; 9 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 10 | import com.nostra13.universalimageloader.core.assist.ImageScaleType; 11 | 12 | public class App extends Application { 13 | 14 | public static DetailedAndroidLogger L; 15 | 16 | public static Context instance; 17 | 18 | @Override public void onCreate() { 19 | super.onCreate(); 20 | instance = this; 21 | 22 | L = new DetailedAndroidLogger("RXJAVA", IAndroidLogger.LoggingLevel.DEBUG); 23 | 24 | DisplayImageOptions defaultOptions = 25 | new DisplayImageOptions.Builder().showImageOnFail(R.drawable.ic_launcher) 26 | .showImageOnLoading(R.drawable.ic_launcher) 27 | .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) 28 | .cacheInMemory(true) 29 | .cacheOnDisk(true) 30 | .build(); 31 | ImageLoaderConfiguration config = 32 | new ImageLoaderConfiguration.Builder(getApplicationContext()).defaultDisplayImageOptions( 33 | defaultOptions).build(); 34 | ImageLoader.getInstance().init(config); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials; 2 | 3 | import android.app.FragmentManager; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.os.StrictMode; 7 | import android.support.v4.widget.DrawerLayout; 8 | import android.support.v7.app.ActionBarActivity; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.Menu; 11 | import butterknife.ButterKnife; 12 | import butterknife.InjectView; 13 | import com.packtpub.apps.rxjava_essentials.chapter4.DistinctExampleFragment; 14 | import com.packtpub.apps.rxjava_essentials.chapter4.FilterExampleFragment; 15 | import com.packtpub.apps.rxjava_essentials.chapter4.TakeExampleFragment; 16 | import com.packtpub.apps.rxjava_essentials.chapter5.GroupByExampleFragment; 17 | import com.packtpub.apps.rxjava_essentials.chapter5.MapExampleFragment; 18 | import com.packtpub.apps.rxjava_essentials.chapter5.ScanExampleFragment; 19 | import com.packtpub.apps.rxjava_essentials.chapter6.AndThenWhenExampleFragment; 20 | import com.packtpub.apps.rxjava_essentials.chapter6.CombineLatestExampleFragment; 21 | import com.packtpub.apps.rxjava_essentials.chapter6.JoinExampleFragment; 22 | import com.packtpub.apps.rxjava_essentials.chapter6.MergeExampleFragment; 23 | import com.packtpub.apps.rxjava_essentials.chapter6.ZipExampleFragment; 24 | import com.packtpub.apps.rxjava_essentials.chapter7.LongTaskFragment; 25 | import com.packtpub.apps.rxjava_essentials.chapter7.NetworkTaskFragment; 26 | import com.packtpub.apps.rxjava_essentials.chapter7.SharedPreferencesListFragment; 27 | import com.packtpub.apps.rxjava_essentials.chapter8.SoActivity; 28 | import com.packtpub.apps.rxjava_essentials.example1.FirstExampleFragment; 29 | import com.packtpub.apps.rxjava_essentials.example2.SecondExampleFragment; 30 | import com.packtpub.apps.rxjava_essentials.example3.ThirdExampleFragment; 31 | import com.packtpub.apps.rxjava_essentials.navigation_drawer.NavigationDrawerCallbacks; 32 | import com.packtpub.apps.rxjava_essentials.navigation_drawer.NavigationDrawerFragment; 33 | 34 | public class MainActivity extends ActionBarActivity implements NavigationDrawerCallbacks { 35 | 36 | @InjectView(R.id.toolbar_actionbar) Toolbar mToolbar; 37 | 38 | @InjectView(R.id.drawer) DrawerLayout mDrawerLayout; 39 | 40 | private NavigationDrawerFragment mNavigationDrawerFragment; 41 | 42 | @Override protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_main); 45 | ButterKnife.inject(this); 46 | 47 | setSupportActionBar(mToolbar); 48 | getSupportActionBar().setDisplayShowHomeEnabled(true); 49 | 50 | mNavigationDrawerFragment = 51 | (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer); 52 | mNavigationDrawerFragment.setup(R.id.fragment_drawer, mDrawerLayout, mToolbar); 53 | 54 | if (BuildConfig.DEBUG) { 55 | StrictMode.setThreadPolicy( 56 | new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); 57 | StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); 58 | } 59 | } 60 | 61 | @Override public boolean onCreateOptionsMenu(Menu menu) { 62 | getMenuInflater().inflate(com.packtpub.apps.rxjava_essentials.R.menu.main, menu); 63 | return super.onCreateOptionsMenu(menu); 64 | } 65 | 66 | @Override public void onNavigationDrawerItemSelected(int position) { 67 | FragmentManager fragmentManager = getFragmentManager(); 68 | switch (position) { 69 | case 0: 70 | fragmentManager.beginTransaction() 71 | .replace(R.id.container, new FirstExampleFragment()) 72 | .commit(); 73 | break; 74 | case 1: 75 | fragmentManager.beginTransaction() 76 | .replace(R.id.container, new SecondExampleFragment()) 77 | .commit(); 78 | break; 79 | case 2: 80 | fragmentManager.beginTransaction() 81 | .replace(R.id.container, new ThirdExampleFragment()) 82 | .commit(); 83 | break; 84 | case 3: 85 | fragmentManager.beginTransaction() 86 | .replace(R.id.container, new FilterExampleFragment()) 87 | .commit(); 88 | break; 89 | case 4: 90 | fragmentManager.beginTransaction() 91 | .replace(R.id.container, new TakeExampleFragment()) 92 | .commit(); 93 | break; 94 | case 5: 95 | fragmentManager.beginTransaction() 96 | .replace(R.id.container, new DistinctExampleFragment()) 97 | .commit(); 98 | break; 99 | case 6: 100 | fragmentManager.beginTransaction() 101 | .replace(R.id.container, new MapExampleFragment()) 102 | .commit(); 103 | break; 104 | case 7: 105 | fragmentManager.beginTransaction() 106 | .replace(R.id.container, new ScanExampleFragment()) 107 | .commit(); 108 | break; 109 | case 8: 110 | fragmentManager.beginTransaction() 111 | .replace(R.id.container, new GroupByExampleFragment()) 112 | .commit(); 113 | break; 114 | case 9: 115 | fragmentManager.beginTransaction() 116 | .replace(R.id.container, new MergeExampleFragment()) 117 | .commit(); 118 | break; 119 | case 10: 120 | fragmentManager.beginTransaction() 121 | .replace(R.id.container, new ZipExampleFragment()) 122 | .commit(); 123 | break; 124 | case 11: 125 | fragmentManager.beginTransaction() 126 | .replace(R.id.container, new JoinExampleFragment()) 127 | .commit(); 128 | break; 129 | case 12: 130 | fragmentManager.beginTransaction() 131 | .replace(R.id.container, new CombineLatestExampleFragment()) 132 | .commit(); 133 | break; 134 | case 13: 135 | fragmentManager.beginTransaction() 136 | .replace(R.id.container, new AndThenWhenExampleFragment()) 137 | .commit(); 138 | break; 139 | case 14: 140 | fragmentManager.beginTransaction() 141 | .replace(R.id.container, new SharedPreferencesListFragment()) 142 | .commit(); 143 | break; 144 | case 15: 145 | fragmentManager.beginTransaction().replace(R.id.container, new LongTaskFragment()).commit(); 146 | break; 147 | case 16: 148 | fragmentManager.beginTransaction() 149 | .replace(R.id.container, new NetworkTaskFragment()) 150 | .commit(); 151 | break; 152 | case 17: 153 | startActivity(new Intent(this, SoActivity.class)); 154 | break; 155 | } 156 | } 157 | 158 | @Override public void onBackPressed() { 159 | if (mNavigationDrawerFragment.isDrawerOpen()) { 160 | mNavigationDrawerFragment.closeDrawer(); 161 | } else { 162 | super.onBackPressed(); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/ScrimInsetsFrameLayout.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v4.view.ViewCompat; 9 | import android.util.AttributeSet; 10 | import android.widget.FrameLayout; 11 | 12 | /** 13 | * A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the 14 | * area above UI chrome 15 | * (status and navigation bars, overlay action bars). 16 | */ 17 | public class ScrimInsetsFrameLayout extends FrameLayout { 18 | 19 | private Drawable mInsetForeground; 20 | 21 | private Rect mInsets; 22 | 23 | private Rect mTempRect = new Rect(); 24 | 25 | private OnInsetsCallback mOnInsetsCallback; 26 | 27 | public ScrimInsetsFrameLayout(Context context) { 28 | super(context); 29 | init(context, null, 0); 30 | } 31 | 32 | public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | init(context, attrs, 0); 35 | } 36 | 37 | public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) { 38 | super(context, attrs, defStyle); 39 | init(context, attrs, defStyle); 40 | } 41 | 42 | private void init(Context context, AttributeSet attrs, int defStyle) { 43 | final TypedArray a = context.obtainStyledAttributes(attrs, 44 | com.packtpub.apps.rxjava_essentials.R.styleable.ScrimInsetsView, defStyle, 0); 45 | if (a == null) { 46 | return; 47 | } 48 | mInsetForeground = a.getDrawable( 49 | com.packtpub.apps.rxjava_essentials.R.styleable.ScrimInsetsView_insetForeground); 50 | a.recycle(); 51 | 52 | setWillNotDraw(true); 53 | } 54 | 55 | @Override protected boolean fitSystemWindows(Rect insets) { 56 | mInsets = new Rect(insets); 57 | setWillNotDraw(mInsetForeground == null); 58 | ViewCompat.postInvalidateOnAnimation(this); 59 | if (mOnInsetsCallback != null) { 60 | mOnInsetsCallback.onInsetsChanged(insets); 61 | } 62 | return true; // consume insets 63 | } 64 | 65 | @Override public void draw(Canvas canvas) { 66 | super.draw(canvas); 67 | 68 | int width = getWidth(); 69 | int height = getHeight(); 70 | if (mInsets != null && mInsetForeground != null) { 71 | int sc = canvas.save(); 72 | canvas.translate(getScrollX(), getScrollY()); 73 | 74 | // Top 75 | mTempRect.set(0, 0, width, mInsets.top); 76 | mInsetForeground.setBounds(mTempRect); 77 | mInsetForeground.draw(canvas); 78 | 79 | // Bottom 80 | mTempRect.set(0, height - mInsets.bottom, width, height); 81 | mInsetForeground.setBounds(mTempRect); 82 | mInsetForeground.draw(canvas); 83 | 84 | // Left 85 | mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); 86 | mInsetForeground.setBounds(mTempRect); 87 | mInsetForeground.draw(canvas); 88 | 89 | // Right 90 | mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); 91 | mInsetForeground.setBounds(mTempRect); 92 | mInsetForeground.draw(canvas); 93 | 94 | canvas.restoreToCount(sc); 95 | } 96 | } 97 | 98 | @Override protected void onAttachedToWindow() { 99 | super.onAttachedToWindow(); 100 | if (mInsetForeground != null) { 101 | mInsetForeground.setCallback(this); 102 | } 103 | } 104 | 105 | @Override protected void onDetachedFromWindow() { 106 | super.onDetachedFromWindow(); 107 | if (mInsetForeground != null) { 108 | mInsetForeground.setCallback(null); 109 | } 110 | } 111 | 112 | /** 113 | * Allows the calling container to specify a callback for custom processing when insets change 114 | * (i.e. when 115 | * {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements 116 | * based on 117 | * UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, 118 | * remember to set 119 | * clipToPadding to false. 120 | */ 121 | public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) { 122 | mOnInsetsCallback = onInsetsCallback; 123 | } 124 | 125 | public static interface OnInsetsCallback { 126 | 127 | public void onInsetsChanged(Rect insets); 128 | } 129 | } -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/Utils.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.drawable.BitmapDrawable; 7 | import android.graphics.drawable.Drawable; 8 | import java.io.FileOutputStream; 9 | import java.io.IOException; 10 | import rx.schedulers.Schedulers; 11 | 12 | public class Utils { 13 | 14 | public static Bitmap drawableToBitmap(Drawable drawable) { 15 | if (drawable instanceof BitmapDrawable) { 16 | return ((BitmapDrawable) drawable).getBitmap(); 17 | } 18 | 19 | Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), 20 | Bitmap.Config.ARGB_8888); 21 | Canvas canvas = new Canvas(bitmap); 22 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 23 | drawable.draw(canvas); 24 | 25 | return bitmap; 26 | } 27 | 28 | public static void storeBitmap(Context context, Bitmap bitmap, String filename) { 29 | Schedulers.io().createWorker().schedule(() -> { 30 | blockingStoreBitmap(context, bitmap, filename); 31 | }); 32 | } 33 | 34 | private static void blockingStoreBitmap(Context context, Bitmap bitmap, String filename) { 35 | FileOutputStream fOut = null; 36 | try { 37 | fOut = context.openFileOutput(filename, Context.MODE_PRIVATE); 38 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); 39 | fOut.flush(); 40 | fOut.close(); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | } finally { 44 | try { 45 | if (fOut != null) { 46 | fOut.close(); 47 | } 48 | } catch (IOException e) { 49 | e.printStackTrace(); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/apps/AppInfo.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.apps; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data @Accessors(prefix = "m") public class AppInfo implements Comparable { 7 | 8 | long mLastUpdateTime; 9 | 10 | String mName; 11 | 12 | String mIcon; 13 | 14 | public AppInfo(String name, String icon, long lastUpdateTime) { 15 | mName = name; 16 | mIcon = icon; 17 | mLastUpdateTime = lastUpdateTime; 18 | } 19 | 20 | @Override public int compareTo(Object another) { 21 | AppInfo f = (AppInfo) another; 22 | return getName().compareTo(f.getName()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/apps/AppInfoRich.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.apps; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.ComponentName; 5 | import android.content.Context; 6 | import android.content.pm.PackageInfo; 7 | import android.content.pm.PackageManager.NameNotFoundException; 8 | import android.content.pm.ResolveInfo; 9 | import android.content.res.AssetManager; 10 | import android.content.res.Configuration; 11 | import android.content.res.Resources; 12 | import android.graphics.drawable.Drawable; 13 | import android.util.DisplayMetrics; 14 | import java.util.Locale; 15 | import lombok.Setter; 16 | import lombok.experimental.Accessors; 17 | 18 | @Accessors(prefix = "m") public class AppInfoRich implements Comparable { 19 | 20 | @Setter String mName = null; 21 | 22 | private Context mContext; 23 | 24 | private ResolveInfo mResolveInfo; 25 | 26 | private ComponentName mComponentName = null; 27 | 28 | private PackageInfo pi = null; 29 | 30 | private Drawable icon = null; 31 | 32 | public AppInfoRich(Context ctx, ResolveInfo ri) { 33 | mContext = ctx; 34 | mResolveInfo = ri; 35 | 36 | mComponentName = 37 | new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name); 38 | 39 | try { 40 | pi = ctx.getPackageManager().getPackageInfo(getPackageName(), 0); 41 | } catch (NameNotFoundException e) { 42 | } 43 | } 44 | 45 | public String getName() { 46 | if (mName != null) { 47 | return mName; 48 | } else { 49 | try { 50 | return getNameFromResolveInfo(mResolveInfo); 51 | } catch (NameNotFoundException e) { 52 | return getPackageName(); 53 | } 54 | } 55 | } 56 | 57 | public String getActivityName() { 58 | return mResolveInfo.activityInfo.name; 59 | } 60 | 61 | public String getPackageName() { 62 | return mResolveInfo.activityInfo.packageName; 63 | } 64 | 65 | public ComponentName getComponentName() { 66 | return mComponentName; 67 | } 68 | 69 | public String getComponentInfo() { 70 | if (getComponentName() != null) { 71 | return getComponentName().toString(); 72 | } else { 73 | return ""; 74 | } 75 | } 76 | 77 | public ResolveInfo getResolveInfo() { 78 | return mResolveInfo; 79 | } 80 | 81 | public PackageInfo getPackageInfo() { 82 | return pi; 83 | } 84 | 85 | public String getVersionName() { 86 | PackageInfo pi = getPackageInfo(); 87 | if (pi != null) { 88 | return pi.versionName; 89 | } else { 90 | return ""; 91 | } 92 | } 93 | 94 | public int getVersionCode() { 95 | PackageInfo pi = getPackageInfo(); 96 | if (pi != null) { 97 | return pi.versionCode; 98 | } else { 99 | return 0; 100 | } 101 | } 102 | 103 | public Drawable getIcon() { 104 | if (icon == null) { 105 | icon = getResolveInfo().loadIcon(mContext.getPackageManager()); 106 | /* 107 | Drawable dr = getResolveInfo().loadIcon(mContext.getPackageManager()); 108 | Bitmap bitmap = ((BitmapDrawable) dr).getBitmap(); 109 | icon = new BitmapDrawable(mContext.getResources(), AppHelper.getResizedBitmap(bitmap, 144, 144)); 110 | */ 111 | } 112 | return icon; 113 | } 114 | 115 | @SuppressLint("NewApi") public long getFirstInstallTime() { 116 | PackageInfo pi = getPackageInfo(); 117 | if (pi != null 118 | && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) { 119 | return pi.firstInstallTime; 120 | } else { 121 | return 0; 122 | } 123 | } 124 | 125 | @SuppressLint("NewApi") public long getLastUpdateTime() { 126 | PackageInfo pi = getPackageInfo(); 127 | if (pi != null 128 | && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) { 129 | return pi.lastUpdateTime; 130 | } else { 131 | return 0; 132 | } 133 | } 134 | 135 | @Override public int compareTo(Object o) { 136 | AppInfoRich f = (AppInfoRich) o; 137 | return getName().compareTo(f.getName()); 138 | } 139 | 140 | @Override public String toString() { 141 | return getName(); 142 | } 143 | 144 | /** 145 | * Helper method to get an applications name! 146 | */ 147 | 148 | public String getNameFromResolveInfo(ResolveInfo ri) throws NameNotFoundException { 149 | String name = ri.resolvePackageName; 150 | if (ri.activityInfo != null) { 151 | Resources res = 152 | mContext.getPackageManager().getResourcesForApplication(ri.activityInfo.applicationInfo); 153 | Resources engRes = getEnglishRessources(res); 154 | 155 | if (ri.activityInfo.labelRes != 0) { 156 | name = engRes.getString(ri.activityInfo.labelRes); 157 | 158 | if (name == null || name.equals("")) { 159 | name = res.getString(ri.activityInfo.labelRes); 160 | } 161 | } else { 162 | name = ri.activityInfo.applicationInfo.loadLabel(mContext.getPackageManager()).toString(); 163 | } 164 | } 165 | return name; 166 | } 167 | 168 | public Resources getEnglishRessources(Resources standardResources) { 169 | AssetManager assets = standardResources.getAssets(); 170 | DisplayMetrics metrics = standardResources.getDisplayMetrics(); 171 | Configuration config = new Configuration(standardResources.getConfiguration()); 172 | config.locale = Locale.US; 173 | return new Resources(assets, metrics, config); 174 | } 175 | } -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/apps/ApplicationAdapter.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.apps; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | import com.packtpub.apps.rxjava_essentials.R; 12 | import java.util.List; 13 | import rx.Observable; 14 | import rx.android.schedulers.AndroidSchedulers; 15 | import rx.schedulers.Schedulers; 16 | 17 | public class ApplicationAdapter extends RecyclerView.Adapter { 18 | 19 | private List mApplications; 20 | 21 | private int mRowLayout; 22 | 23 | public ApplicationAdapter(List applications, int rowLayout) { 24 | mApplications = applications; 25 | mRowLayout = rowLayout; 26 | } 27 | 28 | public void addApplications(List applications) { 29 | mApplications.clear(); 30 | mApplications.addAll(applications); 31 | notifyDataSetChanged(); 32 | } 33 | 34 | public void addApplication(int position, AppInfo appInfo) { 35 | if (position < 0) { 36 | position = 0; 37 | } 38 | mApplications.add(position, appInfo); 39 | notifyItemInserted(position); 40 | } 41 | 42 | @Override public ViewHolder onCreateViewHolder(final ViewGroup viewGroup, int i) { 43 | View v = LayoutInflater.from(viewGroup.getContext()).inflate(mRowLayout, viewGroup, false); 44 | return new ViewHolder(v); 45 | } 46 | 47 | @Override public void onBindViewHolder(final ViewHolder viewHolder, int i) { 48 | final AppInfo appInfo = mApplications.get(i); 49 | viewHolder.name.setText(appInfo.getName()); 50 | getBitmap(appInfo.getIcon()).subscribeOn(Schedulers.io()) 51 | .observeOn(AndroidSchedulers.mainThread()) 52 | .subscribe(viewHolder.image::setImageBitmap); 53 | } 54 | 55 | @Override public int getItemCount() { 56 | return mApplications == null ? 0 : mApplications.size(); 57 | } 58 | 59 | private Observable getBitmap(String icon) { 60 | return Observable.create(subscriber -> { 61 | subscriber.onNext(BitmapFactory.decodeFile(icon)); 62 | subscriber.onCompleted(); 63 | }); 64 | } 65 | 66 | public static class ViewHolder extends RecyclerView.ViewHolder { 67 | 68 | public TextView name; 69 | 70 | public ImageView image; 71 | 72 | public ViewHolder(View itemView) { 73 | super(itemView); 74 | name = (TextView) itemView.findViewById(R.id.name); 75 | image = (ImageView) itemView.findViewById(R.id.image); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/apps/ApplicationsList.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.apps; 2 | 3 | import java.util.List; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.experimental.Accessors; 7 | 8 | @Accessors(prefix = "m") public class ApplicationsList { 9 | 10 | private static ApplicationsList ourInstance = new ApplicationsList(); 11 | 12 | @Getter @Setter private List mList; 13 | 14 | private ApplicationsList() { 15 | } 16 | 17 | public static ApplicationsList getInstance() { 18 | return ourInstance; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter4/DistinctExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter4; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | 24 | public class DistinctExampleFragment extends Fragment { 25 | 26 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 27 | 28 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 29 | 30 | private ApplicationAdapter mAdapter; 31 | 32 | private ArrayList mAddedApps = new ArrayList<>(); 33 | 34 | public DistinctExampleFragment() { 35 | } 36 | 37 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 38 | Bundle savedInstanceState) { 39 | return inflater.inflate(R.layout.fragment_example, container, false); 40 | } 41 | 42 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | ButterKnife.inject(this, view); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 47 | 48 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 49 | mRecyclerView.setAdapter(mAdapter); 50 | 51 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 52 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 53 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 54 | getResources().getDisplayMetrics())); 55 | 56 | // Progress 57 | mSwipeRefreshLayout.setEnabled(false); 58 | mSwipeRefreshLayout.setRefreshing(true); 59 | mRecyclerView.setVisibility(View.GONE); 60 | 61 | List apps = ApplicationsList.getInstance().getList(); 62 | 63 | loadList(apps); 64 | } 65 | 66 | private void loadList(List apps) { 67 | mRecyclerView.setVisibility(View.VISIBLE); 68 | 69 | Observable fullOfDuplicates = Observable.from(apps).take(3).repeat(3); 70 | 71 | fullOfDuplicates.distinct().subscribe(new Observer() { 72 | @Override public void onCompleted() { 73 | mSwipeRefreshLayout.setRefreshing(false); 74 | } 75 | 76 | @Override public void onError(Throwable e) { 77 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 78 | mSwipeRefreshLayout.setRefreshing(false); 79 | } 80 | 81 | @Override public void onNext(AppInfo appInfo) { 82 | mAddedApps.add(appInfo); 83 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 84 | } 85 | }); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter4/FilterExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter4; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | 24 | public class FilterExampleFragment extends Fragment { 25 | 26 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 27 | 28 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 29 | 30 | private ApplicationAdapter mAdapter; 31 | 32 | private ArrayList mAddedApps = new ArrayList<>(); 33 | 34 | public FilterExampleFragment() { 35 | } 36 | 37 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 38 | Bundle savedInstanceState) { 39 | return inflater.inflate(R.layout.fragment_example, container, false); 40 | } 41 | 42 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | ButterKnife.inject(this, view); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 47 | 48 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 49 | mRecyclerView.setAdapter(mAdapter); 50 | 51 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 52 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 53 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 54 | getResources().getDisplayMetrics())); 55 | 56 | // Progress 57 | mSwipeRefreshLayout.setEnabled(false); 58 | mSwipeRefreshLayout.setRefreshing(true); 59 | mRecyclerView.setVisibility(View.GONE); 60 | 61 | List apps = ApplicationsList.getInstance().getList(); 62 | 63 | loadList(apps); 64 | } 65 | 66 | private void loadList(List apps) { 67 | mRecyclerView.setVisibility(View.VISIBLE); 68 | 69 | Observable.from(apps) 70 | .filter((appInfo) -> appInfo.getName().startsWith("C")) 71 | .subscribe(new Observer() { 72 | @Override public void onCompleted() { 73 | mSwipeRefreshLayout.setRefreshing(false); 74 | } 75 | 76 | @Override public void onError(Throwable e) { 77 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 78 | mSwipeRefreshLayout.setRefreshing(false); 79 | } 80 | 81 | @Override public void onNext(AppInfo appInfo) { 82 | mAddedApps.add(appInfo); 83 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 84 | } 85 | }); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter4/TakeExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter4; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | 24 | public class TakeExampleFragment extends Fragment { 25 | 26 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 27 | 28 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 29 | 30 | private ApplicationAdapter mAdapter; 31 | 32 | private ArrayList mAddedApps = new ArrayList<>(); 33 | 34 | public TakeExampleFragment() { 35 | } 36 | 37 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 38 | Bundle savedInstanceState) { 39 | return inflater.inflate(R.layout.fragment_example, container, false); 40 | } 41 | 42 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | ButterKnife.inject(this, view); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 47 | 48 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 49 | mRecyclerView.setAdapter(mAdapter); 50 | 51 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 52 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 53 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 54 | getResources().getDisplayMetrics())); 55 | 56 | // Progress 57 | mSwipeRefreshLayout.setEnabled(false); 58 | mSwipeRefreshLayout.setRefreshing(true); 59 | mRecyclerView.setVisibility(View.GONE); 60 | 61 | List apps = ApplicationsList.getInstance().getList(); 62 | 63 | loadList(apps); 64 | } 65 | 66 | private void loadList(List apps) { 67 | mRecyclerView.setVisibility(View.VISIBLE); 68 | 69 | Observable.from(apps).take(3).subscribe(new Observer() { 70 | @Override public void onCompleted() { 71 | mSwipeRefreshLayout.setRefreshing(false); 72 | } 73 | 74 | @Override public void onError(Throwable e) { 75 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 76 | mSwipeRefreshLayout.setRefreshing(false); 77 | } 78 | 79 | @Override public void onNext(AppInfo appInfo) { 80 | mAddedApps.add(appInfo); 81 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 82 | } 83 | }); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter5/GroupByExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter5; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.text.SimpleDateFormat; 20 | import java.util.ArrayList; 21 | import java.util.Date; 22 | import java.util.List; 23 | import rx.Observable; 24 | import rx.Observer; 25 | import rx.functions.Func1; 26 | import rx.observables.GroupedObservable; 27 | 28 | public class GroupByExampleFragment extends Fragment { 29 | 30 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 31 | 32 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 33 | 34 | private ApplicationAdapter mAdapter; 35 | 36 | private ArrayList mAddedApps = new ArrayList<>(); 37 | 38 | public GroupByExampleFragment() { 39 | } 40 | 41 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 42 | Bundle savedInstanceState) { 43 | return inflater.inflate(R.layout.fragment_example, container, false); 44 | } 45 | 46 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 47 | super.onViewCreated(view, savedInstanceState); 48 | ButterKnife.inject(this, view); 49 | 50 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 51 | 52 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 53 | mRecyclerView.setAdapter(mAdapter); 54 | 55 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 56 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 57 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 58 | getResources().getDisplayMetrics())); 59 | 60 | // Progress 61 | mSwipeRefreshLayout.setEnabled(false); 62 | mSwipeRefreshLayout.setRefreshing(true); 63 | mRecyclerView.setVisibility(View.GONE); 64 | 65 | List apps = ApplicationsList.getInstance().getList(); 66 | 67 | loadList(apps); 68 | } 69 | 70 | private void loadList(List apps) { 71 | mRecyclerView.setVisibility(View.VISIBLE); 72 | 73 | Observable> groupedItems = 74 | Observable.from(apps).groupBy(new Func1() { 75 | @Override public String call(AppInfo appInfo) { 76 | SimpleDateFormat formatter = new SimpleDateFormat("MM/yyyy"); 77 | return formatter.format(new Date(appInfo.getLastUpdateTime())); 78 | } 79 | }); 80 | 81 | Observable.concat(groupedItems).subscribe(new Observer() { 82 | @Override public void onCompleted() { 83 | mSwipeRefreshLayout.setRefreshing(false); 84 | } 85 | 86 | @Override public void onError(Throwable e) { 87 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 88 | mSwipeRefreshLayout.setRefreshing(false); 89 | } 90 | 91 | @Override public void onNext(AppInfo appInfo) { 92 | mAddedApps.add(appInfo); 93 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 94 | } 95 | }); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter5/MapExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter5; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | import rx.functions.Func1; 24 | 25 | public class MapExampleFragment extends Fragment { 26 | 27 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 28 | 29 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 30 | 31 | private ApplicationAdapter mAdapter; 32 | 33 | private ArrayList mAddedApps = new ArrayList<>(); 34 | 35 | public MapExampleFragment() { 36 | } 37 | 38 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 39 | Bundle savedInstanceState) { 40 | return inflater.inflate(R.layout.fragment_example, container, false); 41 | } 42 | 43 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 44 | super.onViewCreated(view, savedInstanceState); 45 | ButterKnife.inject(this, view); 46 | 47 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 48 | 49 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 50 | mRecyclerView.setAdapter(mAdapter); 51 | 52 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 53 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 54 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 55 | getResources().getDisplayMetrics())); 56 | 57 | // Progress 58 | mSwipeRefreshLayout.setEnabled(false); 59 | mSwipeRefreshLayout.setRefreshing(true); 60 | mRecyclerView.setVisibility(View.GONE); 61 | 62 | List apps = ApplicationsList.getInstance().getList(); 63 | 64 | loadList(apps); 65 | } 66 | 67 | private void loadList(List apps) { 68 | mRecyclerView.setVisibility(View.VISIBLE); 69 | 70 | Observable.from(apps).map(new Func1() { 71 | @Override public AppInfo call(AppInfo appInfo) { 72 | String currentName = appInfo.getName(); 73 | String lowerCaseName = currentName.toLowerCase(); 74 | appInfo.setName(lowerCaseName); 75 | return appInfo; 76 | } 77 | }).subscribe(new Observer() { 78 | @Override public void onCompleted() { 79 | mSwipeRefreshLayout.setRefreshing(false); 80 | } 81 | 82 | @Override public void onError(Throwable e) { 83 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 84 | mSwipeRefreshLayout.setRefreshing(false); 85 | } 86 | 87 | @Override public void onNext(AppInfo appInfo) { 88 | mAddedApps.add(appInfo); 89 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 90 | } 91 | }); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter5/ScanExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter5; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | 24 | public class ScanExampleFragment extends Fragment { 25 | 26 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 27 | 28 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 29 | 30 | private ApplicationAdapter mAdapter; 31 | 32 | private ArrayList mAddedApps = new ArrayList<>(); 33 | 34 | public ScanExampleFragment() { 35 | } 36 | 37 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 38 | Bundle savedInstanceState) { 39 | return inflater.inflate(R.layout.fragment_example, container, false); 40 | } 41 | 42 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | ButterKnife.inject(this, view); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 47 | 48 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 49 | mRecyclerView.setAdapter(mAdapter); 50 | 51 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 52 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 53 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 54 | getResources().getDisplayMetrics())); 55 | 56 | // Progress 57 | mSwipeRefreshLayout.setEnabled(false); 58 | mSwipeRefreshLayout.setRefreshing(true); 59 | mRecyclerView.setVisibility(View.GONE); 60 | 61 | List apps = ApplicationsList.getInstance().getList(); 62 | 63 | loadList(apps); 64 | } 65 | 66 | private void loadList(List apps) { 67 | mRecyclerView.setVisibility(View.VISIBLE); 68 | 69 | Observable.from(apps).scan((appInfo, appInfo2) -> { 70 | if (appInfo.getName().length() > appInfo2.getName().length()) { 71 | return appInfo; 72 | } else { 73 | return appInfo2; 74 | } 75 | }).distinct().subscribe(new Observer() { 76 | @Override public void onCompleted() { 77 | mSwipeRefreshLayout.setRefreshing(false); 78 | } 79 | 80 | @Override public void onError(Throwable e) { 81 | Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show(); 82 | mSwipeRefreshLayout.setRefreshing(false); 83 | } 84 | 85 | @Override public void onNext(AppInfo appInfo) { 86 | mAddedApps.add(appInfo); 87 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 88 | } 89 | }); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter6/AndThenWhenExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter6; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.concurrent.TimeUnit; 22 | import rx.Observable; 23 | import rx.Observer; 24 | import rx.android.schedulers.AndroidSchedulers; 25 | import rx.joins.Pattern2; 26 | import rx.joins.Plan0; 27 | import rx.observables.JoinObservable; 28 | 29 | public class AndThenWhenExampleFragment extends Fragment { 30 | 31 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 32 | 33 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 34 | 35 | private ApplicationAdapter mAdapter; 36 | 37 | private ArrayList mAddedApps = new ArrayList<>(); 38 | 39 | public AndThenWhenExampleFragment() { 40 | } 41 | 42 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 43 | Bundle savedInstanceState) { 44 | return inflater.inflate(R.layout.fragment_example, container, false); 45 | } 46 | 47 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 48 | super.onViewCreated(view, savedInstanceState); 49 | ButterKnife.inject(this, view); 50 | 51 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 52 | 53 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 54 | mRecyclerView.setAdapter(mAdapter); 55 | 56 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 57 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 58 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 59 | getResources().getDisplayMetrics())); 60 | 61 | // Progress 62 | mSwipeRefreshLayout.setEnabled(false); 63 | mSwipeRefreshLayout.setRefreshing(true); 64 | mRecyclerView.setVisibility(View.GONE); 65 | 66 | List apps = ApplicationsList.getInstance().getList(); 67 | 68 | loadList(apps); 69 | } 70 | 71 | private void loadList(List apps) { 72 | mRecyclerView.setVisibility(View.VISIBLE); 73 | 74 | Observable observableApp = Observable.from(apps); 75 | 76 | Observable tictoc = Observable.interval(1, TimeUnit.SECONDS); 77 | 78 | Pattern2 pattern = JoinObservable.from(observableApp).and(tictoc); 79 | Plan0 plan = pattern.then(this::updateTitle); 80 | JoinObservable.when(plan) 81 | .toObservable() 82 | .observeOn(AndroidSchedulers.mainThread()) 83 | .subscribe(new Observer() { 84 | @Override public void onCompleted() { 85 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 86 | } 87 | 88 | @Override public void onError(Throwable e) { 89 | mSwipeRefreshLayout.setRefreshing(false); 90 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 91 | } 92 | 93 | @Override public void onNext(AppInfo appInfo) { 94 | if (mSwipeRefreshLayout.isRefreshing()) { 95 | mSwipeRefreshLayout.setRefreshing(false); 96 | } 97 | mAddedApps.add(appInfo); 98 | int position = mAddedApps.size() - 1; 99 | mAdapter.addApplication(position, appInfo); 100 | mRecyclerView.smoothScrollToPosition(position); 101 | } 102 | }); 103 | } 104 | 105 | private AppInfo updateTitle(AppInfo appInfo, Long time) { 106 | appInfo.setName(time + " " + appInfo.getName()); 107 | return appInfo; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter6/CombineLatestExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter6; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.concurrent.TimeUnit; 22 | import rx.Observable; 23 | import rx.Observer; 24 | import rx.android.schedulers.AndroidSchedulers; 25 | 26 | public class CombineLatestExampleFragment extends Fragment { 27 | 28 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 29 | 30 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 31 | 32 | private ApplicationAdapter mAdapter; 33 | 34 | private ArrayList mAddedApps = new ArrayList<>(); 35 | 36 | public CombineLatestExampleFragment() { 37 | } 38 | 39 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | return inflater.inflate(R.layout.fragment_example, container, false); 42 | } 43 | 44 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 45 | super.onViewCreated(view, savedInstanceState); 46 | ButterKnife.inject(this, view); 47 | 48 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 49 | 50 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 51 | mRecyclerView.setAdapter(mAdapter); 52 | 53 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 54 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 55 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 56 | getResources().getDisplayMetrics())); 57 | 58 | // Progress 59 | mSwipeRefreshLayout.setEnabled(false); 60 | mSwipeRefreshLayout.setRefreshing(true); 61 | mRecyclerView.setVisibility(View.GONE); 62 | 63 | List apps = ApplicationsList.getInstance().getList(); 64 | 65 | loadList(apps); 66 | } 67 | 68 | private void loadList(List apps) { 69 | mRecyclerView.setVisibility(View.VISIBLE); 70 | 71 | Observable appsSequence = Observable.interval(1000, TimeUnit.MILLISECONDS) 72 | .map(position -> apps.get(position.intValue())); 73 | 74 | Observable tictoc = Observable.interval(1500, TimeUnit.MILLISECONDS); 75 | 76 | Observable.combineLatest(appsSequence, tictoc, this::updateTitle) 77 | .observeOn(AndroidSchedulers.mainThread()) 78 | .subscribe(new Observer() { 79 | @Override public void onCompleted() { 80 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 81 | } 82 | 83 | @Override public void onError(Throwable e) { 84 | mSwipeRefreshLayout.setRefreshing(false); 85 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 86 | } 87 | 88 | @Override public void onNext(AppInfo appInfo) { 89 | if (mSwipeRefreshLayout.isRefreshing()) { 90 | mSwipeRefreshLayout.setRefreshing(false); 91 | } 92 | mAddedApps.add(appInfo); 93 | int position = mAddedApps.size() - 1; 94 | mAdapter.addApplication(position, appInfo); 95 | mRecyclerView.smoothScrollToPosition(position); 96 | } 97 | }); 98 | } 99 | 100 | private AppInfo updateTitle(AppInfo appInfo, Long time) { 101 | appInfo.setName(time + " " + appInfo.getName()); 102 | return appInfo; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter6/JoinExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter6; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.App; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 19 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.concurrent.TimeUnit; 23 | import rx.Observable; 24 | import rx.Observer; 25 | import rx.android.schedulers.AndroidSchedulers; 26 | 27 | public class JoinExampleFragment extends Fragment { 28 | 29 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 30 | 31 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 32 | 33 | private ApplicationAdapter mAdapter; 34 | 35 | private ArrayList mAddedApps = new ArrayList<>(); 36 | 37 | public JoinExampleFragment() { 38 | } 39 | 40 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 41 | Bundle savedInstanceState) { 42 | return inflater.inflate(R.layout.fragment_example, container, false); 43 | } 44 | 45 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 46 | super.onViewCreated(view, savedInstanceState); 47 | ButterKnife.inject(this, view); 48 | 49 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 50 | 51 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 52 | mRecyclerView.setAdapter(mAdapter); 53 | 54 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 55 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 56 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 57 | getResources().getDisplayMetrics())); 58 | 59 | // Progress 60 | mSwipeRefreshLayout.setEnabled(false); 61 | mSwipeRefreshLayout.setRefreshing(true); 62 | mRecyclerView.setVisibility(View.GONE); 63 | 64 | List apps = ApplicationsList.getInstance().getList(); 65 | 66 | loadList(apps); 67 | } 68 | 69 | private void loadList(List apps) { 70 | mRecyclerView.setVisibility(View.VISIBLE); 71 | 72 | Observable appsSequence = 73 | Observable.interval(1000, TimeUnit.MILLISECONDS).map(position -> { 74 | App.L.debug("Position: " + position); 75 | return apps.get(position.intValue()); 76 | }); 77 | Observable tictoc = Observable.interval(1000, TimeUnit.MILLISECONDS); 78 | 79 | appsSequence.join(tictoc, appInfo -> Observable.timer(2, TimeUnit.SECONDS), 80 | time -> Observable.timer(0, TimeUnit.SECONDS), this::updateTitle) 81 | .observeOn(AndroidSchedulers.mainThread()) 82 | .take(10) 83 | .subscribe(new Observer() { 84 | @Override public void onCompleted() { 85 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 86 | } 87 | 88 | @Override public void onError(Throwable e) { 89 | mSwipeRefreshLayout.setRefreshing(false); 90 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 91 | } 92 | 93 | @Override public void onNext(AppInfo appInfo) { 94 | if (mSwipeRefreshLayout.isRefreshing()) { 95 | mSwipeRefreshLayout.setRefreshing(false); 96 | } 97 | mAddedApps.add(appInfo); 98 | int position = mAddedApps.size() - 1; 99 | mAdapter.addApplication(position, appInfo); 100 | mRecyclerView.smoothScrollToPosition(position); 101 | } 102 | }); 103 | } 104 | 105 | private AppInfo updateTitle(AppInfo appInfo, Long time) { 106 | appInfo.setName(time + " " + appInfo.getName()); 107 | return appInfo; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter6/MergeExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter6; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.google.common.collect.Lists; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 19 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import rx.Observable; 23 | import rx.Observer; 24 | 25 | public class MergeExampleFragment extends Fragment { 26 | 27 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 28 | 29 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 30 | 31 | private ApplicationAdapter mAdapter; 32 | 33 | private ArrayList mAddedApps = new ArrayList<>(); 34 | 35 | public MergeExampleFragment() { 36 | } 37 | 38 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 39 | Bundle savedInstanceState) { 40 | return inflater.inflate(R.layout.fragment_example, container, false); 41 | } 42 | 43 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 44 | super.onViewCreated(view, savedInstanceState); 45 | ButterKnife.inject(this, view); 46 | 47 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 48 | 49 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 50 | mRecyclerView.setAdapter(mAdapter); 51 | 52 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 53 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 54 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 55 | getResources().getDisplayMetrics())); 56 | 57 | // Progress 58 | mSwipeRefreshLayout.setEnabled(false); 59 | mSwipeRefreshLayout.setRefreshing(true); 60 | mRecyclerView.setVisibility(View.GONE); 61 | 62 | List apps = ApplicationsList.getInstance().getList(); 63 | 64 | loadList(apps); 65 | } 66 | 67 | private void loadList(List apps) { 68 | mRecyclerView.setVisibility(View.VISIBLE); 69 | 70 | List reversedApps = Lists.reverse(apps); 71 | 72 | Observable observableApps = Observable.from(apps); 73 | Observable observableReversedApps = Observable.from(reversedApps); 74 | 75 | Observable mergedObserbable = Observable.merge(observableApps, observableReversedApps); 76 | 77 | mergedObserbable.subscribe(new Observer() { 78 | @Override public void onCompleted() { 79 | mSwipeRefreshLayout.setRefreshing(false); 80 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 81 | } 82 | 83 | @Override public void onError(Throwable e) { 84 | Toast.makeText(getActivity(), "One of the two Observable threw an error!", 85 | Toast.LENGTH_SHORT).show(); 86 | mSwipeRefreshLayout.setRefreshing(false); 87 | } 88 | 89 | @Override public void onNext(AppInfo appInfo) { 90 | mAddedApps.add(appInfo); 91 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 92 | } 93 | }); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter6/ZipExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter6; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.concurrent.TimeUnit; 22 | import rx.Observable; 23 | import rx.Observer; 24 | import rx.android.schedulers.AndroidSchedulers; 25 | 26 | public class ZipExampleFragment extends Fragment { 27 | 28 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 29 | 30 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 31 | 32 | private ApplicationAdapter mAdapter; 33 | 34 | private ArrayList mAddedApps = new ArrayList<>(); 35 | 36 | public ZipExampleFragment() { 37 | } 38 | 39 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | return inflater.inflate(R.layout.fragment_example, container, false); 42 | } 43 | 44 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 45 | super.onViewCreated(view, savedInstanceState); 46 | ButterKnife.inject(this, view); 47 | 48 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 49 | 50 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 51 | mRecyclerView.setAdapter(mAdapter); 52 | 53 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 54 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 55 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 56 | getResources().getDisplayMetrics())); 57 | 58 | // Progress 59 | mSwipeRefreshLayout.setEnabled(false); 60 | mSwipeRefreshLayout.setRefreshing(true); 61 | mRecyclerView.setVisibility(View.GONE); 62 | 63 | List apps = ApplicationsList.getInstance().getList(); 64 | 65 | loadList(apps); 66 | } 67 | 68 | private void loadList(List apps) { 69 | mRecyclerView.setVisibility(View.VISIBLE); 70 | 71 | Observable observableApp = Observable.from(apps); 72 | 73 | Observable tictoc = Observable.interval(1, TimeUnit.SECONDS); 74 | 75 | Observable.zip(observableApp, tictoc, this::updateTitle) 76 | .observeOn(AndroidSchedulers.mainThread()) 77 | .subscribe(new Observer() { 78 | @Override public void onCompleted() { 79 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 80 | } 81 | 82 | @Override public void onError(Throwable e) { 83 | mSwipeRefreshLayout.setRefreshing(false); 84 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 85 | } 86 | 87 | @Override public void onNext(AppInfo appInfo) { 88 | if (mSwipeRefreshLayout.isRefreshing()) { 89 | mSwipeRefreshLayout.setRefreshing(false); 90 | } 91 | mAddedApps.add(appInfo); 92 | int position = mAddedApps.size() - 1; 93 | mAdapter.addApplication(position, appInfo); 94 | mRecyclerView.smoothScrollToPosition(position); 95 | } 96 | }); 97 | } 98 | 99 | private AppInfo updateTitle(AppInfo appInfo, Long time) { 100 | appInfo.setName(time + " " + appInfo.getName()); 101 | return appInfo; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter7/LongTaskFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter7; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | import rx.android.schedulers.AndroidSchedulers; 24 | import rx.schedulers.Schedulers; 25 | 26 | public class LongTaskFragment extends Fragment { 27 | 28 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 29 | 30 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 31 | 32 | private ApplicationAdapter mAdapter; 33 | 34 | private ArrayList mAddedApps = new ArrayList<>(); 35 | 36 | public LongTaskFragment() { 37 | } 38 | 39 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | return inflater.inflate(R.layout.fragment_example, container, false); 42 | } 43 | 44 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 45 | super.onViewCreated(view, savedInstanceState); 46 | ButterKnife.inject(this, view); 47 | 48 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 49 | 50 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 51 | mRecyclerView.setAdapter(mAdapter); 52 | 53 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 54 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 55 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 56 | getResources().getDisplayMetrics())); 57 | 58 | // Progress 59 | mSwipeRefreshLayout.setEnabled(false); 60 | mSwipeRefreshLayout.setRefreshing(true); 61 | mRecyclerView.setVisibility(View.GONE); 62 | 63 | List apps = ApplicationsList.getInstance().getList(); 64 | 65 | loadList(apps); 66 | } 67 | 68 | private void loadList(List apps) { 69 | mRecyclerView.setVisibility(View.VISIBLE); 70 | 71 | getObservableApps(apps).onBackpressureBuffer() 72 | .subscribeOn(Schedulers.computation()) 73 | .observeOn(AndroidSchedulers.mainThread()) 74 | .subscribe(new Observer() { 75 | @Override public void onCompleted() { 76 | mSwipeRefreshLayout.setRefreshing(false); 77 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 78 | } 79 | 80 | @Override public void onError(Throwable e) { 81 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 82 | if (mSwipeRefreshLayout != null) { 83 | mSwipeRefreshLayout.setRefreshing(false); 84 | } 85 | } 86 | 87 | @Override public void onNext(AppInfo appInfo) { 88 | mAddedApps.add(appInfo); 89 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 90 | } 91 | }); 92 | } 93 | 94 | private Observable getObservableApps(List apps) { 95 | return Observable.create(subscriber -> { 96 | for (double i = 0; i < 1000000000; i++) { 97 | double y = i * i; 98 | } 99 | 100 | for (AppInfo app : apps) { 101 | subscriber.onNext(app); 102 | } 103 | subscriber.onCompleted(); 104 | }); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter7/NetworkTaskFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter7; 2 | 3 | import android.app.Fragment; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Toast; 11 | import butterknife.ButterKnife; 12 | import butterknife.InjectView; 13 | import butterknife.OnClick; 14 | import com.github.lzyzsd.circleprogress.ArcProgress; 15 | import com.packtpub.apps.rxjava_essentials.App; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.rey.material.widget.Button; 18 | import java.io.File; 19 | import java.io.FileOutputStream; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.OutputStream; 23 | import java.net.HttpURLConnection; 24 | import java.net.URL; 25 | import rx.Observable; 26 | import rx.Observer; 27 | import rx.android.schedulers.AndroidSchedulers; 28 | import rx.schedulers.Schedulers; 29 | import rx.subjects.PublishSubject; 30 | 31 | public class NetworkTaskFragment extends Fragment { 32 | 33 | @InjectView(R.id.arc_progress) ArcProgress mArcProgress; 34 | 35 | @InjectView(R.id.button_download) Button mButton; 36 | 37 | private PublishSubject mDownloadProgress = PublishSubject.create(); 38 | 39 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | return inflater.inflate(R.layout.fragment_download, container, false); 42 | } 43 | 44 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 45 | super.onViewCreated(view, savedInstanceState); 46 | ButterKnife.inject(this, view); 47 | } 48 | 49 | @OnClick(R.id.button_download) void download() { 50 | mButton.setText(getString(R.string.downloading)); 51 | mButton.setClickable(false); 52 | 53 | mDownloadProgress.distinct() 54 | .observeOn(AndroidSchedulers.mainThread()) 55 | .subscribe(new Observer() { 56 | @Override public void onCompleted() { 57 | App.L.debug("Completed"); 58 | } 59 | 60 | @Override public void onError(Throwable e) { 61 | App.L.error(e.toString()); 62 | } 63 | 64 | @Override public void onNext(Integer progress) { 65 | mArcProgress.setProgress(progress); 66 | } 67 | }); 68 | 69 | String destination = "/sdcard/softboy.avi"; 70 | 71 | obserbableDownload("http://archive.blender.org/fileadmin/movies/softboy.avi", 72 | destination).subscribeOn(Schedulers.io()) 73 | .observeOn(AndroidSchedulers.mainThread()) 74 | .subscribe(success -> { 75 | resetDownloadButton(); 76 | Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 77 | File file = new File(destination); 78 | intent.setDataAndType(Uri.fromFile(file), "video/avi"); 79 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 80 | startActivity(intent); 81 | }, error -> { 82 | Toast.makeText(getActivity(), "Something went south", Toast.LENGTH_SHORT).show(); 83 | resetDownloadButton(); 84 | }); 85 | } 86 | 87 | private void resetDownloadButton() { 88 | mButton.setText(getString(R.string.download)); 89 | mButton.setClickable(true); 90 | mArcProgress.setProgress(0); 91 | } 92 | 93 | private Observable obserbableDownload(String source, String destination) { 94 | return Observable.create(subscriber -> { 95 | try { 96 | boolean result = downloadFile(source, destination); 97 | if (result) { 98 | subscriber.onNext(true); 99 | subscriber.onCompleted(); 100 | } else { 101 | subscriber.onError(new Throwable("Download failed.")); 102 | } 103 | } catch (Exception e) { 104 | subscriber.onError(e); 105 | } 106 | }); 107 | } 108 | 109 | private boolean downloadFile(String source, String destination) { 110 | boolean result = false; 111 | InputStream input = null; 112 | OutputStream output = null; 113 | HttpURLConnection connection = null; 114 | try { 115 | URL url = new URL(source); 116 | connection = (HttpURLConnection) url.openConnection(); 117 | connection.connect(); 118 | 119 | if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { 120 | return false; 121 | } 122 | 123 | int fileLength = connection.getContentLength(); 124 | 125 | input = connection.getInputStream(); 126 | output = new FileOutputStream(destination); 127 | 128 | byte data[] = new byte[4096]; 129 | long total = 0; 130 | int count; 131 | while ((count = input.read(data)) != -1) { 132 | total += count; 133 | 134 | if (fileLength > 0) { 135 | int percentage = (int) (total * 100 / fileLength); 136 | mDownloadProgress.onNext(percentage); 137 | } 138 | output.write(data, 0, count); 139 | } 140 | mDownloadProgress.onCompleted(); 141 | result = true; 142 | } catch (Exception e) { 143 | mDownloadProgress.onError(e); 144 | } finally { 145 | try { 146 | if (output != null) { 147 | output.close(); 148 | } 149 | if (input != null) { 150 | input.close(); 151 | } 152 | } catch (IOException e) { 153 | mDownloadProgress.onError(e); 154 | } 155 | 156 | if (connection != null) { 157 | connection.disconnect(); 158 | mDownloadProgress.onCompleted(); 159 | } 160 | } 161 | return result; 162 | } 163 | 164 | @Override public void onDestroyView() { 165 | super.onDestroyView(); 166 | ButterKnife.reset(this); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter7/SharedPreferencesListFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter7; 2 | 3 | import android.app.Fragment; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.os.Bundle; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.TypedValue; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.Toast; 15 | import butterknife.ButterKnife; 16 | import butterknife.InjectView; 17 | import com.google.gson.Gson; 18 | import com.google.gson.reflect.TypeToken; 19 | import com.packtpub.apps.rxjava_essentials.R; 20 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 21 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 22 | import java.lang.reflect.Type; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | import rx.Observable; 26 | import rx.Observer; 27 | import rx.android.schedulers.AndroidSchedulers; 28 | import rx.schedulers.Schedulers; 29 | 30 | public class SharedPreferencesListFragment extends Fragment { 31 | 32 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 33 | 34 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 35 | 36 | private ApplicationAdapter mAdapter; 37 | 38 | private ArrayList mAddedApps = new ArrayList<>(); 39 | 40 | public SharedPreferencesListFragment() { 41 | } 42 | 43 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 44 | Bundle savedInstanceState) { 45 | return inflater.inflate(R.layout.fragment_example, container, false); 46 | } 47 | 48 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 49 | super.onViewCreated(view, savedInstanceState); 50 | ButterKnife.inject(this, view); 51 | 52 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 53 | 54 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 55 | mRecyclerView.setAdapter(mAdapter); 56 | 57 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 58 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 59 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 60 | getResources().getDisplayMetrics())); 61 | 62 | mSwipeRefreshLayout.setEnabled(false); 63 | mSwipeRefreshLayout.setRefreshing(true); 64 | mRecyclerView.setVisibility(View.GONE); 65 | 66 | loadList(); 67 | } 68 | 69 | private void loadList() { 70 | mRecyclerView.setVisibility(View.VISIBLE); 71 | 72 | getApps().onBackpressureBuffer() 73 | .subscribeOn(Schedulers.io()) 74 | .observeOn(AndroidSchedulers.mainThread()) 75 | .subscribe(new Observer() { 76 | @Override public void onCompleted() { 77 | mSwipeRefreshLayout.setRefreshing(false); 78 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 79 | } 80 | 81 | @Override public void onError(Throwable e) { 82 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 83 | mSwipeRefreshLayout.setRefreshing(false); 84 | } 85 | 86 | @Override public void onNext(AppInfo appInfo) { 87 | mAddedApps.add(appInfo); 88 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 89 | } 90 | }); 91 | } 92 | 93 | private Observable getApps() { 94 | return Observable.create(subscriber -> { 95 | List apps = new ArrayList<>(); 96 | 97 | SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); 98 | Type appInfoType = new TypeToken>() { 99 | }.getType(); 100 | String serializedApps = sharedPref.getString("APPS", ""); 101 | if (!"".equals(serializedApps)) { 102 | apps = new Gson().fromJson(serializedApps, appInfoType); 103 | } 104 | 105 | for (AppInfo app : apps) { 106 | subscriber.onNext(app); 107 | } 108 | subscriber.onCompleted(); 109 | }); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/SoActivity.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v4.widget.SwipeRefreshLayout; 7 | import android.support.v7.app.ActionBarActivity; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.App; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.SeApiManager; 18 | import java.util.ArrayList; 19 | 20 | public class SoActivity extends ActionBarActivity 21 | implements SoAdapter.ViewHolder.OpenProfileListener { 22 | 23 | @InjectView(R.id.so_recyclerview) RecyclerView mRecyclerView; 24 | 25 | @InjectView(R.id.so_swipe) SwipeRefreshLayout mSwipe; 26 | 27 | private SoAdapter mAdapter; 28 | 29 | private SeApiManager mSeApiManager; 30 | 31 | @Override protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_so); 34 | ButterKnife.inject(this); 35 | 36 | mAdapter = new SoAdapter(new ArrayList<>()); 37 | mAdapter.setOpenProfileListener(this); 38 | 39 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); 40 | mRecyclerView.setAdapter(mAdapter); 41 | 42 | mSeApiManager = new SeApiManager(); 43 | 44 | mSwipe.setOnRefreshListener(this::refreshList); 45 | 46 | refreshList(); 47 | } 48 | 49 | private void refreshList() { 50 | showRefresh(true); 51 | mSeApiManager.getMostPopularSOusers(10).subscribe(users -> { 52 | showRefresh(false); 53 | mAdapter.updateUsers(users); 54 | }, error -> { 55 | App.L.error(error.toString()); 56 | showRefresh(false); 57 | }); 58 | } 59 | 60 | private void showRefresh(boolean show) { 61 | mSwipe.setRefreshing(show); 62 | int visibility = show ? View.GONE : View.VISIBLE; 63 | mRecyclerView.setVisibility(visibility); 64 | } 65 | 66 | @Override public boolean onCreateOptionsMenu(Menu menu) { 67 | // Inflate the menu; this adds items to the action bar if it is present. 68 | getMenuInflater().inflate(R.menu.menu_so, menu); 69 | return true; 70 | } 71 | 72 | @Override public boolean onOptionsItemSelected(MenuItem item) { 73 | // Handle action bar item clicks here. The action bar will 74 | // automatically handle clicks on the Home/Up button, so long 75 | // as you specify a parent activity in AndroidManifest.xml. 76 | int id = item.getItemId(); 77 | 78 | //noinspection SimplifiableIfStatement 79 | if (id == R.id.action_settings) { 80 | return true; 81 | } 82 | 83 | return super.onOptionsItemSelected(item); 84 | } 85 | 86 | @Override public void open(String url) { 87 | Intent i = new Intent(Intent.ACTION_VIEW); 88 | i.setData(Uri.parse(url)); 89 | startActivity(i); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/SoAdapter.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | import butterknife.ButterKnife; 11 | import butterknife.InjectView; 12 | import com.nostra13.universalimageloader.core.ImageLoader; 13 | import com.nostra13.universalimageloader.core.assist.FailReason; 14 | import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; 15 | import com.packtpub.apps.rxjava_essentials.App; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.OpenWeatherMapApiManager; 18 | import com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models.WeatherResponse; 19 | import com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models.User; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import rx.Observable; 23 | import rx.Observer; 24 | import rx.android.schedulers.AndroidSchedulers; 25 | import rx.android.view.ViewObservable; 26 | import rx.schedulers.Schedulers; 27 | 28 | import static rx.android.internal.Preconditions.checkNotNull; 29 | 30 | public class SoAdapter extends RecyclerView.Adapter { 31 | 32 | private static ViewHolder.OpenProfileListener mProfileListener; 33 | 34 | private List mUsers = new ArrayList<>(); 35 | 36 | public SoAdapter(List users) { 37 | mUsers = users; 38 | } 39 | 40 | public void updateUsers(List users) { 41 | mUsers.clear(); 42 | mUsers.addAll(users); 43 | notifyDataSetChanged(); 44 | } 45 | 46 | @Override public SoAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 47 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.so_list_item, parent, false); 48 | return new ViewHolder(v); 49 | } 50 | 51 | @Override public void onBindViewHolder(SoAdapter.ViewHolder holder, int position) { 52 | if (position < mUsers.size()) { 53 | User user = mUsers.get(position); 54 | holder.setUser(user); 55 | } 56 | } 57 | 58 | @Override public int getItemCount() { 59 | return mUsers == null ? 0 : mUsers.size(); 60 | } 61 | 62 | public void setOpenProfileListener(ViewHolder.OpenProfileListener listener) { 63 | mProfileListener = listener; 64 | } 65 | 66 | public static class ViewHolder extends RecyclerView.ViewHolder { 67 | 68 | private final View mView; 69 | 70 | @InjectView(R.id.name) TextView name; 71 | 72 | @InjectView(R.id.city) TextView city; 73 | 74 | @InjectView(R.id.reputation) TextView reputation; 75 | 76 | @InjectView(R.id.user_image) ImageView user_image; 77 | 78 | @InjectView(R.id.city_image) ImageView city_image; 79 | 80 | public ViewHolder(View view) { 81 | super(view); 82 | ButterKnife.inject(this, view); 83 | mView = view; 84 | } 85 | 86 | private Observable loadBitmap(String url) { 87 | return Observable.create(subscriber -> { 88 | ImageLoader.getInstance().displayImage(url, city_image, new ImageLoadingListener() { 89 | @Override public void onLoadingStarted(String imageUri, View view) { 90 | 91 | } 92 | 93 | @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { 94 | subscriber.onError(failReason.getCause()); 95 | } 96 | 97 | @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { 98 | subscriber.onNext(loadedImage); 99 | subscriber.onCompleted(); 100 | } 101 | 102 | @Override public void onLoadingCancelled(String imageUri, View view) { 103 | subscriber.onError(new Throwable("Image loading cancelled")); 104 | } 105 | }); 106 | }); 107 | } 108 | 109 | public void setUser(User user) { 110 | name.setText(user.getDisplayName()); 111 | city.setText(user.getLocation()); 112 | reputation.setText(String.valueOf(user.getReputation())); 113 | 114 | ImageLoader.getInstance().displayImage(user.getProfileImage(), user_image); 115 | 116 | displayWeatherInfos(user); 117 | 118 | ViewObservable.clicks(mView).subscribe(onClickEvent -> { 119 | checkNotNull(mProfileListener, "Must implement OpenProfileListener"); 120 | 121 | String url = user.getWebsiteUrl(); 122 | if (url != null && !url.equals("") && !url.contains("search")) { 123 | mProfileListener.open(url); 124 | } else { 125 | mProfileListener.open(user.getLink()); 126 | } 127 | }); 128 | } 129 | 130 | private void displayWeatherInfos(User user) { 131 | String location = user.getLocation(); 132 | int separatorPosition = getSeparatorPosition(location); 133 | 134 | if (isCityValid(location)) { 135 | String city = getCity(location, separatorPosition); 136 | OpenWeatherMapApiManager.getInstance() 137 | .getForecastByCity(city) 138 | .filter(response -> response != null) 139 | .filter(response -> response.getWeather().size() > 0) 140 | .flatMap(response -> { 141 | String url = getWeatherIconUrl(response); 142 | return loadBitmap(url); 143 | }) 144 | .subscribeOn(Schedulers.io()) 145 | .observeOn(AndroidSchedulers.mainThread()) 146 | .subscribe(new Observer() { 147 | @Override public void onCompleted() { 148 | 149 | } 150 | 151 | @Override public void onError(Throwable e) { 152 | App.L.error(e.toString()); 153 | } 154 | 155 | @Override public void onNext(Bitmap icon) { 156 | city_image.setImageBitmap(icon); 157 | } 158 | }); 159 | } 160 | } 161 | 162 | private String getWeatherIconUrl(WeatherResponse weatherResponse) { 163 | return "http://openweathermap.org/img/w/" 164 | + weatherResponse.getWeather().get(0).getIcon() 165 | + ".png"; 166 | } 167 | 168 | private boolean isCityValid(String location) { 169 | int separatorPosition = getSeparatorPosition(location); 170 | return !"".equals(location) && separatorPosition > -1; 171 | } 172 | 173 | private int getSeparatorPosition(String location) { 174 | int separatorPosition = -1; 175 | checkNotNull(location, "Location can't be null"); 176 | separatorPosition = location.indexOf(","); 177 | return separatorPosition; 178 | } 179 | 180 | private String getCity(String location, int position) { 181 | if (location != null) { 182 | return location.substring(0, position); 183 | } else { 184 | return ""; 185 | } 186 | } 187 | 188 | public interface OpenProfileListener { 189 | 190 | public void open(String url); 191 | } 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/OpenWeatherMapApiManager.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap; 2 | 3 | import com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models.WeatherResponse; 4 | import lombok.Getter; 5 | import retrofit.RestAdapter; 6 | import rx.Observable; 7 | import rx.android.schedulers.AndroidSchedulers; 8 | import rx.schedulers.Schedulers; 9 | 10 | public class OpenWeatherMapApiManager { 11 | 12 | @Getter private static OpenWeatherMapApiManager instance = new OpenWeatherMapApiManager(); 13 | 14 | private final OpenWeatherMapService mOpenWeatherMapService; 15 | 16 | private OpenWeatherMapApiManager() { 17 | RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://api.openweathermap.org") 18 | .setLogLevel(RestAdapter.LogLevel.BASIC) 19 | .build(); 20 | 21 | mOpenWeatherMapService = restAdapter.create(OpenWeatherMapService.class); 22 | } 23 | 24 | public Observable getForecastByCity(String city) { 25 | return mOpenWeatherMapService.getForecastByCity(city) 26 | .subscribeOn(Schedulers.io()) 27 | .observeOn(AndroidSchedulers.mainThread()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/OpenWeatherMapService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap; 2 | 3 | import com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models.WeatherResponse; 4 | import retrofit.http.GET; 5 | import retrofit.http.Query; 6 | import rx.Observable; 7 | 8 | public interface OpenWeatherMapService { 9 | 10 | @GET("/data/2.5/weather") Observable getForecastByCity(@Query("q") String city); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Clouds.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | 5 | public class Clouds { 6 | 7 | @Expose private Integer all; 8 | 9 | /** 10 | * @return The all 11 | */ 12 | public Integer getAll() { 13 | return all; 14 | } 15 | 16 | /** 17 | * @param all The all 18 | */ 19 | public void setAll(Integer all) { 20 | this.all = all; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Coord.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | 5 | public class Coord { 6 | 7 | @Expose private Double lon; 8 | @Expose private Double lat; 9 | 10 | /** 11 | * @return The lon 12 | */ 13 | public Double getLon() { 14 | return lon; 15 | } 16 | 17 | /** 18 | * @param lon The lon 19 | */ 20 | public void setLon(Double lon) { 21 | this.lon = lon; 22 | } 23 | 24 | /** 25 | * @return The lat 26 | */ 27 | public Double getLat() { 28 | return lat; 29 | } 30 | 31 | /** 32 | * @param lat The lat 33 | */ 34 | public void setLat(Double lat) { 35 | this.lat = lat; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Main.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | public class Main { 7 | 8 | @Expose private Double temp; 9 | @SerializedName("temp_min") @Expose private Double tempMin; 10 | @SerializedName("temp_max") @Expose private Double tempMax; 11 | @Expose private Double pressure; 12 | @SerializedName("sea_level") @Expose private Double seaLevel; 13 | @SerializedName("grnd_level") @Expose private Double grndLevel; 14 | @Expose private Integer humidity; 15 | 16 | /** 17 | * @return The temp 18 | */ 19 | public Double getTemp() { 20 | return temp; 21 | } 22 | 23 | /** 24 | * @param temp The temp 25 | */ 26 | public void setTemp(Double temp) { 27 | this.temp = temp; 28 | } 29 | 30 | /** 31 | * @return The tempMin 32 | */ 33 | public Double getTempMin() { 34 | return tempMin; 35 | } 36 | 37 | /** 38 | * @param tempMin The temp_min 39 | */ 40 | public void setTempMin(Double tempMin) { 41 | this.tempMin = tempMin; 42 | } 43 | 44 | /** 45 | * @return The tempMax 46 | */ 47 | public Double getTempMax() { 48 | return tempMax; 49 | } 50 | 51 | /** 52 | * @param tempMax The temp_max 53 | */ 54 | public void setTempMax(Double tempMax) { 55 | this.tempMax = tempMax; 56 | } 57 | 58 | /** 59 | * @return The pressure 60 | */ 61 | public Double getPressure() { 62 | return pressure; 63 | } 64 | 65 | /** 66 | * @param pressure The pressure 67 | */ 68 | public void setPressure(Double pressure) { 69 | this.pressure = pressure; 70 | } 71 | 72 | /** 73 | * @return The seaLevel 74 | */ 75 | public Double getSeaLevel() { 76 | return seaLevel; 77 | } 78 | 79 | /** 80 | * @param seaLevel The sea_level 81 | */ 82 | public void setSeaLevel(Double seaLevel) { 83 | this.seaLevel = seaLevel; 84 | } 85 | 86 | /** 87 | * @return The grndLevel 88 | */ 89 | public Double getGrndLevel() { 90 | return grndLevel; 91 | } 92 | 93 | /** 94 | * @param grndLevel The grnd_level 95 | */ 96 | public void setGrndLevel(Double grndLevel) { 97 | this.grndLevel = grndLevel; 98 | } 99 | 100 | /** 101 | * @return The humidity 102 | */ 103 | public Integer getHumidity() { 104 | return humidity; 105 | } 106 | 107 | /** 108 | * @param humidity The humidity 109 | */ 110 | public void setHumidity(Integer humidity) { 111 | this.humidity = humidity; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Sys.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | 5 | public class Sys { 6 | 7 | @Expose private Double message; 8 | 9 | @Expose private String country; 10 | 11 | @Expose private Integer sunrise; 12 | 13 | @Expose private Integer sunset; 14 | 15 | /** 16 | * @return The message 17 | */ 18 | public Double getMessage() { 19 | return message; 20 | } 21 | 22 | /** 23 | * @param message The message 24 | */ 25 | public void setMessage(Double message) { 26 | this.message = message; 27 | } 28 | 29 | /** 30 | * @return The country 31 | */ 32 | public String getCountry() { 33 | return country; 34 | } 35 | 36 | /** 37 | * @param country The country 38 | */ 39 | public void setCountry(String country) { 40 | this.country = country; 41 | } 42 | 43 | /** 44 | * @return The sunrise 45 | */ 46 | public Integer getSunrise() { 47 | return sunrise; 48 | } 49 | 50 | /** 51 | * @param sunrise The sunrise 52 | */ 53 | public void setSunrise(Integer sunrise) { 54 | this.sunrise = sunrise; 55 | } 56 | 57 | /** 58 | * @return The sunset 59 | */ 60 | public Integer getSunset() { 61 | return sunset; 62 | } 63 | 64 | /** 65 | * @param sunset The sunset 66 | */ 67 | public void setSunset(Integer sunset) { 68 | this.sunset = sunset; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Weather.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | 5 | public class Weather { 6 | 7 | @Expose private Integer id; 8 | @Expose private String main; 9 | @Expose private String description; 10 | @Expose private String icon; 11 | 12 | /** 13 | * @return The id 14 | */ 15 | public Integer getId() { 16 | return id; 17 | } 18 | 19 | /** 20 | * @param id The id 21 | */ 22 | public void setId(Integer id) { 23 | this.id = id; 24 | } 25 | 26 | /** 27 | * @return The main 28 | */ 29 | public String getMain() { 30 | return main; 31 | } 32 | 33 | /** 34 | * @param main The main 35 | */ 36 | public void setMain(String main) { 37 | this.main = main; 38 | } 39 | 40 | /** 41 | * @return The description 42 | */ 43 | public String getDescription() { 44 | return description; 45 | } 46 | 47 | /** 48 | * @param description The description 49 | */ 50 | public void setDescription(String description) { 51 | this.description = description; 52 | } 53 | 54 | /** 55 | * @return The icon 56 | */ 57 | public String getIcon() { 58 | return icon; 59 | } 60 | 61 | /** 62 | * @param icon The icon 63 | */ 64 | public void setIcon(String icon) { 65 | this.icon = icon; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/WeatherResponse.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class WeatherResponse { 8 | 9 | @Expose private Coord coord; 10 | @Expose private Sys sys; 11 | @Expose private List weather = new ArrayList(); 12 | @Expose private String base; 13 | @Expose private Main main; 14 | @Expose private Wind wind; 15 | @Expose private Clouds clouds; 16 | @Expose private Integer dt; 17 | @Expose private Integer id; 18 | @Expose private String name; 19 | @Expose private Integer cod; 20 | 21 | /** 22 | * @return The coord 23 | */ 24 | public Coord getCoord() { 25 | return coord; 26 | } 27 | 28 | /** 29 | * @param coord The coord 30 | */ 31 | public void setCoord(Coord coord) { 32 | this.coord = coord; 33 | } 34 | 35 | /** 36 | * @return The sys 37 | */ 38 | public Sys getSys() { 39 | return sys; 40 | } 41 | 42 | /** 43 | * @param sys The sys 44 | */ 45 | public void setSys(Sys sys) { 46 | this.sys = sys; 47 | } 48 | 49 | /** 50 | * @return The weather 51 | */ 52 | public List getWeather() { 53 | return weather; 54 | } 55 | 56 | /** 57 | * @param weather The weather 58 | */ 59 | public void setWeather(List weather) { 60 | this.weather = weather; 61 | } 62 | 63 | /** 64 | * @return The base 65 | */ 66 | public String getBase() { 67 | return base; 68 | } 69 | 70 | /** 71 | * @param base The base 72 | */ 73 | public void setBase(String base) { 74 | this.base = base; 75 | } 76 | 77 | /** 78 | * @return The main 79 | */ 80 | public Main getMain() { 81 | return main; 82 | } 83 | 84 | /** 85 | * @param main The main 86 | */ 87 | public void setMain(Main main) { 88 | this.main = main; 89 | } 90 | 91 | /** 92 | * @return The wind 93 | */ 94 | public Wind getWind() { 95 | return wind; 96 | } 97 | 98 | /** 99 | * @param wind The wind 100 | */ 101 | public void setWind(Wind wind) { 102 | this.wind = wind; 103 | } 104 | 105 | /** 106 | * @return The clouds 107 | */ 108 | public Clouds getClouds() { 109 | return clouds; 110 | } 111 | 112 | /** 113 | * @param clouds The clouds 114 | */ 115 | public void setClouds(Clouds clouds) { 116 | this.clouds = clouds; 117 | } 118 | 119 | /** 120 | * @return The dt 121 | */ 122 | public Integer getDt() { 123 | return dt; 124 | } 125 | 126 | /** 127 | * @param dt The dt 128 | */ 129 | public void setDt(Integer dt) { 130 | this.dt = dt; 131 | } 132 | 133 | /** 134 | * @return The id 135 | */ 136 | public Integer getId() { 137 | return id; 138 | } 139 | 140 | /** 141 | * @param id The id 142 | */ 143 | public void setId(Integer id) { 144 | this.id = id; 145 | } 146 | 147 | /** 148 | * @return The name 149 | */ 150 | public String getName() { 151 | return name; 152 | } 153 | 154 | /** 155 | * @param name The name 156 | */ 157 | public void setName(String name) { 158 | this.name = name; 159 | } 160 | 161 | /** 162 | * @return The cod 163 | */ 164 | public Integer getCod() { 165 | return cod; 166 | } 167 | 168 | /** 169 | * @param cod The cod 170 | */ 171 | public void setCod(Integer cod) { 172 | this.cod = cod; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/openweathermap/models/Wind.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.openweathermap.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | 5 | public class Wind { 6 | 7 | @Expose private Double speed; 8 | 9 | @Expose private Double deg; 10 | 11 | /** 12 | * @return The speed 13 | */ 14 | public Double getSpeed() { 15 | return speed; 16 | } 17 | 18 | /** 19 | * @param speed The speed 20 | */ 21 | public void setSpeed(Double speed) { 22 | this.speed = speed; 23 | } 24 | 25 | /** 26 | * @return The deg 27 | */ 28 | public Double getDeg() { 29 | return deg; 30 | } 31 | 32 | /** 33 | * @param deg The deg 34 | */ 35 | public void setDeg(Double deg) { 36 | this.deg = deg; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/stackexchange/SeApiManager.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange; 2 | 3 | import com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models.User; 4 | import com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models.UsersResponse; 5 | import java.util.List; 6 | import lombok.experimental.Accessors; 7 | import retrofit.RestAdapter; 8 | import rx.Observable; 9 | import rx.android.schedulers.AndroidSchedulers; 10 | import rx.schedulers.Schedulers; 11 | 12 | @Accessors(prefix = "m") public class SeApiManager { 13 | 14 | private final StackExchangeService mStackExchangeService; 15 | 16 | public SeApiManager() { 17 | RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://api.stackexchange.com") 18 | .setLogLevel(RestAdapter.LogLevel.BASIC) 19 | .build(); 20 | 21 | mStackExchangeService = restAdapter.create(StackExchangeService.class); 22 | } 23 | 24 | public Observable> getTenMostPopularSOusers() { 25 | return mStackExchangeService.getTenMostPopularSOusers() 26 | .map(UsersResponse::getUsers) 27 | .subscribeOn(Schedulers.io()) 28 | .observeOn(AndroidSchedulers.mainThread()); 29 | } 30 | 31 | public Observable> getMostPopularSOusers(int howmany) { 32 | return mStackExchangeService.getMostPopularSOusers(howmany) 33 | .map(UsersResponse::getUsers) 34 | .subscribeOn(Schedulers.io()) 35 | .observeOn(AndroidSchedulers.mainThread()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/stackexchange/StackExchangeService.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange; 2 | 3 | import com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models.UsersResponse; 4 | import retrofit.http.GET; 5 | import retrofit.http.Query; 6 | import rx.Observable; 7 | 8 | public interface StackExchangeService { 9 | 10 | @GET("/2.2/users?order=desc&pagesize=10&sort=reputation&site=stackoverflow") 11 | Observable getTenMostPopularSOusers(); 12 | 13 | @GET("/2.2/users?order=desc&sort=reputation&site=stackoverflow") 14 | Observable getMostPopularSOusers(@Query("pagesize") int howmany); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/stackexchange/models/BadgeCounts.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import lombok.Data; 5 | 6 | @Data public class BadgeCounts { 7 | 8 | @Expose private Integer bronze; 9 | 10 | @Expose private Integer silver; 11 | 12 | @Expose private Integer gold; 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/stackexchange/models/User.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | import lombok.Data; 6 | 7 | @Data public class User { 8 | 9 | @SerializedName("badge_counts") @Expose private BadgeCounts badgeCounts; 10 | 11 | @SerializedName("account_id") @Expose private Integer accountId; 12 | 13 | @SerializedName("is_employee") @Expose private Boolean isEmployee; 14 | 15 | @SerializedName("last_modified_date") @Expose private Integer lastModifiedDate; 16 | 17 | @SerializedName("last_access_date") @Expose private Integer lastAccessDate; 18 | 19 | @SerializedName("reputation_change_year") @Expose private Integer reputationChangeYear; 20 | 21 | @SerializedName("reputation_change_quarter") @Expose private Integer reputationChangeQuarter; 22 | 23 | @SerializedName("reputation_change_month") @Expose private Integer reputationChangeMonth; 24 | 25 | @SerializedName("reputation_change_week") @Expose private Integer reputationChangeWeek; 26 | 27 | @SerializedName("reputation_change_day") @Expose private Integer reputationChangeDay; 28 | 29 | @Expose private Integer reputation; 30 | 31 | @SerializedName("creation_date") @Expose private Integer creationDate; 32 | 33 | @SerializedName("user_type") @Expose private String userType; 34 | 35 | @SerializedName("user_id") @Expose private Integer userId; 36 | 37 | @Expose private Integer age; 38 | 39 | @Expose private String location; 40 | 41 | @SerializedName("website_url") @Expose private String websiteUrl; 42 | 43 | @Expose private String link; 44 | 45 | @SerializedName("display_name") @Expose private String displayName; 46 | 47 | @SerializedName("profile_image") @Expose private String profileImage; 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/chapter8/api/stackexchange/models/UsersResponse.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.chapter8.api.stackexchange.models; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | import java.util.List; 6 | import lombok.Data; 7 | 8 | @Data public class UsersResponse { 9 | 10 | @SerializedName("items") @Expose private List users; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/example1/FirstExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.example1; 2 | 3 | import android.app.Fragment; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.content.pm.ResolveInfo; 8 | import android.graphics.Bitmap; 9 | import android.os.Bundle; 10 | import android.support.v4.widget.SwipeRefreshLayout; 11 | import android.support.v7.widget.LinearLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.util.TypedValue; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.widget.Toast; 18 | import butterknife.ButterKnife; 19 | import butterknife.InjectView; 20 | import com.google.gson.Gson; 21 | import com.google.gson.reflect.TypeToken; 22 | import com.packtpub.apps.rxjava_essentials.App; 23 | import com.packtpub.apps.rxjava_essentials.R; 24 | import com.packtpub.apps.rxjava_essentials.Utils; 25 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 26 | import com.packtpub.apps.rxjava_essentials.apps.AppInfoRich; 27 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 28 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 29 | import java.io.File; 30 | import java.lang.reflect.Type; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | import rx.Observable; 34 | import rx.Observer; 35 | import rx.android.schedulers.AndroidSchedulers; 36 | import rx.schedulers.Schedulers; 37 | 38 | public class FirstExampleFragment extends Fragment { 39 | 40 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 41 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 42 | 43 | private ApplicationAdapter mAdapter; 44 | private File mFilesDir; 45 | 46 | public FirstExampleFragment() { 47 | } 48 | 49 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle state) { 50 | return inflater.inflate(R.layout.fragment_example, container, false); 51 | } 52 | 53 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 54 | super.onViewCreated(view, savedInstanceState); 55 | ButterKnife.inject(this, view); 56 | 57 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 58 | 59 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 60 | mRecyclerView.setAdapter(mAdapter); 61 | 62 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 63 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 64 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 65 | getResources().getDisplayMetrics())); 66 | 67 | // Progress 68 | mSwipeRefreshLayout.setEnabled(false); 69 | mSwipeRefreshLayout.setRefreshing(true); 70 | mRecyclerView.setVisibility(View.GONE); 71 | 72 | getFileDir().subscribeOn(Schedulers.io()) 73 | .observeOn(AndroidSchedulers.mainThread()) 74 | .subscribe(file -> { 75 | mFilesDir = file; 76 | refreshTheList(); 77 | }); 78 | } 79 | 80 | private Observable getFileDir() { 81 | return Observable.create(subscriber -> { 82 | subscriber.onNext(App.instance.getFilesDir()); 83 | subscriber.onCompleted(); 84 | }); 85 | } 86 | 87 | private void refreshTheList() { 88 | getApps().toSortedList().subscribe(new Observer>() { 89 | @Override public void onCompleted() { 90 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 91 | } 92 | 93 | @Override public void onError(Throwable e) { 94 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 95 | mSwipeRefreshLayout.setRefreshing(false); 96 | } 97 | 98 | @Override public void onNext(List appInfos) { 99 | mRecyclerView.setVisibility(View.VISIBLE); 100 | mAdapter.addApplications(appInfos); 101 | mSwipeRefreshLayout.setRefreshing(false); 102 | storeList(appInfos); 103 | } 104 | }); 105 | } 106 | 107 | private void storeList(List appInfos) { 108 | ApplicationsList.getInstance().setList(appInfos); 109 | 110 | Schedulers.io().createWorker().schedule(() -> { 111 | SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); 112 | Type appInfoType = new TypeToken>() { 113 | }.getType(); 114 | sharedPref.edit().putString("APPS", new Gson().toJson(appInfos, appInfoType)).apply(); 115 | }); 116 | } 117 | 118 | private Observable getApps() { 119 | return Observable.create(subscriber -> { 120 | List apps = new ArrayList<>(); 121 | 122 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 123 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 124 | 125 | List infos = 126 | getActivity().getPackageManager().queryIntentActivities(mainIntent, 0); 127 | for (ResolveInfo info : infos) { 128 | apps.add(new AppInfoRich(getActivity(), info)); 129 | } 130 | 131 | for (AppInfoRich appInfo : apps) { 132 | Bitmap icon = Utils.drawableToBitmap(appInfo.getIcon()); 133 | String name = appInfo.getName(); 134 | String iconPath = mFilesDir + "/" + name; 135 | Utils.storeBitmap(App.instance, icon, name); 136 | 137 | if (subscriber.isUnsubscribed()) { 138 | return; 139 | } 140 | subscriber.onNext(new AppInfo(name, iconPath, appInfo.getLastUpdateTime())); 141 | } 142 | if (!subscriber.isUnsubscribed()) { 143 | subscriber.onCompleted(); 144 | } 145 | }); 146 | } 147 | 148 | @Override public void onDestroyView() { 149 | super.onDestroyView(); 150 | ButterKnife.reset(this); 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/example2/SecondExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.example2; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.TypedValue; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Toast; 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | import com.packtpub.apps.rxjava_essentials.R; 16 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 17 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import rx.Observable; 22 | import rx.Observer; 23 | 24 | public class SecondExampleFragment extends Fragment { 25 | 26 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 27 | 28 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 29 | 30 | private ApplicationAdapter mAdapter; 31 | 32 | private ArrayList mAddedApps = new ArrayList<>(); 33 | 34 | public SecondExampleFragment() { 35 | } 36 | 37 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 38 | Bundle savedInstanceState) { 39 | return inflater.inflate(R.layout.fragment_example, container, false); 40 | } 41 | 42 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 43 | super.onViewCreated(view, savedInstanceState); 44 | ButterKnife.inject(this, view); 45 | 46 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 47 | 48 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 49 | mRecyclerView.setAdapter(mAdapter); 50 | 51 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 52 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 53 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 54 | getResources().getDisplayMetrics())); 55 | 56 | // Progress 57 | mSwipeRefreshLayout.setEnabled(false); 58 | mSwipeRefreshLayout.setRefreshing(true); 59 | mRecyclerView.setVisibility(View.GONE); 60 | 61 | List apps = ApplicationsList.getInstance().getList(); 62 | 63 | loadList(apps); 64 | } 65 | 66 | private void loadList(List apps) { 67 | mRecyclerView.setVisibility(View.VISIBLE); 68 | 69 | Observable.from(apps).subscribe(new Observer() { 70 | @Override public void onCompleted() { 71 | mSwipeRefreshLayout.setRefreshing(false); 72 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 73 | } 74 | 75 | @Override public void onError(Throwable e) { 76 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 77 | mSwipeRefreshLayout.setRefreshing(false); 78 | } 79 | 80 | @Override public void onNext(AppInfo appInfo) { 81 | mAddedApps.add(appInfo); 82 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 83 | } 84 | }); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/example3/ThirdExampleFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.example3; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.Log; 9 | import android.util.TypedValue; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Toast; 14 | import butterknife.ButterKnife; 15 | import butterknife.InjectView; 16 | import com.packtpub.apps.rxjava_essentials.R; 17 | import com.packtpub.apps.rxjava_essentials.apps.AppInfo; 18 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationAdapter; 19 | import com.packtpub.apps.rxjava_essentials.apps.ApplicationsList; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.concurrent.TimeUnit; 23 | import rx.Observable; 24 | import rx.Observer; 25 | import rx.Subscription; 26 | 27 | public class ThirdExampleFragment extends Fragment { 28 | 29 | @InjectView(R.id.fragment_first_example_list) RecyclerView mRecyclerView; 30 | 31 | @InjectView(R.id.fragment_first_example_swipe_container) SwipeRefreshLayout mSwipeRefreshLayout; 32 | 33 | private ApplicationAdapter mAdapter; 34 | 35 | private ArrayList mAddedApps = new ArrayList<>(); 36 | 37 | private Subscription mTimeSubscription; 38 | 39 | public ThirdExampleFragment() { 40 | } 41 | 42 | @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 43 | Bundle savedInstanceState) { 44 | return inflater.inflate(R.layout.fragment_example, container, false); 45 | } 46 | 47 | @Override public void onViewCreated(View view, Bundle savedInstanceState) { 48 | super.onViewCreated(view, savedInstanceState); 49 | ButterKnife.inject(this, view); 50 | 51 | mRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); 52 | 53 | mAdapter = new ApplicationAdapter(new ArrayList<>(), R.layout.applications_list_item); 54 | mRecyclerView.setAdapter(mAdapter); 55 | 56 | mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myPrimaryColor)); 57 | mSwipeRefreshLayout.setProgressViewOffset(false, 0, 58 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, 59 | getResources().getDisplayMetrics())); 60 | 61 | // Progress 62 | mSwipeRefreshLayout.setEnabled(false); 63 | mSwipeRefreshLayout.setRefreshing(true); 64 | mRecyclerView.setVisibility(View.GONE); 65 | 66 | List apps = ApplicationsList.getInstance().getList(); 67 | 68 | AppInfo appOne = apps.get(0); 69 | 70 | AppInfo appTwo = apps.get(1); 71 | 72 | AppInfo appThree = apps.get(2); 73 | 74 | loadApps(appOne, appTwo, appThree); 75 | } 76 | 77 | private void loadApps(AppInfo appOne, AppInfo appTwo, AppInfo appThree) { 78 | mRecyclerView.setVisibility(View.VISIBLE); 79 | 80 | Observable threeOfThem = Observable.just(appOne, appTwo, appThree); 81 | 82 | threeOfThem.subscribe(new Observer() { 83 | @Override public void onCompleted() { 84 | mSwipeRefreshLayout.setRefreshing(false); 85 | Toast.makeText(getActivity(), "Here is the list!", Toast.LENGTH_LONG).show(); 86 | } 87 | 88 | @Override public void onError(Throwable e) { 89 | Toast.makeText(getActivity(), "Something went wrong!", Toast.LENGTH_SHORT).show(); 90 | mSwipeRefreshLayout.setRefreshing(false); 91 | } 92 | 93 | @Override public void onNext(AppInfo appInfo) { 94 | mAddedApps.add(appInfo); 95 | mAdapter.addApplication(mAddedApps.size() - 1, appInfo); 96 | } 97 | }); 98 | 99 | mTimeSubscription = Observable.timer(3, 3, TimeUnit.SECONDS).subscribe(new Observer() { 100 | @Override public void onCompleted() { 101 | 102 | } 103 | 104 | @Override public void onError(Throwable e) { 105 | } 106 | 107 | @Override public void onNext(Long number) { 108 | Log.d("RXJAVA", "I say " + number); 109 | } 110 | }); 111 | } 112 | 113 | @Override public void onDestroyView() { 114 | super.onDestroyView(); 115 | if (!mTimeSubscription.isUnsubscribed()) { 116 | mTimeSubscription.unsubscribe(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/navigation_drawer/NavigationDrawerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.navigation_drawer; 2 | 3 | import android.graphics.Color; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | import com.packtpub.apps.rxjava_essentials.R; 11 | import java.util.List; 12 | 13 | public class NavigationDrawerAdapter 14 | extends RecyclerView.Adapter { 15 | 16 | private List mData; 17 | 18 | private NavigationDrawerCallbacks mNavigationDrawerCallbacks; 19 | 20 | private int mSelectedPosition; 21 | 22 | private int mTouchedPosition = -1; 23 | 24 | public NavigationDrawerAdapter(List data) { 25 | mData = data; 26 | } 27 | 28 | public NavigationDrawerCallbacks getNavigationDrawerCallbacks() { 29 | return mNavigationDrawerCallbacks; 30 | } 31 | 32 | public void setNavigationDrawerCallbacks(NavigationDrawerCallbacks navigationDrawerCallbacks) { 33 | mNavigationDrawerCallbacks = navigationDrawerCallbacks; 34 | } 35 | 36 | @Override 37 | public NavigationDrawerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 38 | View v = 39 | LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.drawer_row, viewGroup, false); 40 | return new ViewHolder(v); 41 | } 42 | 43 | @Override 44 | public void onBindViewHolder(NavigationDrawerAdapter.ViewHolder viewHolder, final int i) { 45 | viewHolder.textView.setText(mData.get(i).getText()); 46 | viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(mData.get(i).getDrawable(), null, 47 | null, null); 48 | 49 | viewHolder.itemView.setOnTouchListener((v, event) -> { 50 | switch (event.getAction()) { 51 | case MotionEvent.ACTION_DOWN: 52 | touchPosition(i); 53 | return false; 54 | case MotionEvent.ACTION_CANCEL: 55 | touchPosition(-1); 56 | return false; 57 | case MotionEvent.ACTION_MOVE: 58 | return false; 59 | case MotionEvent.ACTION_UP: 60 | touchPosition(-1); 61 | return false; 62 | } 63 | return true; 64 | }); 65 | viewHolder.itemView.setOnClickListener(v -> { 66 | if (mNavigationDrawerCallbacks != null) { 67 | mNavigationDrawerCallbacks.onNavigationDrawerItemSelected(i); 68 | } 69 | }); 70 | 71 | //TODO: selected menu position, change layout accordingly 72 | if (mSelectedPosition == i || mTouchedPosition == i) { 73 | viewHolder.itemView.setBackgroundColor( 74 | viewHolder.itemView.getContext().getResources().getColor(R.color.selected_gray)); 75 | } else { 76 | viewHolder.itemView.setBackgroundColor(Color.TRANSPARENT); 77 | } 78 | } 79 | 80 | private void touchPosition(int position) { 81 | int lastPosition = mTouchedPosition; 82 | mTouchedPosition = position; 83 | if (lastPosition >= 0) { 84 | notifyItemChanged(lastPosition); 85 | } 86 | if (position >= 0) { 87 | notifyItemChanged(position); 88 | } 89 | } 90 | 91 | public void selectPosition(int position) { 92 | int lastPosition = mSelectedPosition; 93 | mSelectedPosition = position; 94 | notifyItemChanged(lastPosition); 95 | notifyItemChanged(position); 96 | } 97 | 98 | @Override public int getItemCount() { 99 | return mData != null ? mData.size() : 0; 100 | } 101 | 102 | public static class ViewHolder extends RecyclerView.ViewHolder { 103 | 104 | public TextView textView; 105 | 106 | public ViewHolder(View itemView) { 107 | super(itemView); 108 | textView = (TextView) itemView.findViewById(R.id.item_name); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/navigation_drawer/NavigationDrawerCallbacks.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.navigation_drawer; 2 | 3 | public interface NavigationDrawerCallbacks { 4 | 5 | void onNavigationDrawerItemSelected(int position); 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/navigation_drawer/NavigationDrawerFragment.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.navigation_drawer; 2 | 3 | import android.app.Activity; 4 | import android.app.Fragment; 5 | import android.content.Context; 6 | import android.content.SharedPreferences; 7 | import android.content.res.Configuration; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.support.v4.widget.DrawerLayout; 11 | import android.support.v7.app.ActionBarDrawerToggle; 12 | import android.support.v7.widget.LinearLayoutManager; 13 | import android.support.v7.widget.RecyclerView; 14 | import android.support.v7.widget.Toolbar; 15 | import android.view.LayoutInflater; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import com.packtpub.apps.rxjava_essentials.R; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | public class NavigationDrawerFragment extends Fragment implements NavigationDrawerCallbacks { 23 | 24 | private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; 25 | 26 | private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; 27 | 28 | private static final String PREFERENCES_FILE = "my_app_settings"; //TODO: change this to your file 29 | 30 | private NavigationDrawerCallbacks mCallbacks; 31 | 32 | private RecyclerView mDrawerList; 33 | 34 | private View mFragmentContainerView; 35 | 36 | private DrawerLayout mDrawerLayout; 37 | 38 | private ActionBarDrawerToggle mActionBarDrawerToggle; 39 | 40 | private boolean mUserLearnedDrawer; 41 | 42 | private boolean mFromSavedInstanceState; 43 | 44 | private int mCurrentSelectedPosition; 45 | 46 | public static void saveSharedSetting(Context ctx, String settingName, String settingValue) { 47 | SharedPreferences sharedPref = ctx.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); 48 | SharedPreferences.Editor editor = sharedPref.edit(); 49 | editor.putString(settingName, settingValue); 50 | editor.apply(); 51 | } 52 | 53 | public static String readSharedSetting(Context ctx, String settingName, String defaultValue) { 54 | SharedPreferences sharedPref = ctx.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE); 55 | return sharedPref.getString(settingName, defaultValue); 56 | } 57 | 58 | @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, 59 | Bundle savedInstanceState) { 60 | View view = inflater.inflate(R.layout.fragment_navigation_drawer, container, false); 61 | mDrawerList = (RecyclerView) view.findViewById(R.id.drawerList); 62 | LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); 63 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 64 | mDrawerList.setLayoutManager(layoutManager); 65 | mDrawerList.setHasFixedSize(true); 66 | 67 | final List navigationItems = getMenu(); 68 | NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(navigationItems); 69 | adapter.setNavigationDrawerCallbacks(this); 70 | mDrawerList.setAdapter(adapter); 71 | selectItem(mCurrentSelectedPosition); 72 | return view; 73 | } 74 | 75 | @Override public void onCreate(Bundle savedInstanceState) { 76 | super.onCreate(savedInstanceState); 77 | mUserLearnedDrawer = 78 | Boolean.valueOf(readSharedSetting(getActivity(), PREF_USER_LEARNED_DRAWER, "false")); 79 | if (savedInstanceState != null) { 80 | mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); 81 | mFromSavedInstanceState = true; 82 | } 83 | } 84 | 85 | @Override public void onAttach(Activity activity) { 86 | super.onAttach(activity); 87 | try { 88 | mCallbacks = (NavigationDrawerCallbacks) activity; 89 | } catch (ClassCastException e) { 90 | throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); 91 | } 92 | } 93 | 94 | public ActionBarDrawerToggle getActionBarDrawerToggle() { 95 | return mActionBarDrawerToggle; 96 | } 97 | 98 | public void setActionBarDrawerToggle(ActionBarDrawerToggle actionBarDrawerToggle) { 99 | mActionBarDrawerToggle = actionBarDrawerToggle; 100 | } 101 | 102 | public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { 103 | mFragmentContainerView = getActivity().findViewById(fragmentId); 104 | mDrawerLayout = drawerLayout; 105 | mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.myPrimaryDarkColor)); 106 | 107 | mActionBarDrawerToggle = 108 | new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, 109 | R.string.drawer_close) { 110 | @Override public void onDrawerClosed(View drawerView) { 111 | super.onDrawerClosed(drawerView); 112 | if (!isAdded()) { 113 | return; 114 | } 115 | getActivity().invalidateOptionsMenu(); 116 | } 117 | 118 | @Override public void onDrawerOpened(View drawerView) { 119 | super.onDrawerOpened(drawerView); 120 | if (!isAdded()) { 121 | return; 122 | } 123 | if (!mUserLearnedDrawer) { 124 | mUserLearnedDrawer = true; 125 | saveSharedSetting(getActivity(), PREF_USER_LEARNED_DRAWER, "true"); 126 | } 127 | 128 | getActivity().invalidateOptionsMenu(); 129 | } 130 | }; 131 | 132 | if (!mUserLearnedDrawer && !mFromSavedInstanceState) { 133 | mDrawerLayout.openDrawer(mFragmentContainerView); 134 | } 135 | 136 | mDrawerLayout.post(new Runnable() { 137 | @Override public void run() { 138 | mActionBarDrawerToggle.syncState(); 139 | } 140 | }); 141 | 142 | mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); 143 | } 144 | 145 | public void openDrawer() { 146 | mDrawerLayout.openDrawer(mFragmentContainerView); 147 | } 148 | 149 | public void closeDrawer() { 150 | mDrawerLayout.closeDrawer(mFragmentContainerView); 151 | } 152 | 153 | @Override public void onDetach() { 154 | super.onDetach(); 155 | mCallbacks = null; 156 | } 157 | 158 | public List getMenu() { 159 | List items = new ArrayList<>(); 160 | items.add( 161 | new NavigationItem("Example 1", getResources().getDrawable(R.drawable.ic_action_android))); 162 | items.add( 163 | new NavigationItem("Example 2", getResources().getDrawable(R.drawable.ic_action_android))); 164 | items.add( 165 | new NavigationItem("Example 3", getResources().getDrawable(R.drawable.ic_action_android))); 166 | 167 | items.add( 168 | new NavigationItem("Filter", getResources().getDrawable(R.drawable.ic_action_filter))); 169 | items.add(new NavigationItem("Take and TakeLast", 170 | getResources().getDrawable(R.drawable.ic_action_filter))); 171 | items.add(new NavigationItem("Distinct abd DistinctUntilChanged", 172 | getResources().getDrawable(R.drawable.ic_action_filter))); 173 | 174 | items.add(new NavigationItem("Map", getResources().getDrawable(R.drawable.ic_action_wizard))); 175 | items.add(new NavigationItem("Scan", getResources().getDrawable(R.drawable.ic_action_wizard))); 176 | items.add( 177 | new NavigationItem("GroupBy", getResources().getDrawable(R.drawable.ic_action_wizard))); 178 | 179 | items.add( 180 | new NavigationItem("Merge", getResources().getDrawable(R.drawable.ic_action_process_save))); 181 | items.add( 182 | new NavigationItem("Zip", getResources().getDrawable(R.drawable.ic_action_process_save))); 183 | items.add( 184 | new NavigationItem("Join", getResources().getDrawable(R.drawable.ic_action_process_save))); 185 | items.add(new NavigationItem("CombineLatest", 186 | getResources().getDrawable(R.drawable.ic_action_process_save))); 187 | items.add(new NavigationItem("And Then When", 188 | getResources().getDrawable(R.drawable.ic_action_process_save))); 189 | 190 | items.add(new NavigationItem("SharedPreferences", 191 | getResources().getDrawable(R.drawable.ic_action_playback_schuffle))); 192 | items.add(new NavigationItem("Long task", 193 | getResources().getDrawable(R.drawable.ic_action_playback_schuffle))); 194 | items.add(new NavigationItem("Network task", 195 | getResources().getDrawable(R.drawable.ic_action_playback_schuffle))); 196 | 197 | items.add(new NavigationItem("Stack Overflow", 198 | getResources().getDrawable(R.drawable.ic_action_android))); 199 | 200 | return items; 201 | } 202 | 203 | void selectItem(int position) { 204 | mCurrentSelectedPosition = position; 205 | if (mDrawerLayout != null) { 206 | mDrawerLayout.closeDrawer(mFragmentContainerView); 207 | } 208 | if (mCallbacks != null) { 209 | mCallbacks.onNavigationDrawerItemSelected(position); 210 | } 211 | ((NavigationDrawerAdapter) mDrawerList.getAdapter()).selectPosition(position); 212 | } 213 | 214 | public boolean isDrawerOpen() { 215 | return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); 216 | } 217 | 218 | @Override public void onConfigurationChanged(Configuration newConfig) { 219 | super.onConfigurationChanged(newConfig); 220 | mActionBarDrawerToggle.onConfigurationChanged(newConfig); 221 | } 222 | 223 | @Override public void onSaveInstanceState(Bundle outState) { 224 | super.onSaveInstanceState(outState); 225 | outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); 226 | } 227 | 228 | @Override public void onNavigationDrawerItemSelected(int position) { 229 | selectItem(position); 230 | } 231 | 232 | public DrawerLayout getDrawerLayout() { 233 | return mDrawerLayout; 234 | } 235 | 236 | public void setDrawerLayout(DrawerLayout drawerLayout) { 237 | mDrawerLayout = drawerLayout; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /app/src/main/java/com/packtpub/apps/rxjava_essentials/navigation_drawer/NavigationItem.java: -------------------------------------------------------------------------------- 1 | package com.packtpub.apps.rxjava_essentials.navigation_drawer; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | public class NavigationItem { 6 | 7 | private String mText; 8 | 9 | private Drawable mDrawable; 10 | 11 | public NavigationItem(String text, Drawable drawable) { 12 | mText = text; 13 | mDrawable = drawable; 14 | } 15 | 16 | public String getText() { 17 | return mText; 18 | } 19 | 20 | public void setText(String text) { 21 | mText = text; 22 | } 23 | 24 | public Drawable getDrawable() { 25 | return mDrawable; 26 | } 27 | 28 | public void setDrawable(Drawable drawable) { 29 | mDrawable = drawable; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_action_android.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_action_filter.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_playback_schuffle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_action_playback_schuffle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_process_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_action_process_save.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_action_wizard.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_menu_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-hdpi/ic_menu_check.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_action_android.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_action_filter.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_playback_schuffle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_action_playback_schuffle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_process_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_action_process_save.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_action_wizard.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_menu_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-mdpi/ic_menu_check.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_bt_raise.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/bg_bt_raise.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_bt_raise_color.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/bg_bt_raise_color.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_action_android.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_action_filter.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_playback_schuffle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_action_playback_schuffle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_process_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_action_process_save.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_action_wizard.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_menu_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xhdpi/ic_menu_check.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_action_android.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_action_filter.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_playback_schuffle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_action_playback_schuffle.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_process_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_action_process_save.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_action_wizard.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_menu_check.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/ic_menu_check.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/packt_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable-xxhdpi/packt_logo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_rect_list_normal.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_rect_list_secondary.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_round.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/color_tpi.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/round.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/round_touch.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/transparent_pixel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/drawable/transparent_pixel.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 24 | 25 | 30 | 31 | 36 | 37 | 38 | 39 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_so.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 9 | 10 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/applications_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 21 | 22 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/drawer_row.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_download.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 23 | 24 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_example.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_item_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_navigation_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/so_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | 17 | 26 | 27 | 35 | 36 | 45 | 46 | 55 | 56 | 65 | 66 | 67 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /app/src/main/res/layout/toolbar_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_so.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-large/refs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | @layout/fragment_item_grid 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values-sw600dp/refs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | @layout/fragment_item_grid 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | 24 | 25 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #F59927 4 | #ffcd8221 5 | #000000 6 | #F2F2F2 7 | #DEDEDE 8 | #000000 9 | #000000 10 | 11 | #ffdbdbdb 12 | 13 | #FCFCFC 14 | #F2F2F2 15 | 16 | #FFFFFFFF 17 | #99FFFFFF 18 | #ffffff 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 8 | 240dp 9 | 4dp 10 | 11 | 16sp 12 | 13 | 36dp 14 | 15 | 5dp 16 | 5dp 17 | 5dp 18 | 20dp 19 | 10dp 20 | 21 | 50dp 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/values/refs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | @layout/fragment_item_list 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RxJava Essentials 5 | Menu opened 6 | Menu closed 7 | Settings 8 | Hello blank fragment 9 | Downloading 10 | Download 11 | SoActivity 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 22 | 23 | 27 | 28 | 33 | 34 | 35 | 36 | 43 | 44 | 47 | 48 | 56 | 57 | 58 | 59 | 60 | 63 | 64 | 67 | 68 | 73 | 74 | 78 | 79 | 86 | 87 | 94 | 95 | 103 | 104 | 112 | 113 | 114 | 115 | 122 | 123 | 130 | 131 | 138 | 139 | 146 | 147 | 150 | 151 | 154 | 155 | 167 | 168 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /app/src/main/res/xml/fab_icon_states.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 0.5 7 | 0 8 | 0.5 9 | 1 10 | 11 | 0 12 | 0.5 13 | 1 14 | 0.5 15 | 16 | 17 | 18 | 19 | 20 | 0.633 21 | 0.161 22 | 0 23 | 0.793 24 | 25 | 0.633 26 | 0.161 27 | 1 28 | 0.527 29 | 30 | 31 | 32 | 0 33 | 1 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:1.3.0' 8 | classpath 'me.tatarka:gradle-retrolambda:3.2.0' 9 | classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2' 10 | } 11 | 12 | // Exclude the version that the android plugin depends on. 13 | configurations.classpath.exclude group: 'com.android.tools.external.lombok' 14 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jun 17 15:03:07 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /screenshots/drawer_bellow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/screenshots/drawer_bellow.gif -------------------------------------------------------------------------------- /screenshots/drawer_over_toolbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/screenshots/drawer_over_toolbar.gif -------------------------------------------------------------------------------- /screenshots/playstore_style.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/screenshots/playstore_style.gif -------------------------------------------------------------------------------- /screenshots/screenshot1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcoRS/rxjava-essentials/4e5a0fc47ed43251c976f1eadec16094031b8c00/screenshots/screenshot1.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------