diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3911b173 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +libs +example_app/release/* +github.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..b0f7c91c --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +XS2A Wizard \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..7643783a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..61a9130c --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/maikmursall.xml b/.idea/dictionaries/maikmursall.xml new file mode 100644 index 00000000..c4e0caa4 --- /dev/null +++ b/.idea/dictionaries/maikmursall.xml @@ -0,0 +1,8 @@ + + + + encryptor + gson + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..cabd7836 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..44a2d26d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..d5d35ec4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..5ace414d --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/DEPENDENCY_LICENSES b/DEPENDENCY_LICENSES new file mode 100644 index 00000000..e6cfd258 --- /dev/null +++ b/DEPENDENCY_LICENSES @@ -0,0 +1,621 @@ +Third party open source software components: +* AES-Everywhere Java (https://github.com/mervick/aes-everywhere-java): +MIT License + +AES Everywhere is Cross Language Encryption Library which provides the +ability to encrypt and decrypt data using a single algorithm in different +programming languages and on different platforms. + +This is an implementation of the AES algorithm, specifically CBC mode, +with 256 bits key length and PKCS7 padding. It implements OpenSSL +compatible cryptography with random generated salt + +Copyright (c) 2018-2019 Andrey Izman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* Volley (https://github.com/google/volley): + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. + + +* Android Jetpack/AndroidX (https://github.com/androidx/androidx): + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + +* Material Components for Android (https://github.com/material-components/material-components-android): + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..fb499a48 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 FinTecSystems GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..98b216c6 --- /dev/null +++ b/README.md @@ -0,0 +1,235 @@ +![header](https://fintecsystems.com/android-sdk-header.jpg) +# XS2A Android - Native Android SDK for XS2A + +## Installation +[![Maven Central](https://img.shields.io/maven-central/v/com.fintecsystems/xs2awizard.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.fintecsystems%22%20AND%20a:%22xs2awizard%22) + +Add the dependency to your `build.gradle`. + +```gradle +dependencies { + // ... Other Dependencies + + implementation "com.fintecsystems:xs2awizard:" +} +``` + +### Update proguard rules + +Since we use reflection for our serialization, please add the following to your +`proguard-rules.pro` file: + +``` +-keep class com.fintecsystems.xs2awizard.** { *; } +-keepclassmembers class com.fintecsystems.xs2awizard.** { *; } +``` + +## Initialization + +1. Setup a configuration object. + +```kotlin +val xs2aConfig = XS2AWizardConfig( + sessionKey = "your-session-key", // Generated on your backend. + backendURL = "http://localhost:8000", // Optional + onFinish = ::onFinish, // See Callbacks + onAbort = ::onAbort, // See Callbacks + onError = ::onError, // See Callbacks + styleResId = R.style.CustomXS2ATheme // See Styling +) +``` + +2. Initialize the wizard. + +```kotlin +val xs2aWizard = XS2AWizard(xs2aConfig) +``` + +3. Add the wizard to your view. + +```kotlin +supportFragmentManager.beginTransaction().apply { + add(R.id.xs2a_container, xs2aWizard) + commit() +} +``` + +## Callbacks + +```kotlin +fun onFinish(credentials: String?) { + // credentials will only be set for XS2A.API with connection sync_mode set to "shared" + // credentials will contain the shared credentials then. + // e.g. present a success view. +} +``` + +```kotlin +fun onAbort() { + // The user aborted the transaction. + // e.g. present a abort view. +} +``` + +```kotlin +data class XS2AWizardError( + val errorCode: String, + val messages: List, + val recoverable: Boolean, // Can this transaction be continued? +) + +fun onError(xs2aWizardError: XS2AWizardError) { + // A technical error occured. + // e.g. present a error view. +} +``` + +## Styling + +You are able to define your own theme for the wizard. +An example would be the following: + +`res/values/styles.xml` +```xml + + + + +``` + +The following attributes are styleable: +``` +tintColor +textColor + +placeholderColor +backgroundColor + + +paragraph_background_color +paragraph_text_color + +paragraph_error_background_color +paragraph_error_text_color + +paragraph_info_background_color +paragraph_info_text_color + +paragraph_warning_background_color +paragraph_warning_text_color + + +button_submit_background_color +button_submit_text_color + +button_abort_background_color +button_abort_text_color + +button_back_background_color +button_back_text_color + +button_restart_background_color +button_restart_text_color + +button_redirect_background_color +button_redirect_text_color +``` + +### Example (Kotlin) +
+ Style file + + Android Studio may mark the style-items as undefined. + The project will still compile and the style will still be applied. + +`res/values/styles.xml` +```xml + + + + +``` +
+ +
+ Layout file + +`res/layout/activity_main.xml` +```xml + + + + + +``` +
+ +
+ Code File + +`java/com/fintecsystems/xs2awizard_example/MainActivity.kt` +```kotlin +package com.fintecsystems.xs2awizard_example + +import android.os.Bundle +import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import com.fintecsystems.xs2awizard.XS2AWizard +import com.fintecsystems.xs2awizard.XS2AWizard.XS2AWizardConfig + + +private const val TAG = "MainActivity" + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + val xS2AWizardConfig = XS2AWizardConfig( + sessionKey = "your-session-key", + styleResId = R.style.CustomXS2ATheme, + onFinish = ::onFinish, + onAbort = ::onAbort, + ) + + val xs2aWizard = XS2AWizard(xS2AWizardConfig) + + supportFragmentManager.beginTransaction().let { + it.add(R.id.xs2a_wizard_container, xs2aWizard) + it.commit() + } + } + + private fun onFinish(credentials: String?) { + Log.d(TAG, "onFinish: $credentials") + } + + private fun onAbort() { + Log.d(TAG, "onAbort") + } +} +``` +
diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..6a134266 --- /dev/null +++ b/build.gradle @@ -0,0 +1,26 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + ext.kotlin_version = '1.5.31' + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..320c1892 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,41 @@ +# 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=-Xmx2048m -Dfile.encoding=UTF-8 +# 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 +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +GROUP=com.fintecsystems +VERSION_NAME=1.2.0 +POM_URL=https://github.com/FinTecSystems/xs2a-android +POM_SCM_URL=git@github.com:FinTecSystems/xs2a-android.git +POM_SCM_CONNECTION=scm:git:git@github.com:FinTecSystems/xs2a-android.git +POM_SCM_DEV_CONNECTION=scm:git:git@github.com:FinTecSystems/xs2a-android.git +POM_LICENCE_NAME=The MIT License +POM_LICENCE_URL=https://opensource.org/licenses/MIT +POM_LICENCE_DIST=repo +POM_DESCRIPTION=Android SDK for XS2A-Wizard +POM_NAME=XS2A-Wizard Android +POM_ARTIFACT_ID=xs2awizard +POM_PACKAGING=aar +POM_ORGANIZATION_NAME=FintecSystems +POM_ORGANIZATION_URL=https://fintecsystems.com +POM_DEVELOPER_ID=maik-mursall +POM_DEVELOPER_NAME=Maik Mursall +POM_DEVELOPER_EMAIL=mmursall@fintecsystems.com +OSSRH_STAGING_NAME=OSSRH +OSSRH_STAGING_URL=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..f6b961fd 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 00000000..bfb82ec2 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Sep 22 15:53:51 CEST 2021 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100755 index 00000000..cccdd3d5 --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# 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 + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# 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 +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +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" -a "$nonstop" = "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 + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..e95643d6 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@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 + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@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= + +@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 Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_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=%* + +: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 00000000..d59e88df --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +include ':xs2awizard' +rootProject.name = "XS2A Wizard" diff --git a/xs2awizard/.gitignore b/xs2awizard/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/xs2awizard/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/xs2awizard/build.gradle b/xs2awizard/build.gradle new file mode 100644 index 00000000..2dbce68d --- /dev/null +++ b/xs2awizard/build.gradle @@ -0,0 +1,151 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' + id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.21' + id 'maven-publish' + id 'signing' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 30 + versionCode 1 + versionName VERSION_NAME + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' + + implementation 'com.android.volley:volley:1.2.1' + implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1' + + def lifecycle_version = "2.3.1" + + // ViewModel + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" + // LiveData + implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" + // Lifecycles only (without ViewModel or LiveData) + implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" + + implementation "androidx.fragment:fragment-ktx:1.3.6" + + implementation "androidx.browser:browser:1.3.0" + + implementation "com.fintecsystems:xs2awizard_networking:1.1.0" +} + +publishing { + publications { + bar(MavenPublication) { + groupId GROUP + artifactId POM_ARTIFACT_ID + version VERSION_NAME + artifact("$buildDir/outputs/aar/$POM_ARTIFACT_ID-release.aar") + + pom { + name = POM_NAME + description = POM_DESCRIPTION + url = POM_URL + packaging = POM_PACKAGING + + licenses { + license { + name = POM_LICENCE_NAME + url = POM_LICENCE_URL + distribution = POM_LICENCE_DIST + } + } + + developers { + developer { + id = POM_DEVELOPER_ID + name = POM_DEVELOPER_NAME + email = POM_DEVELOPER_EMAIL + } + } + + organization { + name = POM_ORGANIZATION_NAME + url = POM_ORGANIZATION_URL + } + + scm { + connection = POM_SCM_CONNECTION + developerConnection = POM_SCM_DEV_CONNECTION + url = POM_SCM_URL + } + } + + pom.withXml { + final dependenciesNode = asNode().appendNode('dependencies') + ext.addDependency = { Dependency dep, String scope -> + if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified") + return + final dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', dep.group) + dependencyNode.appendNode('artifactId', dep.name) + dependencyNode.appendNode('version', dep.version) + dependencyNode.appendNode('scope', scope) + if (!dep.transitive) { + final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') + exclusionNode.appendNode('groupId', '*') + exclusionNode.appendNode('artifactId', '*') + } else if (!dep.properties.excludeRules.empty) { + final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') + dep.properties.excludeRules.each { ExcludeRule rule -> + exclusionNode.appendNode('groupId', rule.group ?: '*') + exclusionNode.appendNode('artifactId', rule.module ?: '*') + } + } + } + + configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") } + configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") } + configurations.implementation.getDependencies().each { dep -> addDependency(dep, "runtime") } + } + } + } + + repositories { + maven { + name = OSSRH_STAGING_NAME + url = OSSRH_STAGING_URL + credentials { + username = project.hasProperty('OSSRH_USER') ? OSSRH_USER : "" + password = project.hasProperty('OSSRH_PASSWORD') ? OSSRH_PASSWORD : "" + } + } + } +} + +signing { + sign publishing.publications +} diff --git a/xs2awizard/consumer-rules.pro b/xs2awizard/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/xs2awizard/proguard-rules.pro b/xs2awizard/proguard-rules.pro new file mode 100644 index 00000000..90746a94 --- /dev/null +++ b/xs2awizard/proguard-rules.pro @@ -0,0 +1,20 @@ +# 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: +-keep class com.fintecsystems.xs2awizard.** { *; } +-keepclassmembers class com.fintecsystems.xs2awizard.** { *; } + +# 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 \ No newline at end of file diff --git a/xs2awizard/src/androidTest/java/com/fintecsystems/xs2awizard/ExampleInstrumentedTest.kt b/xs2awizard/src/androidTest/java/com/fintecsystems/xs2awizard/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..55baa60e --- /dev/null +++ b/xs2awizard/src/androidTest/java/com/fintecsystems/xs2awizard/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.fintecsystems.xs2awizard + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.fintecsystems.xs2a_wizard.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/xs2awizard/src/main/AndroidManifest.xml b/xs2awizard/src/main/AndroidManifest.xml new file mode 100644 index 00000000..240c697a --- /dev/null +++ b/xs2awizard/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/XS2AWizard.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/XS2AWizard.kt new file mode 100644 index 00000000..2fffb742 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/XS2AWizard.kt @@ -0,0 +1,702 @@ +package com.fintecsystems.xs2awizard + +import android.os.Bundle +import android.text.SpannableStringBuilder +import android.text.Spanned +import android.text.method.LinkMovementMethod +import android.text.style.ClickableSpan +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.webkit.* +import android.widget.LinearLayout +import android.widget.TextView +import androidx.core.text.toSpannable +import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels +import androidx.fragment.app.viewModels +import com.fintecsystems.xs2awizard.components.CustomTabsURLSpan +import com.fintecsystems.xs2awizard.components.LoadingIndicator +import com.fintecsystems.xs2awizard.components.XS2AJavascriptInterface +import com.fintecsystems.xs2awizard.form.components.* +import com.fintecsystems.xs2awizard.form.* +import com.fintecsystems.xs2awizard.form.components.selectLine.SelectLine +import com.fintecsystems.xs2awizard.form.components.textLine.TextLine +import com.fintecsystems.xs2awizard.helper.Utils +import com.fintecsystems.xs2awizard.components.GenericViewModel +import com.fintecsystems.xs2awizard.form.components.textLine.AutoCompleteResponse +import com.fintecsystems.xs2awizard_networking.NetworkingInstance +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationException +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.* +import kotlinx.serialization.modules.* +import java.util.* + +private const val TAG = "XS2AWizard" + +/** + * Action delegate to be used by the form elements of the wizard. + */ +interface XS2AWizardActionDelegate { + fun goBack() + fun abort() + fun restart() + fun submitForm() + fun submitForm(action: String) + fun submitForm(jsonBody: JsonElement, showIndicator: Boolean = true) + fun submitFormWithCallback(action: String, onSuccess: (AutoCompleteResponse) -> Unit) + fun triggerAutoSubmit(delay: Long) + fun openWebView(url: String) + fun parseMarkupText(tv: TextView, textToParse: String?) + fun constructFragment(formElementData: FormLineData): FormLine? + fun incrementLoadingIndicatorLock() + fun decrementLoadingIndicatorLock() +} + +/** + * A [Fragment] subclass. + * Implementation of the XS2A Wizard + * Implements [XS2AWizardActionDelegate] for use in children. + */ +class XS2AWizard() : Fragment(), XS2AWizardActionDelegate { + data class XS2AWizardViewModel( + var config: XS2AWizardConfig? = null, + var autoSubmitTask: Runnable? = null + ) + + // ViewModel used to save config data and autoSubmitTask reference during view rebuilds. + private val viewModel: GenericViewModel by viewModels() + + // activityViewModel is shared across the entire activity to be shared amongst components. + private val styleIdModel: GenericViewModel by activityViewModels() + + // mConfig is used to temporarily store config data until viewModel is ready to be called. + // ViewModels are only available during and after the onCreate lifecycle method. + // That's why we cannot save the config data to the viewModel directly on instantiation. + private var mConfig: XS2AWizardConfig? = null + private val config: XS2AWizardConfig + get() { + return viewModel.liveData.value?.config!! + } + + private val formElements = mutableListOf() + + private lateinit var loadingIndicator: LoadingIndicator + private var loadingIndicatorLock = 0 + + private var autoSubmitTask: Runnable? + get() { + return viewModel.liveData.value?.autoSubmitTask + } + set(value) { + viewModel.liveData.value?.autoSubmitTask = value + } + + // The following variables are to keep the App from crashing while being in the background + // or during the transition to the background. + // Used to keep track, if app is in background or foreground. + private var isInBackground = false + + // If a autosubmit request tried to fire in the background. + private var triedToAutoSubmit = false + + // onFormReceived body if it got captured while being in background. + private var onFormReceivedDataFromBackground: String? = null + + // Secondary constructor used by the User to pass config. + constructor(_config: XS2AWizardConfig) : this() { + mConfig = _config + } + + override fun onPause() { + super.onPause() + + if (autoSubmitTask != null) { + isInBackground = true + } + } + + override fun onResume() { + super.onResume() + + isInBackground = false + + // If we received an form response while being in background, we captured it + // and process it now instead. + if (onFormReceivedDataFromBackground != null) { + onFormReceived(onFormReceivedDataFromBackground!!) + onFormReceivedDataFromBackground = null + } + + // We tried to "autosubmit" while being in the background, but we cannot do that. + // Just do that now instead. + if (triedToAutoSubmit) { + triedToAutoSubmit = false + submitForm(constructJsonBody("autosubmit"), false) + } + } + + override fun onStart() { + super.onStart() + + // If mConfig is set, that means a new instance of the wizard got created. + // onStart is also called during rebuilds (e.g. screen orientation changed) or + // coming back into foreground. + // With this check we can ensure, that the form doesn't get initialized a second time. + if (mConfig != null) { + // Set mConfig back to null, so that on future onStart calls the wizard doesn't get + // initialized again. + mConfig = null + + // Configure NetworkingInstance + NetworkingInstance.getInstance(requireContext()).apply { + sessionKey = config.sessionKey + backendURL = config.backendURL + } + + initForm() + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Initialize viewModel if not existent. + if (viewModel.liveData.value == null) { + viewModel.liveData.value = XS2AWizardViewModel() + } + + // Apply config + // Unlike onStart we don't null mConfig after the check. + // That's because onStart is called after onCreate and that would break the onStart logic. + if (mConfig != null) { + viewModel.liveData.value?.config = mConfig + + styleIdModel.liveData.value = mConfig?.styleResId + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? = Utils.getThemedInflater( + inflater, + requireContext(), + styleIdModel.liveData.value + ).inflate(R.layout.fragment_x_s2_a__wizard, container, false).also { + loadingIndicator = it.findViewById(R.id.loading_indicator) + + // Apply custom style of the user to loadingIndicator, if it exists. + if (styleIdModel.liveData.value != null) { + loadingIndicator.context.theme.applyStyle(styleIdModel.liveData.value!!, true) + } + } + + + /** + * Initializes the Form + * + * This function does the very first API call to XS2A + * and gets a form to render as response. + */ + private fun initForm() = submitForm( + buildJsonObject { + put("version", JsonPrimitive(requireContext().getString(R.string.xs2a_version))) + put("client", JsonPrimitive(requireContext().getString(R.string.xs2a_client_tag))) + } + ) + + /** + * Tells the server to go one step back + */ + override fun goBack() = submitForm( + buildJsonObject { + put("action", JsonPrimitive("back")) + } + ) + + /** + * Tells the server to abort the session + */ + override fun abort() { + if (autoSubmitTask != null) { + view?.removeCallbacks(autoSubmitTask!!) + } + + submitForm( + buildJsonObject { + put("action", JsonPrimitive("abort")) + } + ) + } + + /** + * Tells the server to restarts the session + */ + override fun restart() = submitForm( + buildJsonObject { + put("action", JsonPrimitive("restart")) + } + ) + + /** + * Append data of formLine to the resulting jsonObject. + * Used for recursion purposes on MultiLine. + * + * @param jsonBuilder current [JsonBuilder] instance. + * @param formLine [FormLine] element used for appending it's data to [JsonBuilder]. + */ + private fun appendValueToJson(jsonBuilder: JsonObjectBuilder, formLine: FormLine) { + when (val data = formLine.getFormData()) { + is ValueFormLineData -> jsonBuilder.put(data.name, data.value ?: JsonNull) + is MultiLineData -> { + jsonBuilder.put(data.name, data.selected) + + (formLine as MultiLine).getCurrentForm() + ?.forEach { appendValueToJson(jsonBuilder, it) } + } + } + } + + /** + * Construct the JSON body for the form request to the backend. + * + * @param action [String] that describes the action of the form request. + * @param values [JsonObject] used to override fields of request body. + * + * @return built [JsonObject] + */ + private fun constructJsonBody(action: String, values: JsonObject? = null) = buildJsonObject { + formElements.forEach { appendValueToJson(this, it) } + + put("action", JsonPrimitive(action)) + + values?.entries?.forEach { + put(it.key, it.value) + } + }.also { Log.d(TAG, "constructJsonBody: $it") } + + /** + * Submits form using standard "submit" action. + */ + override fun submitForm(): Unit = submitForm("submit") + + /** + * Constructs request body and submits form using the specified action. + * + * @param action action to use. + */ + override fun submitForm(action: String): Unit = submitForm(constructJsonBody(action), true) + + /** + * Submits form using the specified request body. + * + * @param jsonBody request body. + * @param showIndicator show loading indicator during request. + */ + override fun submitForm(jsonBody: JsonElement, showIndicator: Boolean) { + if (showIndicator) { + incrementLoadingIndicatorLock() + } + + Utils.hideSoftKeyboard(activity) + + return NetworkingInstance.getInstance(requireContext()) + .encodeAndSendMessage( + jsonBody.toString(), + ::onFormReceived + ) + } + + /** + * Submits form with specified action and calls specified callback on success. + * + * @param action action to use. + * @param onSuccess on success callback to use. + */ + override fun submitFormWithCallback(action: String, onSuccess: (AutoCompleteResponse) -> Unit) = + NetworkingInstance.getInstance(requireContext()) + .encodeAndSendMessage( + constructJsonBody(action).toString(), + { + onSuccess(formatJson.decodeFromString(it)) + } + ) + + /** + * Try to do an autoSubmit. + * If app is in background, the request will not be sent but saved to fire when + * the app is returning to foreground. + */ + private fun tryToAutoSubmit() { + if (!isInBackground) { + submitForm(constructJsonBody("autosubmit"), false) + } else { + triedToAutoSubmit = true + } + } + + /** + * Trigger autosubmit after a specified delay. + * + * @param delay delay until request is fired. + */ + override fun triggerAutoSubmit(delay: Long) { + if (autoSubmitTask != null) { + view?.removeCallbacks(autoSubmitTask!!) + } + + autoSubmitTask = Runnable { + autoSubmitTask = null + + tryToAutoSubmit() + } + + view?.postDelayed(autoSubmitTask!!, delay) + } + + /** + * Opens specified url in a WebView. + * + * @param url url to open. + */ + override fun openWebView(url: String) { + view?.findViewById(R.id.webview)!!.apply { + visibility = View.VISIBLE + + settings.javaScriptEnabled = true + settings.domStorageEnabled = true + addJavascriptInterface(XS2AJavascriptInterface(this@XS2AWizard), "App") + + webViewClient = object : WebViewClient() { + override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { + view.loadUrl(url) + return true + } + + override fun onPageFinished(view: WebView?, url: String?) { + super.onPageFinished(view, url) + + // Page has finished loading, we can hide the loadingIndicator now. + decrementLoadingIndicatorLock() + } + } + + loadUrl(url) + } + + view?.findViewById(R.id.form_container).apply { + this?.visibility = View.GONE + } + + // Shows loadingIndicator until page is finished loading + incrementLoadingIndicatorLock() + } + + /** + * Parses provided text and applies result to provided TextView + * + * @param tv [TextView], that's being applied to. + * @param textToParse [String] to parse for markups. + */ + override fun parseMarkupText(tv: TextView, textToParse: String?) { + if (textToParse == null) { + tv.text = null + return + } + + // Replace HTML linebreak and middot with Kotlin String counterparts. + val text = lineBreakRegex + .replace( + middotRegex.replace(textToParse, "\u00B7"), + "\n", + ) + + val spannableStringBuilder = SpannableStringBuilder() + + // Cursor used to determine startIndex of the current section. + var cursor = 0 + + do { + // Search for markups beginning at the cursor. + val regexResult = markupRegex.find(text, cursor) + + if (regexResult != null) { + spannableStringBuilder.apply { + // Append all text between the cursor and beginning of markup. + append(text.slice(cursor until regexResult.range.first)) + + // Append textValue of markup. + append(regexResult.groupValues[1]) + + // Create Span + val span = when (regexResult.groupValues[2]) { + "autosubmit" -> object : ClickableSpan() { + override fun onClick(widget: View) { + // Parse markup values into JSON. + val jsonBody = buildJsonObject { + autoSubmitPayloadRegex.findAll(regexResult.groupValues[3]) + .forEach { + it.groupValues.let { group -> + put(group[1], JsonPrimitive(group[2])) + } + } + } + + submitForm(constructJsonBody("autosubmit", jsonBody)) + } + } + else -> CustomTabsURLSpan(regexResult.groupValues[3]) + } + + // Apply span to area of markup text. + setSpan( + span, + length - regexResult.groupValues[1].length, + length, + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE + ) + } + + cursor = regexResult.range.last + 1 + } + } while (regexResult != null) + + // If there is still text left, append the remaining section. + if (cursor < text.length) { + spannableStringBuilder.append(text.slice(cursor until text.length)) + } + + // Apply parsed text to TextView. + tv.apply { + setText(spannableStringBuilder.toSpannable()) + + // Needed otherwise touch events won't get captured. + movementMethod = LinkMovementMethod.getInstance() + } + } + + /** + * Constructs a [FormLine] [Fragment] using the specified [FormLineData]. + * + * @param formElementData the [FormLineData] for the form line. + * + * @return the [FormLine] or null, if we don't have an implementation yet. + */ + override fun constructFragment(formElementData: FormLineData): FormLine? { + val createdFragment: FormLine? = when (formElementData) { + is AutoSubmitLineData -> AutoSubmitLine() + is ParagraphLineData -> ParagraphLine() + is DescriptionLineData -> DescriptionLine() + is TextLineData -> TextLine() + is PasswordLineData -> PasswordLine() + is CaptchaLineData -> CaptchaLine() + is SelectLineData -> SelectLine() + is CheckBoxLineData -> CheckBoxLine() + is HiddenLineData -> HiddenLine() + is RadioLineData -> RadioLine() + is ImageLineData -> ImageLine() + is LogoLineData -> LogoLine() + is FlickerLineData -> FlickerLine() + is SubmitLineData -> SubmitLine() + is AbortLineData -> AbortLine() + is RestartLineData -> RestartLine() + is TabsLineData -> TabsLine() + is RedirectLineData -> RedirectLine() + is MultiLineData -> MultiLine() + else -> null + } + + createdFragment?.setFormData(formElementData) + + return createdFragment + } + + override fun incrementLoadingIndicatorLock() { + if (++loadingIndicatorLock == 1) + loadingIndicator.show() + } + + override fun decrementLoadingIndicatorLock() { + if (--loadingIndicatorLock <= 0) { + loadingIndicatorLock = 0 + loadingIndicator.hide() + } + } + + /** + * Parses [FormResponse] for possible callbacks + * + * @param response [FormResponse] to parse. + */ + private fun parseCallback(response: FormResponse) { + when (response.callback) { + "finish" -> config.onFinish(response.callbackParams?.getOrNull(0)?.jsonPrimitive?.content) + "abort" -> config.onAbort() + } + + if (response.error != null && response.error == "tech_error") { + config.onError( + XS2AWizardError( + response.error, + emptyList(), + false + ) + ) + } + } + + /** + * Checks if the form language matches the device language. + * If the form languages don't match, the device language will be checked against our + * supported languages. + * + * @param language language to check. + * + * @return true if language should be changed, false otherwise. + */ + private fun checkIfLanguageNeedsToBeChanged(language: String?): Boolean { + if (language != null) { + val deviceLanguage = Locale.getDefault().language + val formLanguage = Locale(language).language + + return languageWhitelist.contains(deviceLanguage) && !(deviceLanguage.equals( + formLanguage + )) + } + + return false + } + + + @Serializable + data class FormResponse( + val form: List? = null, + val language: String? = null, + val callback: String? = null, + val callbackParams: List? = null, + val error: String? = null, + ) + + /** + * Parses form response and possibly re-/builds the form. + * + * @param jsonString form response as a JSON [String]. + */ + private fun onFormReceived(jsonString: String) { + try { + Log.d(TAG, "onFormReceived: $jsonString") + + // Postpone until we're back into foreground. + if (isInBackground) { + onFormReceivedDataFromBackground = jsonString + + return + } + + val formResponse = formatJson.decodeFromString(jsonString) + + // Check if we're in the right language. If not change it. + if (checkIfLanguageNeedsToBeChanged(formResponse.language)) { + Log.d( + TAG, + "onFormReceived: Language is not the same! Form: ${formResponse.language} Device: ${Locale.getDefault().language}, Changing!" + ) + + submitForm( + buildJsonObject { + put("action", "change-language") + put("language", Locale.getDefault().language) + } + ) + + decrementLoadingIndicatorLock() + + return + } + + // Begin transaction to modify children of this fragment. + childFragmentManager.beginTransaction().apply { + // Completely removed previous form elements. + formElements.forEach { fragment -> remove(fragment) } + formElements.clear() + + // Build the new form if we got the data. + if (formResponse.form != null) { + formResponse.form.forEach { formElementData -> + // Construct the form line or entirely skip it, if we don't have an + // implementation for it yet. + val createdFragment = constructFragment(formElementData) ?: return@forEach + + formElements.add(createdFragment) + add(R.id.form_container, createdFragment) + } + + } + + commit() + } + + decrementLoadingIndicatorLock() + + parseCallback(formResponse) + } catch (serializationException: SerializationException) { + Log.e(TAG, "onFormReceived: $serializationException") + } + } + + companion object { + private val markupRegex = Regex("\\[([\\w\\s\\-()]+)\\|(\\w+)::([&=\\w:/\\\\.]+)]") + private val lineBreakRegex = Regex("
") + private val middotRegex = Regex("·") + private val autoSubmitPayloadRegex = Regex("(\\w+)=(\\w+)") + + private val languageWhitelist = listOf("de", "en", "fr", "it", "es") + + // Serializer Module used to de-/serialize between json and our FormLineData classes. + private val formLineDataModule = SerializersModule { + polymorphic(FormLineData::class) { + subclass(MultiLineData::class) + subclass(TabsLineData::class) + subclass(RestartLineData::class) + subclass(AbortLineData::class) + subclass(SubmitLineData::class) + subclass(ImageLineData::class) + subclass(LogoLineData::class) + subclass(DescriptionLineData::class) + subclass(ParagraphLineData::class) + subclass(RedirectLineData::class) + subclass(TextLineData::class) + subclass(PasswordLineData::class) + subclass(CaptchaLineData::class) + subclass(FlickerLineData::class) + subclass(HiddenLineData::class) + subclass(CheckBoxLineData::class) + subclass(RadioLineData::class) + subclass(SelectLineData::class) + subclass(AutoSubmitLineData::class) + } + } + + private val formatJson = Json { + serializersModule = formLineDataModule; ignoreUnknownKeys = true; isLenient = true + } + } + + data class XS2AWizardError( + val errorCode: String, + val messages: List, + val recoverable: Boolean, + ) + + data class XS2AWizardConfig( + val sessionKey: String, + val backendURL: String? = null, + val onFinish: (String?) -> Unit, + val onAbort: () -> Unit, + val onError: (XS2AWizardError) -> Unit = {}, + val styleResId: Int? = null, + ) +} diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/CustomTabsURLSpan.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/CustomTabsURLSpan.kt new file mode 100644 index 00000000..cbf99410 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/CustomTabsURLSpan.kt @@ -0,0 +1,37 @@ +package com.fintecsystems.xs2awizard.components + +import android.net.Uri +import android.os.Build +import android.os.Parcel +import android.text.style.URLSpan +import android.view.View +import androidx.browser.customtabs.CustomTabsIntent +import java.lang.Exception + + +/** + * Extension of URLSpan which opens an Custom Tab instead of the Standard Browser. + */ +class CustomTabsURLSpan : URLSpan { + constructor(url: String) : super(url) + constructor(src: Parcel) : super(src) + + // https://stackoverflow.com/a/36358745 + override fun onClick(widget: View) { + try { + // Custom Tabs are only available since Android 4.1. + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + CustomTabsIntent.Builder().build().launchUrl(widget.context, Uri.parse(url)) + } else { + // Just open the url in the standard Browser. + super.onClick(widget) + } + } catch (e: Exception) { + // It seems like we're on or above Android 4.1 but there is no Browser with Custom Tab support installed. + e.printStackTrace() + + // Just open the url in the standard Browser. + super.onClick(widget) + } + } +} \ No newline at end of file diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/GenericViewModel.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/GenericViewModel.kt new file mode 100644 index 00000000..1c4f5718 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/GenericViewModel.kt @@ -0,0 +1,11 @@ +package com.fintecsystems.xs2awizard.components + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel + +/** + * Wrapper to easily store data into an fragment's/activity's view model. + */ +class GenericViewModel : ViewModel() { + val liveData: MutableLiveData = MutableLiveData() +} \ No newline at end of file diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LinkTransformationMethod.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LinkTransformationMethod.kt new file mode 100644 index 00000000..ff3592d6 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LinkTransformationMethod.kt @@ -0,0 +1,52 @@ +package com.fintecsystems.xs2awizard.components + +import android.graphics.Rect +import android.text.Spannable +import android.text.Spanned +import android.text.method.TransformationMethod +import android.text.style.URLSpan +import android.view.View +import android.widget.TextView + +// https://gist.github.com/NikolaDespotoski/e543b532fb6255c7e39c#file-linktransformationmethod-java +/** + * TransformationMethod implementation to replace [URLSpan] with [CustomTabsURLSpan] within a [TextView]. + */ +class LinkTransformationMethod : TransformationMethod { + override fun getTransformation(source: CharSequence, view: View?): CharSequence { + if (view is TextView) { + if (view.text == null || view.text !is Spannable) { + return source + } + + val text = view.text as Spannable + + // Retrieve all URLSpans in the text. + val spans = text.getSpans(0, view.length(), URLSpan::class.java) + + for (i in spans.indices.reversed()) { + // Replace URLSpan with CustomTabsURLSpan + val oldSpan = spans[i] + val start = text.getSpanStart(oldSpan) + val end = text.getSpanEnd(oldSpan) + val url = oldSpan.url + text.removeSpan(oldSpan) + + text.setSpan(CustomTabsURLSpan(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + return text + } + + return source + } + + override fun onFocusChanged( + view: View?, + sourceText: CharSequence?, + focused: Boolean, + direction: Int, + previouslyFocusedRect: Rect? + ) { + } +} \ No newline at end of file diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LoadingIndicator.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LoadingIndicator.kt new file mode 100644 index 00000000..5292a617 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/LoadingIndicator.kt @@ -0,0 +1,31 @@ +package com.fintecsystems.xs2awizard.components + +import android.content.Context +import android.util.AttributeSet +import android.util.Log +import android.widget.LinearLayout +import com.fintecsystems.xs2awizard.R + +/** + * Simple loading indicator with helper methods to easily hide or show it. + */ +class LoadingIndicator( + context: Context, + attrs: AttributeSet?, + defStyle: Int +): LinearLayout(context, attrs, defStyle) { + constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) + constructor(context: Context) : this(context, null, 0) + + init { + inflate(context, R.layout.view_indicator_loading, this) + } + + fun hide() { + visibility = GONE + } + + fun show() { + visibility = VISIBLE + } +} \ No newline at end of file diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/XS2AJavascriptInterface.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/XS2AJavascriptInterface.kt new file mode 100644 index 00000000..73c5cb6c --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/components/XS2AJavascriptInterface.kt @@ -0,0 +1,41 @@ +package com.fintecsystems.xs2awizard.components + +import android.view.View +import android.webkit.JavascriptInterface +import android.webkit.WebView +import android.widget.LinearLayout +import com.fintecsystems.xs2awizard.R +import com.fintecsystems.xs2awizard.XS2AWizard + +/** + * JavaScript interface used to catch callback methods of redirects. + */ +class XS2AJavascriptInterface ( + private val wizard: XS2AWizard +) { + private fun closeWebView() { + wizard.view?.findViewById(R.id.webview)?.apply { + loadUrl("about:blank") + visibility = View.GONE + } + wizard.view?.findViewById(R.id.form_container)?.apply { + visibility = View.VISIBLE + } + } + + @JavascriptInterface + fun successCallback() { + wizard.view?.post { + closeWebView() + + wizard.submitForm("post-code") + } + } + + @JavascriptInterface + fun abortCallback() { + wizard.view?.post { + closeWebView() + } + } +} diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/FormLineData.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/FormLineData.kt new file mode 100644 index 00000000..8d5b0d2f --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/FormLineData.kt @@ -0,0 +1,203 @@ +package com.fintecsystems.xs2awizard.form + +import kotlinx.serialization.Polymorphic +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonElement + +/** + * BaseClass for the data of all form lines. + */ +@Polymorphic +@Serializable +abstract class FormLineData + +/** + * [FormLineData] extension for form lines, that display a label. + */ +@Polymorphic +@Serializable +abstract class LabelFormLineData : FormLineData() { + abstract val label: String? +} + +/** + * [LabelFormLineData] extension for form lines, that store a value. + */ +@Polymorphic +@Serializable +abstract class ValueFormLineData : LabelFormLineData() { + abstract val name: String + abstract var value: JsonElement? +} + +@Serializable +data class MultiForm( + val form: List, + val label: String, + val value: String, +) + +@SerialName("multi") +@Serializable +class MultiLineData( + val name: String, + var selected: String, + val forms: List, +) : FormLineData() + +@SerialName("tabs") +@Serializable +class TabsLineData( + val action: String, + val selected: String, + val tabs: Map +) : FormLineData() + +@SerialName("restart") +@Serializable +class RestartLineData( + override val label: String? +) : LabelFormLineData() + +@SerialName("abort") +@Serializable +class AbortLineData( + override val label: String? +) : LabelFormLineData() + +@SerialName("submit") +@Serializable +class SubmitLineData( + override val label: String?, + @SerialName("back") + val backLabel: String? = null, +) : LabelFormLineData() + +@SerialName("image") +@Serializable +class ImageLineData( + val data: String, + val align: String, +) : FormLineData() + +@SerialName("logo") +@Serializable +class LogoLineData( + val tooltip: String? = null, + @SerialName("logo_variation") + val logoVariation: String? = null, +) : FormLineData() + +@SerialName("description") +@Serializable +class DescriptionLineData( + val text: String? = null, +) : FormLineData() + +@SerialName("paragraph") +@Serializable +class ParagraphLineData( + val text: String, + val title: String? = null, + val severity: String? = null, +) : FormLineData() + +@SerialName("redirect") +@Serializable +class RedirectLineData( + val name: String, + override val label: String? = null, + @SerialName("back") + val backLabel: String? = null, + val url: String? = null, +) : LabelFormLineData() + +@SerialName("text") +@Serializable +class TextLineData( + override val name: String, + override val label: String? = null, + override var value: JsonElement? = null, + val disabled: Boolean? = false, + val placeholder: String? = null, + @SerialName("autocomplete_action") + val autoCompleteAction: String? = null, + @SerialName("override_type") + val overrideType: String? = null, + @SerialName("maxlength") + val maxLength: Int? = 0, +) : ValueFormLineData() + +@SerialName("password") +@Serializable +class PasswordLineData( + override val name: String, + override val label: String? = null, + override var value: JsonElement? = null, + val placeholder: String? = null, +) : ValueFormLineData() + +@SerialName("captcha") +@Serializable +class CaptchaLineData( + override val name: String, + override val label: String? = null, + override var value: JsonElement? = null, + val placeholder: String, + val data: String, +) : ValueFormLineData() + +@SerialName("flicker") +@Serializable +class FlickerLineData( + override val name: String, + override val label: String? = null, + override var value: JsonElement? = null, + val placeholder: String? = null, + val code: List>, +) : ValueFormLineData() + +@SerialName("hidden") +@Serializable +class HiddenLineData( + override val name: String, + override val label: String? = null, + override var value: JsonElement? = null, +) : ValueFormLineData() + +@SerialName("checkbox") +@Serializable +class CheckBoxLineData( + override val name: String, + override val label: String? = null, + @SerialName("checked") + override var value: JsonElement? = null, + val disabled: Boolean? = false, +) : ValueFormLineData() + +@SerialName("radio") +@Serializable +class RadioLineData( + override val name: String, + override val label: String? = null, + @SerialName("checked") + override var value: JsonElement? = null, + val options: List, +) : ValueFormLineData() + +@SerialName("select") +@Serializable +class SelectLineData( + override val name: String, + override val label: String? = null, + @SerialName("selected") + override var value: JsonElement? = null, + val options: JsonElement, +) : ValueFormLineData() + +@SerialName("autosubmit") +@Serializable +class AutoSubmitLineData( + val interval: Int, +) : FormLineData() diff --git a/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/components/AbortLine.kt b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/components/AbortLine.kt new file mode 100644 index 00000000..3ab39f59 --- /dev/null +++ b/xs2awizard/src/main/java/com/fintecsystems/xs2awizard/form/components/AbortLine.kt @@ -0,0 +1,24 @@ +package com.fintecsystems.xs2awizard.form.components + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import com.fintecsystems.xs2awizard.R +import com.fintecsystems.xs2awizard.form.AbortLineData + +/** + * Subclass of [FormLine]. + * Displays abort button + */ +class AbortLine: FormLine() { + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View = getThemedInflater(inflater).inflate(R.layout.fragment_line_abort, container, false) + .also { inflatedView -> + inflatedView.findViewById