commit 05d080b95c02a74cd0f548e24f613987fbbe7eca Author: Mario Danic Date: Mon Oct 23 12:40:38 2017 +0200 Initial import Signed-off-by: Mario Danic diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ce5f00f43 --- /dev/null +++ b/.gitignore @@ -0,0 +1,56 @@ +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Intellij +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/dictionaries +.idea/libraries + +# Keystore files +*.jks + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json +.DS_Store diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..a1757ae52 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/GPL3.xml b/.idea/copyright/GPL3.xml new file mode 100644 index 000000000..636e6b33a --- /dev/null +++ b/.idea/copyright/GPL3.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 000000000..98091ccf7 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..97626ba45 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..0e3b8d65b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..70fb12571 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 000000000..7f68460d8 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..45cf85c20 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENCE b/LICENCE new file mode 100644 index 000000000..114f15c8e --- /dev/null +++ b/LICENCE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + {project} Copyright (C) {year} {fullname} + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 000000000..a11e91a2b --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,114 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion '26.0.2' + defaultConfig { + applicationId "com.nextcloud.talk" + minSdkVersion 21 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + // Enabling multidex support. + multiDexEnabled true + + vectorDrawables.useSupportLibrary = true + + lintOptions { + disable 'InvalidPackage' + } + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + packagingOptions { + exclude 'META-INF/LICENSE' + exclude 'META-INF/NOTICE' + exclude 'META-INF/rxjava.properties' + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + +} + +ext { + supportLibraryVersion = '26.1.0' +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "com.android.support:appcompat-v7:${supportLibraryVersion}" + implementation "com.android.support:design:${supportLibraryVersion}" + implementation 'com.android.support:multidex:1.0.2' + + compile 'io.reactivex.rxjava2:rxandroid:2.0.1' + compile "io.reactivex.rxjava2:rxjava:2.1.4" + + implementation 'com.bluelinelabs:conductor:2.1.4' + implementation 'com.bluelinelabs:conductor-support:2.1.4' + + implementation 'com.squareup.okhttp3:okhttp:3.8.1' + implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.6.0' + implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' + + implementation 'com.bluelinelabs:logansquare:1.3.7' + annotationProcessor 'com.bluelinelabs:logansquare-compiler:1.3.7' + + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' + implementation 'com.github.aurae.retrofit2:converter-logansquare:1.4.1' + + implementation 'com.google.dagger:dagger:2.8' + annotationProcessor 'com.google.dagger:dagger-compiler:2.8' + implementation 'com.github.lukaspili.autodagger2:autodagger2:1.1' + annotationProcessor 'com.github.lukaspili.autodagger2:autodagger2-compiler:1.1' + + implementation 'org.greenrobot:eventbus:3.0.0' + + compile 'io.requery:requery:1.4.0' + compile 'io.requery:requery-android:1.4.0' + compile 'net.zetetic:android-database-sqlcipher:3.5.7' + annotationProcessor 'io.requery:requery-processor:1.4.0' + + compile 'org.parceler:parceler-api:1.1.9' + annotationProcessor 'org.parceler:parceler:1.1.9' + + compile 'net.orange-box.storebox:storebox-lib:1.4.0' + + compileOnly "org.projectlombok:lombok:1.16.18" + annotationProcessor "org.projectlombok:lombok:1.16.18" + + compile 'com.jakewharton:butterknife:8.8.1' + annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' + + debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4' + releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' + + compile "javax.transaction:transaction-api:1.1-rev-1" + + compile 'com.github.HITGIF:TextFieldBoxes:1.3.4' + + compile 'eu.davidea:flexible-adapter:5.0.0-rc2' + + compile 'cn.carbs.android:AvatarImageView:1.0.4' + + compile 'com.github.bumptech.glide:glide:4.2.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0' + compile 'com.github.bumptech.glide:okhttp3-integration:4.2.0@aar' + + testImplementation 'junit:junit:4.12' + androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.1', { + exclude group: 'com.android.support', module: 'support-annotations' + }) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java new file mode 100644 index 000000000..f03f9c85e --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.nextcloud.talk; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.nextcloud.talk", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..5d044a93e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java new file mode 100644 index 000000000..ea618c97b --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.java @@ -0,0 +1,93 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.activities; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.ViewGroup; + +import com.bluelinelabs.conductor.Conductor; +import com.bluelinelabs.conductor.Router; +import com.bluelinelabs.conductor.RouterTransaction; +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler; +import com.nextcloud.talk.R; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.BottomNavigationController; +import com.nextcloud.talk.controllers.ServerSelectionController; +import com.nextcloud.talk.controllers.base.providers.ActionBarProvider; +import com.nextcloud.talk.utils.database.user.UserUtils; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import butterknife.ButterKnife; +import io.requery.Persistable; +import io.requery.reactivex.ReactiveEntityStore; + +@AutoInjector(NextcloudTalkApplication.class) +public final class MainActivity extends AppCompatActivity implements ActionBarProvider { + + @BindView(R.id.toolbar) + Toolbar toolbar; + @BindView(R.id.controller_container) + ViewGroup container; + + @Inject + UserUtils userUtils; + @Inject + ReactiveEntityStore dataStore; + + private Router router; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_main); + + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + ButterKnife.bind(this); + + setSupportActionBar(toolbar); + + router = Conductor.attachRouter(this, container, savedInstanceState); + + + if (!router.hasRootController() && userUtils.anyUserExists()) { + router.setRoot(RouterTransaction.with(new BottomNavigationController(R.menu.menu_navigation)) + .pushChangeHandler(new FadeChangeHandler()) + .popChangeHandler(new FadeChangeHandler())); + } else if (!router.hasRootController()) { + router.setRoot(RouterTransaction.with(new ServerSelectionController()) + .pushChangeHandler(new FadeChangeHandler()) + .popChangeHandler(new FadeChangeHandler())); + } + } + + @Override + public void onBackPressed() { + if (!router.handleBack()) { + super.onBackPressed(); + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/RoomItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/RoomItem.java new file mode 100644 index 000000000..0ea55c970 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/RoomItem.java @@ -0,0 +1,180 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.adapters.items; + +import android.text.TextUtils; +import android.text.format.DateUtils; +import android.view.View; +import android.widget.TextView; + +import com.bumptech.glide.load.model.GlideUrl; +import com.bumptech.glide.load.model.LazyHeaders; +import com.nextcloud.talk.R; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.api.models.json.rooms.Room; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.persistence.entities.UserEntity; +import com.nextcloud.talk.utils.ColorUtils; +import com.nextcloud.talk.utils.GlideApp; + +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import cn.carbs.android.avatarimageview.library.AvatarImageView; +import eu.davidea.flexibleadapter.FlexibleAdapter; +import eu.davidea.flexibleadapter.items.AbstractFlexibleItem; +import eu.davidea.flexibleadapter.items.IFilterable; +import eu.davidea.flexibleadapter.utils.FlexibleUtils; +import eu.davidea.viewholders.FlexibleViewHolder; + +public class RoomItem extends AbstractFlexibleItem implements IFilterable { + + private Room room; + private UserEntity userEntity; + + public RoomItem(Room room, UserEntity userEntity) { + this.room = room; + this.userEntity = userEntity; + } + + @Override + public boolean equals(Object o) { + if (o instanceof RoomItem) { + RoomItem inItem = (RoomItem) o; + return room.equals(inItem.getModel()); + } + return false; + } + + @Override + public int hashCode() { + return room.hashCode(); + } + + /** + * @return the model object + */ + + public Room getModel() { + return room; + } + + /** + * Filter is applied to the model fields. + */ + + @Override + public int getLayoutRes() { + return R.layout.rv_item_call; + } + + @Override + public RoomItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) { + return new RoomItemViewHolder(view, adapter); + } + + @Override + public void bindViewHolder(final FlexibleAdapter adapter, RoomItemViewHolder holder, int position, List payloads) { + if (adapter.hasSearchText()) { + FlexibleUtils.highlightText(holder.roomDisplayName, room.getDisplayName(), adapter.getSearchText()); + } else { + holder.roomDisplayName.setText(room.getDisplayName()); + } + + if (room.getLastPing() == 0) { + holder.roomLastPing.setText(R.string.nc_invited); + } else { + holder.roomLastPing.setText(DateUtils.getRelativeTimeSpanString(room.getLastPing() * 1000L, + System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE)); + } + + + switch (room.getType()) { + case ROOM_TYPE_ONE_TO_ONE_CALL: + holder.avatarImageView.setVisibility(View.VISIBLE); + + holder.avatarImageViewInvisible.setTextAndColorSeed(String.valueOf(room.getDisplayName(). + toUpperCase().charAt(0)), ColorUtils.colorSeed); + + if (!TextUtils.isEmpty(room.getName())) { + GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(), + room.getName()), new LazyHeaders.Builder() + .addHeader("OCS-APIRequest", "true") + .addHeader("User-Agent", ApiHelper.getUserAgent()) + .addHeader("Accept", "*/*") + .addHeader("Authorization", () -> + ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken())) + .build()); + + GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext()) + .asBitmap() + .skipMemoryCache(true) + .load(glideUrl) + .placeholder(holder.avatarImageViewInvisible.getDrawable()) + .circleCrop() + .centerInside() + .into(holder.avatarImageView); + } else { + holder.avatarImageView.setDrawable(holder.avatarImageViewInvisible.getDrawable()); + } + break; + case ROOM_GROUP_CALL: + holder.avatarImageView.setVisibility(View.VISIBLE); + holder.avatarImageView.setImageResource(R.drawable.ic_group_black_24dp); + break; + case ROOM_PUBLIC_CALL: + holder.avatarImageView.setVisibility(View.VISIBLE); + holder.avatarImageView.setImageResource(R.drawable.ic_public_black_24dp); + break; + default: + holder.avatarImageView.setVisibility(View.GONE); + + } + } + + @Override + public boolean filter(String constraint) { + return room.getDisplayName() != null && room.getDisplayName().toLowerCase().trim().contains( + constraint.toLowerCase()); + + } + + static class RoomItemViewHolder extends FlexibleViewHolder { + + @BindView(R.id.name_text) + public TextView roomDisplayName; + @BindView(R.id.timestamp_text) + public TextView roomLastPing; + @BindView(R.id.avatar_image) + public AvatarImageView avatarImageView; + @BindView(R.id.avatar_image_invisible) + public AvatarImageView avatarImageViewInvisible; + + /** + * Default constructor. + */ + RoomItemViewHolder(View view, FlexibleAdapter adapter) { + super(view, adapter); + ButterKnife.bind(this, view); + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java new file mode 100644 index 000000000..17cba3b5f --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java @@ -0,0 +1,145 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.adapters.items; + +import android.view.View; +import android.widget.TextView; + +import com.bumptech.glide.load.model.GlideUrl; +import com.bumptech.glide.load.model.LazyHeaders; +import com.nextcloud.talk.R; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.api.models.User; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.persistence.entities.UserEntity; +import com.nextcloud.talk.utils.ColorUtils; +import com.nextcloud.talk.utils.GlideApp; + +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import cn.carbs.android.avatarimageview.library.AvatarImageView; +import eu.davidea.flexibleadapter.FlexibleAdapter; +import eu.davidea.flexibleadapter.items.AbstractFlexibleItem; +import eu.davidea.flexibleadapter.items.IFilterable; +import eu.davidea.flexibleadapter.utils.FlexibleUtils; +import eu.davidea.viewholders.FlexibleViewHolder; + +public class UserItem extends AbstractFlexibleItem implements IFilterable { + + private User user; + private UserEntity userEntity; + + public UserItem(User user, UserEntity userEntity) { + this.user = user; + this.userEntity = userEntity; + } + + @Override + public boolean equals(Object o) { + if (o instanceof UserItem) { + UserItem inItem = (UserItem) o; + return user.equals(inItem.getModel()); + } + return false; + } + + @Override + public int hashCode() { + return user.hashCode(); + } + + /** + * @return the model object + */ + + public User getModel() { + return user; + } + + @Override + public int getLayoutRes() { + return R.layout.rv_item_contact; + } + + @Override + public UserItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) { + return new UserItemViewHolder(view, adapter); + } + + @Override + public void bindViewHolder(FlexibleAdapter adapter, UserItemViewHolder holder, int position, List payloads) { + if (adapter.hasSearchText()) { + FlexibleUtils.highlightText(holder.contactDisplayName, user.getName(), adapter.getSearchText()); + } else { + holder.contactDisplayName.setText(user.getName()); + } + + // Awful hack + holder.avatarImageViewInvisible.setTextAndColorSeed(String.valueOf(user.getName(). + toUpperCase().charAt(0)), ColorUtils.colorSeed); + + GlideUrl glideUrl = new GlideUrl(ApiHelper.getUrlForAvatarWithName(userEntity.getBaseUrl(), + user.getUserId()), new LazyHeaders.Builder() + .addHeader("OCS-APIRequest", "true") + .addHeader("User-Agent", ApiHelper.getUserAgent()) + .addHeader("Accept", "*/*") + .addHeader("Authorization", () -> + ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken())) + .build()); + + GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext()) + .asBitmap() + .skipMemoryCache(true) + .placeholder(holder.avatarImageViewInvisible.getDrawable()) + .load(glideUrl) + .circleCrop() + .centerInside() + .into(holder.avatarImageView); + } + + @Override + public boolean filter(String constraint) { + return user.getName() != null && user.getName().toLowerCase().trim().contains(constraint.toLowerCase()); + } + + + static class UserItemViewHolder extends FlexibleViewHolder { + + @BindView(R.id.name_text) + public TextView contactDisplayName; + @BindView(R.id.avatar_image) + public AvatarImageView avatarImageView; + @BindView(R.id.avatar_image_invisible) + public AvatarImageView avatarImageViewInvisible; + + /** + * Default constructor. + */ + UserItemViewHolder(View view, FlexibleAdapter adapter) { + super(view, adapter); + ButterKnife.bind(this, view); + } + } + + +} diff --git a/app/src/main/java/com/nextcloud/talk/api/NcApi.java b/app/src/main/java/com/nextcloud/talk/api/NcApi.java new file mode 100644 index 000000000..ee2437999 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/NcApi.java @@ -0,0 +1,184 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api; + +import com.nextcloud.talk.api.models.json.call.CallOverall; +import com.nextcloud.talk.api.models.json.generic.Status; +import com.nextcloud.talk.api.models.json.participants.AddParticipantOverall; +import com.nextcloud.talk.api.models.json.participants.ParticipantsOverall; +import com.nextcloud.talk.api.models.json.rooms.RoomOverall; +import com.nextcloud.talk.api.models.json.rooms.RoomsOverall; +import com.nextcloud.talk.api.models.json.sharees.ShareesOverall; +import com.nextcloud.talk.api.models.json.userprofile.UserProfileOverall; + +import java.util.Map; + +import io.reactivex.Observable; +import retrofit2.http.DELETE; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.QueryMap; +import retrofit2.http.Url; + +public interface NcApi { + + /* + QueryMap items are as follows: + - "format" : "json" + - "search" : "" + - "perPage" : "200" + - "itemType" : "call" + + Server URL is: baseUrl + ocsApiVersion + /apps/files_sharing/api/v1/sharees + */ + @GET + Observable getContactsWithSearchParam(@Header("Authorization") String authorization, @Url String url, + @QueryMap Map options); + + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room + */ + @GET + Observable getRooms(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken + */ + @GET + Observable getRoom(@Header("Authorization") String authorization, @Url String url); + + /* + QueryMap items are as follows: + - "roomType" : "" + - "invite" : "" + + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room + */ + + @POST + Observable createRoom(@Header("Authorization") String authorization, @Url String url, + @QueryMap Map options); + + /* + QueryMap items are as follows: + - "roomName" : "newName" + + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken + */ + + @PUT + Observable renameRoom(@Header("Authorization") String authorization, @Url String url, + @QueryMap Map options); + + + /* + QueryMap items are as follows: + - "newParticipant" : "user" + + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants + */ + @POST + Observable addParticipant(@Header("Authorization") String authorization, @Url String url, + @QueryMap Map options); + + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/participants/self + */ + + @DELETE + Observable removeSelfFromRoom(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public + */ + @POST + Observable makeRoomPublic(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /room/roomToken/public + */ + @DELETE + Observable makeRoomPrivate(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken + */ + @GET + Observable getPeersForCall(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken + */ + @POST + Observable joinCall(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken/ping + */ + @POST + Observable pingCall(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /call/callToken + */ + @DELETE + Observable leaveCall(@Header("Authorization") String authorization, @Url String url); + + /* + QueryMap items are as follows: + - "messages" : "message" + + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling + */ + @POST + Observable sendSignalingMessages(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + ocsApiVersion + spreedApiVersion + /signaling + */ + @GET + Observable pullSignalingMessages(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + /index.php/avatar/userId/128 + Avatar OkHttp + */ + + /* + QueryMap items are as follows: + - "format" : "json" + + Server URL is: baseUrl + ocsApiVersion + "/cloud/user" + */ + + @GET + Observable getUserProfile(@Header("Authorization") String authorization, @Url String url); + + /* + Server URL is: baseUrl + /status.php + */ + @GET + Observable getServerStatus(@Url String url); +} diff --git a/app/src/main/java/com/nextcloud/talk/api/helpers/api/ApiHelper.java b/app/src/main/java/com/nextcloud/talk/api/helpers/api/ApiHelper.java new file mode 100644 index 000000000..b5e03da2a --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/helpers/api/ApiHelper.java @@ -0,0 +1,141 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.helpers.api; + +import android.net.Uri; + +import com.nextcloud.talk.BuildConfig; +import com.nextcloud.talk.api.models.RetrofitBucket; + +import java.util.HashMap; +import java.util.Map; + +import okhttp3.Credentials; + +public class ApiHelper { + private static String ocsApiVersion = "/ocs/v2.php"; + private static String spreedApiVersion = "/apps/spreed/api/v1"; + + private static String userAgent = "Nextcloud Talk Android/v"; + + public static String getUserAgent() { + return userAgent + BuildConfig.VERSION_NAME; + } + + public static RetrofitBucket getRetrofitBucketForContactsSearch(String baseUrl, String searchQuery) { + RetrofitBucket retrofitBucket = new RetrofitBucket(); + retrofitBucket.setUrl(baseUrl + ocsApiVersion + "/apps/files_sharing/api/v1/sharees"); + + Map queryMap = new HashMap<>(); + + queryMap.put("format", "json"); + queryMap.put("search", searchQuery); + queryMap.put("perPage", "200"); + queryMap.put("itemType", "call"); + + retrofitBucket.setQueryMap(queryMap); + + return retrofitBucket; + } + + public static String getUrlForGetRooms(String baseUrl) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/room"; + } + + public static String getRoom(String baseUrl, String token) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token; + } + + public static RetrofitBucket getRetrofitBucketForCreateRoom(String baseUrl, String roomType, String invite) { + RetrofitBucket retrofitBucket = new RetrofitBucket(); + retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room"); + Map queryMap = new HashMap<>(); + + queryMap.put("roomType", roomType); + queryMap.put("invite", invite); + + retrofitBucket.setQueryMap(queryMap); + + return retrofitBucket; + } + + public static RetrofitBucket getRetrofitBucketForRenameRoom(String baseUrl, String token, String newRoomName) { + RetrofitBucket retrofitBucket = new RetrofitBucket(); + retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token); + + Map queryMap = new HashMap<>(); + + queryMap.put("roomName", newRoomName); + + retrofitBucket.setQueryMap(queryMap); + + return retrofitBucket; + } + + public static RetrofitBucket getRetrofitBucketForAddParticipant(String baseUrl, String token, String user) { + RetrofitBucket retrofitBucket = new RetrofitBucket(); + retrofitBucket.setUrl(baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants"); + + Map queryMap = new HashMap<>(); + + queryMap.put("newParticipant", user); + + retrofitBucket.setQueryMap(queryMap); + + return retrofitBucket; + + } + + public static String getUrlForRemoveSelfFromRoom(String baseUrl, String token) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/participants/self"; + } + + public static String getUrlForRoomVisibility(String baseUrl, String token) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/room/" + token + "/public"; + } + + public static String getUrlForCall(String baseUrl, String token) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/call/" + token; + } + + public static String getUrlForCallPing(String baseUrl, String token) { + return getUrlForCall(baseUrl, token) + "/ping"; + } + + public static String getUrlForSignaling(String baseUrl) { + return baseUrl + ocsApiVersion + spreedApiVersion + "/signaling"; + } + + public static String getUrlForUserProfile(String baseUrl) { + return baseUrl + ocsApiVersion + "/cloud/user"; + } + + public static String getUrlPostfixForStatus() { + return "/status.php"; + } + + public static String getUrlForAvatarWithName(String baseUrl, String name) { + return baseUrl + "/index.php/avatar/" + Uri.encode(name) + "/128"; + } + + public static String getCredentials(String username, String token) { + return Credentials.basic(username, token); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/RetrofitBucket.java b/app/src/main/java/com/nextcloud/talk/api/models/RetrofitBucket.java new file mode 100644 index 000000000..0d0a82493 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/RetrofitBucket.java @@ -0,0 +1,34 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models; + +import org.parceler.Parcel; + +import java.util.Map; + +import lombok.Data; + +@Parcel +@Data +public class RetrofitBucket { + String url; + Map queryMap; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/User.java b/app/src/main/java/com/nextcloud/talk/api/models/User.java new file mode 100644 index 000000000..16a91942f --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/User.java @@ -0,0 +1,40 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class User { + @JsonField(name = "userId") + String userId; + @JsonField(name = "type") + int type; + @JsonField(name = "name") + String name; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/call/Call.java b/app/src/main/java/com/nextcloud/talk/api/models/json/call/Call.java new file mode 100644 index 000000000..6f0cce1e5 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/call/Call.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.call; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Call { + @JsonField(name = "sessionId") + String sessionId; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOCS.java new file mode 100644 index 000000000..c44e8ea69 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOCS.java @@ -0,0 +1,31 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.call; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +@JsonObject +public class CallOCS extends GenericOCS { + @JsonField(name = "data") + Call data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOverall.java new file mode 100644 index 000000000..806de4766 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/call/CallOverall.java @@ -0,0 +1,30 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.call; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +@JsonObject +public class CallOverall { + @JsonField(name = "ocs") + CallOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/converters/EnumRoomTypeConverter.java b/app/src/main/java/com/nextcloud/talk/api/models/json/converters/EnumRoomTypeConverter.java new file mode 100644 index 000000000..fff35959f --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/converters/EnumRoomTypeConverter.java @@ -0,0 +1,56 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.api.models.json.converters; + +import com.bluelinelabs.logansquare.typeconverters.IntBasedTypeConverter; +import com.nextcloud.talk.api.models.json.rooms.Room; + +public class EnumRoomTypeConverter extends IntBasedTypeConverter { + @Override + public Room.RoomType getFromInt(int i) { + switch (i) { + case 1: + return Room.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL; + case 2: + return Room.RoomType.ROOM_GROUP_CALL; + case 3: + return Room.RoomType.ROOM_PUBLIC_CALL; + default: + return Room.RoomType.DUMMY; + } + } + + @Override + public int convertToInt(Room.RoomType object) { + switch (object) { + case DUMMY: + return 0; + case ROOM_TYPE_ONE_TO_ONE_CALL: + return 1; + case ROOM_GROUP_CALL: + return 2; + case ROOM_PUBLIC_CALL: + return 3; + default: + return 0; + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericMeta.java b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericMeta.java new file mode 100644 index 000000000..f8c23509d --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericMeta.java @@ -0,0 +1,42 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.generic; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class GenericMeta { + @JsonField(name = "status") + String status; + + @JsonField(name = "statuscode") + String statusCode; + + @JsonField(name = "message") + String message; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOCS.java new file mode 100644 index 000000000..ec5be04fd --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOCS.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.generic; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class GenericOCS { + @JsonField(name = "meta") + GenericMeta meta; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOverall.java new file mode 100644 index 000000000..a860c0822 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/GenericOverall.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.generic; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class GenericOverall { + @JsonField(name = "ocs") + GenericOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/generic/Status.java b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/Status.java new file mode 100644 index 000000000..98a583c08 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/generic/Status.java @@ -0,0 +1,54 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.api.models.json.generic; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Status { + @JsonField(name = "installed") + boolean installed; + + @JsonField(name = "maintenance") + boolean maintenance; + + @JsonField(name = "upgrade") + boolean needsUpgrade; + + @JsonField(name = "version") + String version; + + @JsonField(name = "versionstring") + String versionString; + + @JsonField(name = "edition") + String edition; + + @JsonField(name = "productname") + String productName; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOCS.java new file mode 100644 index 000000000..081d99599 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOCS.java @@ -0,0 +1,35 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.participants; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; +import com.nextcloud.talk.api.models.json.rooms.Room; + +@JsonObject +public class AddParticipantOCS extends GenericOCS { + /* + Returned room will have only type set, and sometimes even that will be null + */ + @JsonField(name = "data") + Room data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOverall.java new file mode 100644 index 000000000..c341c176e --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/AddParticipantOverall.java @@ -0,0 +1,31 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.participants; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.rooms.RoomsOCS; + +@JsonObject +public class AddParticipantOverall { + @JsonField(name = "ocs") + RoomsOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/participants/Participant.java b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/Participant.java new file mode 100644 index 000000000..3119561ec --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/Participant.java @@ -0,0 +1,42 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.participants; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Participant { + @JsonField(name = "userId") + String userId; + + @JsonField(name = "lastPing") + long lastPing; + + @JsonField(name = "sessionId") + String sessionId; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOCS.java new file mode 100644 index 000000000..88feeb2da --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOCS.java @@ -0,0 +1,33 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.participants; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +import java.util.List; + +@JsonObject +public class ParticipantsOCS extends GenericOCS { + @JsonField(name = "data") + List data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOverall.java new file mode 100644 index 000000000..c0e612991 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/participants/ParticipantsOverall.java @@ -0,0 +1,38 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.participants; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class ParticipantsOverall { + @JsonField(name = "ocs") + List ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/Room.java b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/Room.java new file mode 100644 index 000000000..ac42dc9d0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/Room.java @@ -0,0 +1,69 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.rooms; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.User; +import com.nextcloud.talk.api.models.json.converters.EnumRoomTypeConverter; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Room { + @JsonField(name = "id") + String roomId; + @JsonField(name = "token") + String token; + @JsonField(name = "name") + String name; + @JsonField(name = "displayName") + String displayName; + @JsonField(name = "type", typeConverter = EnumRoomTypeConverter.class) + RoomType type; + @JsonField(name = "count") + long count; + @JsonField(name = "lastPing") + long lastPing; + @JsonField(name = "numGuests") + long numberOfGuests; + @JsonField(name = "guestList") + List guestList; + @JsonField(name = "participants") + List participants; + @JsonField(name = "hasPassword") + boolean hasPassword; + @JsonField(name = "sessionId") + String sessionId; + + public enum RoomType { + DUMMY, + ROOM_TYPE_ONE_TO_ONE_CALL, + ROOM_GROUP_CALL, + ROOM_PUBLIC_CALL + } +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOCS.java new file mode 100644 index 000000000..c9ec7a90e --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOCS.java @@ -0,0 +1,31 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.rooms; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +@JsonObject +public class RoomOCS extends GenericOCS { + @JsonField(name = "data") + Room data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOverall.java new file mode 100644 index 000000000..31dcaffa2 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomOverall.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.rooms; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class RoomOverall { + @JsonField(name = "ocs") + Room ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOCS.java new file mode 100644 index 000000000..49ba72edf --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOCS.java @@ -0,0 +1,39 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.rooms; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class RoomsOCS extends GenericOCS { + @JsonField(name = "data") + List data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOverall.java new file mode 100644 index 000000000..39de69ce9 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/rooms/RoomsOverall.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.rooms; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class RoomsOverall { + @JsonField(name = "ocs") + RoomsOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ExactSharees.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ExactSharees.java new file mode 100644 index 000000000..c0b1e04de --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ExactSharees.java @@ -0,0 +1,38 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class ExactSharees { + @JsonField(name = "exact") + List exactSharees; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Sharee.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Sharee.java new file mode 100644 index 000000000..492443ec4 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Sharee.java @@ -0,0 +1,39 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Sharee { + @JsonField(name = "value") + Value value; + + @JsonField(name = "label") + String label; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOCS.java new file mode 100644 index 000000000..b76c67673 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOCS.java @@ -0,0 +1,37 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +import org.parceler.Parcel; + +import lombok.Data; + +@Data +@Parcel +@JsonObject +public class ShareesOCS extends GenericOCS { + @JsonField(name = "data") + SharesData data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOverall.java new file mode 100644 index 000000000..b9580f9f0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/ShareesOverall.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class ShareesOverall { + @JsonField(name = "ocs") + ShareesOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/SharesData.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/SharesData.java new file mode 100644 index 000000000..94a3928e0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/SharesData.java @@ -0,0 +1,42 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import java.util.List; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class SharesData { + @JsonField(name = "users") + List users; + + @JsonField(name = "exact") + ExactSharees exactUsers; + +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Value.java b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Value.java new file mode 100644 index 000000000..566380401 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/sharees/Value.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.sharees; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class Value { + @JsonField(name = "shareWith") + String shareWith; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileData.java b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileData.java new file mode 100644 index 000000000..13f256df7 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileData.java @@ -0,0 +1,42 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.userprofile; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject() +public class UserProfileData { + @JsonField(name = "display-name") + String displayName; + + @JsonField(name = "displayname") + String displayNameAlt; + + @JsonField(name = "id") + String userId; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOCS.java b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOCS.java new file mode 100644 index 000000000..86595dd98 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOCS.java @@ -0,0 +1,37 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.userprofile; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; +import com.nextcloud.talk.api.models.json.generic.GenericOCS; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class UserProfileOCS extends GenericOCS { + @JsonField(name = "data") + UserProfileData data; +} diff --git a/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOverall.java b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOverall.java new file mode 100644 index 000000000..d6ef5d3b3 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/api/models/json/userprofile/UserProfileOverall.java @@ -0,0 +1,36 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.api.models.json.userprofile; + +import com.bluelinelabs.logansquare.annotation.JsonField; +import com.bluelinelabs.logansquare.annotation.JsonObject; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +@JsonObject +public class UserProfileOverall { + @JsonField(name = "ocs") + UserProfileOCS ocs; +} diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java new file mode 100644 index 000000000..7d3f03878 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java @@ -0,0 +1,125 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.application; + +import android.content.Context; +import android.support.multidex.MultiDex; +import android.support.multidex.MultiDexApplication; + +import com.nextcloud.talk.BuildConfig; +import com.nextcloud.talk.dagger.modules.BusModule; +import com.nextcloud.talk.dagger.modules.ContextModule; +import com.nextcloud.talk.dagger.modules.DatabaseModule; +import com.nextcloud.talk.dagger.modules.RestModule; +import com.nextcloud.talk.utils.database.cache.CacheModule; +import com.nextcloud.talk.utils.database.user.UserModule; +import com.squareup.leakcanary.LeakCanary; +import com.squareup.leakcanary.RefWatcher; + +import java.security.GeneralSecurityException; + +import javax.inject.Singleton; + +import autodagger.AutoComponent; +import autodagger.AutoInjector; + +@AutoComponent( + modules = { + BusModule.class, + ContextModule.class, + DatabaseModule.class, + RestModule.class, + UserModule.class, + CacheModule.class + } +) + +@Singleton +@AutoInjector(NextcloudTalkApplication.class) +public class NextcloudTalkApplication extends MultiDexApplication { + private static final String TAG = NextcloudTalkApplication.class.getSimpleName(); + + //region Public variables + public static RefWatcher refWatcher; + //endregion + + //region Singleton + protected static NextcloudTalkApplication sharedApplication; + //region Fields (components) + protected NextcloudTalkApplicationComponent componentApplication; + //endregion + + public static NextcloudTalkApplication getSharedApplication() { + return sharedApplication; + } + //endregion + + //region Overridden methods + @Override + public void onCreate() { + super.onCreate(); + sharedApplication = this; + + try { + buildComponent(); + } catch (final GeneralSecurityException exception) { + if (BuildConfig.DEBUG) { + exception.printStackTrace(); + } + } + + componentApplication.inject(this); + refWatcher = LeakCanary.install(this); + } + + + @Override + public void onTerminate() { + super.onTerminate(); + sharedApplication = null; + } + //endregion + + //region Getters + public NextcloudTalkApplicationComponent getComponentApplication() { + return componentApplication; + } + //endregion + + //region Protected methods + protected void buildComponent() throws GeneralSecurityException { + componentApplication = DaggerNextcloudTalkApplicationComponent.builder() + .busModule(new BusModule()) + .contextModule(new ContextModule(getApplicationContext())) + .databaseModule(new DatabaseModule()) + .restModule(new RestModule()) + .userModule(new UserModule()) + .cacheModule(new CacheModule()) + .build(); + } + + @Override + protected void attachBaseContext(Context base) { + super.attachBaseContext(base); + MultiDex.install(this); + } + //endregion +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java new file mode 100644 index 000000000..ae20ea29c --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/AccountVerificationController.java @@ -0,0 +1,223 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.controllers; + +import android.content.pm.ActivityInfo; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.bluelinelabs.conductor.RouterTransaction; +import com.nextcloud.talk.R; +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.utils.BundleKeys; +import com.nextcloud.talk.utils.database.user.UserUtils; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import io.reactivex.CompletableObserver; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + + +@AutoInjector(NextcloudTalkApplication.class) +public class AccountVerificationController extends BaseController { + + public static final String TAG = "AccountVerificationController"; + + @Inject + NcApi ncApi; + + @Inject + UserUtils userUtils; + + @BindView(R.id.progress_text) + TextView progressText; + + private Disposable roomsQueryDisposable; + private Disposable profileQueryDisposable; + private Disposable dbQueryDisposable; + + private String baseUrl; + private String username; + private String token; + + public AccountVerificationController(Bundle args) { + super(args); + if (args != null) { + baseUrl = args.getString(BundleKeys.KEY_BASE_URL); + username = args.getString(BundleKeys.KEY_USERNAME); + token = args.getString(BundleKeys.KEY_TOKEN); + } + } + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_account_verification, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + + dispose(null); + + String credentials = ApiHelper.getCredentials(username, token); + + roomsQueryDisposable = ncApi.getRooms(credentials, ApiHelper.getUrlForGetRooms(baseUrl)) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomsOverall -> { + progressText.setText(String.format(getResources().getString( + R.string.nc_nextcloud_talk_app_installed), getResources().getString(R.string.nc_app_name))); + + profileQueryDisposable = ncApi.getUserProfile(credentials, + ApiHelper.getUrlForUserProfile(baseUrl)) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(userProfileOverall -> { + progressText.setText(progressText.getText().toString() + "\n" + + getResources().getString(R.string.nc_display_name_fetched)); + + String displayName = null; + if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData() + .getDisplayName())) { + displayName = userProfileOverall.getOcs().getData() + .getDisplayName(); + } else if (!TextUtils.isEmpty(userProfileOverall.getOcs().getData() + .getDisplayNameAlt())) { + displayName = userProfileOverall.getOcs().getData() + .getDisplayNameAlt(); + } + + if (!TextUtils.isEmpty(displayName)) { + dbQueryDisposable = userUtils.createOrUpdateUser(username, token, + baseUrl, displayName) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(userEntity -> { + progressText.setText(progressText.getText().toString() + + "\n" + + getResources().getString( + R.string.nc_display_name_stored)); + getRouter().setRoot(RouterTransaction.with(new + BottomNavigationController(R.menu.menu_navigation))); + }, + throwable -> { + progressText.setText(progressText.getText().toString() + + "\n" + + getResources().getString( + R.string.nc_display_name_not_stored)); + abortVerification(); + }, () -> dispose(dbQueryDisposable)); + + } else { + progressText.setText(progressText.getText().toString() + "\n" + + getResources().getString(R.string.nc_display_name_not_fetched)); + abortVerification(); + } + }, throwable -> { + progressText.setText(progressText.getText().toString() + + "\n" + getResources().getString( + R.string.nc_display_name_not_fetched)); + abortVerification(); + }, () -> dispose(profileQueryDisposable)); + + }, throwable -> { + progressText.setText(String.format(getResources().getString( + R.string.nc_nextcloud_talk_app_not_installed), getResources().getString(R.string.nc_app_name))); + abortVerification(); + }, () -> dispose(roomsQueryDisposable)); + + + } + + private void dispose(@Nullable Disposable disposable) { + if (disposable != null && !disposable.isDisposed()) { + disposable.dispose(); + } else if (disposable == null) { + if (roomsQueryDisposable != null && !roomsQueryDisposable.isDisposed()) { + roomsQueryDisposable.dispose(); + roomsQueryDisposable = null; + } + + if (profileQueryDisposable != null && !profileQueryDisposable.isDisposed()) { + profileQueryDisposable.dispose(); + profileQueryDisposable = null; + } + + if (dbQueryDisposable != null && !dbQueryDisposable.isDisposed()) { + dbQueryDisposable.dispose(); + dbQueryDisposable = null; + } + + } + + disposable = null; + } + + @Override + protected void onDestroyView(@NonNull View view) { + super.onDestroyView(view); + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); + } + } + + private void abortVerification() { + dispose(null); + + userUtils.deleteUser(username, baseUrl).subscribe(new CompletableObserver() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onComplete() { + new Handler().postDelayed(() -> getRouter().popToRoot(), 5000); + } + + @Override + public void onError(Throwable e) { + + } + }); + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/BottomNavigationController.java b/app/src/main/java/com/nextcloud/talk/controllers/BottomNavigationController.java new file mode 100644 index 000000000..f2a1af4f3 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/BottomNavigationController.java @@ -0,0 +1,218 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * The bottom navigation was taken from a PR to Conductor by Chris6647@gmail.com + * https://github.com/bluelinelabs/Conductor/pull/316 + * and of course modified by yours truly. v v xzcs an + */ + +package com.nextcloud.talk.controllers; + +import android.os.Bundle; +import android.support.annotation.MenuRes; +import android.support.annotation.NonNull; +import android.support.design.widget.BottomNavigationView; +import android.util.SparseArray; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import com.bluelinelabs.conductor.ChangeHandlerFrameLayout; +import com.bluelinelabs.conductor.Controller; +import com.bluelinelabs.conductor.Router; +import com.bluelinelabs.conductor.RouterTransaction; +import com.nextcloud.talk.R; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.utils.BundleBuilder; + +import butterknife.BindView; + +/** + * Backstack per menu item goes against Google Design Guidelines. + * https://material.io/guidelines/components/bottom-navigation.html#bottom-navigation-behavior + */ +public class BottomNavigationController extends BaseController { + + public static final String TAG = "BottomNavigationController"; + + private static final String KEY_MENU_RESOURCE = "key_menu_resource"; + private static final String KEY_STATE_ROUTER_BUNDLES = "key_state_router_bundles"; + private static final String KEY_STATE_CURRENTLY_SELECTED_ID = "key_state_currently_selected_id"; + + @BindView(R.id.bottom_navigation_root) + LinearLayout bottomNavigationRoot; + + @BindView(R.id.navigation) + BottomNavigationView bottomNavigationView; + + @BindView(R.id.bottom_navigation_controller_container) + ChangeHandlerFrameLayout controllerContainer; + + private int currentlySelectedItemId; + + private SparseArray routerBundles; + + private Router childRouter; + + public BottomNavigationController(@MenuRes int menu) { + this(new BundleBuilder(new Bundle()).putInt(KEY_MENU_RESOURCE, menu).build()); + } + + public BottomNavigationController(Bundle args) { + super(args); + } + + private static Controller getControllerFor(int menuItemId) { + Controller controller; + switch (menuItemId) { + case R.id.navigation_calls: + controller = new CallsListController(); + break; + case R.id.navigation_contacts: + controller = new ContactsController(); + break; + case R.id.navigation_settings: + controller = new SettingsController(); + break; + default: + throw new IllegalStateException( + "Unknown bottomNavigationView item selected."); + } + return controller; + } + + @NonNull + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_bottom_navigation, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + + /* Setup the BottomNavigationView with the constructor supplied Menu resource */ + bottomNavigationView.inflateMenu(getMenuResource()); + + Menu menu = bottomNavigationView.getMenu(); + int menuSize = menu.size(); + + childRouter = getChildRouter(controllerContainer); + + /* + * Not having access to Backstack or RouterTransaction constructors, + * we have to save/restore the entire routers for each backstack. + */ + if (routerBundles == null) { + routerBundles = new SparseArray<>(menuSize); + for (int i = 0; i < menuSize; i++) { + MenuItem menuItem = menu.getItem(i); + int itemId = menuItem.getItemId(); + /* Ensure the first checked item is shown */ + if (menuItem.isChecked()) { + childRouter.setRoot(RouterTransaction.with(BottomNavigationController.getControllerFor( + itemId))); + bottomNavigationView.setSelectedItemId(itemId); + currentlySelectedItemId = bottomNavigationView.getSelectedItemId(); + break; + } + } + } else { + /* + * Since we are restoring our state, + * and onRestoreInstanceState is called before onViewBound, + * all we need to do is rebind. + */ + childRouter.rebindIfNeeded(); + } + + bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + if (currentlySelectedItemId != item.getItemId()) { + saveChildRouter(currentlySelectedItemId); + clearChildRouter(); + + currentlySelectedItemId = item.getItemId(); + Bundle routerBundle = routerBundles.get(currentlySelectedItemId); + if (routerBundle != null && !routerBundle.isEmpty()) { + childRouter.restoreInstanceState(routerBundle); + childRouter.rebindIfNeeded(); + } else { + childRouter.setRoot(RouterTransaction.with(BottomNavigationController.getControllerFor( + currentlySelectedItemId))); + } + return true; + } else { + return false; + } + } + }); + } + + private void saveChildRouter(int itemId) { + Bundle routerBundle = new Bundle(); + childRouter.saveInstanceState(routerBundle); + routerBundles.put(itemId, routerBundle); + } + + /** + * Removes ALL {@link Controller}'s in the child{@link Router}'s backstack + */ + private void clearChildRouter() { + childRouter.setPopsLastView(true); /* Ensure the last view can be removed while we do this */ + childRouter.popToRoot(); + childRouter.popCurrentController(); + childRouter.setPopsLastView(false); + } + + private int getMenuResource() { + return getArgs().getInt(KEY_MENU_RESOURCE); + } + + @Override + protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { + routerBundles = savedInstanceState.getSparseParcelableArray(KEY_STATE_ROUTER_BUNDLES); + currentlySelectedItemId = savedInstanceState.getInt(KEY_STATE_CURRENTLY_SELECTED_ID); + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + saveChildRouter(currentlySelectedItemId); + outState.putSparseParcelableArray(KEY_STATE_ROUTER_BUNDLES, routerBundles); + /* + * For some reason the BottomNavigationView does not seem to correctly restore its + * selectedId, even though the view appears with the correct state. + * So we keep track of it manually + */ + outState.putInt(KEY_STATE_CURRENTLY_SELECTED_ID, currentlySelectedItemId); + } + + @Override + public boolean handleBack() { + /* + * The childRouter should handleBack, + * as this BottomNavigationController doesn't have a back step sensible to the user. + */ + return childRouter.handleBack(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/controllers/CallsListController.java b/app/src/main/java/com/nextcloud/talk/controllers/CallsListController.java new file mode 100644 index 000000000..1c8404a37 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/CallsListController.java @@ -0,0 +1,346 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.controllers; + +import android.app.SearchManager; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.design.widget.BottomNavigationView; +import android.support.v4.view.MenuItemCompat; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; +import android.text.InputType; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.inputmethod.EditorInfo; + +import com.bluelinelabs.conductor.RouterTransaction; +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler; +import com.bluelinelabs.logansquare.LoganSquare; +import com.nextcloud.talk.R; +import com.nextcloud.talk.adapters.items.RoomItem; +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.api.models.json.rooms.Room; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.persistence.entities.UserEntity; +import com.nextcloud.talk.utils.database.cache.CacheUtils; +import com.nextcloud.talk.utils.database.user.UserUtils; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import eu.davidea.flexibleadapter.FlexibleAdapter; +import eu.davidea.flexibleadapter.common.FlexibleItemDecoration; +import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +@AutoInjector(NextcloudTalkApplication.class) +public class CallsListController extends BaseController implements SearchView.OnQueryTextListener { + + public static final String TAG = "CallsListController"; + + private static final String KEY_FROM_RESTORE_VIEW = "CallsListController.fromRestoreView"; + private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery"; + + @Inject + UserUtils userUtils; + + @Inject + CacheUtils cacheUtils; + + @Inject + NcApi ncApi; + @BindView(R.id.recycler_view) + RecyclerView recyclerView; + + @BindView(R.id.swipe_refresh_layout) + SwipeRefreshLayout swipeRefreshLayout; + + private UserEntity userEntity; + private Disposable roomsQueryDisposable; + private Disposable cacheQueryDisposable; + private FlexibleAdapter adapter; + private List roomItems = new ArrayList<>(); + + private boolean isFromRestore; + private String searchQuery; + + private MenuItem searchItem; + private SearchView searchView; + + public CallsListController() { + super(); + setHasOptionsMenu(true); + } + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_generic_rv, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + adapter = new FlexibleAdapter<>(roomItems, getActivity(), false); + prepareRecyclerView(); + + swipeRefreshLayout.setOnRefreshListener(() -> fetchData(true)); + swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.colorPrimary)); + } + + @Override + protected void onAttach(@NonNull View view) { + super.onAttach(view); + + if ((userEntity = userUtils.getCurrentUser()) != null) { + if (!cacheUtils.cacheExistsForContext(TAG) || !isFromRestore) { + fetchData(true); + } else { + fetchData(false); + } + } else { + // Fallback to login if we have no users + if (getParentController().getRouter() != null) { + getParentController().getRouter().setRoot((RouterTransaction.with(new ServerSelectionController()) + .pushChangeHandler(new FadeChangeHandler()) + .popChangeHandler(new FadeChangeHandler()))); + } + } + } + + private void initSearchView() { + if (getActivity() != null) { + SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); + if (searchItem != null) { + searchView = (SearchView) MenuItemCompat.getActionView(searchItem); + searchView.setMaxWidth(Integer.MAX_VALUE); + searchView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER); + searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN); + searchView.setQueryHint(getResources().getString(R.string.nc_search)); + if (searchManager != null) { + searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); + } + searchView.setOnQueryTextListener(this); + } + } + + final View mSearchEditFrame = searchView + .findViewById(android.support.v7.appcompat.R.id.search_edit_frame); + + BottomNavigationView bottomNavigationView = getParentController().getView().findViewById(R.id.navigation); + + Handler handler = new Handler(); + ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + int oldVisibility = -1; + + @Override + public void onGlobalLayout() { + + int currentVisibility = mSearchEditFrame.getVisibility(); + + if (currentVisibility != oldVisibility) { + if (currentVisibility == View.VISIBLE) { + handler.postDelayed(() -> bottomNavigationView.setVisibility(View.GONE), 100); + } else { + handler.postDelayed(() -> { + bottomNavigationView.setVisibility(View.VISIBLE); + searchItem.setVisible(roomItems.size() > 0); + }, 500); + } + + oldVisibility = currentVisibility; + } + + } + }); + + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_filter, menu); + searchItem = menu.findItem(R.id.action_search); + initSearchView(); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + searchItem.setVisible(roomItems.size() > 0); + } + + private void fetchData(boolean forceNew) { + dispose(null); + + roomItems = new ArrayList<>(); + + if (forceNew) { + roomsQueryDisposable = ncApi.getRooms(ApiHelper.getCredentials(userEntity.getUsername(), + userEntity.getToken()), ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl())) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(roomsOverall -> { + + if (roomsOverall != null) { + for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) { + roomItems.add(new RoomItem(roomsOverall.getOcs().getData().get(i), userEntity)); + } + + adapter.updateDataSet(roomItems, true); + if (searchItem != null) { + searchItem.setVisible(roomItems.size() > 0); + } + + cacheQueryDisposable = cacheUtils.createOrUpdateViewCache( + LoganSquare.serialize(roomsOverall.getOcs().getData()), + userEntity.getId(), TAG).subscribe(cacheEntity -> { + // do nothing + }, throwable -> dispose(cacheQueryDisposable), + () -> dispose(cacheQueryDisposable)); + } + }, throwable -> { + if (searchItem != null) { + searchItem.setVisible(false); + } + dispose(roomsQueryDisposable); + } + , () -> { + dispose(roomsQueryDisposable); + swipeRefreshLayout.setRefreshing(false); + }); + } else { + cacheQueryDisposable = cacheUtils.getViewCache(userEntity.getId(), TAG) + .subscribe(o -> { + if (o != null) { + List rooms = LoganSquare.parseList(o.getValue(), Room.class); + for (Room room : rooms) { + roomItems.add(new RoomItem(room, userEntity)); + } + + if (!TextUtils.isEmpty(searchQuery) && searchItem != null && searchView != null) { + searchItem.expandActionView(); + searchView.setQuery(searchQuery, false); + recyclerView.setAdapter(null); + adapter.updateDataSet(roomItems, false); + onQueryTextSubmit(searchQuery); + recyclerView.setAdapter(adapter); + } else { + adapter.updateDataSet(roomItems, true); + if (searchItem != null) { + searchItem.setVisible(roomItems.size() > 0); + } + } + } + }, throwable -> { + if (searchItem != null) { + searchItem.setVisible(false); + } + dispose(cacheQueryDisposable); + }, + () -> dispose(cacheQueryDisposable)); + } + } + + private void prepareRecyclerView() { + recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity())); + recyclerView.setHasFixedSize(true); + recyclerView.setAdapter(adapter); + + recyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) + .withDivider(R.drawable.divider)); + } + + private void dispose(@Nullable Disposable disposable) { + if (disposable != null && !disposable.isDisposed()) { + disposable.dispose(); + } else if (disposable == null) { + + if (roomsQueryDisposable != null && !roomsQueryDisposable.isDisposed()) { + roomsQueryDisposable.dispose(); + roomsQueryDisposable = null; + } + + if (cacheQueryDisposable != null && !cacheQueryDisposable.isDisposed()) { + cacheQueryDisposable.dispose(); + cacheQueryDisposable = null; + } + } + } + + + @Override + public void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { + super.onSaveViewState(view, outState); + outState.putBoolean(KEY_FROM_RESTORE_VIEW, true); + if (searchView != null && !TextUtils.isEmpty(searchView.getQuery())) { + outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString()); + } + } + + @Override + public void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) { + super.onRestoreViewState(view, savedViewState); + isFromRestore = savedViewState.getBoolean(KEY_FROM_RESTORE_VIEW, false); + searchQuery = savedViewState.getString(KEY_SEARCH_QUERY, ""); + } + + @Override + public boolean onQueryTextChange(String newText) { + if (adapter.hasNewSearchText(newText)) { + adapter.setSearchText(newText); + + adapter.filterItems(300); + } + + if (swipeRefreshLayout != null) { + swipeRefreshLayout.setEnabled(!adapter.hasSearchText()); + } + + return true; + } + + @Override + public boolean onQueryTextSubmit(String query) { + return onQueryTextChange(query); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java new file mode 100644 index 000000000..dd695450e --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java @@ -0,0 +1,391 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.controllers; + +import android.app.SearchManager; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.design.widget.BottomNavigationView; +import android.support.v4.view.MenuItemCompat; +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; +import android.text.InputType; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.inputmethod.EditorInfo; + +import com.bluelinelabs.conductor.RouterTransaction; +import com.bluelinelabs.conductor.changehandler.FadeChangeHandler; +import com.bluelinelabs.logansquare.LoganSquare; +import com.nextcloud.talk.R; +import com.nextcloud.talk.adapters.items.UserItem; +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.api.models.RetrofitBucket; +import com.nextcloud.talk.api.models.User; +import com.nextcloud.talk.api.models.json.sharees.Sharee; +import com.nextcloud.talk.api.models.json.sharees.SharesData; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.persistence.entities.UserEntity; +import com.nextcloud.talk.utils.database.cache.CacheUtils; +import com.nextcloud.talk.utils.database.user.UserUtils; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import eu.davidea.flexibleadapter.FlexibleAdapter; +import eu.davidea.flexibleadapter.common.FlexibleItemDecoration; +import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +@AutoInjector(NextcloudTalkApplication.class) +public class ContactsController extends BaseController implements SearchView.OnQueryTextListener { + + public static final String TAG = "ContactsController"; + + private static final String KEY_FROM_RESTORE_VIEW = "ContactsController.fromRestoreView"; + private static final String KEY_SEARCH_QUERY = "ContactsController.searchQuery"; + + @Inject + UserUtils userUtils; + + @Inject + CacheUtils cacheUtils; + + @Inject + NcApi ncApi; + @BindView(R.id.recycler_view) + RecyclerView recyclerView; + + @BindView(R.id.swipe_refresh_layout) + SwipeRefreshLayout swipeRefreshLayout; + + private UserEntity userEntity; + private Disposable contactsQueryDisposable; + private Disposable cacheQueryDisposable; + private FlexibleAdapter adapter; + private List contactItems = new ArrayList<>(); + + private boolean isFromRestore; + private String searchQuery; + + private MenuItem searchItem; + private SearchView searchView; + + public ContactsController() { + super(); + setHasOptionsMenu(true); + } + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_generic_rv, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + adapter = new FlexibleAdapter<>(contactItems, getActivity(), false); + prepareRecyclerView(); + + swipeRefreshLayout.setOnRefreshListener(() -> fetchData(true)); + swipeRefreshLayout.setProgressBackgroundColorSchemeColor(getResources().getColor(R.color.colorPrimary)); + } + + @Override + protected void onAttach(@NonNull View view) { + super.onAttach(view); + + if ((userEntity = userUtils.getCurrentUser()) != null) { + if (!cacheUtils.cacheExistsForContext(TAG) || !isFromRestore) { + fetchData(true); + } else { + fetchData(false); + } + } else { + // Fallback to login if we have no users + if (getParentController().getRouter() != null) { + getParentController().getRouter().setRoot((RouterTransaction.with(new ServerSelectionController()) + .pushChangeHandler(new FadeChangeHandler()) + .popChangeHandler(new FadeChangeHandler()))); + } + } + } + + private void initSearchView() { + if (getActivity() != null) { + SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); + if (searchItem != null) { + searchView = (SearchView) MenuItemCompat.getActionView(searchItem); + searchView.setMaxWidth(Integer.MAX_VALUE); + searchView.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER); + searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_FULLSCREEN); + searchView.setQueryHint(getResources().getString(R.string.nc_search)); + if (searchManager != null) { + searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); + } + searchView.setOnQueryTextListener(this); + } + } + + final View mSearchEditFrame = searchView + .findViewById(android.support.v7.appcompat.R.id.search_edit_frame); + + BottomNavigationView bottomNavigationView = getParentController().getView().findViewById(R.id.navigation); + + Handler handler = new Handler(); + ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver(); + vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + int oldVisibility = -1; + + @Override + public void onGlobalLayout() { + + int currentVisibility = mSearchEditFrame.getVisibility(); + + if (currentVisibility != oldVisibility) { + if (currentVisibility == View.VISIBLE) { + handler.postDelayed(() -> bottomNavigationView.setVisibility(View.GONE), 100); + } else { + handler.postDelayed(() -> { + bottomNavigationView.setVisibility(View.VISIBLE); + searchItem.setVisible(contactItems.size() > 0); + }, 500); + } + + oldVisibility = currentVisibility; + } + + } + }); + + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_filter, menu); + searchItem = menu.findItem(R.id.action_search); + initSearchView(); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + searchItem.setVisible(contactItems.size() > 0); + } + + private void fetchData(boolean forceNew) { + dispose(null); + + Set shareeHashSet = new HashSet<>(); + + contactItems = new ArrayList<>(); + + if (forceNew) { + RetrofitBucket retrofitBucket = ApiHelper.getRetrofitBucketForContactsSearch(userEntity.getBaseUrl(), + ""); + contactsQueryDisposable = ncApi.getContactsWithSearchParam( + ApiHelper.getCredentials(userEntity.getUsername(), userEntity.getToken()), + retrofitBucket.getUrl(), retrofitBucket.getQueryMap()) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(shareesOverall -> { + if (shareesOverall != null) { + + if (shareesOverall.getOcs().getData().getUsers() != null) { + shareeHashSet.addAll(shareesOverall.getOcs().getData().getUsers()); + } + + if (shareesOverall.getOcs().getData().getExactUsers() != null && + shareesOverall.getOcs().getData().getExactUsers().getExactSharees() != null) { + shareeHashSet.addAll(shareesOverall.getOcs().getData(). + getExactUsers().getExactSharees()); + } + + User user; + for (Sharee sharee : shareeHashSet) { + if (!sharee.getValue().getShareWith().equals(userEntity.getUsername())) { + user = new User(); + user.setName(sharee.getLabel()); + user.setUserId(sharee.getValue().getShareWith()); + contactItems.add(new UserItem(user, userEntity)); + } + + } + + adapter.updateDataSet(contactItems, true); + searchItem.setVisible(contactItems.size() > 0); + + cacheQueryDisposable = cacheUtils.createOrUpdateViewCache( + LoganSquare.serialize(shareesOverall.getOcs().getData()), + userEntity.getId(), TAG).subscribe(cacheEntity -> { + // do nothing + }, throwable -> dispose(cacheQueryDisposable), + () -> dispose(cacheQueryDisposable)); + } + + }, throwable -> { + if (searchItem != null) { + searchItem.setVisible(false); + } + dispose(contactsQueryDisposable); + } + , () -> { + swipeRefreshLayout.setRefreshing(false); + dispose(contactsQueryDisposable); + }); + } else { + cacheQueryDisposable = cacheUtils.getViewCache(userEntity.getId(), TAG) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(o -> { + if (o != null) { + SharesData sharesData = LoganSquare.parse(o.getValue(), SharesData.class); + + if (sharesData.getUsers() != null) { + shareeHashSet.addAll(sharesData.getUsers()); + } + + if (sharesData.getExactUsers() != null && sharesData.getExactUsers() + .getExactSharees() != null) { + shareeHashSet.addAll(sharesData.getExactUsers().getExactSharees()); + } + + User user; + for (Sharee sharee : shareeHashSet) { + if (!sharee.getValue().getShareWith().equals(userEntity.getUsername())) { + user = new User(); + user.setName(sharee.getLabel()); + user.setUserId(sharee.getValue().getShareWith()); + contactItems.add(new UserItem(user, userEntity)); + } + + } + + if (!TextUtils.isEmpty(searchQuery) && searchItem != null && searchView != null) { + searchItem.expandActionView(); + searchView.setQuery(searchQuery, false); + recyclerView.setAdapter(null); + adapter.updateDataSet(contactItems, false); + onQueryTextSubmit(searchQuery); + recyclerView.setAdapter(adapter); + } else { + adapter.updateDataSet(contactItems, true); + searchItem.setVisible(contactItems.size() > 0); + } + + } + }, throwable -> { + dispose(cacheQueryDisposable); + if (searchItem != null) { + searchItem.setVisible(false); + } + }, + () -> { + dispose(cacheQueryDisposable); + }); + } + } + + private void prepareRecyclerView() { + recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(getActivity())); + recyclerView.setHasFixedSize(true); + recyclerView.setAdapter(adapter); + + recyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity()) + .withDivider(R.drawable.divider)); + } + + private void dispose(@Nullable Disposable disposable) { + if (disposable != null && !disposable.isDisposed()) { + disposable.dispose(); + } else if (disposable == null) { + + if (contactsQueryDisposable != null && !contactsQueryDisposable.isDisposed()) { + contactsQueryDisposable.dispose(); + contactsQueryDisposable = null; + } + + if (cacheQueryDisposable != null && !cacheQueryDisposable.isDisposed()) { + cacheQueryDisposable.dispose(); + cacheQueryDisposable = null; + } + } + } + + @Override + public void onSaveViewState(@NonNull View view, @NonNull Bundle outState) { + super.onSaveViewState(view, outState); + outState.putBoolean(KEY_FROM_RESTORE_VIEW, true); + if (searchView != null && !TextUtils.isEmpty(searchView.getQuery())) { + outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString()); + } + } + + @Override + public void onRestoreViewState(@NonNull View view, @NonNull Bundle savedViewState) { + super.onRestoreViewState(view, savedViewState); + isFromRestore = savedViewState.getBoolean(KEY_FROM_RESTORE_VIEW, false); + searchQuery = savedViewState.getString(KEY_SEARCH_QUERY, ""); + } + + @Override + public boolean onQueryTextChange(String newText) { + if (adapter.hasNewSearchText(newText)) { + adapter.setSearchText(newText); + + adapter.filterItems(300); + } + + if (swipeRefreshLayout != null) { + swipeRefreshLayout.setEnabled(!adapter.hasSearchText()); + } + + return true; + } + + @Override + public boolean onQueryTextSubmit(String query) { + return onQueryTextChange(query); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java new file mode 100644 index 000000000..e7c21adf8 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/ServerSelectionController.java @@ -0,0 +1,165 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.controllers; + +import android.content.pm.ActivityInfo; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; + +import com.bluelinelabs.conductor.RouterTransaction; +import com.nextcloud.talk.R; +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; +import studio.carbonylgroup.textfieldboxes.ExtendedEditText; +import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; + +@AutoInjector(NextcloudTalkApplication.class) +public class ServerSelectionController extends BaseController { + + public static final String TAG = "ServerSelectionController"; + + @BindView(R.id.extended_edit_text) + ExtendedEditText serverEntry; + @BindView(R.id.text_field_boxes) + TextFieldBoxes textFieldBoxes; + + @Inject + NcApi ncApi; + + private Disposable statusQueryDisposable; + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_server_selection, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + + textFieldBoxes.setLabelText(getResources().getString(R.string.nc_app_name) + " " + getResources().getString(R.string.nc_appended_server_url)); + + serverEntry.requestFocus(); + + serverEntry.setOnEditorActionListener((textView, i, keyEvent) -> { + if (i == EditorInfo.IME_ACTION_DONE) { + dispose(); + + String url = serverEntry.getText().toString().trim(); + + if (url.startsWith("http://") || url.startsWith("https://")) { + serverEntry.setEnabled(false); + + if (url.endsWith("/")) { + url = url.substring(0, url.length() - 1); + } + + String queryUrl = url + ApiHelper.getUrlPostfixForStatus(); + final String finalServerUrl = url; + + statusQueryDisposable = ncApi.getServerStatus(queryUrl) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(status -> { + String productName = getResources().getString(R.string.nc_server_product_name); + + if (status.isInstalled() && !status.isMaintenance() && + !status.isNeedsUpgrade() && + status.getProductName().equals( + getResources().getString(R.string.nc_server_product_name))) { + + getRouter().pushController(RouterTransaction.with( + new WebViewLoginController(finalServerUrl))); + } else if (!status.isInstalled()) { + textFieldBoxes.setError(String.format( + getResources().getString(R.string.nc_server_not_installed), productName), + true); + } else if (status.isNeedsUpgrade()) { + textFieldBoxes.setError(String.format(getResources(). + getString(R.string.nc_server_db_upgrade_needed), productName), true); + } else if (status.isMaintenance()) { + textFieldBoxes.setError(String.format(getResources(). + getString(R.string.nc_server_maintenance), productName), + true); + } else if (!status.getProductName().equals( + getResources().getString(R.string.nc_server_product_name))) { + textFieldBoxes.setError(String.format(getResources(). + getString(R.string.nc_server_not_nc), + getResources().getString(R.string.nc_app_name) + , productName), true); + } + + }, throwable -> { + textFieldBoxes.setError(throwable.getLocalizedMessage(), true); + if (serverEntry != null) { + serverEntry.setEnabled(true); + } + dispose(); + + }, this::dispose); + } else { + textFieldBoxes.setError(getResources().getString(R.string.nc_server_url_prefix), true); + serverEntry.setEnabled(true); + return true; + } + + } + + return false; + }); + } + + @Override + protected void onDestroyView(@NonNull View view) { + super.onDestroyView(view); + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); + } + } + + private void dispose() { + if (statusQueryDisposable != null && !statusQueryDisposable.isDisposed()) { + statusQueryDisposable.dispose(); + } + + statusQueryDisposable = null; + } + + +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java new file mode 100644 index 000000000..b69bb742f --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java @@ -0,0 +1,43 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.controllers; + +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.nextcloud.talk.R; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; + +import autodagger.AutoInjector; + +@AutoInjector(NextcloudTalkApplication.class) +public class SettingsController extends BaseController { + + public static final String TAG = "SettingsController"; + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_settings, container, false); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java new file mode 100644 index 000000000..d8a0fcaeb --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java @@ -0,0 +1,222 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.controllers; + +import android.content.pm.ActivityInfo; +import android.net.http.SslError; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.SslErrorHandler; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import com.bluelinelabs.conductor.RouterTransaction; +import com.nextcloud.talk.R; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.controllers.base.BaseController; +import com.nextcloud.talk.models.LoginData; +import com.nextcloud.talk.utils.BundleBuilder; +import com.nextcloud.talk.utils.BundleKeys; +import com.nextcloud.talk.utils.database.user.UserUtils; + +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import butterknife.BindView; +import io.reactivex.disposables.Disposable; +import io.requery.Persistable; +import io.requery.reactivex.ReactiveEntityStore; + +@AutoInjector(NextcloudTalkApplication.class) +public class WebViewLoginController extends BaseController { + + public static final String TAG = "WebViewLoginController"; + + private final String PROTOCOL_SUFFIX = "://"; + private final String LOGIN_URL_DATA_KEY_VALUE_SEPARATOR = ":"; + + @Inject + UserUtils userUtils; + @Inject + ReactiveEntityStore dataStore; + + @BindView(R.id.webview) + WebView webView; + + private String assembledPrefix; + + private Disposable userQueryDisposable; + + private String baseUrl; + + public WebViewLoginController(String baseUrl) { + this.baseUrl = baseUrl; + } + + public WebViewLoginController(Bundle args) { + super(args); + } + + @Override + protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + return inflater.inflate(R.layout.controller_web_view_login, container, false); + } + + @Override + protected void onViewBound(@NonNull View view) { + super.onViewBound(view); + NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this); + + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + } + + assembledPrefix = getResources().getString(R.string.nc_talk_login_scheme) + PROTOCOL_SUFFIX + "login/"; + + webView.getSettings().setAllowFileAccess(false); + webView.getSettings().setAllowFileAccessFromFileURLs(false); + webView.getSettings().setJavaScriptEnabled(true); + webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false); + webView.getSettings().setDomStorageEnabled(true); + webView.getSettings().setUserAgentString(ApiHelper.getUserAgent()); + webView.getSettings().setSaveFormData(false); + webView.getSettings().setSavePassword(false); + webView.clearCache(true); + webView.clearFormData(); + + Map headers = new HashMap<>(); + headers.put("OCS-APIRequest", "true"); + + webView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + if (url.startsWith(assembledPrefix)) { + parseAndLoginFromWebView(url); + return true; + } + return false; + } + + @Override + public void onPageFinished(WebView view, String url) { + super.onPageFinished(view, url); + + } + + @Override + public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { + super.onReceivedSslError(view, handler, error); + } + + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + super.onReceivedError(view, errorCode, description, failingUrl); + } + }); + + webView.loadUrl(baseUrl + "/index.php/login/flow", headers); + } + + + private void dispose() { + if (userQueryDisposable != null && !userQueryDisposable.isDisposed()) { + userQueryDisposable.dispose(); + } + + userQueryDisposable = null; + } + + private void parseAndLoginFromWebView(String dataString) { + LoginData loginData = parseLoginData(assembledPrefix, dataString); + + if (loginData != null) { + dispose(); + + // We use the URL user entered because one provided by the server is NOT reliable + userQueryDisposable = userUtils.createOrUpdateUser(loginData.getUsername(), loginData.getToken(), + baseUrl, null).subscribe(userEntity -> { + BundleBuilder bundleBuilder = new BundleBuilder(new Bundle()); + bundleBuilder.putString(BundleKeys.KEY_USERNAME, userEntity.getUsername()); + bundleBuilder.putString(BundleKeys.KEY_TOKEN, userEntity.getToken()); + bundleBuilder.putString(BundleKeys.KEY_BASE_URL, userEntity.getBaseUrl()); + getRouter().pushController(RouterTransaction.with(new AccountVerificationController + (bundleBuilder.build()))); + }, throwable -> dispose(), + this::dispose); + } + } + + private LoginData parseLoginData(String prefix, String dataString) { + if (dataString.length() < prefix.length()) { + return null; + } + + LoginData loginData = new LoginData(); + + // format is xxx://login/server:xxx&user:xxx&password:xxx + String data = dataString.substring(prefix.length()); + + String[] values = data.split("&"); + + if (values.length != 3) { + return null; + } + + for (String value : values) { + if (value.startsWith("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) { + loginData.setUsername(URLDecoder.decode( + value.substring(("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()))); + } else if (value.startsWith("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) { + loginData.setToken(URLDecoder.decode( + value.substring(("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()))); + } else if (value.startsWith("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) { + loginData.setServerUrl(URLDecoder.decode( + value.substring(("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length()))); + } else { + return null; + } + } + + if (!TextUtils.isEmpty(loginData.getServerUrl()) && !TextUtils.isEmpty(loginData.getUsername()) && + !TextUtils.isEmpty(loginData.getToken())) { + return loginData; + } else { + return null; + } + } + + @Override + protected void onDestroyView(@NonNull View view) { + super.onDestroyView(view); + if (getActivity() != null) { + getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR); + } + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java new file mode 100644 index 000000000..c2864b8b3 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/BaseController.java @@ -0,0 +1,70 @@ +/** + * Nextcloud Talk application + * + * @author BlueLine Labs, Inc. + * Copyright (C) 2016 BlueLine Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.nextcloud.talk.controllers.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.ActionBar; +import android.view.View; + +import com.bluelinelabs.conductor.Controller; +import com.nextcloud.talk.controllers.base.providers.ActionBarProvider; + +public abstract class BaseController extends RefWatchingController { + + protected BaseController() { + } + + protected BaseController(Bundle args) { + super(args); + } + + // Note: This is just a quick demo of how an ActionBar *can* be accessed, not necessarily how it *should* + // be accessed. In a production app, this would use Dagger instead. + protected ActionBar getActionBar() { + ActionBarProvider actionBarProvider = ((ActionBarProvider) getActivity()); + return actionBarProvider != null ? actionBarProvider.getSupportActionBar() : null; + } + + @Override + protected void onAttach(@NonNull View view) { + setTitle(); + super.onAttach(view); + } + + protected void setTitle() { + Controller parentController = getParentController(); + while (parentController != null) { + if (parentController instanceof BaseController && ((BaseController) parentController).getTitle() != null) { + return; + } + parentController = parentController.getParentController(); + } + + String title = getTitle(); + ActionBar actionBar = getActionBar(); + if (title != null && actionBar != null) { + actionBar.setTitle(title); + } + } + + protected String getTitle() { + return null; + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/ButterKnifeController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/ButterKnifeController.java new file mode 100644 index 000000000..f7a67e385 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/ButterKnifeController.java @@ -0,0 +1,64 @@ +/** + * Nextcloud Talk application + * + * @author BlueLine Labs, Inc. + * Copyright (C) 2016 BlueLine Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.nextcloud.talk.controllers.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.bluelinelabs.conductor.Controller; + +import butterknife.ButterKnife; +import butterknife.Unbinder; + +public abstract class ButterKnifeController extends Controller { + + private Unbinder unbinder; + + protected ButterKnifeController() { + } + + protected ButterKnifeController(Bundle args) { + super(args); + } + + protected abstract View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container); + + @NonNull + @Override + protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) { + View view = inflateView(inflater, container); + unbinder = ButterKnife.bind(this, view); + onViewBound(view); + return view; + } + + protected void onViewBound(@NonNull View view) { + } + + @Override + protected void onDestroyView(@NonNull View view) { + super.onDestroyView(view); + unbinder.unbind(); + unbinder = null; + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/RefWatchingController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/RefWatchingController.java new file mode 100644 index 000000000..6b7421da6 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/RefWatchingController.java @@ -0,0 +1,57 @@ +/** + * Nextcloud Talk application + * + * @author BlueLine Labs, Inc. + * Copyright (C) 2016 BlueLine Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.nextcloud.talk.controllers.base; + +import android.os.Bundle; +import android.support.annotation.NonNull; + +import com.bluelinelabs.conductor.ControllerChangeHandler; +import com.bluelinelabs.conductor.ControllerChangeType; +import com.nextcloud.talk.application.NextcloudTalkApplication; + +public abstract class RefWatchingController extends ButterKnifeController { + + private boolean hasExited; + + protected RefWatchingController() { + } + + protected RefWatchingController(Bundle args) { + super(args); + } + + @Override + public void onDestroy() { + super.onDestroy(); + + if (hasExited) { + NextcloudTalkApplication.refWatcher.watch(this); + } + } + + @Override + protected void onChangeEnded(@NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) { + super.onChangeEnded(changeHandler, changeType); + + hasExited = !changeType.isEnter; + if (isDestroyed()) { + NextcloudTalkApplication.refWatcher.watch(this); + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/providers/ActionBarProvider.java b/app/src/main/java/com/nextcloud/talk/controllers/base/providers/ActionBarProvider.java new file mode 100644 index 000000000..b98351eb1 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/providers/ActionBarProvider.java @@ -0,0 +1,25 @@ +/* + * Nextcloud Talk application + * + * @author BlueLine Labs, Inc. + * Copyright (C) 2016 BlueLine Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.nextcloud.talk.controllers.base.providers; + +import android.support.v7.app.ActionBar; + +public interface ActionBarProvider { + ActionBar getSupportActionBar(); +} diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/BusModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/BusModule.java new file mode 100644 index 000000000..86bda87c0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/BusModule.java @@ -0,0 +1,38 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.dagger.modules; + +import org.greenrobot.eventbus.EventBus; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; + +@Module +public class BusModule { + + @Provides + @Singleton + public EventBus provideEventBus() { + return EventBus.getDefault(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/ContextModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/ContextModule.java new file mode 100644 index 000000000..bfa115ba0 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/ContextModule.java @@ -0,0 +1,41 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.dagger.modules; + +import android.content.Context; +import android.support.annotation.NonNull; + +import dagger.Module; +import dagger.Provides; + +@Module +public class ContextModule { + private final Context context; + + public ContextModule(@NonNull final Context context) { + this.context = context; + } + + @Provides + public Context provideContext() { + return context; + } +} diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java new file mode 100644 index 000000000..e859bfe60 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/DatabaseModule.java @@ -0,0 +1,64 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.dagger.modules; + +import android.content.Context; +import android.support.annotation.NonNull; + +import com.nextcloud.talk.R; +import com.nextcloud.talk.persistence.entities.Models; + +import net.orange_box.storebox.StoreBox; + +import java.util.prefs.Preferences; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import io.requery.Persistable; +import io.requery.android.sqlcipher.SqlCipherDatabaseSource; +import io.requery.reactivex.ReactiveEntityStore; +import io.requery.reactivex.ReactiveSupport; +import io.requery.sql.Configuration; +import io.requery.sql.EntityDataStore; + +@Module +public class DatabaseModule { + + @Provides + @Singleton + public ReactiveEntityStore provideDataStore(@NonNull final Context context) { + + final SqlCipherDatabaseSource source = new SqlCipherDatabaseSource(context, Models.DEFAULT, + context.getResources().getString(R.string.nc_app_name).toLowerCase() + .replace(" ", "_").trim() + ".sqlite", + context.getString(R.string.nc_talk_database_encryption_key), 1); + final Configuration configuration = source.getConfiguration(); + return ReactiveSupport.toReactiveStore(new EntityDataStore(configuration)); + } + + @Provides + @Singleton + public Preferences providePreferences(@NonNull final Context poContext) { + return StoreBox.create(poContext, Preferences.class); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java new file mode 100644 index 000000000..2a1dcd8c8 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/dagger/modules/RestModule.java @@ -0,0 +1,104 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.dagger.modules; + +import android.support.annotation.NonNull; + +import com.github.aurae.retrofit2.LoganSquareConverterFactory; +import com.nextcloud.talk.BuildConfig; +import com.nextcloud.talk.api.NcApi; +import com.nextcloud.talk.api.helpers.api.ApiHelper; +import com.nextcloud.talk.application.NextcloudTalkApplication; + +import java.io.IOException; + +import javax.inject.Singleton; + +import dagger.Module; +import dagger.Provides; +import io.reactivex.schedulers.Schedulers; +import okhttp3.Cache; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.logging.HttpLoggingInterceptor; +import retrofit2.Retrofit; +import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; + +@Module +public class RestModule { + + @Provides + @Singleton + NcApi provideNcApi(Retrofit retrofit) { + return retrofit.create(NcApi.class); + } + + @Provides + @Singleton + Retrofit provideRetrofit(OkHttpClient httpClient) { + Retrofit.Builder retrofitBuilder = new Retrofit.Builder() + .client(httpClient) + .baseUrl("https://nextcloud.com") + .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) + .addConverterFactory(LoganSquareConverterFactory.create()); + + return retrofitBuilder.build(); + } + + @Provides + @Singleton + OkHttpClient provideHttpClient() { + OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); + + int cacheSize = 128 * 1024 * 1024; // 128 MB + + httpClient.cache(new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize)); + + if (BuildConfig.DEBUG) { + HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); + loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); + + httpClient.addInterceptor(loggingInterceptor); + } + httpClient.addInterceptor(new HeadersInterceptor()); + + return httpClient.build(); + } + + private class HeadersInterceptor implements Interceptor { + + @Override + public Response intercept(@NonNull Chain chain) throws IOException { + Request original = chain.request(); + + Request request = original.newBuilder() + .header("User-Agent", ApiHelper.getUserAgent()) + .header("Accept", "application/json") + .header("OCS-APIRequest", "true") + .method(original.method(), original.body()) + .build(); + + return chain.proceed(request); + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/models/LoginData.java b/app/src/main/java/com/nextcloud/talk/models/LoginData.java new file mode 100644 index 000000000..c9b90b9ac --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/LoginData.java @@ -0,0 +1,33 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.models; + +import org.parceler.Parcel; + +import lombok.Data; + +@Parcel +@Data +public class LoginData { + String serverUrl; + String username; + String token; +} diff --git a/app/src/main/java/com/nextcloud/talk/persistence/entities/Cache.java b/app/src/main/java/com/nextcloud/talk/persistence/entities/Cache.java new file mode 100644 index 000000000..ac2a7d993 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/persistence/entities/Cache.java @@ -0,0 +1,43 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.persistence.entities; + +import android.os.Parcelable; + +import java.io.Serializable; + +import io.requery.Entity; +import io.requery.Generated; +import io.requery.Key; +import io.requery.Persistable; + +@Entity +public interface Cache extends Parcelable, Persistable, Serializable { + @Key + @Generated + long getId(); + + String getKey(); + + String getValue(); + + Long getUserId(); +} diff --git a/app/src/main/java/com/nextcloud/talk/persistence/entities/User.java b/app/src/main/java/com/nextcloud/talk/persistence/entities/User.java new file mode 100644 index 000000000..51b92e786 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/persistence/entities/User.java @@ -0,0 +1,45 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.persistence.entities; + +import android.os.Parcelable; + +import java.io.Serializable; + +import io.requery.Entity; +import io.requery.Generated; +import io.requery.Key; +import io.requery.Persistable; + +@Entity +public interface User extends Parcelable, Persistable, Serializable { + @Key + @Generated + long getId(); + + String getUsername(); + + String getBaseUrl(); + + String getToken(); + + String getDisplayName(); +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/BundleBuilder.java b/app/src/main/java/com/nextcloud/talk/utils/BundleBuilder.java new file mode 100644 index 000000000..f1fea96f7 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/BundleBuilder.java @@ -0,0 +1,190 @@ +/* + * Nextcloud Talk application + * + * @author BlueLine Labs, Inc. + * Copyright (C) 2016 BlueLine Labs, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.nextcloud.talk.utils; + +import android.os.Bundle; +import android.os.Parcelable; +import android.util.SparseArray; + +import java.io.Serializable; +import java.util.ArrayList; + +public class BundleBuilder { + + private final Bundle bundle; + + public BundleBuilder(Bundle bundle) { + this.bundle = bundle; + } + + public BundleBuilder putAll(Bundle bundle) { + this.bundle.putAll(bundle); + return this; + } + + public BundleBuilder putBoolean(String key, boolean value) { + bundle.putBoolean(key, value); + return this; + } + + public BundleBuilder putBooleanArray(String key, boolean[] value) { + bundle.putBooleanArray(key, value); + return this; + } + + public BundleBuilder putDouble(String key, double value) { + bundle.putDouble(key, value); + return this; + } + + public BundleBuilder putDoubleArray(String key, double[] value) { + bundle.putDoubleArray(key, value); + return this; + } + + public BundleBuilder putLong(String key, long value) { + bundle.putLong(key, value); + return this; + } + + public BundleBuilder putLongArray(String key, long[] value) { + bundle.putLongArray(key, value); + return this; + } + + public BundleBuilder putString(String key, String value) { + bundle.putString(key, value); + return this; + } + + public BundleBuilder putStringArray(String key, String[] value) { + bundle.putStringArray(key, value); + return this; + } + + public BundleBuilder putBundle(String key, Bundle value) { + bundle.putBundle(key, value); + return this; + } + + public BundleBuilder putByte(String key, byte value) { + bundle.putByte(key, value); + return this; + } + + public BundleBuilder putByteArray(String key, byte[] value) { + bundle.putByteArray(key, value); + return this; + } + + public BundleBuilder putChar(String key, char value) { + bundle.putChar(key, value); + return this; + } + + public BundleBuilder putCharArray(String key, char[] value) { + bundle.putCharArray(key, value); + return this; + } + + public BundleBuilder putCharSequence(String key, CharSequence value) { + bundle.putCharSequence(key, value); + return this; + } + + public BundleBuilder putCharSequenceArray(String key, CharSequence[] value) { + bundle.putCharSequenceArray(key, value); + return this; + } + + public BundleBuilder putCharSequenceArrayList(String key, ArrayList value) { + bundle.putCharSequenceArrayList(key, value); + return this; + } + + public BundleBuilder putInt(String key, int value) { + bundle.putInt(key, value); + return this; + } + + public BundleBuilder putIntArray(String key, int[] value) { + bundle.putIntArray(key, value); + return this; + } + + public BundleBuilder putFloat(String key, float value) { + bundle.putFloat(key, value); + return this; + } + + public BundleBuilder putFloatArray(String key, float[] value) { + bundle.putFloatArray(key, value); + return this; + } + + public BundleBuilder putIntegerArrayList(String key, ArrayList value) { + bundle.putIntegerArrayList(key, value); + return this; + } + + public BundleBuilder putParcelable(String key, Parcelable value) { + bundle.putParcelable(key, value); + return this; + } + + public BundleBuilder putParcelableArray(String key, Parcelable[] value) { + bundle.putParcelableArray(key, value); + return this; + } + + public BundleBuilder putParcelableArrayList(String key, ArrayList value) { + bundle.putParcelableArrayList(key, value); + return this; + } + + public BundleBuilder putSerializable(String key, Serializable value) { + bundle.putSerializable(key, value); + return this; + } + + public BundleBuilder putShort(String key, short value) { + bundle.putShort(key, value); + return this; + } + + public BundleBuilder putShortArray(String key, short[] value) { + bundle.putShortArray(key, value); + return this; + } + + public BundleBuilder putSparseParcelableArray(String key, SparseArray value) { + bundle.putSparseParcelableArray(key, value); + return this; + } + + public BundleBuilder putStringArrayList(String key, ArrayList value) { + bundle.putStringArrayList(key, value); + return this; + } + + public Bundle build() { + return bundle; + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/BundleKeys.java b/app/src/main/java/com/nextcloud/talk/utils/BundleKeys.java new file mode 100644 index 000000000..5d9c984f8 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/BundleKeys.java @@ -0,0 +1,28 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.utils; + +public class BundleKeys { + public static final String KEY_USERNAME = "KEY_USERNAME"; + public static final String KEY_TOKEN = "KEY_TOKEN"; + public static final String KEY_BASE_URL = "KEY_BASE_URL"; + +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/CachingGlideModule.java b/app/src/main/java/com/nextcloud/talk/utils/CachingGlideModule.java new file mode 100644 index 000000000..85f3fa0fb --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/CachingGlideModule.java @@ -0,0 +1,60 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.utils; + + +import android.content.Context; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.GlideBuilder; +import com.bumptech.glide.Registry; +import com.bumptech.glide.annotation.GlideModule; +import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader; +import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; +import com.bumptech.glide.load.model.GlideUrl; +import com.bumptech.glide.module.AppGlideModule; +import com.nextcloud.talk.application.NextcloudTalkApplication; + +import java.io.InputStream; + +import okhttp3.Cache; +import okhttp3.OkHttpClient; + +@GlideModule +public class CachingGlideModule extends AppGlideModule { + // 128 MB + private static final int OK_HTTP_CLIENT_CACHE = 128 * 1024 * 1024; + // 256 MB + private static final int IMAGE_CACHE_SIZE = 256 * 1024 * 1024; + + @Override + public void registerComponents(Context context, Glide glide, Registry registry) { + OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); + httpClient.cache(new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), + OK_HTTP_CLIENT_CACHE)); + registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(httpClient.build())); + } + + @Override + public void applyOptions(Context context, GlideBuilder builder) { + builder.setDiskCache(new InternalCacheDiskCacheFactory(context, IMAGE_CACHE_SIZE)); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java new file mode 100644 index 000000000..08ccfeed4 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java @@ -0,0 +1,25 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.utils; + +public class ColorUtils { + public static String colorSeed = "ballast butte permute doxy graham rummage grateful songbook pledge escapade"; +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheModule.java b/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheModule.java new file mode 100644 index 000000000..efb6bcd07 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheModule.java @@ -0,0 +1,47 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.utils.database.cache; + +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.dagger.modules.DatabaseModule; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import dagger.Module; +import dagger.Provides; +import io.requery.Persistable; +import io.requery.reactivex.ReactiveEntityStore; + +@Module(includes = DatabaseModule.class) +@AutoInjector(NextcloudTalkApplication.class) +public class CacheModule { + + @Inject + public CacheModule() { + } + + @Provides + public CacheUtils provideCacheUtils(ReactiveEntityStore dataStore) { + return new CacheUtils(dataStore); + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheUtils.java b/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheUtils.java new file mode 100644 index 000000000..be22b6a45 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/cache/CacheUtils.java @@ -0,0 +1,72 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils.database.cache; + +import com.nextcloud.talk.persistence.entities.Cache; +import com.nextcloud.talk.persistence.entities.CacheEntity; + +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; +import io.requery.Persistable; +import io.requery.query.Result; +import io.requery.reactivex.ReactiveEntityStore; + +public class CacheUtils { + private ReactiveEntityStore dataStore; + + CacheUtils(ReactiveEntityStore dataStore) { + this.dataStore = dataStore; + + } + + public boolean cacheExistsForContext(String context) { + return (dataStore.count(Cache.class).where(CacheEntity.KEY.eq(context)).limit(1).get().value() > 0); + } + + public Observable getViewCache(Long userId, String context) { + return dataStore.select(CacheEntity.class).where(CacheEntity.KEY.eq(context). + and(CacheEntity.USER_ID.eq(userId))).limit(1).get().observable() + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()); + } + + public Observable createOrUpdateViewCache(String cache, Long userId, String context) { + Result findUserQueryResult = dataStore.select(CacheEntity.class).where(CacheEntity.KEY.eq(context). + and(CacheEntity.USER_ID.eq(userId))).limit(1).get(); + + CacheEntity cacheEntity = (CacheEntity) findUserQueryResult.firstOrNull(); + + if (cacheEntity == null) { + cacheEntity = new CacheEntity(); + cacheEntity.setKey(context); + cacheEntity.setUserId(userId); + cacheEntity.setValue(cache); + } else { + cacheEntity.setValue(cache); + } + + return dataStore.upsert(cacheEntity) + .toObservable() + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()); + } + +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/user/UserModule.java b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserModule.java new file mode 100644 index 000000000..db450c3ba --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserModule.java @@ -0,0 +1,45 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils.database.user; + +import com.nextcloud.talk.application.NextcloudTalkApplication; +import com.nextcloud.talk.dagger.modules.DatabaseModule; + +import javax.inject.Inject; + +import autodagger.AutoInjector; +import dagger.Module; +import dagger.Provides; +import io.requery.Persistable; +import io.requery.reactivex.ReactiveEntityStore; + +@Module(includes = DatabaseModule.class) +@AutoInjector(NextcloudTalkApplication.class) +public class UserModule { + + @Inject + public UserModule() { + } + + @Provides + public UserUtils provideUserUtils(ReactiveEntityStore dataStore) { + return new UserUtils(dataStore); + } +} diff --git a/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java new file mode 100644 index 000000000..8e9b00226 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java @@ -0,0 +1,101 @@ +/* + * + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.nextcloud.talk.utils.database.user; + +import android.support.annotation.Nullable; +import android.text.TextUtils; + +import com.nextcloud.talk.persistence.entities.User; +import com.nextcloud.talk.persistence.entities.UserEntity; + +import io.reactivex.Completable; +import io.reactivex.Observable; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.schedulers.Schedulers; +import io.requery.Persistable; +import io.requery.query.Result; +import io.requery.reactivex.ReactiveEntityStore; + +public class UserUtils { + private ReactiveEntityStore dataStore; + + UserUtils(ReactiveEntityStore dataStore) { + this.dataStore = dataStore; + + } + + public boolean anyUserExists() { + return (dataStore.count(User.class).limit(1).get().value() > 0); + } + + // temporary method while we only support 1 user + public UserEntity getCurrentUser() { + Result findUserQueryResult = dataStore.select(User.class).limit(1).get(); + + return (UserEntity) findUserQueryResult.firstOrNull(); + } + + public Completable deleteUser(String username, String serverUrl) { + Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username). + and(UserEntity.BASE_URL.eq(serverUrl.toLowerCase()))).limit(1).get(); + + UserEntity user = (UserEntity) findUserQueryResult.firstOrNull(); + + return dataStore.delete(user) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()); + + } + + public Observable createOrUpdateUser(String username, String token, String serverUrl, + @Nullable String displayName) { + Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username). + and(UserEntity.BASE_URL.eq(serverUrl.toLowerCase()))).limit(1).get(); + + UserEntity user = (UserEntity) findUserQueryResult.firstOrNull(); + + if (user == null) { + user = new UserEntity(); + user.setBaseUrl(serverUrl); + user.setUsername(username); + user.setToken(token); + + if (!TextUtils.isEmpty(displayName)) { + user.setDisplayName(displayName); + } + + } else { + if (!token.equals(user.getToken())) { + user.setToken(token); + } + + if (!TextUtils.isEmpty(displayName) && !displayName.equals(user.getDisplayName())) { + user.setDisplayName(displayName); + } + } + + return dataStore.upsert(user) + .toObservable() + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()); + } + +} diff --git a/app/src/main/res/drawable/divider.xml b/app/src/main/res/drawable/divider.xml new file mode 100644 index 000000000..0d9702995 --- /dev/null +++ b/app/src/main/res/drawable/divider.xml @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_call_black_24dp.xml b/app/src/main/res/drawable/ic_call_black_24dp.xml new file mode 100644 index 000000000..3dd2ef2d7 --- /dev/null +++ b/app/src/main/res/drawable/ic_call_black_24dp.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_group_black_24dp.xml b/app/src/main/res/drawable/ic_group_black_24dp.xml new file mode 100644 index 000000000..4cfd86960 --- /dev/null +++ b/app/src/main/res/drawable/ic_group_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..e499363b7 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_person_black_24dp.xml b/app/src/main/res/drawable/ic_person_black_24dp.xml new file mode 100644 index 000000000..f75b5e7a3 --- /dev/null +++ b/app/src/main/res/drawable/ic_person_black_24dp.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_public_black_24dp.xml b/app/src/main/res/drawable/ic_public_black_24dp.xml new file mode 100644 index 000000000..d976b4244 --- /dev/null +++ b/app/src/main/res/drawable/ic_public_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_search_white_24dp.xml b/app/src/main/res/drawable/ic_search_white_24dp.xml new file mode 100644 index 000000000..a23fcd1be --- /dev/null +++ b/app/src/main/res/drawable/ic_search_white_24dp.xml @@ -0,0 +1,36 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_settings_black_24dp.xml b/app/src/main/res/drawable/ic_settings_black_24dp.xml new file mode 100644 index 000000000..b1ed64c70 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_black_24dp.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_voice_chat_black_24dp.xml b/app/src/main/res/drawable/ic_voice_chat_black_24dp.xml new file mode 100644 index 000000000..9f9dcb8bd --- /dev/null +++ b/app/src/main/res/drawable/ic_voice_chat_black_24dp.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..ef10ae505 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/layout/controller_account_verification.xml b/app/src/main/res/layout/controller_account_verification.xml new file mode 100644 index 000000000..5e2cf1ddb --- /dev/null +++ b/app/src/main/res/layout/controller_account_verification.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/controller_bottom_navigation.xml b/app/src/main/res/layout/controller_bottom_navigation.xml new file mode 100644 index 000000000..d262a422d --- /dev/null +++ b/app/src/main/res/layout/controller_bottom_navigation.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/controller_generic_rv.xml b/app/src/main/res/layout/controller_generic_rv.xml new file mode 100644 index 000000000..11a67ce51 --- /dev/null +++ b/app/src/main/res/layout/controller_generic_rv.xml @@ -0,0 +1,34 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/controller_server_selection.xml b/app/src/main/res/layout/controller_server_selection.xml new file mode 100644 index 000000000..1d0459d5a --- /dev/null +++ b/app/src/main/res/layout/controller_server_selection.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/controller_settings.xml b/app/src/main/res/layout/controller_settings.xml new file mode 100644 index 000000000..5a15ddc13 --- /dev/null +++ b/app/src/main/res/layout/controller_settings.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/controller_web_view_login.xml b/app/src/main/res/layout/controller_web_view_login.xml new file mode 100644 index 000000000..9d012a362 --- /dev/null +++ b/app/src/main/res/layout/controller_web_view_login.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/rv_item_call.xml b/app/src/main/res/layout/rv_item_call.xml new file mode 100644 index 000000000..e7db1307f --- /dev/null +++ b/app/src/main/res/layout/rv_item_call.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/rv_item_contact.xml b/app/src/main/res/layout/rv_item_contact.xml new file mode 100644 index 000000000..3e928f0bf --- /dev/null +++ b/app/src/main/res/layout/rv_item_contact.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_filter.xml b/app/src/main/res/menu/menu_filter.xml new file mode 100644 index 000000000..5253447f4 --- /dev/null +++ b/app/src/main/res/menu/menu_filter.xml @@ -0,0 +1,33 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_navigation.xml b/app/src/main/res/menu/menu_navigation.xml new file mode 100644 index 000000000..7af46c15c --- /dev/null +++ b/app/src/main/res/menu/menu_navigation.xml @@ -0,0 +1,19 @@ + + + + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 000000000..c4a603d4c --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 000000000..c4a603d4c --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..550730310 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 000000000..4e526c95b Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 000000000..8fab6a3a5 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..6bc7fcd6f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 000000000..2c38c7190 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 000000000..1eecc0e7d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..ec87dcebe Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 000000000..072467eaa Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 000000000..05ca079ca Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..6f67f21ba Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 000000000..78a6b7a34 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..8bac0f274 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..0327e13fa Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 000000000..68ebe33fe Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..bacd3e758 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values-land/dimens.xml b/app/src/main/res/values-land/dimens.xml new file mode 100644 index 000000000..1e0bb5f1a --- /dev/null +++ b/app/src/main/res/values-land/dimens.xml @@ -0,0 +1,8 @@ + + + 24dp + 24dp + + 120dp + 16dp + diff --git a/app/src/main/res/values-sw600dp/dimens.xml b/app/src/main/res/values-sw600dp/dimens.xml new file mode 100644 index 000000000..653bb990b --- /dev/null +++ b/app/src/main/res/values-sw600dp/dimens.xml @@ -0,0 +1,8 @@ + + + + + 24dp + 9dp + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 000000000..63fc81644 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..852f0bebb --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #0082c9 + #006AA3 + #007CC2 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 000000000..57b70e274 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,13 @@ + + + 16dp + 16dp + + 200dp + 24dp + + + 16dp + 8dp + + diff --git a/app/src/main/res/values/setup.xml b/app/src/main/res/values/setup.xml new file mode 100644 index 000000000..df17e7ad8 --- /dev/null +++ b/app/src/main/res/values/setup.xml @@ -0,0 +1,11 @@ + + + + mario + nc + + Nextcloud Talk + Nextcloud + + @color/per70white + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..0058053c1 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,27 @@ + + + Calls + Contacts + Settings + + + server URL + Please enter http:// or https:// before the hostname + Please finish your %1$s installation + Please upgrade your %1$s database + Please bring your %1$s out of maintenance + %1$s! only works with %2$s servers + + + Display name fetched + Display name couldn\'t be fetched, aborting + %1$s app found + %1$s app not installed, aborting + Display name stored + Display name not stored, aborting + + Invited + + Search + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 000000000..0eb88fe33 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/test/java/com/nextcloud/talk/ExampleUnitTest.java b/app/src/test/java/com/nextcloud/talk/ExampleUnitTest.java new file mode 100644 index 000000000..25624bb44 --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.nextcloud.talk; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 000000000..0d257be9c --- /dev/null +++ b/build.gradle @@ -0,0 +1,38 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:3.0.0-rc1' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +configurations.all { + // check for updates every build + resolutionStrategy.cacheChangingModulesFor 0, 'seconds' +} + +allprojects { + repositories { + google() + jcenter() + maven { + url 'https://oss.sonatype.org/content/repositories/snapshots' + } + maven { + url 'https://jitpack.io' + } + maven { url 'https://maven.google.com' } + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 000000000..aac7c9b46 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..13372aef5 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..508be2a2f --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue Sep 19 12:04:53 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 000000000..9d82f7891 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 000000000..aec99730b --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 000000000..e7b4def49 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app'