├── LICENSE ├── README.md ├── Screenshot_GIF.gif ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sourabhkarkal │ │ └── movieapp │ │ ├── ExampleInstrumentedTest.java │ │ └── activity │ │ └── HomeScreenUITest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sourabhkarkal │ │ │ └── movieapp │ │ │ ├── ApplicationController.java │ │ │ ├── activity │ │ │ ├── BaseActivity.java │ │ │ └── HomeScreen.java │ │ │ ├── fragment │ │ │ ├── BaseFragment.java │ │ │ ├── MovieDetailFragment.java │ │ │ ├── MovieFragment.java │ │ │ └── WebViewFragment.java │ │ │ ├── listener │ │ │ ├── OnLoadMoreListener.java │ │ │ ├── RecyclerItemClickListener.java │ │ │ └── RecyclerOnLongClickListener.java │ │ │ ├── modal │ │ │ ├── GenresDTO.java │ │ │ ├── MovieDetailDTO.java │ │ │ ├── MoviePageDTO.java │ │ │ ├── MoviesDTO.java │ │ │ ├── RegionDTO.java │ │ │ └── SubEntityDTO.java │ │ │ ├── realm │ │ │ └── modal │ │ │ │ ├── RGenresDTO.java │ │ │ │ ├── RMovieDetailDTO.java │ │ │ │ ├── RMoviesDTO.java │ │ │ │ ├── RRegionDTO.java │ │ │ │ └── RSubEntityDTO.java │ │ │ ├── service │ │ │ ├── DataRequest.java │ │ │ ├── DataResponse.java │ │ │ ├── RestTemplateExecutor.java │ │ │ └── iWebListener.java │ │ │ ├── utils │ │ │ ├── Constants.java │ │ │ ├── HttpOperation.java │ │ │ ├── ManagePreferences.java │ │ │ └── Utils.java │ │ │ └── widget │ │ │ ├── AutoScrollViewPager.java │ │ │ ├── CustomDurationScroller.java │ │ │ └── ImageViewPager.java │ └── res │ │ ├── anim │ │ ├── enter.xml │ │ ├── exit.xml │ │ ├── left_to_right.xml │ │ └── right_to_left.xml │ │ ├── drawable │ │ ├── book_icon.png │ │ ├── circle.xml │ │ ├── movie_placeholder.png │ │ └── rectangle.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── home_screen.xml │ │ ├── movie_detail_layout.xml │ │ ├── movie_detail_sub_layout.xml │ │ ├── movie_item.xml │ │ ├── progressbar_item.xml │ │ └── webview_fragment.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sourabhkarkal │ └── movieapp │ ├── ExampleUnitTest.java │ └── activity │ ├── HomeScreenUnitTest.java │ └── MockSupport.java ├── build.gradle ├── build ├── generated │ └── mockable-android-24.default-values.jar └── intermediates │ └── dex-cache │ └── cache.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TMDB APP 2 | This is a Demo App which gets list of movies from TMDB with detail view 3 | 4 | ## TMDB API 5 | https://www.themoviedb.org/documentation/api 6 | 7 | ####Screens 8 | 9 | ![Demo](https://github.com/Auto-Droid/TMDB-App/blob/master/Screenshot_GIF.gif) 10 | 11 | 12 | ##External Libs Used : 13 | 1. **Glide** : Image loading 14 |
compile 'com.github.bumptech.glide:glide:3.5.2' 15 | 2. **RxJava** : Asynchronous call 16 |
compile 'io.reactivex:rxandroid:1.0.1' 17 |
compile 'io.reactivex:rxjava:1.0.14' 18 | 3. **OkHttp** : Rest Client API calls 19 |
compile 'com.squareup.okhttp3:okhttp:3.4.2' 20 | 21 | ###UI Testing 22 | **Expresso** 23 | ###Unit Testing 24 | **Robolectric** and **Mockito** 25 | -------------------------------------------------------------------------------- /Screenshot_GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auto-Droid/TMDB-App/8aaebbe6a656ad64d41df7bade59a85333d57120/Screenshot_GIF.gif -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'realm-android' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "23.0.2" 7 | useLibrary 'org.apache.http.legacy' 8 | 9 | defaultConfig { 10 | applicationId "com.sourabhkarkal.movieapp" 11 | minSdkVersion 15 12 | targetSdkVersion 24 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | testOptions { 24 | unitTests.returnDefaultValues = true 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 31 | exclude group: 'com.android.support', module: 'support-annotations' 32 | }) 33 | compile 'com.android.support:appcompat-v7:24.2.0' 34 | compile 'com.android.support:design:24.2.0' 35 | compile 'com.android.support:palette-v7:24.2.0' 36 | compile 'com.fasterxml.jackson.core:jackson-databind:2.4.1.2' 37 | compile 'com.fasterxml.jackson.core:jackson-core:2.4.1.1' 38 | compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.1' 39 | compile 'com.android.support:recyclerview-v7:24.2.0' 40 | compile 'com.android.support:cardview-v7:24.2.0' 41 | compile 'com.squareup.okhttp3:okhttp:3.4.2' 42 | compile 'io.reactivex:rxandroid:1.0.1' 43 | compile 'io.reactivex:rxjava:1.0.14' 44 | compile 'com.github.bumptech.glide:glide:3.5.2' 45 | 46 | //testing dependency 47 | testCompile "org.robolectric:robolectric:3.0" 48 | testCompile "org.mockito:mockito-core:1.10.19" 49 | testCompile 'org.robolectric:shadows-support-v4:3.0' 50 | testCompile "org.powermock:powermock-module-junit4:1.6.2" 51 | testCompile "org.powermock:powermock-module-junit4-rule:1.6.2" 52 | testCompile "org.powermock:powermock-api-mockito:1.6.2" 53 | testCompile "org.powermock:powermock-classloading-xstream:1.6.2" 54 | 55 | testCompile 'org.mockito:mockito-core:1.10.19' 56 | testCompile 'junit:junit:4.12' 57 | androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2', { 58 | exclude group: 'com.android.support', module: 'support-annotations' 59 | exclude group: 'com.android.support', module: 'support-v4' 60 | exclude group: 'com.android.support', module: 'design' 61 | exclude group: 'com.android.support', module: 'recyclerview-v7' 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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 /Users/sourabhkarkal/Library/Android/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/androidTest/java/com/sourabhkarkal/movieapp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.sourabhkarkal.movieapp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sourabhkarkal/movieapp/activity/HomeScreenUITest.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.activity; 2 | 3 | 4 | import android.support.test.espresso.ViewInteraction; 5 | import android.support.test.rule.ActivityTestRule; 6 | import android.support.test.runner.AndroidJUnit4; 7 | import android.test.suitebuilder.annotation.LargeTest; 8 | 9 | import com.sourabhkarkal.movieapp.R; 10 | 11 | import org.junit.Rule; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | 15 | import static android.support.test.espresso.Espresso.onView; 16 | import static android.support.test.espresso.Espresso.pressBack; 17 | import static android.support.test.espresso.action.ViewActions.*; 18 | import static android.support.test.espresso.assertion.ViewAssertions.*; 19 | import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; 20 | import static android.support.test.espresso.matcher.ViewMatchers.*; 21 | import static org.hamcrest.Matchers.allOf; 22 | 23 | @LargeTest 24 | @RunWith(AndroidJUnit4.class) 25 | public class HomeScreenUITest { 26 | 27 | @Rule 28 | public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(HomeScreen.class); 29 | 30 | @Test 31 | public void homeScreenUITest() { 32 | ViewInteraction recyclerView = onView( 33 | allOf(withId(R.id.rvMovieList), isDisplayed())); 34 | recyclerView.perform(actionOnItemAtPosition(2, click())); 35 | 36 | 37 | ViewInteraction appCompatButton = onView( 38 | allOf(withId(R.id.btnDetailBook), withText("BOOK TICKETS"), 39 | withParent(allOf(withId(R.id.htab_maincontent), 40 | withParent(withId(R.id.mainfragment)))), 41 | isDisplayed())); 42 | appCompatButton.perform(click()); 43 | 44 | pressBack(); 45 | 46 | pressBack(); 47 | 48 | ViewInteraction recyclerView3 = onView( 49 | allOf(withId(R.id.rvMovieList), isDisplayed())); 50 | recyclerView3.perform(actionOnItemAtPosition(19, click())); 51 | 52 | pressBack(); 53 | 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/ApplicationController.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp; 2 | 3 | 4 | import android.app.Application; 5 | import android.content.Context; 6 | import android.graphics.Typeface; 7 | 8 | import io.realm.RealmConfiguration; 9 | 10 | /** 11 | * Created by sourabhkarkal on 24/02/17. 12 | */ 13 | public class ApplicationController extends Application { 14 | 15 | public static final String TAG = ApplicationController.class 16 | .getSimpleName(); 17 | private static ApplicationController mInstance; 18 | private static Context mContext; 19 | private RealmConfiguration localconfig = null; 20 | 21 | public static synchronized ApplicationController getInstance() { 22 | return mInstance; 23 | } 24 | 25 | @Override 26 | protected void attachBaseContext(Context base) { 27 | super.attachBaseContext(base); 28 | } 29 | 30 | public Context getContext() { 31 | return mContext; 32 | } 33 | 34 | @Override 35 | public void onCreate() { 36 | super.onCreate(); 37 | mInstance = this; 38 | mContext = getApplicationContext(); 39 | 40 | } 41 | 42 | public RealmConfiguration getRealmConfig() { 43 | //realm migration 44 | if (localconfig == null) { 45 | localconfig = new RealmConfiguration.Builder(getContext()) 46 | .name("LocalDB") 47 | .schemaVersion(1) 48 | //.migration(new RealmMigration()) 49 | .deleteRealmIfMigrationNeeded() 50 | .build(); 51 | } 52 | return localconfig; 53 | } 54 | 55 | @Override 56 | public void onLowMemory() { 57 | super.onLowMemory(); 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | import android.widget.TextView; 10 | 11 | import com.sourabhkarkal.movieapp.service.iWebListener; 12 | 13 | 14 | /** 15 | * Created by sourabhkarkal on 24/02/17. 16 | */ 17 | public abstract class BaseActivity extends AppCompatActivity implements iWebListener,View.OnClickListener { 18 | 19 | 20 | @Override 21 | protected void onCreate(@Nullable Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | } 24 | 25 | public View makeClickable(Activity activity, int id) 26 | { 27 | View viewobj = activity.findViewById(id); 28 | if(viewobj !=null) 29 | { 30 | viewobj.setOnClickListener(this); 31 | } 32 | return viewobj; 33 | } 34 | 35 | 36 | @Override 37 | public void onClick(View v) { 38 | 39 | } 40 | 41 | @Override 42 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 43 | super.onActivityResult(requestCode, resultCode, data); 44 | } 45 | 46 | 47 | public void setText(View view,int id,String strMessage) 48 | { 49 | TextView txtView = (TextView)view.findViewById(id); 50 | if(txtView != null) 51 | txtView.setText(strMessage); 52 | } 53 | 54 | @Override 55 | public void onTaskComplete(int taskId, Object object, boolean isError) { 56 | 57 | } 58 | 59 | @Override 60 | public void setTitle(CharSequence title) { 61 | super.setTitle(title); 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/activity/HomeScreen.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | 6 | import com.sourabhkarkal.movieapp.R; 7 | import com.sourabhkarkal.movieapp.fragment.MovieFragment; 8 | 9 | /** 10 | * Created by sourabhkarkal on 25/02/17. 11 | */ 12 | 13 | public class HomeScreen extends BaseActivity { 14 | 15 | @Override 16 | protected void onCreate(@Nullable Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.home_screen); 19 | 20 | // setting up Home Fragment 21 | setMainFragment(); 22 | } 23 | 24 | private void setMainFragment() { 25 | MovieFragment movieFragment = new MovieFragment(); 26 | final android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); 27 | ft.replace(R.id.mainfragment, movieFragment, "Home"); 28 | ft.commit(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.fragment; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.sourabhkarkal.movieapp.service.iWebListener; 11 | 12 | 13 | /** 14 | * Created by sourabhkarkal on 24/02/17. 15 | */ 16 | public abstract class BaseFragment extends Fragment implements iWebListener,View.OnClickListener { 17 | 18 | 19 | @Override 20 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 21 | return super.onCreateView(inflater, container, savedInstanceState); 22 | } 23 | 24 | @Override 25 | public void onActivityCreated(Bundle savedInstanceState) { 26 | super.onActivityCreated(savedInstanceState); 27 | } 28 | 29 | public View makeClickable(View view,int id) 30 | { 31 | View viewobj = view.findViewById(id); 32 | if(viewobj !=null) 33 | { 34 | viewobj.setOnClickListener(this); 35 | } 36 | return view; 37 | } 38 | 39 | 40 | @Override 41 | public void onClick(View v) { 42 | 43 | } 44 | 45 | @Override 46 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 47 | super.onActivityResult(requestCode, resultCode, data); 48 | } 49 | 50 | 51 | @Override 52 | public void onTaskComplete(int taskId, Object object, boolean isError) {} 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/fragment/MovieDetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.design.widget.CollapsingToolbarLayout; 6 | import android.text.TextUtils; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import com.fasterxml.jackson.databind.ObjectMapper; 16 | import com.sourabhkarkal.movieapp.ApplicationController; 17 | import com.sourabhkarkal.movieapp.R; 18 | import com.sourabhkarkal.movieapp.modal.MovieDetailDTO; 19 | import com.sourabhkarkal.movieapp.modal.MoviesDTO; 20 | import com.sourabhkarkal.movieapp.realm.modal.RMovieDetailDTO; 21 | import com.sourabhkarkal.movieapp.realm.modal.RMoviesDTO; 22 | import com.sourabhkarkal.movieapp.service.DataRequest; 23 | import com.sourabhkarkal.movieapp.service.DataResponse; 24 | import com.sourabhkarkal.movieapp.service.RestTemplateExecutor; 25 | import com.sourabhkarkal.movieapp.utils.Constants; 26 | import com.sourabhkarkal.movieapp.utils.HttpOperation; 27 | import com.sourabhkarkal.movieapp.utils.Utils; 28 | import com.sourabhkarkal.movieapp.widget.AutoScrollViewPager; 29 | import com.sourabhkarkal.movieapp.widget.ImageViewPager; 30 | import java.io.IOException; 31 | import java.util.ArrayList; 32 | 33 | 34 | import io.realm.Realm; 35 | 36 | /** 37 | * Created by sourabhkarkal on 25/02/17. 38 | * 39 | * This fragment shows the detail page for the Movie 40 | * {@link #viewPager} viewPager is added to show multiple images and auto scrolling is done using {@link AutoScrollViewPager} 41 | * Title is set on {@link #mToolbar} which is an object CollapsingToolbarLayout 42 | * 43 | * Data is fetched according to {@link #movieId} which is passed by {@link MovieFragment} as an argument 44 | * 45 | * 46 | * Realm DB table {@link RMovieDetailDTO} 47 | */ 48 | 49 | public class MovieDetailFragment extends BaseFragment { 50 | 51 | private View rootView; 52 | private final int MOVIE_DETAIL_TASK_ID = 101; 53 | final String TAG = getClass().getName(); 54 | CollapsingToolbarLayout mToolbar; 55 | private TextView tvDetailTagline, tvDetailWebsite, tvDetailDescription, tvDetailDuration; 56 | private TextView tvDetailBudget, tvDetailRevenue, tvDetailCountry, tvDetailPopularity; 57 | private TextView tvDetailLanguage, tvDetailGerene, tvDetailVotesPercent, tvDetailVotesCount; 58 | String movieId; 59 | AutoScrollViewPager viewPager; 60 | 61 | 62 | @Override 63 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 64 | rootView = inflater.inflate(R.layout.movie_detail_layout, container, false); 65 | init(rootView); 66 | 67 | movieId = getArguments().getString("id"); 68 | 69 | Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig()); 70 | RMovieDetailDTO rMovieDetailDTO = realm.where(RMovieDetailDTO.class).equalTo("id", Integer.parseInt(movieId)).findFirst(); 71 | if (rMovieDetailDTO != null) 72 | setData(new MovieDetailDTO(rMovieDetailDTO)); 73 | realm.close(); 74 | 75 | if (Utils.isNetworkAvailable()) { 76 | DataRequest dataRequest = new DataRequest(MOVIE_DETAIL_TASK_ID, Constants.MAIN_URL + Constants.DETAIL_URL + movieId + "?api_key=" + Constants.API_KEY, getActivity(), MovieDetailFragment.this, HttpOperation.GET, null); 77 | new RestTemplateExecutor().callServerApi(dataRequest); 78 | } else { 79 | Utils.showSnackBar(rootView, getString(R.string.no_internet_available), Utils.MessageType.ERROR); 80 | } 81 | 82 | 83 | return rootView; 84 | } 85 | 86 | //region ************* intialize view ************* 87 | private void init(View rootView) { 88 | mToolbar = (CollapsingToolbarLayout) rootView.findViewById(R.id.toolbar); 89 | tvDetailTagline = (TextView) rootView.findViewById(R.id.tvDetailTagline); 90 | tvDetailWebsite = (TextView) rootView.findViewById(R.id.tvDetailWebsite); 91 | tvDetailBudget = (TextView) rootView.findViewById(R.id.tvDetailBudget); 92 | tvDetailRevenue = (TextView) rootView.findViewById(R.id.tvDetailRevenue); 93 | tvDetailCountry = (TextView) rootView.findViewById(R.id.tvDetailCountry); 94 | tvDetailLanguage = (TextView) rootView.findViewById(R.id.tvDetailLanguage); 95 | tvDetailGerene = (TextView) rootView.findViewById(R.id.tvDetailGerene); 96 | tvDetailVotesPercent = (TextView) rootView.findViewById(R.id.tvDetailVotesPercent); 97 | tvDetailVotesCount = (TextView) rootView.findViewById(R.id.tvDetailVotesCount); 98 | tvDetailDescription = (TextView) rootView.findViewById(R.id.tvDetailDescription); 99 | tvDetailPopularity = (TextView) rootView.findViewById(R.id.tvDetailPopularity); 100 | tvDetailDuration = (TextView) rootView.findViewById(R.id.tvDetailDuration); 101 | viewPager = (AutoScrollViewPager) rootView.findViewById(R.id.autoScrollViewPager); 102 | 103 | makeClickable(rootView, R.id.btnDetailBook); 104 | } 105 | //endregion 106 | 107 | 108 | //region ************* OnTaskComplete Method ************* 109 | @Override 110 | public void onTaskComplete(int taskId, Object object, boolean isError) { 111 | super.onTaskComplete(taskId, object, isError); 112 | if (MOVIE_DETAIL_TASK_ID == taskId) { 113 | 114 | if (isError) 115 | Log.e(TAG, object.toString()); 116 | else { 117 | DataResponse dataResponse = (DataResponse) object; 118 | MovieDetailDTO movieDetailDTO; 119 | try { 120 | movieDetailDTO = new ObjectMapper().readValue(dataResponse.getObject().toString(), MovieDetailDTO.class); 121 | Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig()); 122 | realm.beginTransaction(); 123 | realm.copyToRealmOrUpdate(new RMovieDetailDTO(movieDetailDTO)); 124 | realm.commitTransaction(); 125 | RMoviesDTO rMoviesDTO = realm.where(RMoviesDTO.class).equalTo("id", movieId).findFirst(); 126 | setData(movieDetailDTO); 127 | realm.close(); 128 | 129 | } catch (IOException e) { 130 | e.printStackTrace(); 131 | } 132 | } 133 | } 134 | } 135 | //endregion 136 | 137 | //region ************* Set Detail Screen Data ************* 138 | private void setData(MovieDetailDTO movieDetailDTO) { 139 | 140 | mToolbar.setTitle(movieDetailDTO.getTitle()); 141 | mToolbar.setExpandedTitleColor(Utils.getColor(getActivity(), R.color.white)); 142 | mToolbar.setCollapsedTitleTextColor(Utils.getColor(getActivity(), R.color.white)); 143 | 144 | mToolbar.setBackgroundColor(Utils.getColor(getActivity(), R.color.semi_transparent)); 145 | mToolbar.setStatusBarScrimColor(Utils.getColor(getActivity(), R.color.semi_transparent)); 146 | mToolbar.setContentScrimColor(Utils.getColor(getActivity(), R.color.semi_transparent)); 147 | 148 | tvDetailTagline.setText(movieDetailDTO.getTagline() == null || movieDetailDTO.getTagline().isEmpty() ? "N/A" : movieDetailDTO.getTagline()); 149 | tvDetailWebsite.setText(movieDetailDTO.getHomepage() == null || movieDetailDTO.getHomepage().isEmpty() ? "N/A" : movieDetailDTO.getHomepage()); 150 | tvDetailBudget.setText("" + movieDetailDTO.getBudget()); 151 | tvDetailRevenue.setText("" + movieDetailDTO.getRevenue()); 152 | tvDetailCountry.setText(movieDetailDTO.getProduction_countries().isEmpty() ? "N/A" : TextUtils.join(",", movieDetailDTO.getProduction_countries())); 153 | tvDetailGerene.setText(movieDetailDTO.getGenres().isEmpty() ? "N/A" : TextUtils.join(",", movieDetailDTO.getGenres())); 154 | tvDetailVotesPercent.setText("" + movieDetailDTO.getVote_average() + "/10"); 155 | tvDetailVotesCount.setText(movieDetailDTO.getVote_count() + " votes"); 156 | tvDetailDescription.setText(movieDetailDTO.getOverview() == null || movieDetailDTO.getOverview().isEmpty() ? "N/A" : movieDetailDTO.getOverview()); 157 | tvDetailLanguage.setText(movieDetailDTO.getOriginal_language().toUpperCase()); 158 | tvDetailPopularity.setText("❤ " + ((int) (movieDetailDTO.getPopularity()))); 159 | 160 | int time = movieDetailDTO.getRuntime(); 161 | tvDetailDuration.setText((time / 60) + " hrs " + (time % 60) + " min"); 162 | 163 | 164 | // Adding all available images to list 165 | ArrayList imagePathList = new ArrayList<>(); 166 | if (movieDetailDTO.getBelongs_to_collection() != null) { 167 | if (movieDetailDTO.getBelongs_to_collection().getBackdrop_path() != null) 168 | imagePathList.add(movieDetailDTO.getBelongs_to_collection().getBackdrop_path()); 169 | if (movieDetailDTO.getBelongs_to_collection().getPoster_path() != null) 170 | imagePathList.add(movieDetailDTO.getBelongs_to_collection().getPoster_path()); 171 | } 172 | if (movieDetailDTO.getBackdrop_path() != null) 173 | imagePathList.add(movieDetailDTO.getBackdrop_path()); 174 | if (movieDetailDTO.getPoster_path() != null) 175 | imagePathList.add(movieDetailDTO.getPoster_path()); 176 | 177 | ImageViewPager adapter = new ImageViewPager(getActivity(), imagePathList); 178 | viewPager.setAdapter(adapter); 179 | viewPager.startAutoScroll(); 180 | viewPager.setInterval(3000); 181 | viewPager.setCycle(true); 182 | viewPager.setStopScrollWhenTouch(true); 183 | 184 | } 185 | //endregion 186 | 187 | @Override 188 | public void onClick(View v) { 189 | super.onClick(v); 190 | if (v.getId() == R.id.btnDetailBook) { 191 | Utils.replaceFragment(getActivity(), new WebViewFragment(), true); 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/fragment/MovieFragment.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.fragment; 2 | 3 | 4 | import android.os.Handler; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.os.Bundle; 7 | import android.support.v7.widget.CardView; 8 | import android.support.v7.widget.DefaultItemAnimator; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.util.Log; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | import android.widget.ImageView; 17 | import android.widget.ProgressBar; 18 | import android.widget.TextView; 19 | 20 | import com.bumptech.glide.Glide; 21 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 22 | import com.fasterxml.jackson.databind.ObjectMapper; 23 | import com.sourabhkarkal.movieapp.ApplicationController; 24 | import com.sourabhkarkal.movieapp.R; 25 | import com.sourabhkarkal.movieapp.listener.OnLoadMoreListener; 26 | import com.sourabhkarkal.movieapp.modal.MoviePageDTO; 27 | import com.sourabhkarkal.movieapp.modal.MoviesDTO; 28 | import com.sourabhkarkal.movieapp.realm.modal.RMoviesDTO; 29 | import com.sourabhkarkal.movieapp.service.DataRequest; 30 | import com.sourabhkarkal.movieapp.service.DataResponse; 31 | import com.sourabhkarkal.movieapp.service.RestTemplateExecutor; 32 | import com.sourabhkarkal.movieapp.utils.Constants; 33 | import com.sourabhkarkal.movieapp.utils.HttpOperation; 34 | import com.sourabhkarkal.movieapp.utils.ManagePreferences; 35 | import com.sourabhkarkal.movieapp.utils.Utils; 36 | 37 | import java.io.IOException; 38 | import java.text.SimpleDateFormat; 39 | import java.util.ArrayList; 40 | import java.util.Calendar; 41 | import java.util.List; 42 | 43 | import io.realm.Realm; 44 | import io.realm.RealmResults; 45 | import io.realm.Sort; 46 | 47 | /** 48 | * Created by sourabhkarkal on 24/02/17. 49 | * 50 | * This class shows the list of movies form {@link #apiCall(int)} pass 1 for intial page 51 | * to automatically handle pagination call {@link #callMovieApi()} method ,Page No is stored in Preference 52 | * with the help of class {@link ManagePreferences} with Constant {@link ManagePreferences#PAGE_NO} 53 | *

54 | * For Sorting Data according to release date ref {@link #loadDataFromDB()} where data is fetched according to 55 | * release date stored in realmDB 56 | *

57 | * {@link MoviesAdapter#setOnLoadMoreListener} is added to show infinite loading progress bar 58 | * {@link #swipeRefreshLayout} is used for showing pull to refresh where always page 1 is passed to get the latest data 59 | * 60 | * 61 | * Realm DB table {@link RMoviesDTO} 62 | * 63 | */ 64 | 65 | public class MovieFragment extends BaseFragment { 66 | 67 | SwipeRefreshLayout swipeRefreshLayout; 68 | private boolean loading; 69 | ArrayList moviesDTOs; 70 | final String TAG = getClass().getName(); 71 | private RecyclerView rvMovieList; 72 | private MoviesAdapter moviesAdapter; 73 | private final int MOVIE_TASK_ID = 100; 74 | int PAGE_NO = 1; 75 | private View rootView; 76 | 77 | @Override 78 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 79 | rootView = inflater.inflate(R.layout.activity_main, container, false); 80 | moviesDTOs = new ArrayList<>(); 81 | 82 | rvMovieList = (RecyclerView) rootView.findViewById(R.id.rvMovieList); 83 | swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshLayout); 84 | 85 | PAGE_NO = ManagePreferences.getIntData(getActivity(), ManagePreferences.PAGE_NO); //setting stored pageNo 86 | 87 | rvMovieList.setLayoutManager(new LinearLayoutManager(getActivity())); 88 | rvMovieList.setItemAnimator(new DefaultItemAnimator()); 89 | moviesAdapter = new MoviesAdapter(); 90 | rvMovieList.setAdapter(moviesAdapter); 91 | 92 | loadDataFromDB(); // Fetch data from DB 93 | 94 | if (moviesDTOs.isEmpty()) 95 | callMovieApi(); 96 | 97 | moviesAdapter.setOnLoadMoreListener(new OnLoadMoreListener() { 98 | @Override 99 | public void onLoadMore() { 100 | //add null , so the adapter will check view_type and show progress bar at bottom 101 | new Handler().postDelayed(new Runnable() { 102 | @Override 103 | public void run() { 104 | if (moviesDTOs != null) { 105 | moviesDTOs.add(null); 106 | moviesAdapter.notifyDataSetChanged(); 107 | callMovieApi(); 108 | } 109 | } 110 | }, 500); 111 | } 112 | }); 113 | 114 | 115 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 116 | @Override 117 | public void onRefresh() { 118 | if (Utils.isNetworkAvailable()) { 119 | apiCall(1); // Passing the first page to get the latest data 120 | } else { 121 | Utils.showSnackBar(rootView, getString(R.string.no_internet_available), Utils.MessageType.ERROR); 122 | swipeRefreshLayout.setRefreshing(false); 123 | } 124 | } 125 | }); 126 | 127 | 128 | return rootView; 129 | } 130 | 131 | private void callMovieApi() { 132 | if (Utils.isNetworkAvailable()) { 133 | apiCall(PAGE_NO); 134 | PAGE_NO ++; 135 | } else { 136 | Utils.showSnackBar(rootView, getString(R.string.no_internet_available), Utils.MessageType.ERROR); 137 | if (swipeRefreshLayout.isRefreshing()) 138 | swipeRefreshLayout.setRefreshing(false); 139 | if(loading) 140 | if (moviesDTOs != null && moviesDTOs.size() > 0) { 141 | if (moviesDTOs.get(moviesDTOs.size() - 1) == null) { 142 | moviesDTOs.remove(moviesDTOs.size() - 1); 143 | moviesAdapter.notifyItemRemoved(moviesDTOs.size()); 144 | moviesAdapter.setLoaded(); 145 | } 146 | } 147 | } 148 | } 149 | 150 | private void apiCall(int pageNo) { 151 | Calendar c = Calendar.getInstance(); 152 | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); 153 | String formattedDate = df.format(c.getTime()); 154 | DataRequest dataRequest = new DataRequest(MOVIE_TASK_ID, Constants.MAIN_URL + Constants.LIST_URL + "api_key=" + Constants.API_KEY + "&primary_release_date.lte=" + formattedDate + "&sort_by=release_date.desc&page=" + PAGE_NO, getActivity(), MovieFragment.this, HttpOperation.GET, null); 155 | new RestTemplateExecutor().callServerApi(dataRequest); 156 | } 157 | 158 | 159 | @Override 160 | public void onDestroy() { 161 | super.onDestroy(); 162 | if(moviesDTOs!=null) 163 | moviesDTOs = null; 164 | } 165 | 166 | //region ************* fetch data from realm ************* 167 | private void loadDataFromDB() { 168 | Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig()); 169 | RealmResults rMoviesDTOs = realm.where(RMoviesDTO.class).findAllSorted("release_date", Sort.DESCENDING); 170 | for (RMoviesDTO rMoviesDTO : rMoviesDTOs) { 171 | moviesDTOs.add(new MoviesDTO(rMoviesDTO)); 172 | } 173 | moviesAdapter.notifyDataSetChanged(); 174 | realm.close(); 175 | } 176 | //endregion 177 | 178 | 179 | //region ************* OnTaskComplete Method ************* 180 | @Override 181 | public void onTaskComplete(int taskId, Object object, boolean isError) { 182 | super.onTaskComplete(taskId, object, isError); 183 | 184 | if (MOVIE_TASK_ID == taskId) { 185 | 186 | if (swipeRefreshLayout.isRefreshing()) 187 | swipeRefreshLayout.setRefreshing(false); 188 | 189 | // remove progress item 190 | if (loading) 191 | if (moviesDTOs != null && moviesDTOs.size() > 0) { 192 | if (moviesDTOs.get(moviesDTOs.size() - 1) == null) { 193 | moviesDTOs.remove(moviesDTOs.size() - 1); 194 | moviesAdapter.notifyItemRemoved(moviesDTOs.size()); 195 | moviesAdapter.setLoaded(); 196 | } 197 | } 198 | 199 | if (isError) 200 | Log.e(TAG, object.toString()); 201 | else { 202 | DataResponse dataResponse = (DataResponse) object; 203 | MoviePageDTO moviePageDTO = null; 204 | try { 205 | moviePageDTO = new ObjectMapper().readValue(dataResponse.getObject().toString(), MoviePageDTO.class); 206 | 207 | ManagePreferences.setIntData(getActivity(), ManagePreferences.PAGE_NO, moviePageDTO.getPage());// Store PageNo 208 | 209 | Realm realm = Realm.getInstance(ApplicationController.getInstance().getRealmConfig()); 210 | for (MoviesDTO moviesDTO : moviePageDTO.getResults()) { 211 | RMoviesDTO rMoviesDTO = new RMoviesDTO(moviesDTO); 212 | realm.beginTransaction(); 213 | realm.copyToRealmOrUpdate(rMoviesDTO); 214 | realm.commitTransaction(); 215 | } 216 | realm.close(); 217 | moviesDTOs.clear(); 218 | loadDataFromDB(); 219 | 220 | 221 | } catch (IOException e) { 222 | e.printStackTrace(); 223 | } 224 | } 225 | } 226 | 227 | } 228 | //endregion 229 | 230 | //region ************* Movie Adapter CODE ************* 231 | private final int VIEW_ITEM = 1; 232 | private final int VIEW_PROG = 0; 233 | public class MoviesAdapter extends RecyclerView.Adapter { 234 | 235 | private List moviesList; 236 | private OnLoadMoreListener onLoadMoreListener; 237 | private int totalItemCount, visibleItemCount, displayedPosition; 238 | 239 | public class MovieViewHolder extends RecyclerView.ViewHolder { 240 | 241 | TextView tvLanguage, tvMovieTitle, tvMovieReleaseDate, tvVotesPercent, tvVotesCount; 242 | ImageView imgBanner; 243 | Button btnBook; 244 | CardView cardLayout; 245 | 246 | public MovieViewHolder(View view) { 247 | super(view); 248 | tvLanguage = (TextView) view.findViewById(R.id.tvLanguage); 249 | tvMovieTitle = (TextView) view.findViewById(R.id.tvMovieTitle); 250 | tvVotesCount = (TextView) view.findViewById(R.id.tvVotesCount); 251 | tvVotesPercent = (TextView) view.findViewById(R.id.tvVotesPercent); 252 | tvMovieTitle = (TextView) view.findViewById(R.id.tvMovieTitle); 253 | tvMovieReleaseDate = (TextView) view.findViewById(R.id.tvMovieReleaseDate); 254 | imgBanner = (ImageView) view.findViewById(R.id.imgBanner); 255 | btnBook = (Button) view.findViewById(R.id.btnBook); 256 | cardLayout = (CardView) view.findViewById(R.id.cardView); 257 | } 258 | } 259 | 260 | 261 | public MoviesAdapter() { 262 | 263 | final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) rvMovieList.getLayoutManager(); 264 | 265 | rvMovieList.addOnScrollListener(new RecyclerView.OnScrollListener() { 266 | @Override 267 | public void onScrolled(RecyclerView recyclerView, 268 | int dx, int dy) { 269 | super.onScrolled(recyclerView, dx, dy); 270 | 271 | displayedPosition = linearLayoutManager.findFirstVisibleItemPosition(); 272 | visibleItemCount = linearLayoutManager.getChildCount(); 273 | totalItemCount = linearLayoutManager.getItemCount(); 274 | if (dy > 0) //check for scroll down 275 | { 276 | if (!loading) 277 | if ((visibleItemCount + displayedPosition) >= totalItemCount) { 278 | // End has been reached 279 | if (onLoadMoreListener != null) { 280 | onLoadMoreListener.onLoadMore(); 281 | loading = true; 282 | } 283 | } 284 | } 285 | } 286 | }); 287 | 288 | } 289 | 290 | @Override 291 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 292 | if (holder instanceof MovieViewHolder) { 293 | final MovieViewHolder movieViewHolder = (MovieViewHolder) holder; 294 | final MoviesDTO movie = moviesDTOs.get(position); 295 | movieViewHolder.tvMovieTitle.setText(movie.getTitle()); // title 296 | movieViewHolder.tvLanguage.setText(movie.getOriginal_language().toUpperCase()); // Language 297 | movieViewHolder.tvMovieReleaseDate.setText(movie.getRelease_date()); // Release Date 298 | movieViewHolder.tvVotesPercent.setText("❤ " + ((int) (movie.getPopularity())) + ""); 299 | movieViewHolder.tvVotesCount.setText(movie.getVote_count() + " votes"); 300 | 301 | // Banner Image 302 | Glide.with(MovieFragment.this) 303 | .load(Constants.IMAGE_BASE_PATH + (movie.getBackdrop_path() == null ? movie.getPoster_path() : movie.getBackdrop_path())) 304 | .animate(android.R.anim.fade_in) 305 | .diskCacheStrategy(DiskCacheStrategy.ALL) 306 | .placeholder(R.drawable.movie_placeholder) 307 | .centerCrop() 308 | .into(movieViewHolder.imgBanner); 309 | 310 | // Click action on Book 311 | movieViewHolder.btnBook.setOnClickListener(new View.OnClickListener() { 312 | @Override 313 | public void onClick(View view) { 314 | Utils.replaceFragment(getActivity(), new WebViewFragment(), true); 315 | } 316 | }); 317 | 318 | // Click action for detail screen 319 | movieViewHolder.cardLayout.setOnClickListener(new View.OnClickListener() { 320 | @Override 321 | public void onClick(View view) { 322 | MovieDetailFragment movieDetailFragment = new MovieDetailFragment(); 323 | Bundle bundle = new Bundle(); 324 | bundle.putString("id", movie.getId()); 325 | movieDetailFragment.setArguments(bundle); 326 | Utils.replaceFragment(getActivity(), movieDetailFragment, true); 327 | } 328 | }); 329 | } 330 | 331 | } 332 | 333 | @Override 334 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 335 | RecyclerView.ViewHolder vh; 336 | if (viewType == VIEW_ITEM) { 337 | View v = LayoutInflater.from(parent.getContext()).inflate( 338 | R.layout.movie_item, parent, false); 339 | 340 | vh = new MovieViewHolder(v); 341 | } else { 342 | View v = LayoutInflater.from(parent.getContext()).inflate( 343 | R.layout.progressbar_item, parent, false); 344 | 345 | vh = new ProgressViewHolder(v); 346 | } 347 | return vh; 348 | } 349 | 350 | public class ProgressViewHolder extends RecyclerView.ViewHolder { 351 | public ProgressBar progressBar; 352 | 353 | public ProgressViewHolder(View v) { 354 | super(v); 355 | progressBar = (ProgressBar) v.findViewById(R.id.progressBar); 356 | } 357 | } 358 | 359 | // Return the size of your itemsData (invoked by the layout manager) 360 | @Override 361 | public int getItemCount() { 362 | return moviesDTOs != null ? moviesDTOs.size() : 0; 363 | } 364 | 365 | @Override 366 | public int getItemViewType(int position) { 367 | return moviesDTOs.get(position) != null ? VIEW_ITEM : VIEW_PROG; 368 | } 369 | 370 | public void setLoaded() { 371 | loading = false; 372 | } 373 | 374 | public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) { 375 | this.onLoadMoreListener = onLoadMoreListener; 376 | } 377 | } 378 | //endregion 379 | } 380 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/fragment/WebViewFragment.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.fragment; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.view.KeyEvent; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.webkit.WebView; 10 | import android.webkit.WebViewClient; 11 | import android.widget.ProgressBar; 12 | 13 | import com.sourabhkarkal.movieapp.R; 14 | 15 | /** 16 | * Created by sourabhkarkal on 25/02/17. 17 | * 18 | * This class is called when user taps on book button used in {@link MovieFragment} {@link MovieDetailFragment} 19 | * 20 | */ 21 | 22 | public class WebViewFragment extends BaseFragment { 23 | 24 | private WebView web; 25 | private ProgressBar progressBar; 26 | private View rootView; 27 | 28 | @Override 29 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 30 | rootView = inflater.inflate(R.layout.webview_fragment, container, false); 31 | web = (WebView) rootView.findViewById(R.id.webview); 32 | progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1); 33 | 34 | web.setWebViewClient(new MoiveWebClient()); 35 | web.getSettings().setJavaScriptEnabled(true); 36 | web.loadUrl("http://www.cathaycineplexes.com.sg"); 37 | return rootView; 38 | } 39 | 40 | //region ************* MoiveWebClient Code ************* 41 | public class MoiveWebClient extends WebViewClient { 42 | @Override 43 | public void onPageStarted(WebView view, String url, Bitmap favicon) { 44 | super.onPageStarted(view, url, favicon); 45 | } 46 | 47 | @Override 48 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 49 | progressBar.setVisibility(View.VISIBLE); 50 | view.loadUrl(url); 51 | return true; 52 | 53 | } 54 | 55 | @Override 56 | public void onPageFinished(WebView view, String url) { 57 | super.onPageFinished(view, url); 58 | 59 | progressBar.setVisibility(View.GONE); 60 | } 61 | } 62 | //endregion 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/listener/OnLoadMoreListener.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.listener; 2 | 3 | /** 4 | * Created by sourabhkarkal on 24/02/17. 5 | */ 6 | 7 | public interface OnLoadMoreListener { 8 | void onLoadMore(); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/listener/RecyclerItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.listener; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.GestureDetector; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | 9 | /** 10 | * Created by sourabhkarkal on 24/02/17. 11 | */ 12 | 13 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { 14 | private OnItemClickListener mListener; 15 | private GestureDetector mGestureDetector; 16 | 17 | public interface OnItemClickListener { 18 | void onItemClick(View view, int position, float x, float y); 19 | } 20 | 21 | public RecyclerItemClickListener(Context context, OnItemClickListener listener) { 22 | mListener = listener; 23 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 24 | @Override 25 | public boolean onSingleTapUp(MotionEvent e) { 26 | return true; 27 | } 28 | }); 29 | } 30 | 31 | @Override 32 | public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 33 | View childView = view.findChildViewUnder(e.getX(), e.getY()); 34 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { 35 | mListener.onItemClick(childView, view.getChildPosition(childView), e.getX(), e.getY()); 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | @Override 42 | public void onTouchEvent(RecyclerView view, MotionEvent e) { 43 | } 44 | 45 | @Override 46 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/listener/RecyclerOnLongClickListener.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.listener; 2 | 3 | /** 4 | * Created by sourabhkarkal on 24/02/17. 5 | */ 6 | import android.content.Context; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.GestureDetector; 9 | import android.view.MotionEvent; 10 | import android.view.View; 11 | 12 | public class RecyclerOnLongClickListener implements RecyclerView.OnItemTouchListener { 13 | private OnItemClickListener mListener; 14 | private GestureDetector mGestureDetector; 15 | 16 | public interface OnItemClickListener { 17 | void onItemClick(View view, int position, float x, float y); 18 | public void onItemLongClick(View view, int position); 19 | } 20 | 21 | public RecyclerOnLongClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) { 22 | mListener = listener; 23 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { 24 | @Override 25 | public boolean onSingleTapUp(MotionEvent e) { 26 | return true; 27 | } 28 | 29 | @Override 30 | public void onLongPress(MotionEvent e) 31 | { 32 | View childView = recyclerView.findChildViewUnder(e.getX(), e.getY()); 33 | 34 | if(childView != null && mListener != null) 35 | { 36 | mListener.onItemLongClick(childView, recyclerView.getChildPosition(childView)); 37 | } 38 | } 39 | }); 40 | } 41 | 42 | @Override 43 | public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { 44 | View childView = view.findChildViewUnder(e.getX(), e.getY()); 45 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) { 46 | mListener.onItemClick(childView, view.getChildPosition(childView), e.getX(), e.getY()); 47 | return true; 48 | } 49 | return false; 50 | } 51 | 52 | @Override 53 | public void onTouchEvent(RecyclerView view, MotionEvent e) { 54 | } 55 | 56 | @Override 57 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { 58 | 59 | } 60 | 61 | 62 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/GenresDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.sourabhkarkal.movieapp.realm.modal.RGenresDTO; 5 | 6 | /** 7 | * Created by sourabhkarkal on 23/02/17. 8 | */ 9 | 10 | @JsonIgnoreProperties(ignoreUnknown = true) 11 | public class GenresDTO { 12 | 13 | private int id; 14 | private String name; 15 | 16 | public GenresDTO(){} 17 | 18 | public GenresDTO(RGenresDTO rGenresDTO){ 19 | setId(rGenresDTO.getId()); 20 | setName(rGenresDTO.getName()); 21 | } 22 | 23 | public int getId() { 24 | return id; 25 | } 26 | 27 | public void setId(int id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return this.name; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/MovieDetailDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.sourabhkarkal.movieapp.realm.modal.RGenresDTO; 5 | import com.sourabhkarkal.movieapp.realm.modal.RMovieDetailDTO; 6 | import com.sourabhkarkal.movieapp.realm.modal.RRegionDTO; 7 | import com.sourabhkarkal.movieapp.realm.modal.RSubEntityDTO; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import io.realm.RealmList; 13 | 14 | /** 15 | * Created by sourabhkarkal on 24/02/17. 16 | */ 17 | @JsonIgnoreProperties(ignoreUnknown = true) 18 | public class MovieDetailDTO { 19 | 20 | private int id; 21 | private boolean adult; 22 | private String backdrop_path; 23 | private int budget; 24 | private String homepage; 25 | private String imdb_id; 26 | private String original_language; 27 | private String original_title; 28 | private String overview; 29 | private String poster_path; 30 | private double popularity; 31 | private String release_date; 32 | private int revenue; 33 | private int runtime; 34 | private String status; 35 | private String tagline; 36 | private String title; 37 | private boolean video; 38 | private float vote_average; 39 | private int vote_count; 40 | private List genres; 41 | private List production_companies; 42 | private List production_countries; 43 | private SubEntityDTO belongs_to_collection; 44 | 45 | public MovieDetailDTO(){} 46 | 47 | public MovieDetailDTO(RMovieDetailDTO rMovieDetailDTO){ 48 | setId(rMovieDetailDTO.getId()); 49 | setAdult(rMovieDetailDTO.isAdult()); 50 | setBackdrop_path(rMovieDetailDTO.getBackdrop_path()); 51 | setBudget(rMovieDetailDTO.getBudget()); 52 | setHomepage(rMovieDetailDTO.getHomepage()); 53 | setImdb_id(rMovieDetailDTO.getImdb_id()); 54 | setOriginal_language(rMovieDetailDTO.getOriginal_language()); 55 | setOriginal_title(rMovieDetailDTO.getOriginal_title()); 56 | setOverview(rMovieDetailDTO.getOverview()); 57 | setPoster_path(rMovieDetailDTO.getPoster_path()); 58 | setPopularity(rMovieDetailDTO.getPopularity()); 59 | setRelease_date(rMovieDetailDTO.getRelease_date()); 60 | setRevenue(rMovieDetailDTO.getRevenue()); 61 | setRuntime(rMovieDetailDTO.getRuntime()); 62 | setStatus(rMovieDetailDTO.getStatus()); 63 | setTagline(rMovieDetailDTO.getTagline()); 64 | setTitle(rMovieDetailDTO.getTitle()); 65 | setVideo(rMovieDetailDTO.isVideo()); 66 | setVote_average(rMovieDetailDTO.getVote_average()); 67 | setVote_count(rMovieDetailDTO.getVote_count()); 68 | if(rMovieDetailDTO.getGenres()!=null) { 69 | ArrayList genresDTOs = new ArrayList<>(); 70 | for(RGenresDTO rGenresDTO:rMovieDetailDTO.getGenres()) 71 | genresDTOs.add(new GenresDTO(rGenresDTO)); 72 | setGenres(genresDTOs); 73 | } 74 | if(rMovieDetailDTO.getProduction_companies()!=null) { 75 | ArrayList companiesDTO = new ArrayList<>(); 76 | for(RGenresDTO rGenresDTO:rMovieDetailDTO.getProduction_companies()) 77 | companiesDTO.add(new GenresDTO(rGenresDTO)); 78 | setProduction_companies(companiesDTO); 79 | } 80 | if(rMovieDetailDTO.getProduction_countries()!=null) { 81 | ArrayList countriesDTO = new ArrayList<>(); 82 | for(RRegionDTO rRegionDTO:rMovieDetailDTO.getProduction_countries()) 83 | countriesDTO.add(new RegionDTO(rRegionDTO)); 84 | setProduction_countries(countriesDTO); 85 | } 86 | setBelongs_to_collection(new SubEntityDTO(rMovieDetailDTO.getBelongs_to_collection())); 87 | 88 | } 89 | 90 | 91 | public boolean isAdult() { 92 | return adult; 93 | } 94 | 95 | public void setAdult(boolean adult) { 96 | this.adult = adult; 97 | } 98 | 99 | public String getBackdrop_path() { 100 | return backdrop_path; 101 | } 102 | 103 | public void setBackdrop_path(String backdrop_path) { 104 | this.backdrop_path = backdrop_path; 105 | } 106 | 107 | public int getBudget() { 108 | return budget; 109 | } 110 | 111 | public void setBudget(int budget) { 112 | this.budget = budget; 113 | } 114 | 115 | public String getHomepage() { 116 | return homepage; 117 | } 118 | 119 | public void setHomepage(String homepage) { 120 | this.homepage = homepage; 121 | } 122 | 123 | public int getId() { 124 | return id; 125 | } 126 | 127 | public void setId(int id) { 128 | this.id = id; 129 | } 130 | 131 | public String getImdb_id() { 132 | return imdb_id; 133 | } 134 | 135 | public void setImdb_id(String imdb_id) { 136 | this.imdb_id = imdb_id; 137 | } 138 | 139 | public String getOriginal_language() { 140 | return original_language; 141 | } 142 | 143 | public void setOriginal_language(String original_language) { 144 | this.original_language = original_language; 145 | } 146 | 147 | public String getOriginal_title() { 148 | return original_title; 149 | } 150 | 151 | public void setOriginal_title(String original_title) { 152 | this.original_title = original_title; 153 | } 154 | 155 | public String getOverview() { 156 | return overview; 157 | } 158 | 159 | public void setOverview(String overview) { 160 | this.overview = overview; 161 | } 162 | 163 | public String getPoster_path() { 164 | return poster_path; 165 | } 166 | 167 | public void setPoster_path(String poster_path) { 168 | this.poster_path = poster_path; 169 | } 170 | 171 | public double getPopularity() { 172 | return popularity; 173 | } 174 | 175 | public void setPopularity(double popularity) { 176 | this.popularity = popularity; 177 | } 178 | 179 | public String getRelease_date() { 180 | return release_date; 181 | } 182 | 183 | public void setRelease_date(String release_date) { 184 | this.release_date = release_date; 185 | } 186 | 187 | public int getRevenue() { 188 | return revenue; 189 | } 190 | 191 | public void setRevenue(int revenue) { 192 | this.revenue = revenue; 193 | } 194 | 195 | public int getRuntime() { 196 | return runtime; 197 | } 198 | 199 | public void setRuntime(int runtime) { 200 | this.runtime = runtime; 201 | } 202 | 203 | public String getStatus() { 204 | return status; 205 | } 206 | 207 | public void setStatus(String status) { 208 | this.status = status; 209 | } 210 | 211 | public String getTagline() { 212 | return tagline; 213 | } 214 | 215 | public void setTagline(String tagline) { 216 | this.tagline = tagline; 217 | } 218 | 219 | public String getTitle() { 220 | return title; 221 | } 222 | 223 | public void setTitle(String title) { 224 | this.title = title; 225 | } 226 | 227 | public boolean isVideo() { 228 | return video; 229 | } 230 | 231 | public void setVideo(boolean video) { 232 | this.video = video; 233 | } 234 | 235 | public float getVote_average() { 236 | return vote_average; 237 | } 238 | 239 | public void setVote_average(float vote_average) { 240 | this.vote_average = vote_average; 241 | } 242 | 243 | public int getVote_count() { 244 | return vote_count; 245 | } 246 | 247 | public void setVote_count(int vote_count) { 248 | this.vote_count = vote_count; 249 | } 250 | 251 | public List getGenres() { 252 | return genres; 253 | } 254 | 255 | public void setGenres(List genres) { 256 | this.genres = genres; 257 | } 258 | 259 | public List getProduction_companies() { 260 | return production_companies; 261 | } 262 | 263 | public void setProduction_companies(List production_companies) { 264 | this.production_companies = production_companies; 265 | } 266 | 267 | public List getProduction_countries() { 268 | return production_countries; 269 | } 270 | 271 | public void setProduction_countries(List production_countries) { 272 | this.production_countries = production_countries; 273 | } 274 | 275 | public SubEntityDTO getBelongs_to_collection() { 276 | return belongs_to_collection; 277 | } 278 | 279 | public void setBelongs_to_collection(SubEntityDTO belongs_to_collection) { 280 | this.belongs_to_collection = belongs_to_collection; 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/MoviePageDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by sourabhkarkal on 24/02/17. 7 | */ 8 | 9 | public class MoviePageDTO { 10 | 11 | private int page; 12 | private List results; 13 | private int total_results; 14 | private int total_pages; 15 | 16 | public int getPage() { 17 | return page; 18 | } 19 | 20 | public void setPage(int page) { 21 | this.page = page; 22 | } 23 | 24 | public List getResults() { 25 | return results; 26 | } 27 | 28 | public void setResults(List results) { 29 | this.results = results; 30 | } 31 | 32 | public int getTotal_results() { 33 | return total_results; 34 | } 35 | 36 | public void setTotal_results(int total_results) { 37 | this.total_results = total_results; 38 | } 39 | 40 | public int getTotal_pages() { 41 | return total_pages; 42 | } 43 | 44 | public void setTotal_pages(int total_pages) { 45 | this.total_pages = total_pages; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/MoviesDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.sourabhkarkal.movieapp.realm.modal.RMoviesDTO; 5 | 6 | import java.text.DateFormat; 7 | import java.text.SimpleDateFormat; 8 | 9 | /** 10 | * Created by sourabhkarkal on 24/02/17. 11 | */ 12 | 13 | @JsonIgnoreProperties(ignoreUnknown = true) 14 | public class MoviesDTO { 15 | 16 | private String id; 17 | private String poster_path; 18 | private boolean adult; 19 | private String overview; 20 | private String release_date; 21 | private String original_title; 22 | private String original_language; 23 | private String title; 24 | private String backdrop_path; 25 | private double popularity; 26 | private int vote_count; 27 | private boolean video; 28 | private float vote_average; 29 | 30 | public MoviesDTO(){} 31 | 32 | public MoviesDTO(RMoviesDTO rMoviesDTO){ 33 | if(rMoviesDTO!=null) { 34 | setId(rMoviesDTO.getId()); 35 | setPoster_path(rMoviesDTO.getPoster_path()); 36 | setAdult(rMoviesDTO.isAdult()); 37 | setOverview(rMoviesDTO.getOverview()); 38 | DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 39 | setRelease_date(dateFormat.format(rMoviesDTO.getRelease_date())); 40 | setOriginal_title(rMoviesDTO.getOriginal_title()); 41 | setOriginal_language(rMoviesDTO.getOriginal_language()); 42 | setTitle(rMoviesDTO.getTitle()); 43 | setBackdrop_path(rMoviesDTO.getBackdrop_path()); 44 | setPopularity(rMoviesDTO.getPopularity()); 45 | setVote_count(rMoviesDTO.getVote_count()); 46 | setVideo(rMoviesDTO.isVideo()); 47 | setVote_average(rMoviesDTO.getVote_average()); 48 | } 49 | } 50 | 51 | public String getId() { 52 | return id; 53 | } 54 | 55 | public void setId(String id) { 56 | this.id = id; 57 | } 58 | 59 | public String getPoster_path() { 60 | return poster_path; 61 | } 62 | 63 | public void setPoster_path(String poster_path) { 64 | this.poster_path = poster_path; 65 | } 66 | 67 | public boolean isAdult() { 68 | return adult; 69 | } 70 | 71 | public void setAdult(boolean adult) { 72 | this.adult = adult; 73 | } 74 | 75 | public String getOverview() { 76 | return overview; 77 | } 78 | 79 | public void setOverview(String overview) { 80 | this.overview = overview; 81 | } 82 | 83 | public String getRelease_date() { 84 | return release_date; 85 | } 86 | 87 | public void setRelease_date(String release_date) { 88 | this.release_date = release_date; 89 | } 90 | 91 | public String getOriginal_title() { 92 | return original_title; 93 | } 94 | 95 | public void setOriginal_title(String original_title) { 96 | this.original_title = original_title; 97 | } 98 | 99 | public String getOriginal_language() { 100 | return original_language; 101 | } 102 | 103 | public void setOriginal_language(String original_language) { 104 | this.original_language = original_language; 105 | } 106 | 107 | public String getTitle() { 108 | return title; 109 | } 110 | 111 | public void setTitle(String title) { 112 | this.title = title; 113 | } 114 | 115 | public String getBackdrop_path() { 116 | return backdrop_path; 117 | } 118 | 119 | public void setBackdrop_path(String backdrop_path) { 120 | this.backdrop_path = backdrop_path; 121 | } 122 | 123 | public double getPopularity() { 124 | return popularity; 125 | } 126 | 127 | public void setPopularity(double popularity) { 128 | this.popularity = popularity; 129 | } 130 | 131 | public int getVote_count() { 132 | return vote_count; 133 | } 134 | 135 | public void setVote_count(int vote_count) { 136 | this.vote_count = vote_count; 137 | } 138 | 139 | public boolean isVideo() { 140 | return video; 141 | } 142 | 143 | public void setVideo(boolean video) { 144 | this.video = video; 145 | } 146 | 147 | public float getVote_average() { 148 | return vote_average; 149 | } 150 | 151 | public void setVote_average(float vote_average) { 152 | this.vote_average = vote_average; 153 | } 154 | 155 | 156 | } 157 | 158 | 159 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/RegionDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import com.sourabhkarkal.movieapp.realm.modal.RRegionDTO; 4 | 5 | /** 6 | * Created by sourabhkarkal on 23/02/17. 7 | */ 8 | 9 | public class RegionDTO { 10 | 11 | private String iso_3166_1; 12 | private String name; 13 | 14 | 15 | public RegionDTO(){} 16 | 17 | public RegionDTO(RRegionDTO rRegionDTO){ 18 | setIso_3166_1(rRegionDTO.getIso_3166_1()); 19 | setName(rRegionDTO.getName()); 20 | } 21 | 22 | public String getIso_3166_1() { 23 | return iso_3166_1; 24 | } 25 | 26 | public void setIso_3166_1(String iso_3166_1) { 27 | this.iso_3166_1 = iso_3166_1; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return this.name; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/modal/SubEntityDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.modal; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.sourabhkarkal.movieapp.realm.modal.RSubEntityDTO; 5 | 6 | /** 7 | * Created by sourabhkarkal on 23/02/17. 8 | */ 9 | @JsonIgnoreProperties(ignoreUnknown = true) 10 | public class SubEntityDTO { 11 | 12 | private int id; 13 | private String name; 14 | private String poster_path; 15 | private String backdrop_path; 16 | 17 | public SubEntityDTO(){} 18 | 19 | public SubEntityDTO(RSubEntityDTO rSubEntityDTO){ 20 | setId(rSubEntityDTO.getId()); 21 | setName(rSubEntityDTO.getName()); 22 | setBackdrop_path(rSubEntityDTO.getBackdrop_path()); 23 | setPoster_path(rSubEntityDTO.getPoster_path()); 24 | } 25 | 26 | public int getId() { 27 | return id; 28 | } 29 | 30 | public void setId(int id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getPoster_path() { 43 | return poster_path; 44 | } 45 | 46 | public void setPoster_path(String poster_path) { 47 | this.poster_path = poster_path; 48 | } 49 | 50 | public String getBackdrop_path() { 51 | return backdrop_path; 52 | } 53 | 54 | public void setBackdrop_path(String backdrop_path) { 55 | this.backdrop_path = backdrop_path; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/realm/modal/RGenresDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.realm.modal; 2 | 3 | import com.sourabhkarkal.movieapp.modal.GenresDTO; 4 | 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | /** 9 | * Created by sourabhkarkal on 23/02/17. 10 | */ 11 | 12 | public class RGenresDTO extends RealmObject{ 13 | 14 | @PrimaryKey 15 | private int id; 16 | private String name; 17 | 18 | public RGenresDTO(){} 19 | 20 | public RGenresDTO(GenresDTO genresDTO){ 21 | setId(genresDTO.getId()); 22 | setName(genresDTO.getName()); 23 | } 24 | 25 | public int getId() { 26 | return id; 27 | } 28 | 29 | public void setId(int id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/realm/modal/RMovieDetailDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.realm.modal; 2 | 3 | import com.sourabhkarkal.movieapp.modal.GenresDTO; 4 | import com.sourabhkarkal.movieapp.modal.MovieDetailDTO; 5 | import com.sourabhkarkal.movieapp.modal.RegionDTO; 6 | import com.sourabhkarkal.movieapp.modal.SubEntityDTO; 7 | 8 | import java.util.List; 9 | 10 | import io.realm.RealmList; 11 | import io.realm.RealmObject; 12 | import io.realm.annotations.PrimaryKey; 13 | 14 | /** 15 | * Created by sourabhkarkal on 24/02/17. 16 | */ 17 | 18 | public class RMovieDetailDTO extends RealmObject { 19 | 20 | @PrimaryKey 21 | private int id; 22 | private boolean adult; 23 | private String backdrop_path; 24 | private int budget; 25 | private String homepage; 26 | private String imdb_id; 27 | private String original_language; 28 | private String original_title; 29 | private String overview; 30 | private String poster_path; 31 | private double popularity; 32 | private String release_date; 33 | private int revenue; 34 | private int runtime; 35 | private String status; 36 | private String tagline; 37 | private String title; 38 | private boolean video; 39 | private float vote_average; 40 | private int vote_count; 41 | private RealmList genres; 42 | private RealmList production_companies; 43 | private RealmList production_countries; 44 | private RSubEntityDTO belongs_to_collection; 45 | 46 | public RMovieDetailDTO(){} 47 | 48 | public RMovieDetailDTO(MovieDetailDTO movieDetailDTO){ 49 | setId(movieDetailDTO.getId()); 50 | setAdult(movieDetailDTO.isAdult()); 51 | setBackdrop_path(movieDetailDTO.getBackdrop_path()); 52 | setBudget(movieDetailDTO.getBudget()); 53 | setHomepage(movieDetailDTO.getHomepage()); 54 | setImdb_id(movieDetailDTO.getImdb_id()); 55 | setOriginal_language(movieDetailDTO.getOriginal_language()); 56 | setOriginal_title(movieDetailDTO.getOriginal_title()); 57 | setOverview(movieDetailDTO.getOverview()); 58 | setPoster_path(movieDetailDTO.getPoster_path()); 59 | setPopularity(movieDetailDTO.getPopularity()); 60 | setRelease_date(movieDetailDTO.getRelease_date()); 61 | setRevenue(movieDetailDTO.getRevenue()); 62 | setRuntime(movieDetailDTO.getRuntime()); 63 | setStatus(movieDetailDTO.getStatus()); 64 | setTagline(movieDetailDTO.getTagline()); 65 | setTitle(movieDetailDTO.getTitle()); 66 | setVideo(movieDetailDTO.isVideo()); 67 | setVote_average(movieDetailDTO.getVote_average()); 68 | setVote_count(movieDetailDTO.getVote_count()); 69 | if(movieDetailDTO.getGenres()!=null) { 70 | RealmList genresDTOs = new RealmList<>(); 71 | for(GenresDTO genresDTO:movieDetailDTO.getGenres()) 72 | genresDTOs.add(new RGenresDTO(genresDTO)); 73 | setGenres(genresDTOs); 74 | } 75 | if(movieDetailDTO.getProduction_companies()!=null) { 76 | RealmList companiesDTO = new RealmList<>(); 77 | for(GenresDTO genresDTO:movieDetailDTO.getProduction_companies()) 78 | companiesDTO.add(new RGenresDTO(genresDTO)); 79 | setProduction_companies(companiesDTO); 80 | } 81 | if(movieDetailDTO.getProduction_countries()!=null) { 82 | RealmList countriesDTO = new RealmList<>(); 83 | for(RegionDTO regionDTO:movieDetailDTO.getProduction_countries()) 84 | countriesDTO.add(new RRegionDTO(regionDTO)); 85 | setProduction_countries(countriesDTO); 86 | } 87 | setBelongs_to_collection(new RSubEntityDTO(movieDetailDTO.getBelongs_to_collection())); 88 | 89 | } 90 | 91 | 92 | public boolean isAdult() { 93 | return adult; 94 | } 95 | 96 | public void setAdult(boolean adult) { 97 | this.adult = adult; 98 | } 99 | 100 | public String getBackdrop_path() { 101 | return backdrop_path; 102 | } 103 | 104 | public void setBackdrop_path(String backdrop_path) { 105 | this.backdrop_path = backdrop_path; 106 | } 107 | 108 | public int getBudget() { 109 | return budget; 110 | } 111 | 112 | public void setBudget(int budget) { 113 | this.budget = budget; 114 | } 115 | 116 | public String getHomepage() { 117 | return homepage; 118 | } 119 | 120 | public void setHomepage(String homepage) { 121 | this.homepage = homepage; 122 | } 123 | 124 | public int getId() { 125 | return id; 126 | } 127 | 128 | public void setId(int id) { 129 | this.id = id; 130 | } 131 | 132 | public String getImdb_id() { 133 | return imdb_id; 134 | } 135 | 136 | public void setImdb_id(String imdb_id) { 137 | this.imdb_id = imdb_id; 138 | } 139 | 140 | public String getOriginal_language() { 141 | return original_language; 142 | } 143 | 144 | public void setOriginal_language(String original_language) { 145 | this.original_language = original_language; 146 | } 147 | 148 | public String getOriginal_title() { 149 | return original_title; 150 | } 151 | 152 | public void setOriginal_title(String original_title) { 153 | this.original_title = original_title; 154 | } 155 | 156 | public String getOverview() { 157 | return overview; 158 | } 159 | 160 | public void setOverview(String overview) { 161 | this.overview = overview; 162 | } 163 | 164 | public String getPoster_path() { 165 | return poster_path; 166 | } 167 | 168 | public void setPoster_path(String poster_path) { 169 | this.poster_path = poster_path; 170 | } 171 | 172 | public double getPopularity() { 173 | return popularity; 174 | } 175 | 176 | public void setPopularity(double popularity) { 177 | this.popularity = popularity; 178 | } 179 | 180 | public String getRelease_date() { 181 | return release_date; 182 | } 183 | 184 | public void setRelease_date(String release_date) { 185 | this.release_date = release_date; 186 | } 187 | 188 | public int getRevenue() { 189 | return revenue; 190 | } 191 | 192 | public void setRevenue(int revenue) { 193 | this.revenue = revenue; 194 | } 195 | 196 | public int getRuntime() { 197 | return runtime; 198 | } 199 | 200 | public void setRuntime(int runtime) { 201 | this.runtime = runtime; 202 | } 203 | 204 | public String getStatus() { 205 | return status; 206 | } 207 | 208 | public void setStatus(String status) { 209 | this.status = status; 210 | } 211 | 212 | public String getTagline() { 213 | return tagline; 214 | } 215 | 216 | public void setTagline(String tagline) { 217 | this.tagline = tagline; 218 | } 219 | 220 | public String getTitle() { 221 | return title; 222 | } 223 | 224 | public void setTitle(String title) { 225 | this.title = title; 226 | } 227 | 228 | public boolean isVideo() { 229 | return video; 230 | } 231 | 232 | public void setVideo(boolean video) { 233 | this.video = video; 234 | } 235 | 236 | public float getVote_average() { 237 | return vote_average; 238 | } 239 | 240 | public void setVote_average(float vote_average) { 241 | this.vote_average = vote_average; 242 | } 243 | 244 | public int getVote_count() { 245 | return vote_count; 246 | } 247 | 248 | public void setVote_count(int vote_count) { 249 | this.vote_count = vote_count; 250 | } 251 | 252 | public RealmList getGenres() { 253 | return genres; 254 | } 255 | 256 | public void setGenres(RealmList genres) { 257 | this.genres = genres; 258 | } 259 | 260 | public RealmList getProduction_companies() { 261 | return production_companies; 262 | } 263 | 264 | public void setProduction_companies(RealmList production_companies) { 265 | this.production_companies = production_companies; 266 | } 267 | 268 | public RealmList getProduction_countries() { 269 | return production_countries; 270 | } 271 | 272 | public void setProduction_countries(RealmList production_countries) { 273 | this.production_countries = production_countries; 274 | } 275 | 276 | public RSubEntityDTO getBelongs_to_collection() { 277 | return belongs_to_collection; 278 | } 279 | 280 | public void setBelongs_to_collection(RSubEntityDTO belongs_to_collection) { 281 | this.belongs_to_collection = belongs_to_collection; 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/realm/modal/RMoviesDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.realm.modal; 2 | 3 | import com.sourabhkarkal.movieapp.modal.MoviesDTO; 4 | 5 | import java.text.DateFormat; 6 | import java.text.ParseException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | 10 | import io.realm.RealmObject; 11 | import io.realm.annotations.PrimaryKey; 12 | 13 | /** 14 | * Created by sourabhkarkal on 21/02/17. 15 | */ 16 | 17 | public class RMoviesDTO extends RealmObject{ 18 | 19 | @PrimaryKey 20 | private String id; 21 | private String poster_path; 22 | private boolean adult; 23 | private String overview; 24 | private Date release_date; 25 | private String original_title; 26 | private String original_language; 27 | private String title; 28 | private String backdrop_path; 29 | private double popularity; 30 | private int vote_count; 31 | private boolean video; 32 | private float vote_average; 33 | 34 | public RMoviesDTO(){} 35 | 36 | public RMoviesDTO(MoviesDTO moviesDTO){ 37 | setId(moviesDTO.getId()); 38 | setPoster_path(moviesDTO.getPoster_path()); 39 | setAdult(moviesDTO.isAdult()); 40 | setOverview(moviesDTO.getOverview()); 41 | Date date = null; 42 | try { 43 | date = new SimpleDateFormat("yyyy-MM-dd").parse(moviesDTO.getRelease_date()); 44 | setRelease_date(date); 45 | } catch (ParseException e) { 46 | e.printStackTrace(); 47 | 48 | } 49 | setOriginal_title(moviesDTO.getOriginal_title()); 50 | setOriginal_language(moviesDTO.getOriginal_language()); 51 | setTitle(moviesDTO.getTitle()); 52 | setBackdrop_path(moviesDTO.getBackdrop_path()); 53 | setPopularity(moviesDTO.getPopularity()); 54 | setVote_count(moviesDTO.getVote_count()); 55 | setVideo(moviesDTO.isVideo()); 56 | setVote_average(moviesDTO.getVote_average()); 57 | } 58 | 59 | 60 | public String getId() { 61 | return id; 62 | } 63 | 64 | public void setId(String id) { 65 | this.id = id; 66 | } 67 | 68 | public String getPoster_path() { 69 | return poster_path; 70 | } 71 | 72 | public void setPoster_path(String poster_path) { 73 | this.poster_path = poster_path; 74 | } 75 | 76 | public boolean isAdult() { 77 | return adult; 78 | } 79 | 80 | public void setAdult(boolean adult) { 81 | this.adult = adult; 82 | } 83 | 84 | public String getOverview() { 85 | return overview; 86 | } 87 | 88 | public void setOverview(String overview) { 89 | this.overview = overview; 90 | } 91 | 92 | public Date getRelease_date() { 93 | return release_date; 94 | } 95 | 96 | public void setRelease_date(Date release_date) { 97 | this.release_date = release_date; 98 | } 99 | 100 | public String getOriginal_title() { 101 | return original_title; 102 | } 103 | 104 | public void setOriginal_title(String original_title) { 105 | this.original_title = original_title; 106 | } 107 | 108 | public String getOriginal_language() { 109 | return original_language; 110 | } 111 | 112 | public void setOriginal_language(String original_language) { 113 | this.original_language = original_language; 114 | } 115 | 116 | public String getTitle() { 117 | return title; 118 | } 119 | 120 | public void setTitle(String title) { 121 | this.title = title; 122 | } 123 | 124 | public String getBackdrop_path() { 125 | return backdrop_path; 126 | } 127 | 128 | public void setBackdrop_path(String backdrop_path) { 129 | this.backdrop_path = backdrop_path; 130 | } 131 | 132 | public double getPopularity() { 133 | return popularity; 134 | } 135 | 136 | public void setPopularity(double popularity) { 137 | this.popularity = popularity; 138 | } 139 | 140 | public int getVote_count() { 141 | return vote_count; 142 | } 143 | 144 | public void setVote_count(int vote_count) { 145 | this.vote_count = vote_count; 146 | } 147 | 148 | public boolean isVideo() { 149 | return video; 150 | } 151 | 152 | public void setVideo(boolean video) { 153 | this.video = video; 154 | } 155 | 156 | public float getVote_average() { 157 | return vote_average; 158 | } 159 | 160 | public void setVote_average(float vote_average) { 161 | this.vote_average = vote_average; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/realm/modal/RRegionDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.realm.modal; 2 | 3 | import com.sourabhkarkal.movieapp.modal.RegionDTO; 4 | 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | /** 9 | * Created by sourabhkarkal on 23/02/17. 10 | */ 11 | 12 | public class RRegionDTO extends RealmObject{ 13 | 14 | @PrimaryKey 15 | private String iso_3166_1; 16 | private String name; 17 | 18 | public RRegionDTO(){} 19 | 20 | public RRegionDTO(RegionDTO regionDTO){ 21 | setIso_3166_1(regionDTO.getIso_3166_1()); 22 | setName(regionDTO.getName()); 23 | } 24 | 25 | public String getIso_3166_1() { 26 | return iso_3166_1; 27 | } 28 | 29 | public void setIso_3166_1(String iso_3166_1) { 30 | this.iso_3166_1 = iso_3166_1; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/realm/modal/RSubEntityDTO.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.realm.modal; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import com.sourabhkarkal.movieapp.modal.SubEntityDTO; 5 | 6 | import io.realm.Realm; 7 | import io.realm.RealmObject; 8 | import io.realm.annotations.PrimaryKey; 9 | 10 | /** 11 | * Created by sourabhkarkal on 25/02/17. 12 | */ 13 | public class RSubEntityDTO extends RealmObject{ 14 | 15 | @PrimaryKey 16 | private int id; 17 | private String name; 18 | private String poster_path; 19 | private String backdrop_path; 20 | 21 | public RSubEntityDTO(){} 22 | 23 | public RSubEntityDTO(SubEntityDTO subEntityDTO){ 24 | if(subEntityDTO!=null) { 25 | setId(subEntityDTO.getId()); 26 | setName(subEntityDTO.getName()); 27 | setBackdrop_path(subEntityDTO.getBackdrop_path()); 28 | setPoster_path(subEntityDTO.getPoster_path()); 29 | } 30 | } 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public void setId(int id) { 37 | this.id = id; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | 48 | public String getPoster_path() { 49 | return poster_path; 50 | } 51 | 52 | public void setPoster_path(String poster_path) { 53 | this.poster_path = poster_path; 54 | } 55 | 56 | public String getBackdrop_path() { 57 | return backdrop_path; 58 | } 59 | 60 | public void setBackdrop_path(String backdrop_path) { 61 | this.backdrop_path = backdrop_path; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/service/DataRequest.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.service; 2 | 3 | import android.app.Service; 4 | import android.content.Context; 5 | 6 | import com.sourabhkarkal.movieapp.utils.HttpOperation; 7 | 8 | 9 | /** 10 | * Created by sourabhkarkal on 24/02/17. 11 | */ 12 | public class DataRequest { 13 | 14 | private int taskId; 15 | private iWebListener iWebListener; 16 | private String url; 17 | private HttpOperation httpOperation; 18 | private Context context; 19 | private String token; 20 | private Object data; 21 | private Service service; 22 | private String extraInfo; 23 | 24 | 25 | public DataRequest() { 26 | 27 | } 28 | 29 | public DataRequest(int taskId, String url, Context context, iWebListener iWebListener, HttpOperation httpOperation, String token) { 30 | this.taskId = taskId; 31 | this.url = url; 32 | this.context=context; 33 | this.iWebListener = iWebListener; 34 | this.httpOperation = httpOperation; 35 | this.token=token; 36 | } 37 | 38 | 39 | public int getTaskId() { 40 | return taskId; 41 | } 42 | 43 | public void setTaskId(int taskId) { 44 | this.taskId = taskId; 45 | } 46 | 47 | public iWebListener getiWebListener() { 48 | return iWebListener; 49 | } 50 | 51 | public void setiWebListener(iWebListener iWebListener) { 52 | this.iWebListener = iWebListener; 53 | } 54 | 55 | public String getUrl() { 56 | return url; 57 | } 58 | 59 | public void setUrl(String url) { 60 | this.url = url; 61 | } 62 | 63 | public HttpOperation getHttpOperation() { 64 | return httpOperation; 65 | } 66 | 67 | public void setHttpOperation(HttpOperation httpOperation) { 68 | this.httpOperation = httpOperation; 69 | } 70 | 71 | 72 | public Context getContext() { 73 | return context; 74 | } 75 | 76 | public void setContext(Context context) { 77 | this.context = context; 78 | } 79 | 80 | public String getToken() { 81 | return token; 82 | } 83 | 84 | public void setToken(String token) { 85 | this.token = token; 86 | } 87 | public Object getData() { 88 | return data; 89 | } 90 | 91 | public void setData(Object data) { 92 | this.data = data; 93 | } 94 | 95 | public Service getService() { 96 | return service; 97 | } 98 | 99 | public void setService(Service service) { 100 | this.service = service; 101 | } 102 | 103 | public String getExtraInfo() { 104 | return extraInfo; 105 | } 106 | 107 | public void setExtraInfo(String extraInfo) { 108 | this.extraInfo = extraInfo; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/service/DataResponse.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.service; 2 | 3 | /** 4 | * Created by sourabhkarkal on 24/02/17. 5 | */ 6 | public class DataResponse { 7 | 8 | Object object; 9 | boolean isError; 10 | String message; 11 | int responseCode; 12 | 13 | public Object getObject() { 14 | return object; 15 | } 16 | 17 | public void setObject(Object object) { 18 | this.object = object; 19 | } 20 | 21 | public boolean isError() { 22 | return isError; 23 | } 24 | 25 | public void setError(boolean error) { 26 | isError = error; 27 | } 28 | 29 | public String getMessage() { 30 | return message; 31 | } 32 | 33 | public void setMessage(String message) { 34 | this.message = message; 35 | } 36 | 37 | public int getResponseCode() { 38 | return responseCode; 39 | } 40 | 41 | public void setResponseCode(int responseCode) { 42 | this.responseCode = responseCode; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/service/RestTemplateExecutor.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.service; 2 | 3 | 4 | import android.util.Log; 5 | import okhttp3.MediaType; 6 | import okhttp3.OkHttpClient; 7 | import okhttp3.Request; 8 | import okhttp3.RequestBody; 9 | import okhttp3.Response; 10 | import rx.Observable; 11 | import rx.Subscriber; 12 | import rx.Subscription; 13 | import rx.android.schedulers.AndroidSchedulers; 14 | import rx.functions.Func0; 15 | import rx.schedulers.Schedulers; 16 | 17 | /** 18 | * Created by sourabhkarkal on 24/02/17. 19 | * 20 | * Rx Java is used to handle asynchronous calls with okHttp lib to handle Rest API 21 | * 22 | */ 23 | 24 | public class RestTemplateExecutor{ 25 | 26 | public static final MediaType JSON 27 | = MediaType.parse("application/json; charset=utf-8"); 28 | 29 | private Subscription subscription; 30 | 31 | public void callServerApi(final DataRequest dataRequest) { 32 | subscription = getDataObservable(dataRequest) 33 | .subscribeOn(Schedulers.io()) 34 | .observeOn(AndroidSchedulers.mainThread()) 35 | .subscribe(new Subscriber() { 36 | @Override 37 | public void onCompleted() { 38 | if (subscription != null && !subscription.isUnsubscribed()) 39 | subscription.unsubscribe(); 40 | } 41 | 42 | @Override 43 | public void onError(Throwable e) { 44 | Log.d("Error", e.getMessage(), e); 45 | 46 | } 47 | 48 | @Override 49 | public void onNext(DataResponse dataResponse) { 50 | // MANAGE DATA 51 | dataRequest.getiWebListener().onTaskComplete(dataRequest.getTaskId(), dataResponse, dataResponse.isError()); 52 | } 53 | }); 54 | } 55 | 56 | public DataResponse serverApi(final DataRequest dataRequest) { 57 | 58 | final DataResponse dataResponse = new DataResponse(); 59 | final OkHttpClient client = new OkHttpClient(); 60 | 61 | Response response = null; 62 | try { 63 | switch (dataRequest.getHttpOperation()) { 64 | case GET: 65 | Request requestGet = new Request.Builder() 66 | .url(dataRequest.getUrl()) // Api Call 67 | //.addHeader() 68 | .build(); 69 | response = client.newCall(requestGet).execute(); 70 | 71 | break; 72 | // uncomment below code to set add post request ; not required in this app 73 | /*case POST: 74 | RequestBody requestBody = RequestBody.create(JSON, dataRequest.getData() != null ? dataRequest.getData().toString() : ""); 75 | Request requestPost = new Request.Builder() 76 | .url(dataRequest.getUrl()) // Api Call 77 | .post(requestBody) 78 | .build(); 79 | response = client.newCall(requestPost).execute(); 80 | break;*/ 81 | } 82 | if (response != null) { 83 | if (response.isSuccessful()) { // Success 84 | dataResponse.setError(false); 85 | dataResponse.setObject(response.body().string()); 86 | dataResponse.setResponseCode(response.code()); 87 | } else { // Failure 88 | dataResponse.setMessage(response.body().string()); 89 | dataResponse.setError(true); 90 | dataResponse.setResponseCode(response.code()); 91 | } 92 | } 93 | response.body().close(); 94 | return dataResponse; 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | dataResponse.setError(true); 98 | dataResponse.setMessage(e.getMessage()); 99 | dataResponse.setResponseCode(502); 100 | return dataResponse; 101 | } 102 | } 103 | 104 | 105 | public Observable getDataObservable(final DataRequest dataRequest) { 106 | return Observable.defer(new Func0>() { 107 | @Override 108 | public Observable call() { 109 | try { 110 | return Observable.just(serverApi(dataRequest)); 111 | } catch (Exception e) { 112 | e.printStackTrace(); 113 | return null; 114 | } 115 | } 116 | }); 117 | 118 | } 119 | 120 | } -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/service/iWebListener.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.service; 2 | 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * Created by sourabhkarkal on 24/02/17. 8 | */ 9 | public interface iWebListener { 10 | 11 | public void onTaskComplete(int taskId, Object object, boolean isError); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.utils; 2 | 3 | /** 4 | * Created by sourabhkarkal on 24/02/17. 5 | */ 6 | 7 | public class Constants { 8 | 9 | public static final String MAIN_URL = "http://api.themoviedb.org/3/"; 10 | public static final String API_KEY = "272162b11a9668a01709ef01900a56b7"; 11 | public static final String IMAGE_BASE_PATH = "https://image.tmdb.org/t/p/w500"; 12 | public static final String LIST_URL = "discover/movie?"; 13 | public static final String DETAIL_URL = "movie/"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/utils/HttpOperation.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.utils; 2 | 3 | /** 4 | * Created by sourabhkarkal on 24/02/17. 5 | */ 6 | public enum HttpOperation { 7 | GET, 8 | POST, 9 | PUT, 10 | DELETE, 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/utils/ManagePreferences.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.utils; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by sourabhkarkal on 24/02/17. 8 | */ 9 | 10 | public class ManagePreferences { 11 | 12 | public static final String PAGE_NO ="page_no"; 13 | public static final String PREF ="MovieApp"; 14 | 15 | public static void setIntData(Context context,String key,Integer data){ 16 | SharedPreferences sharedpreferences = context.getSharedPreferences(PREF, Context.MODE_PRIVATE); 17 | sharedpreferences.edit().putInt(key, data).apply(); 18 | } 19 | 20 | public static Integer getIntData(Context context,String key){ 21 | SharedPreferences sharedpreferences = context.getSharedPreferences(PREF, Context.MODE_PRIVATE); 22 | return sharedpreferences.getInt(key, 1); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.utils; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.net.ConnectivityManager; 7 | import android.net.NetworkInfo; 8 | import android.os.Build; 9 | import android.support.design.widget.Snackbar; 10 | import android.support.v4.app.Fragment; 11 | import android.support.v4.app.FragmentActivity; 12 | import android.support.v4.app.FragmentManager; 13 | import android.support.v4.content.ContextCompat; 14 | import android.view.View; 15 | import android.widget.TextView; 16 | import com.sourabhkarkal.movieapp.ApplicationController; 17 | import com.sourabhkarkal.movieapp.R; 18 | 19 | /** 20 | * Created by sourabhkarkal on 24/02/17. 21 | */ 22 | 23 | public class Utils { 24 | 25 | public enum MessageType { 26 | INFO, 27 | ERROR, 28 | SUCCESS 29 | } 30 | 31 | /** 32 | * Checks and returns whether there is an Internet connectivity or not. This 33 | * would be useful to check the network connectivity before making a network 34 | * call. 35 | * 36 | * @return "True" -> is Connected , "False" -> if not. 37 | */ 38 | public static boolean isNetworkAvailable() { 39 | boolean isConnected = false; 40 | final ConnectivityManager connectivityService = (ConnectivityManager) ApplicationController.getInstance().getContext() 41 | .getSystemService(Context.CONNECTIVITY_SERVICE); 42 | if (connectivityService != null) { 43 | final NetworkInfo networkInfo = connectivityService 44 | .getActiveNetworkInfo(); 45 | if (networkInfo != null && networkInfo.isConnected()) { 46 | isConnected = true; 47 | } 48 | } 49 | return isConnected; 50 | } 51 | 52 | /*** 53 | * show snack bar 54 | * 55 | * @param view 56 | * @param message 57 | * @param messageType 58 | */ 59 | 60 | public static void showSnackBar(View view, String message, MessageType messageType) { 61 | Context context = ApplicationController.getInstance().getContext(); 62 | Snackbar bar = Snackbar 63 | .make(view, message, Snackbar.LENGTH_LONG); 64 | TextView textView = (TextView) bar.getView().findViewById(android.support.design.R.id.snackbar_text); 65 | textView.setTextSize(15); 66 | bar.getView().setBackgroundColor(Utils.getColor(context, R.color.light_black)); 67 | if (messageType == MessageType.ERROR) { 68 | textView.setTextColor(Utils.getColor(context, R.color.snack_error)); 69 | } else if (messageType == MessageType.INFO) { 70 | textView.setTextColor(Utils.getColor(context, R.color.snack_info)); 71 | } else if (messageType == MessageType.SUCCESS) { 72 | textView.setTextColor(Utils.getColor(context, R.color.snack_success)); 73 | } 74 | bar.show(); 75 | } 76 | 77 | /** 78 | * Get color from resource according to api level 79 | * 80 | * @param context 81 | * @param id 82 | * @return 83 | */ 84 | 85 | public static int getColor(Context context, int id) { 86 | final int version = Build.VERSION.SDK_INT; 87 | if (version >= 23) { 88 | return ContextCompat.getColor(context, id); 89 | } else { 90 | return context.getResources().getColor(id); 91 | } 92 | 93 | } 94 | 95 | /* 96 | * Replace fragment 97 | * 98 | * @param context 99 | * @param fragment 100 | */ 101 | public static void replaceFragment(FragmentActivity context, Fragment fragment, boolean doAnimate) { 102 | String TAG = fragment.getClass().toString(); 103 | String backStackName = fragment.getClass().getName(); 104 | FragmentManager manager = context.getSupportFragmentManager(); 105 | boolean fragmentPopped = manager.popBackStackImmediate(backStackName, 0); 106 | if (!fragmentPopped && context.getSupportFragmentManager().findFragmentByTag(TAG) == null) { 107 | final android.support.v4.app.FragmentTransaction ft = context.getSupportFragmentManager().beginTransaction(); 108 | if(doAnimate) 109 | ft.setCustomAnimations(R.anim.enter,R.anim.exit,R.anim.left_to_right,R.anim.right_to_left); 110 | else 111 | ft.setCustomAnimations(android.R.anim.fade_in,android.R.anim.fade_out); 112 | ft.replace(R.id.mainfragment, fragment, TAG); 113 | ft.addToBackStack(backStackName); 114 | ft.commit(); 115 | } 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/widget/AutoScrollViewPager.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.widget; 2 | 3 | import android.content.Context; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.v4.view.MotionEventCompat; 7 | import android.support.v4.view.PagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.animation.Interpolator; 12 | 13 | import java.lang.ref.WeakReference; 14 | import java.lang.reflect.Field; 15 | 16 | /** 17 | * Created by sourabhkarkal on 26/02/17. 18 | */ 19 | 20 | public class AutoScrollViewPager extends ViewPager { 21 | 22 | public static final int DEFAULT_INTERVAL = 1500; 23 | 24 | public static final int LEFT = 0; 25 | public static final int RIGHT = 1; 26 | 27 | /** do nothing when sliding at the last or first item **/ 28 | public static final int SLIDE_BORDER_MODE_NONE = 0; 29 | /** cycle when sliding at the last or first item **/ 30 | public static final int SLIDE_BORDER_MODE_CYCLE = 1; 31 | /** deliver event to parent when sliding at the last or first item **/ 32 | public static final int SLIDE_BORDER_MODE_TO_PARENT = 2; 33 | 34 | /** auto scroll time in milliseconds, default is {@link #DEFAULT_INTERVAL} **/ 35 | private long interval = DEFAULT_INTERVAL; 36 | /** auto scroll direction, default is {@link #RIGHT} **/ 37 | private int direction = RIGHT; 38 | /** whether automatic cycle when auto scroll reaching the last or first item, default is true **/ 39 | private boolean isCycle = true; 40 | /** whether stop auto scroll when touching, default is true **/ 41 | private boolean stopScrollWhenTouch = true; 42 | /** how to process when sliding at the last or first item, default is {@link #SLIDE_BORDER_MODE_NONE} **/ 43 | private int slideBorderMode = SLIDE_BORDER_MODE_NONE; 44 | /** whether animating when auto scroll at the last or first item **/ 45 | private boolean isBorderAnimation = true; 46 | /** scroll factor for auto scroll animation, default is 1.0 **/ 47 | private double autoScrollFactor = 1.0; 48 | /** scroll factor for swipe scroll animation, default is 1.0 **/ 49 | private double swipeScrollFactor = 1.0; 50 | 51 | private Handler handler; 52 | private boolean isAutoScroll = false; 53 | private boolean isStopByTouch = false; 54 | private float touchX = 0f, downX = 0f; 55 | private CustomDurationScroller scroller = null; 56 | 57 | public static final int SCROLL_WHAT = 0; 58 | 59 | public AutoScrollViewPager(Context paramContext) { 60 | super(paramContext); 61 | init(); 62 | } 63 | 64 | public AutoScrollViewPager(Context paramContext, AttributeSet paramAttributeSet) { 65 | super(paramContext, paramAttributeSet); 66 | init(); 67 | } 68 | 69 | private void init() { 70 | handler = new MyHandler(this); 71 | setViewPagerScroller(); 72 | } 73 | 74 | /** 75 | * start auto scroll, first scroll delay time is {@link #getInterval()} 76 | */ 77 | public void startAutoScroll() { 78 | isAutoScroll = true; 79 | sendScrollMessage((long)(interval + scroller.getDuration() / autoScrollFactor * swipeScrollFactor)); 80 | } 81 | 82 | /** 83 | * start auto scroll 84 | * 85 | * @param delayTimeInMills first scroll delay time 86 | */ 87 | public void startAutoScroll(int delayTimeInMills) { 88 | isAutoScroll = true; 89 | sendScrollMessage(delayTimeInMills); 90 | } 91 | 92 | /** 93 | * stop auto scroll 94 | */ 95 | public void stopAutoScroll() { 96 | isAutoScroll = false; 97 | handler.removeMessages(SCROLL_WHAT); 98 | } 99 | 100 | /** 101 | * set the factor by which the duration of sliding animation will change while swiping 102 | */ 103 | public void setSwipeScrollDurationFactor(double scrollFactor) { 104 | swipeScrollFactor = scrollFactor; 105 | } 106 | 107 | /** 108 | * set the factor by which the duration of sliding animation will change while auto scrolling 109 | */ 110 | public void setAutoScrollDurationFactor(double scrollFactor) { 111 | autoScrollFactor = scrollFactor; 112 | } 113 | 114 | private void sendScrollMessage(long delayTimeInMills) { 115 | /** remove messages before, keeps one message is running at most **/ 116 | handler.removeMessages(SCROLL_WHAT); 117 | handler.sendEmptyMessageDelayed(SCROLL_WHAT, delayTimeInMills); 118 | } 119 | 120 | /** 121 | * set ViewPager scroller to change animation duration when sliding 122 | */ 123 | private void setViewPagerScroller() { 124 | try { 125 | Field scrollerField = ViewPager.class.getDeclaredField("mScroller"); 126 | scrollerField.setAccessible(true); 127 | Field interpolatorField = ViewPager.class.getDeclaredField("sInterpolator"); 128 | interpolatorField.setAccessible(true); 129 | 130 | scroller = new CustomDurationScroller(getContext(), (Interpolator)interpolatorField.get(null)); 131 | scrollerField.set(this, scroller); 132 | } catch (Exception e) { 133 | e.printStackTrace(); 134 | } 135 | } 136 | 137 | /** 138 | * scroll only once 139 | */ 140 | public void scrollOnce() { 141 | PagerAdapter adapter = getAdapter(); 142 | int currentItem = getCurrentItem(); 143 | int totalCount; 144 | if (adapter == null || (totalCount = adapter.getCount()) <= 1) { 145 | return; 146 | } 147 | 148 | int nextItem = (direction == LEFT) ? --currentItem : ++currentItem; 149 | if (nextItem < 0) { 150 | if (isCycle) { 151 | setCurrentItem(totalCount - 1, isBorderAnimation); 152 | } 153 | } else if (nextItem == totalCount) { 154 | if (isCycle) { 155 | setCurrentItem(0, isBorderAnimation); 156 | } 157 | } else { 158 | setCurrentItem(nextItem, true); 159 | } 160 | } 161 | 162 | /** 163 | *

    164 | * if stopScrollWhenTouch is true 165 | *
  • if event is down, stop auto scroll.
  • 166 | *
  • if event is up, start auto scroll again.
  • 167 | *
168 | */ 169 | @Override 170 | public boolean dispatchTouchEvent(MotionEvent ev) { 171 | int action = MotionEventCompat.getActionMasked(ev); 172 | 173 | if (stopScrollWhenTouch) { 174 | if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) { 175 | isStopByTouch = true; 176 | stopAutoScroll(); 177 | } else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) { 178 | startAutoScroll(); 179 | } 180 | } 181 | 182 | if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) { 183 | touchX = ev.getX(); 184 | if (ev.getAction() == MotionEvent.ACTION_DOWN) { 185 | downX = touchX; 186 | } 187 | int currentItem = getCurrentItem(); 188 | PagerAdapter adapter = getAdapter(); 189 | int pageCount = adapter == null ? 0 : adapter.getCount(); 190 | /** 191 | * current index is first one and slide to right or current index is last one and slide to left.
192 | * if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.
193 | * else scroll to last one when current item is first one, scroll to first one when current item is last 194 | * one. 195 | */ 196 | if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) { 197 | if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) { 198 | getParent().requestDisallowInterceptTouchEvent(false); 199 | } else { 200 | if (pageCount > 1) { 201 | setCurrentItem(pageCount - currentItem - 1, isBorderAnimation); 202 | } 203 | getParent().requestDisallowInterceptTouchEvent(true); 204 | } 205 | return super.dispatchTouchEvent(ev); 206 | } 207 | } 208 | getParent().requestDisallowInterceptTouchEvent(true); 209 | 210 | return super.dispatchTouchEvent(ev); 211 | } 212 | 213 | private static class MyHandler extends Handler { 214 | 215 | private final WeakReference autoScrollViewPager; 216 | 217 | public MyHandler(AutoScrollViewPager autoScrollViewPager) { 218 | this.autoScrollViewPager = new WeakReference(autoScrollViewPager); 219 | } 220 | 221 | @Override 222 | public void handleMessage(Message msg) { 223 | super.handleMessage(msg); 224 | 225 | switch (msg.what) { 226 | case SCROLL_WHAT: 227 | AutoScrollViewPager pager = this.autoScrollViewPager.get(); 228 | if (pager != null) { 229 | pager.scroller.setScrollDurationFactor(pager.autoScrollFactor); 230 | pager.scrollOnce(); 231 | pager.scroller.setScrollDurationFactor(pager.swipeScrollFactor); 232 | pager.sendScrollMessage(pager.interval + pager.scroller.getDuration()); 233 | } 234 | default: 235 | break; 236 | } 237 | } 238 | } 239 | 240 | /** 241 | * get auto scroll time in milliseconds, default is {@link #DEFAULT_INTERVAL} 242 | * 243 | * @return the interval 244 | */ 245 | public long getInterval() { 246 | return interval; 247 | } 248 | 249 | /** 250 | * set auto scroll time in milliseconds, default is {@link #DEFAULT_INTERVAL} 251 | * 252 | * @param interval the interval to set 253 | */ 254 | public void setInterval(long interval) { 255 | this.interval = interval; 256 | } 257 | 258 | /** 259 | * get auto scroll direction 260 | * 261 | * @return {@link #LEFT} or {@link #RIGHT}, default is {@link #RIGHT} 262 | */ 263 | public int getDirection() { 264 | return (direction == LEFT) ? LEFT : RIGHT; 265 | } 266 | 267 | /** 268 | * set auto scroll direction 269 | * 270 | * @param direction {@link #LEFT} or {@link #RIGHT}, default is {@link #RIGHT} 271 | */ 272 | public void setDirection(int direction) { 273 | this.direction = direction; 274 | } 275 | 276 | /** 277 | * whether automatic cycle when auto scroll reaching the last or first item, default is true 278 | * 279 | * @return the isCycle 280 | */ 281 | public boolean isCycle() { 282 | return isCycle; 283 | } 284 | 285 | /** 286 | * set whether automatic cycle when auto scroll reaching the last or first item, default is true 287 | * 288 | * @param isCycle the isCycle to set 289 | */ 290 | public void setCycle(boolean isCycle) { 291 | this.isCycle = isCycle; 292 | } 293 | 294 | /** 295 | * whether stop auto scroll when touching, default is true 296 | * 297 | * @return the stopScrollWhenTouch 298 | */ 299 | public boolean isStopScrollWhenTouch() { 300 | return stopScrollWhenTouch; 301 | } 302 | 303 | /** 304 | * set whether stop auto scroll when touching, default is true 305 | * 306 | * @param stopScrollWhenTouch 307 | */ 308 | public void setStopScrollWhenTouch(boolean stopScrollWhenTouch) { 309 | this.stopScrollWhenTouch = stopScrollWhenTouch; 310 | } 311 | 312 | /** 313 | * get how to process when sliding at the last or first item 314 | * 315 | * @return the slideBorderMode {@link #SLIDE_BORDER_MODE_NONE}, {@link #SLIDE_BORDER_MODE_TO_PARENT}, 316 | * {@link #SLIDE_BORDER_MODE_CYCLE}, default is {@link #SLIDE_BORDER_MODE_NONE} 317 | */ 318 | public int getSlideBorderMode() { 319 | return slideBorderMode; 320 | } 321 | 322 | /** 323 | * set how to process when sliding at the last or first item 324 | * 325 | * @param slideBorderMode {@link #SLIDE_BORDER_MODE_NONE}, {@link #SLIDE_BORDER_MODE_TO_PARENT}, 326 | * {@link #SLIDE_BORDER_MODE_CYCLE}, default is {@link #SLIDE_BORDER_MODE_NONE} 327 | */ 328 | public void setSlideBorderMode(int slideBorderMode) { 329 | this.slideBorderMode = slideBorderMode; 330 | } 331 | 332 | /** 333 | * whether animating when auto scroll at the last or first item, default is true 334 | * 335 | * @return 336 | */ 337 | public boolean isBorderAnimation() { 338 | return isBorderAnimation; 339 | } 340 | 341 | /** 342 | * set whether animating when auto scroll at the last or first item, default is true 343 | * 344 | * @param isBorderAnimation 345 | */ 346 | public void setBorderAnimation(boolean isBorderAnimation) { 347 | this.isBorderAnimation = isBorderAnimation; 348 | } 349 | } 350 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/widget/CustomDurationScroller.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.widget; 2 | 3 | import android.content.Context; 4 | import android.view.animation.Interpolator; 5 | import android.widget.Scroller; 6 | 7 | /** 8 | * Created by sourabhkarkal on 26/02/17. 9 | */ 10 | 11 | public class CustomDurationScroller extends Scroller { 12 | 13 | private double scrollFactor = 1; 14 | 15 | public CustomDurationScroller(Context context) { 16 | super(context); 17 | } 18 | 19 | public CustomDurationScroller(Context context, Interpolator interpolator) { 20 | super(context, interpolator); 21 | } 22 | 23 | public void setScrollDurationFactor(double scrollFactor) { 24 | this.scrollFactor = scrollFactor; 25 | } 26 | 27 | @Override 28 | public void startScroll(int startX, int startY, int dx, int dy, int duration) { 29 | super.startScroll(startX, startY, dx, dy, (int)(duration * scrollFactor)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/sourabhkarkal/movieapp/widget/ImageViewPager.java: -------------------------------------------------------------------------------- 1 | package com.sourabhkarkal.movieapp.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 12 | import com.sourabhkarkal.movieapp.R; 13 | import com.sourabhkarkal.movieapp.utils.Constants; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by sourabhkarkal on 26/02/17. 19 | * 20 | * A {@link ViewPager} that allows pseudo-infinite paging with a wrap-around effect 21 | * Used in class {@link com.sourabhkarkal.movieapp.fragment.MovieDetailFragment} 22 | */ 23 | 24 | public class ImageViewPager extends PagerAdapter { 25 | Context context; 26 | ArrayList pathList; 27 | 28 | public ImageViewPager(Context context, ArrayList pathList){ 29 | this.context=context; 30 | this.pathList = pathList; 31 | } 32 | @Override 33 | public int getCount() { 34 | return pathList.size(); 35 | } 36 | 37 | @Override 38 | public boolean isViewFromObject(View view, Object object) { 39 | return view == ((ImageView) object); 40 | } 41 | 42 | @Override 43 | public Object instantiateItem(ViewGroup container, int position) { 44 | ImageView imageView = new ImageView(context); 45 | int padding = context.getResources().getDimensionPixelSize(R.dimen.small_margin); 46 | imageView.setPadding(padding, padding, padding, padding); 47 | imageView.setScaleType(ImageView.ScaleType.FIT_XY); 48 | Glide.with(context) 49 | .load(Constants.IMAGE_BASE_PATH + pathList.get(position)) 50 | .animate(android.R.anim.fade_in) 51 | .diskCacheStrategy(DiskCacheStrategy.ALL) 52 | .placeholder(R.drawable.movie_placeholder) 53 | .into(imageView); 54 | ((ViewPager) container).addView(imageView, 0); 55 | return imageView; 56 | } 57 | 58 | @Override 59 | public void destroyItem(ViewGroup container, int position, Object object) { 60 | ((ViewPager) container).removeView((ImageView) object); 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/anim/exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/anim/left_to_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/anim/right_to_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/book_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auto-Droid/TMDB-App/8aaebbe6a656ad64d41df7bade59a85333d57120/app/src/main/res/drawable/book_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/movie_placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Auto-Droid/TMDB-App/8aaebbe6a656ad64d41df7bade59a85333d57120/app/src/main/res/drawable/movie_placeholder.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/rectangle.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 17 | 18 | 24 | 25 | 33 | 34 | 42 | 43 | 44 | 45 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/res/layout/home_screen.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/movie_detail_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 22 | 23 | 24 | 31 | 32 | 33 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 60 | 64 | 65 | 66 |