├── .gitignore ├── LICENSE ├── README.md ├── android-nosql-paper ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── florent37 │ └── github │ └── com │ └── androidnosql │ └── paper │ └── PaperDataSaver.java ├── android-nosql ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── florent37 │ │ └── androidnosql │ │ ├── AndroidNoSql.java │ │ ├── Listener.java │ │ ├── NoSql.java │ │ ├── NoSqlSerializerUtils.java │ │ └── datasaver │ │ ├── DataSaver.java │ │ ├── LogDataSaver.java │ │ └── SharedPreferencesDataSaver.java │ └── res │ └── values │ └── strings.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── florent37 │ │ │ └── github │ │ │ └── com │ │ │ └── nosql │ │ │ ├── MainActivity.java │ │ │ ├── MainApplication.java │ │ │ └── model │ │ │ ├── Car.java │ │ │ ├── House.java │ │ │ └── User.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── florent37 │ └── github │ └── com │ └── nosql │ └── SharedPrefsTest.java ├── build.gradle ├── gradle.properties ├── gradle ├── bintray-android-v1.gradle ├── bintray-java-v1.gradle ├── install-v1.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── publish.sh └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | .idea/ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android-NoSql 2 | 3 | Lightweight, simple structured NoSQL database for Android 4 | 5 | 6 | 7 | Android app on Google Play 8 | 9 | 10 | 11 | # Download 12 | 13 | Buy Me a Coffee at ko-fi.com 14 | 15 | [ ![Download](https://api.bintray.com/packages/florent37/maven/android-nosql/images/download.svg) ](https://bintray.com/florent37/maven/android-nosql/_latestVersion) 16 | ```java 17 | dependencies { 18 | implementation 'com.github.florent37:android-nosql:1.0.0' 19 | } 20 | ``` 21 | 22 | Save your datas as a structured tree 23 | 24 | ```java 25 | noSql.put("/users/", "florent") 26 | noSql.put("/users/", "kevin") 27 | nosql.put("/identifiers/florent", 10) 28 | nosql.put("/identifiers/kevin", 12) 29 | ``` 30 | 31 | The data structure will be 32 | 33 | ```java 34 | / 35 | ---users/ 36 | ---"florent" 37 | ---"kevin" 38 | ---identifiers/ 39 | ---florent/ 40 | ---10 41 | ---kevin/ 42 | ---12 43 | ``` 44 | 45 | It'll be simple to search data 46 | 47 | ```java 48 | int myId = noSql.get("/identifiers/florent/").integer(); 49 | ``` 50 | 51 | # Serialize objects 52 | 53 | You can simply add nodes from POJOS 54 | 55 | ```java 56 | final User user = new User( 57 | "flo", 58 | new House("paris"), 59 | Arrays.asList(new Car("chevrolet camaro"), new Car("ford gt")) 60 | ); 61 | 62 | noSql.put("/user/florent/", user); 63 | ``` 64 | 65 | ```java 66 | / 67 | ---users/ 68 | ---florent/ 69 | ---name/ 70 | ---"flo" 71 | ---house/ 72 | ---adress/ 73 | ---"paris" 74 | ---cars/ 75 | ---0/ 76 | ---model/ 77 | ---"chevrolet camaro" 78 | ---1/ 79 | ---model/ 80 | ---"ford gt" 81 | ``` 82 | 83 | # Get Objects from node 84 | 85 | Or fetch nodes directly into Java Objects 86 | 87 | ```java 88 | User user = noSql.get("/user/florent/", User.class); 89 | ``` 90 | 91 | # Navigate 92 | 93 | ```java 94 | noSql.node("/identifiers/") 95 | .child("florent") 96 | .childNodes() 97 | .get(1) 98 | .put("country", "france"); 99 | ``` 100 | 101 | # Listeners 102 | 103 | You can listen for nodes updates 104 | 105 | ```java 106 | noSql.notify("/user/", new Listener() { 107 | @Override 108 | public void nodeChanged(String path, NoSql.Value value) { 109 | //notified when : 110 | // - the node is created 111 | // - the node is deleted 112 | // - a subnode is added / updated 113 | } 114 | }); 115 | ``` 116 | 117 | # Init 118 | 119 | Android-NoSql need to be initialized to store your objects 120 | 121 | ```java 122 | public class MainApplication extends Application { 123 | 124 | @Override 125 | public void onCreate() { 126 | super.onCreate(); 127 | 128 | AndroidNoSql.initWithDefault(context); 129 | } 130 | } 131 | ``` 132 | 133 | You can also define the datasavers using initWith, it means you can store your data into SqlDatabase, or any storage library your want ;) 134 | 135 | # Credits 136 | 137 | Author: Florent Champigny 138 | 139 | Blog : [http://www.tutos-android-france.com/](http://www.www.tutos-android-france.com/) 140 | 141 | Fiches Plateau Moto : [https://www.fiches-plateau-moto.fr/](https://www.fiches-plateau-moto.fr/) 142 | 143 | 144 | Android app on Google Play 145 | 146 | 147 | 148 | Follow me on Google+ 150 | 151 | 152 | Follow me on Twitter 154 | 155 | 156 | Follow me on LinkedIn 158 | 159 | 160 | 161 | License 162 | -------- 163 | 164 | Copyright 2017 Florent37, Inc. 165 | 166 | Licensed under the Apache License, Version 2.0 (the "License"); 167 | you may not use this file except in compliance with the License. 168 | You may obtain a copy of the License at 169 | 170 | http://www.apache.org/licenses/LICENSE-2.0 171 | 172 | Unless required by applicable law or agreed to in writing, software 173 | distributed under the License is distributed on an "AS IS" BASIS, 174 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 175 | See the License for the specific language governing permissions and 176 | limitations under the License. 177 | -------------------------------------------------------------------------------- /android-nosql-paper/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-nosql-paper/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion project.COMPILE_SDK 5 | buildToolsVersion project.BUILD_TOOL 6 | 7 | defaultConfig { 8 | minSdkVersion project.minSdkVersion 9 | targetSdkVersion project.TARGET_SDK 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:'+project.supportVersion 30 | testCompile 'junit:junit:4.12' 31 | 32 | compile 'io.paperdb:paperdb:2.1' 33 | 34 | compile project(path: ':android-nosql') 35 | } -------------------------------------------------------------------------------- /android-nosql-paper/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /android-nosql-paper/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android-nosql-paper/src/main/java/florent37/github/com/androidnosql/paper/PaperDataSaver.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.androidnosql.paper; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.florent37.androidnosql.datasaver.DataSaver; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | import io.paperdb.Book; 11 | import io.paperdb.Paper; 12 | 13 | /** 14 | * Created by florentchampigny on 06/06/2017. 15 | */ 16 | 17 | public class PaperDataSaver implements DataSaver { 18 | 19 | public static final String NODES = "nodes"; 20 | public static final String VALUES = "values"; 21 | 22 | public PaperDataSaver(Context context){ 23 | Paper.init(context); 24 | } 25 | 26 | @Override 27 | public void saveNodes(String completePath, Set values) { 28 | final Set nodes = new HashSet<>(); 29 | nodes.add(completePath); 30 | nodes.addAll(getNodes()); 31 | for (String value : values) { 32 | nodes.add(completePath + value); 33 | } 34 | 35 | Paper.book(NODES).write(NODES, nodes); 36 | } 37 | 38 | @Override 39 | public void saveValue(String completePath, Object value) { 40 | 41 | completePath = formatPath(completePath); 42 | 43 | final Book book = Paper.book(VALUES); 44 | if(value instanceof Integer) { 45 | book.write(completePath, (Integer) value); 46 | } else if(value instanceof Float) { 47 | book.write(completePath, (Float) value); 48 | } else if(value instanceof Boolean) { 49 | book.write(completePath, (Boolean) value); 50 | } else if(value instanceof Long) { 51 | book.write(completePath, (Long) value); 52 | } else { 53 | book.write(completePath, String.valueOf(value)); 54 | } 55 | } 56 | 57 | @Override 58 | public Set getNodes() { 59 | return Paper.book(NODES).read(NODES, new HashSet()); 60 | } 61 | 62 | @Override 63 | public Object getValue(String completePath) { 64 | return Paper.book(VALUES).read(formatPath(completePath)); 65 | } 66 | 67 | private String formatPath(String path){ 68 | return path.replace("/", "_%-"); 69 | } 70 | 71 | @Override 72 | public void remove(String startingPath) { 73 | final Book bookNodes = Paper.book(NODES); 74 | final Book bookValues = Paper.book(VALUES); 75 | final Set nodes = getNodes(); 76 | final Set nodesToKeep = new HashSet<>(); 77 | //update values 78 | for (String node : nodes) { 79 | if(node.startsWith(startingPath)) { 80 | bookValues.delete(formatPath(node)); 81 | } else { 82 | nodesToKeep.add(node); 83 | } 84 | } 85 | bookNodes.write(NODES, nodesToKeep); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /android-nosql/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-nosql/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion project.COMPILE_SDK 5 | buildToolsVersion project.BUILD_TOOL 6 | 7 | defaultConfig { 8 | minSdkVersion project.minSdkVersion 9 | targetSdkVersion project.TARGET_SDK 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | ext { 16 | bintrayRepo = 'maven' 17 | bintrayName = 'android-nosql' 18 | orgName = 'florent37' 19 | 20 | publishedGroupId = 'com.github.florent37' 21 | libraryName = 'Android-NoSql' 22 | artifact = 'android-nosql' 23 | 24 | libraryDescription = 'Android-NoSql' 25 | 26 | siteUrl = 'https://github.com/florent37/android-nosql' 27 | gitUrl = 'https://github.com/florent37/android-nosql.git' 28 | 29 | libraryVersion = rootProject.ext.libraryVersion 30 | 31 | developerId = 'florent37' 32 | developerName = 'florent37' 33 | developerEmail = 'champigny.florent@gmail.com' 34 | 35 | licenseName = 'The Apache Software License, Version 2.0' 36 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 37 | allLicenses = ["Apache-2.0"] 38 | } 39 | 40 | 41 | apply from: rootProject.file('gradle/install-v1.gradle') 42 | apply from: rootProject.file('gradle/bintray-android-v1.gradle') 43 | -------------------------------------------------------------------------------- /android-nosql/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /android-nosql/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/AndroidNoSql.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.Queue; 8 | import java.util.concurrent.LinkedBlockingDeque; 9 | 10 | import com.github.florent37.androidnosql.datasaver.DataSaver; 11 | import com.github.florent37.androidnosql.datasaver.SharedPreferencesDataSaver; 12 | 13 | /** 14 | * Created by florentchampigny on 29/05/2017. 15 | */ 16 | 17 | public class AndroidNoSql { 18 | private static final Queue dataSavers = new LinkedBlockingDeque<>(); 19 | 20 | public static Collection getDataSaver() { 21 | return new ArrayList<>(dataSavers); 22 | } 23 | 24 | public static NoSql getInstance() { 25 | return NoSql.getInstance(); 26 | } 27 | 28 | public static void initWith(DataSaver... savers) { 29 | for (DataSaver saver : savers) { 30 | addDataSaver(saver); 31 | } 32 | } 33 | 34 | public static void initWithDefault(Context context){ 35 | initWith(new SharedPreferencesDataSaver(context)); 36 | } 37 | 38 | public static void addDataSaver(DataSaver saver){ 39 | synchronized (dataSavers) { 40 | final boolean wasEmpty = dataSavers.isEmpty(); 41 | dataSavers.add(saver); 42 | if (wasEmpty && !dataSavers.isEmpty()) { 43 | final NoSql noSql = NoSql.getInstance(); 44 | noSql.load(); 45 | } 46 | } 47 | } 48 | 49 | public static void clearDataSavers(){ 50 | for (DataSaver dataSaver : AndroidNoSql.getDataSaver()) { 51 | dataSaver.remove(NoSql.PATH_SEPARATOR); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/Listener.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql; 2 | 3 | /** 4 | * Created by florentchampigny on 29/05/2017. 5 | */ 6 | 7 | public interface Listener { 8 | void nodeChanged(String path, NoSql.Value value); 9 | } 10 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/NoSql.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql; 2 | 3 | import android.util.Pair; 4 | 5 | import com.github.florent37.androidnosql.datasaver.DataSaver; 6 | 7 | import org.json.JSONArray; 8 | import org.json.JSONException; 9 | import org.json.JSONObject; 10 | 11 | import java.lang.ref.Reference; 12 | import java.lang.ref.SoftReference; 13 | import java.lang.reflect.Field; 14 | import java.util.ArrayList; 15 | import java.util.Collection; 16 | import java.util.HashMap; 17 | import java.util.Iterator; 18 | import java.util.List; 19 | import java.util.Map; 20 | import java.util.Set; 21 | 22 | public class NoSql { 23 | 24 | public static final String PATH_SEPARATOR = "/"; 25 | private static NoSql INSTANCE; 26 | public boolean autoSave = true; 27 | private Map> listeners = new HashMap<>(); 28 | private Node root; 29 | 30 | private NoSql() { 31 | root = new Node(""); 32 | } 33 | 34 | public static NoSql getInstance() { 35 | if (INSTANCE == null) { 36 | INSTANCE = new NoSql(); 37 | } 38 | return INSTANCE; 39 | } 40 | 41 | private Node getNodeOrCreate(String completeFieldPath) { 42 | final Pair nodeDesc = getNode(completeFieldPath); 43 | return getOrCreate(nodeDesc.first, nodeDesc.second); 44 | } 45 | 46 | public NoSql remove(String path) { 47 | if (path.equals(PATH_SEPARATOR)) { 48 | root.removeAll(); 49 | } else { 50 | final Pair nodeDesc = getNode(path); 51 | nodeDesc.first.remove(nodeDesc.second); 52 | } 53 | if (autoSave) { 54 | for (DataSaver dataSaver : AndroidNoSql.getDataSaver()) { 55 | dataSaver.remove(path); 56 | } 57 | } 58 | return this; 59 | } 60 | 61 | private Node getOrCreate(Node node, String name) { 62 | if (node.has(name)) { 63 | if (node.get(name) instanceof Node) { 64 | return node.child(name); 65 | } else { 66 | return null; 67 | } 68 | } else { 69 | final Node node1 = new Node(node.path + PATH_SEPARATOR + name); 70 | node.put(name, node1); 71 | return node1; 72 | } 73 | } 74 | 75 | private NodeDescritption split(String uri) { 76 | uri = uri.replace("//", "/"); 77 | final String[] strings = uri.split("/"); 78 | final List path = new ArrayList<>(); 79 | for (String string : strings) { 80 | if (string.length() > 0) { 81 | path.add(string); 82 | } 83 | } 84 | 85 | final int indexLast = path.size() - 1; 86 | final String name = path.get(indexLast); 87 | path.remove(indexLast); 88 | 89 | return new NodeDescritption(path, name); 90 | } 91 | 92 | public Value get(String uri) { 93 | final Pair node_and_name = getNode(uri); 94 | final Node node = node_and_name.first; 95 | final String name = node_and_name.second; 96 | return node.value(name); 97 | } 98 | 99 | public Pair getNode(String uri) { 100 | Node node = root; 101 | 102 | final NodeDescritption nodeDescritption = split(uri); 103 | for (String nodeName : nodeDescritption.path) { 104 | node = getOrCreate(node, nodeName); 105 | } 106 | 107 | return Pair.create(node, nodeDescritption.name); 108 | } 109 | 110 | public void load() { 111 | final Collection dataSavers = AndroidNoSql.getDataSaver(); 112 | if (!dataSavers.isEmpty()) { 113 | for (DataSaver dataSaver : dataSavers) { 114 | final Set nodes = dataSaver.getNodes(); 115 | if (nodes != null) { 116 | for (String node : nodes) { 117 | final Object value = dataSaver.getValue(node); 118 | if (value != null) { 119 | put(node, value); 120 | } 121 | } 122 | } 123 | } 124 | } 125 | } 126 | 127 | public NoSql reset(){ 128 | root = new Node(""); 129 | clearDataSavers(); 130 | return this; 131 | } 132 | 133 | public NoSql clearDataSavers() { 134 | AndroidNoSql.clearDataSavers(); 135 | return this; 136 | } 137 | 138 | public NoSql save() { 139 | clearDataSavers(); 140 | root.save(AndroidNoSql.getDataSaver()); 141 | return this; 142 | } 143 | 144 | /* 145 | public NoSql putXml(String uri, Object value) { 146 | 147 | } 148 | */ 149 | 150 | public NoSql put(String uri, Object value) { 151 | final Pair node_and_name = getNode(uri); 152 | final Node node = node_and_name.first; 153 | final String name = node_and_name.second; 154 | 155 | if (NoSqlSerializerUtils.isValueObject(value)) { 156 | node.put(name, value); 157 | notifyListeners(node.path + PATH_SEPARATOR + name); 158 | } else { 159 | getOrCreate(node, name).write(value); 160 | } 161 | 162 | if (autoSave) { 163 | node.save(AndroidNoSql.getDataSaver()); 164 | } 165 | 166 | return this; 167 | } 168 | 169 | private void notifyListeners(String path) { 170 | for (String key : listeners.keySet()) { 171 | if (path.startsWith(key)) { 172 | final Reference listener = listeners.get(key); 173 | if (listener != null) { 174 | final Listener listenerValue = listener.get(); 175 | if (listenerValue != null) { 176 | listenerValue.nodeChanged(path, get(path)); 177 | } 178 | } 179 | } 180 | } 181 | 182 | 183 | } 184 | 185 | public T get(String path, Class aClass) { 186 | try { 187 | final Object instance = aClass.newInstance(); 188 | final Set fields = NoSqlSerializerUtils.getAllFields(aClass); 189 | for (Field field : fields) { 190 | field.setAccessible(true); 191 | final String fieldName = field.getName(); 192 | final String completeFieldPath = path + PATH_SEPARATOR + fieldName; 193 | 194 | if (NoSqlSerializerUtils.isPrimitiveField(field)) { 195 | final Value value = get(completeFieldPath); 196 | 197 | final Object fetchedValue = value.object(); 198 | 199 | try { 200 | field.set(instance, fetchedValue); 201 | } catch (Exception e) { 202 | e.printStackTrace(); 203 | } 204 | } else if (NoSqlSerializerUtils.isArray(field)) { 205 | 206 | } else if (NoSqlSerializerUtils.isCollection(field)) { 207 | final List list; 208 | if (NoSqlSerializerUtils.isInterface(field)) { 209 | list = new ArrayList(); 210 | } else { 211 | list = (List) field.getType().newInstance(); 212 | } 213 | 214 | final Node node = getNodeOrCreate(completeFieldPath); 215 | final Class childClass = NoSqlSerializerUtils.genericType(field); 216 | if (NoSqlSerializerUtils.isPrimitive(childClass)) { 217 | for (String key : node.values.keySet()) { 218 | list.add(node.get(key)); 219 | } 220 | } else { 221 | for (String key : node.values.keySet()) { 222 | final String pathChild = completeFieldPath + PATH_SEPARATOR + key; 223 | final Object child = get(pathChild, childClass); 224 | list.add(child); 225 | } 226 | } 227 | 228 | try { 229 | field.set(instance, list); 230 | } catch (Exception e) { 231 | e.printStackTrace(); 232 | } 233 | } else { 234 | final Object child = get(completeFieldPath, field.getType()); 235 | try { 236 | field.set(instance, child); 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | } 240 | } 241 | 242 | } 243 | return (T) instance; 244 | } catch (Exception e) { 245 | e.printStackTrace(); 246 | } 247 | return null; 248 | } 249 | 250 | public void notify(String path, Listener listener) { 251 | listeners.put(path, new SoftReference<>(listener)); 252 | } 253 | 254 | public void removeNotifier(Listener listener) { 255 | for (String key : listeners.keySet()) { 256 | final Reference listenerReference = listeners.get(key); 257 | if (listener.equals(listenerReference.get())) { 258 | listeners.remove(key); 259 | break; 260 | } 261 | } 262 | } 263 | 264 | public Node node(String path) { 265 | return getNodeOrCreate(path); 266 | } 267 | 268 | public static class Value { 269 | 270 | private final Object object; 271 | 272 | public Value(Object object) { 273 | this.object = object; 274 | } 275 | 276 | public Object object() { 277 | return object; 278 | } 279 | 280 | public boolean isNode() { 281 | return object instanceof Node; 282 | } 283 | 284 | public Node node() { 285 | return ((Node) object); 286 | } 287 | 288 | public String string() { 289 | return String.valueOf(object); 290 | } 291 | 292 | public Boolean bool() { 293 | if (object instanceof Boolean) { 294 | return (Boolean) object; 295 | } 296 | return null; 297 | } 298 | 299 | public Integer integer() { 300 | if (object instanceof Integer) { 301 | return (Integer) object; 302 | } 303 | return null; 304 | } 305 | 306 | @Override 307 | public String toString() { 308 | return object.toString(); 309 | } 310 | } 311 | 312 | public class Node { 313 | private final String path; 314 | private final Map values; 315 | 316 | public Node(String path) { 317 | this.path = path; 318 | this.values = new HashMap<>(); 319 | } 320 | 321 | public String getPath() { 322 | return path; 323 | } 324 | 325 | @Override 326 | public String toString() { 327 | return path + " - " + values.toString(); 328 | } 329 | 330 | public Object get(String key) { 331 | if (values.containsKey(key)) { 332 | return values.get(key); 333 | } else { 334 | final Node node = new Node(path + PATH_SEPARATOR + key); 335 | values.put(key, node); 336 | return node; 337 | } 338 | } 339 | 340 | public boolean has(String key) { 341 | return values.containsKey(key); 342 | } 343 | 344 | public Collection keys() { 345 | return values.keySet(); 346 | } 347 | 348 | public List childNodes() { 349 | final List nodes = new ArrayList<>(); 350 | for (String key : keys()) { 351 | final Object child = values.get(key); 352 | if (child instanceof Node) { 353 | nodes.add((Node) child); 354 | } 355 | } 356 | return nodes; 357 | } 358 | 359 | public Node child(String key) { 360 | return ((Node) get(key)); 361 | } 362 | 363 | public void put(String name, Object node) { 364 | values.put(name, node); 365 | if (autoSave) { 366 | save(AndroidNoSql.getDataSaver()); 367 | } 368 | } 369 | 370 | public void save(Collection dataSaver) { 371 | { 372 | //save keys 373 | final String p = path + "/"; 374 | final Set keys = values.keySet(); 375 | for (DataSaver saver : dataSaver) { 376 | saver.saveNodes(p, keys); 377 | } 378 | } 379 | 380 | 381 | for (final String key : values.keySet()) { 382 | final Object value = values.get(key); 383 | 384 | final String completePath = path + PATH_SEPARATOR + key; 385 | if (NoSqlSerializerUtils.isPrimitiveObject(value)) { 386 | for (DataSaver saver : dataSaver) { 387 | saver.saveValue(completePath, value); 388 | } 389 | } else if (value instanceof Node) { 390 | ((Node) value).save(dataSaver); 391 | } 392 | } 393 | } 394 | 395 | public void remove(String key) { 396 | this.values.remove(key); 397 | } 398 | 399 | public void removeAll() { 400 | this.values.clear(); 401 | } 402 | 403 | public Value value(String key) { 404 | return new Value(get(key)); 405 | } 406 | 407 | protected void write(Object value) { 408 | if (value instanceof JSONObject) { //json object 409 | final JSONObject jsonObject = (JSONObject) value; 410 | final Iterator keys = jsonObject.keys(); 411 | while (keys.hasNext()) { 412 | final String key = keys.next(); 413 | try { 414 | final Object childObject = jsonObject.get(key); 415 | if (NoSqlSerializerUtils.isValueObject(childObject)) { 416 | put(key, childObject); 417 | notifyListeners(key); 418 | } else { 419 | child(key).write(childObject); 420 | } 421 | } catch (JSONException e) { 422 | e.printStackTrace(); 423 | } 424 | } 425 | } else if (value instanceof JSONArray) { //json array 426 | final JSONArray jsonArray = (JSONArray) value; 427 | final int length = jsonArray.length(); 428 | for (int i = 0; i < length; ++i) { 429 | try { 430 | final Object childObject = jsonArray.get(i); 431 | final String key = String.valueOf(i); 432 | 433 | if (NoSqlSerializerUtils.isValueObject(childObject)) { 434 | put(key, childObject); 435 | notifyListeners(key); 436 | } else { 437 | child(key).write(childObject); 438 | } 439 | } catch (JSONException e) { 440 | e.printStackTrace(); 441 | } 442 | } 443 | } else { //custom object, write all fields 444 | final Set allFields = NoSqlSerializerUtils.getAllFields(value.getClass()); 445 | for (Field field : allFields) { 446 | field.setAccessible(true); 447 | 448 | try { 449 | final String fieldName = field.getName(); 450 | final Object fieldValue = field.get(value); 451 | if (fieldValue != null) { 452 | 453 | final String completePath = path + PATH_SEPARATOR + fieldName; 454 | 455 | if (NoSqlSerializerUtils.isValueObject(fieldValue)) { 456 | put(fieldName, fieldValue); 457 | notifyListeners(completePath); 458 | } else { 459 | final Node node1 = new Node(completePath); 460 | put(fieldName, node1); 461 | if (NoSqlSerializerUtils.isCollection(field)) { 462 | final Iterable collection = (Iterable) field.get(value); 463 | int index = 0; 464 | for (Object childObject : collection) { 465 | final String key = String.valueOf(index); 466 | if (NoSqlSerializerUtils.isValueObject(childObject)) { 467 | node1.put(key, childObject); 468 | notifyListeners(key); 469 | } else { 470 | node1.child(key).write(childObject); 471 | } 472 | index++; 473 | } 474 | } else if (NoSqlSerializerUtils.isArray(field)) { 475 | final Object[] array = (Object[]) field.get(value); 476 | int index = 0; 477 | for (Object childObject : array) { 478 | final String key = String.valueOf(index); 479 | if (NoSqlSerializerUtils.isValueObject(childObject)) { 480 | node1.put(key, childObject); 481 | notifyListeners(key); 482 | } else { 483 | node1.child(key).write(childObject); 484 | } 485 | index++; 486 | } 487 | } else { 488 | node1.write(fieldValue); 489 | } 490 | } 491 | } 492 | } catch (IllegalAccessException e) { 493 | e.printStackTrace(); 494 | } 495 | } 496 | } 497 | notifyListeners(path); 498 | } 499 | } 500 | 501 | private class NodeDescritption { 502 | final List path; 503 | final String name; 504 | 505 | public NodeDescritption(List path, String name) { 506 | this.path = path; 507 | this.name = name; 508 | } 509 | } 510 | } 511 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/NoSqlSerializerUtils.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.ParameterizedType; 5 | import java.util.Arrays; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | /** 11 | * Created by florentchampigny on 29/05/2017. 12 | */ 13 | 14 | public class NoSqlSerializerUtils { 15 | public static boolean isValueObject(Object object) { 16 | return isPrimitiveObject(object) || 17 | object instanceof NoSql.Node; 18 | } 19 | 20 | public static Class genericType(Field field){ 21 | final ParameterizedType listType = (ParameterizedType) field.getGenericType(); 22 | final Class listClass = (Class) listType.getActualTypeArguments()[0]; 23 | return listClass; 24 | } 25 | 26 | public static boolean isPrimitiveObject(Object object) { 27 | return object instanceof String || 28 | object instanceof Integer || 29 | object instanceof Double || 30 | object instanceof Float || 31 | object instanceof Long; 32 | } 33 | 34 | public static boolean isPrimitiveField(Field field) { 35 | return isPrimitive(field.getType()); 36 | } 37 | 38 | public static boolean isPrimitive(Class type) { 39 | return 40 | Integer.class.isAssignableFrom(type) || 41 | Long.class.isAssignableFrom(type) || 42 | Double.class.isAssignableFrom(type) || 43 | Float.class.isAssignableFrom(type) || 44 | Boolean.class.isAssignableFrom(type) || 45 | String.class.isAssignableFrom(type); 46 | } 47 | 48 | public static boolean isCollection(Field field) { 49 | return List.class.isAssignableFrom(field.getType()); 50 | } 51 | 52 | public static boolean isArray(Field field) { 53 | return field.getType().isArray(); 54 | } 55 | 56 | public static boolean isInterface(Field field) { 57 | return field.getType().isInterface(); 58 | } 59 | 60 | 61 | public static Set getAllFields(Class theClass) { 62 | final Set allFields = new HashSet<>(); 63 | Class tmpClass = theClass; 64 | while (tmpClass != Object.class) { 65 | allFields.addAll(Arrays.asList(tmpClass.getDeclaredFields())); 66 | tmpClass = tmpClass.getSuperclass(); 67 | } 68 | return allFields; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/datasaver/DataSaver.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql.datasaver; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * Created by florentchampigny on 24/05/2017. 7 | */ 8 | 9 | public interface DataSaver { 10 | void saveNodes(String completePath, Set value); 11 | 12 | void saveValue(String completePath, Object value); 13 | 14 | Set getNodes(); 15 | 16 | Object getValue(String completePath); 17 | 18 | void remove(String startingPath); 19 | } 20 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/datasaver/LogDataSaver.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql.datasaver; 2 | 3 | import android.util.Log; 4 | 5 | import java.util.Set; 6 | 7 | /** 8 | * Created by florentchampigny on 24/05/2017. 9 | */ 10 | 11 | public class LogDataSaver implements DataSaver { 12 | 13 | private final String tag; 14 | 15 | public LogDataSaver(String tag) { 16 | this.tag = tag; 17 | } 18 | 19 | @Override 20 | public void saveNodes(String completePath, Set value) { 21 | Log.d(tag, "nodes: " + completePath + " -> " + value.toString()); 22 | } 23 | 24 | @Override 25 | public void saveValue(String completePath, Object value) { 26 | Log.d(tag, "values: " + completePath + " -> " + value.toString()); 27 | } 28 | 29 | @Override 30 | public Set getNodes() { 31 | return null; 32 | } 33 | 34 | @Override 35 | public Object getValue(String completePath) { 36 | return null; 37 | } 38 | 39 | @Override 40 | public void remove(String startingPath) { 41 | Log.d(tag, "remove starting with: " + startingPath); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /android-nosql/src/main/java/com/github/florent37/androidnosql/datasaver/SharedPreferencesDataSaver.java: -------------------------------------------------------------------------------- 1 | package com.github.florent37.androidnosql.datasaver; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | /** 10 | * Created by florentchampigny on 24/05/2017. 11 | */ 12 | 13 | public class SharedPreferencesDataSaver implements DataSaver { 14 | 15 | public static final String NODES = "%nodes%"; 16 | public static final String NODES_SHARED_PREFS = "%nodes%"; 17 | 18 | private final SharedPreferences sharedPreferences; 19 | 20 | public SharedPreferencesDataSaver(SharedPreferences sharedPreferences) { 21 | this.sharedPreferences = sharedPreferences; 22 | } 23 | 24 | public SharedPreferencesDataSaver(Context context) { 25 | this(context.getSharedPreferences(NODES_SHARED_PREFS, Context.MODE_PRIVATE)); 26 | } 27 | 28 | @Override 29 | public void saveNodes(String completePath, Set values) { 30 | final Set nodes = new HashSet<>(); 31 | nodes.add(completePath); 32 | nodes.addAll(getNodes()); 33 | for (String value : values) { 34 | nodes.add(completePath + value); 35 | } 36 | 37 | sharedPreferences.edit() 38 | .putStringSet(NODES, nodes) 39 | .apply(); 40 | } 41 | 42 | @Override 43 | public void saveValue(String completePath, Object value) { 44 | final SharedPreferences.Editor editor = sharedPreferences.edit(); 45 | 46 | if(value instanceof Integer) { 47 | editor.putInt(completePath, (Integer) value); 48 | } else if(value instanceof Float) { 49 | editor.putFloat(completePath, (Float) value); 50 | } else if(value instanceof Boolean) { 51 | editor.putBoolean(completePath, (Boolean) value); 52 | } else if(value instanceof Long) { 53 | editor.putLong(completePath, (Long) value); 54 | } else { 55 | editor.putString(completePath, String.valueOf(value)); 56 | } 57 | 58 | editor.apply(); 59 | } 60 | 61 | @Override 62 | public Set getNodes(){ 63 | return sharedPreferences.getStringSet(NODES, new HashSet()); 64 | } 65 | 66 | @Override 67 | public Object getValue(String completePath){ 68 | return sharedPreferences.getAll().get(completePath); 69 | } 70 | 71 | @Override 72 | public void remove(String startingPath) { 73 | final Set nodes = getNodes(); 74 | final Set nodesToKeep = new HashSet<>(); 75 | //update values 76 | for (String node : nodes) { 77 | if(node.startsWith(startingPath)) { 78 | sharedPreferences.edit().remove(node).apply(); 79 | } else { 80 | nodesToKeep.add(node); 81 | } 82 | } 83 | sharedPreferences.edit() 84 | .putStringSet(NODES, nodesToKeep) 85 | .apply(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /android-nosql/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidNoSql 3 | 4 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion project.COMPILE_SDK 5 | buildToolsVersion project.BUILD_TOOL 6 | 7 | defaultConfig { 8 | minSdkVersion project.minSdkVersion 9 | targetSdkVersion project.TARGET_SDK 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | } 14 | 15 | dependencies { 16 | compile fileTree(dir: 'libs', include: ['*.jar']) 17 | 18 | compile project(':android-nosql') 19 | compile project(':android-nosql-paper') 20 | 21 | compile 'com.android.support:appcompat-v7:'+project.supportVersion 22 | 23 | compile 'com.facebook.stetho:stetho:1.5.0' 24 | 25 | testCompile "org.robolectric:robolectric:3.3.2" 26 | testCompile 'junit:junit:4.12' 27 | testCompile "com.google.truth:truth:0.31" 28 | testCompile 'org.mockito:mockito-core:2.8.9' 29 | } 30 | 31 | configurations.all { 32 | resolutionStrategy { 33 | force 'org.ow2.asm:asm:5.0.4' 34 | force 'org.objenesis:objenesis:2.5' 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/florentchampigny/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/florent37/github/com/nosql/MainActivity.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | 7 | import com.github.florent37.androidnosql.Listener; 8 | import com.github.florent37.androidnosql.NoSql; 9 | 10 | import java.util.Arrays; 11 | 12 | import florent37.github.com.nosql.model.Car; 13 | import florent37.github.com.nosql.model.House; 14 | import florent37.github.com.nosql.model.User; 15 | 16 | public class MainActivity extends Activity { 17 | 18 | TextView textView; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | textView = ((TextView) findViewById(R.id.text)); 25 | 26 | final NoSql noSql = NoSql.getInstance(); 27 | 28 | final User user = new User( 29 | "flo", 30 | new House("paris"), 31 | Arrays.asList(3, 5), 32 | Arrays.asList(new Car("chevrolet", "camaro"), new Car("ford", "gt")) 33 | ); 34 | 35 | noSql.notify("/user/", new Listener() { 36 | @Override 37 | public void nodeChanged(String path, NoSql.Value value) { 38 | 39 | } 40 | }); 41 | 42 | noSql.put("/user/florent/", user); 43 | 44 | final User userFetched = noSql.get("/user/florent/", User.class); 45 | textView.setText(userFetched.toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/florent37/github/com/nosql/MainApplication.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | 6 | import com.facebook.stetho.Stetho; 7 | 8 | import com.github.florent37.androidnosql.AndroidNoSql; 9 | import com.github.florent37.androidnosql.datasaver.LogDataSaver; 10 | import com.github.florent37.androidnosql.datasaver.SharedPreferencesDataSaver; 11 | 12 | import florent37.github.com.androidnosql.paper.PaperDataSaver; 13 | 14 | /** 15 | * Created by florentchampigny on 29/05/2017. 16 | */ 17 | 18 | public class MainApplication extends Application { 19 | 20 | @Override 21 | public void onCreate() { 22 | super.onCreate(); 23 | Stetho.initializeWithDefaults(this); 24 | 25 | AndroidNoSql.initWith( 26 | new PaperDataSaver(this), 27 | //new SharedPreferencesDataSaver(getSharedPreferences("test", Context.MODE_PRIVATE)), 28 | new LogDataSaver("LogDataSaver") 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/florent37/github/com/nosql/model/Car.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql.model; 2 | 3 | /** 4 | * Created by florentchampigny on 29/05/2017. 5 | */ 6 | 7 | public class Car { 8 | String constructor; 9 | String name; 10 | 11 | public String getConstructor() { 12 | return constructor; 13 | } 14 | 15 | public void setConstructor(String constructor) { 16 | this.constructor = constructor; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public Car(String constructor, String name) { 28 | this.constructor = constructor; 29 | this.name = name; 30 | } 31 | 32 | public Car() { 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Car{" + '\n' + 38 | "constructor='" + constructor + '\n' + 39 | "name='" + name + '\n' + 40 | '}' + '\n'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/florent37/github/com/nosql/model/House.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql.model; 2 | 3 | /** 4 | * Created by florentchampigny on 24/05/2017. 5 | */ 6 | 7 | public class House { 8 | private String adress; 9 | 10 | public House() { 11 | } 12 | 13 | public House(String adress) { 14 | this.adress = adress; 15 | } 16 | 17 | public String getAdress() { 18 | return adress; 19 | } 20 | 21 | public void setAdress(String adress) { 22 | this.adress = adress; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return "House {" + '\n' + 28 | "- adress :" + adress + '\n' + 29 | '}'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/florent37/github/com/nosql/model/User.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by florentchampigny on 24/05/2017. 7 | */ 8 | 9 | public class User { 10 | 11 | private String name; 12 | private House house; 13 | 14 | private List favorites; 15 | private List cars; 16 | 17 | public User() { 18 | } 19 | 20 | public User(String name) { 21 | this.name = name; 22 | } 23 | 24 | public User(String name, House house, List favorites, List cars) { 25 | this.name = name; 26 | this.house = house; 27 | this.favorites = favorites; 28 | this.cars = cars; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public House getHouse() { 40 | return house; 41 | } 42 | 43 | public void setHouse(House house) { 44 | this.house = house; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "User{" + '\n' + 50 | "name='" + name + '\n' + 51 | "house=\n" + house + '\n' + 52 | "favorites=\n" + favorites + '\n' + 53 | "cars=\n" + cars + '\n' + 54 | '}'; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NoSql 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/florent37/github/com/nosql/SharedPrefsTest.java: -------------------------------------------------------------------------------- 1 | package florent37.github.com.nosql; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | 7 | import com.github.florent37.androidnosql.AndroidNoSql; 8 | import com.github.florent37.androidnosql.Listener; 9 | import com.github.florent37.androidnosql.NoSql; 10 | import com.github.florent37.androidnosql.datasaver.DataSaver; 11 | import com.github.florent37.androidnosql.datasaver.SharedPreferencesDataSaver; 12 | 13 | import org.assertj.core.util.Sets; 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.junit.runner.RunWith; 17 | import org.mockito.ArgumentMatcher; 18 | import org.robolectric.RobolectricTestRunner; 19 | import org.robolectric.RuntimeEnvironment; 20 | import org.robolectric.annotation.Config; 21 | 22 | import java.util.Arrays; 23 | 24 | import florent37.github.com.androidnosql.paper.PaperDataSaver; 25 | import florent37.github.com.nosql.model.Car; 26 | import florent37.github.com.nosql.model.House; 27 | import florent37.github.com.nosql.model.User; 28 | 29 | import static com.google.common.truth.Truth.assertThat; 30 | import static org.mockito.ArgumentMatchers.any; 31 | import static org.mockito.ArgumentMatchers.eq; 32 | import static org.mockito.Mockito.atLeastOnce; 33 | import static org.mockito.Mockito.mock; 34 | import static org.mockito.Mockito.spy; 35 | import static org.mockito.Mockito.times; 36 | import static org.mockito.Mockito.verify; 37 | import static org.mockito.Mockito.verifyNoMoreInteractions; 38 | 39 | @RunWith(RobolectricTestRunner.class) 40 | @Config(constants = BuildConfig.class) 41 | public class SharedPrefsTest { 42 | 43 | private NoSql noSql; 44 | private SharedPreferences sharedPreferences; 45 | private DataSaver dataSaver; 46 | 47 | @Before 48 | public void setUp() throws Exception { 49 | final Application application = RuntimeEnvironment.application; 50 | sharedPreferences = application.getSharedPreferences("test", Context.MODE_PRIVATE); 51 | sharedPreferences.edit().clear().apply(); 52 | 53 | //dataSaver = new SharedPreferencesDataSaver(sharedPreferences); 54 | dataSaver = new PaperDataSaver(application); 55 | dataSaver = spy(dataSaver); 56 | 57 | AndroidNoSql.initWith( 58 | dataSaver 59 | ); 60 | noSql = NoSql.getInstance(); 61 | noSql.reset(); 62 | } 63 | 64 | @Test 65 | public void testAdd() throws Exception { 66 | //Given 67 | 68 | //When 69 | noSql.put("/numbers/a", 3); 70 | noSql.put("/numbers/b", 2); 71 | 72 | //Then 73 | final NoSql.Node node = noSql.node("/numbers/"); 74 | assertThat(node.keys()).containsAllIn(Arrays.asList("a", "b")); 75 | } 76 | 77 | @Test 78 | public void testAddUser() throws Exception { 79 | //Given 80 | final User user = new User("flo"); 81 | 82 | //When 83 | noSql.put("/user/florent/", user); 84 | 85 | //Then 86 | final NoSql.Node node = noSql.node("/user/florent/"); 87 | assertThat(node.keys()).contains("name"); 88 | assertThat(node.get("name")).isEqualTo("flo"); 89 | } 90 | 91 | @Test 92 | public void testRemove() throws Exception { 93 | //Given 94 | final User user = new User("flo"); 95 | noSql.put("/user/florent/", user); 96 | 97 | //When 98 | noSql.remove("/user/florent/"); 99 | 100 | //Then 101 | final NoSql.Node node = noSql.node("/user/"); 102 | assertThat(node.keys()).isEmpty(); 103 | } 104 | 105 | @Test 106 | public void testAddUser_complex() throws Exception { 107 | //Given 108 | final User user = new User( 109 | "flo", 110 | new House("paris"), 111 | Arrays.asList(3, 5), 112 | Arrays.asList(new Car("chevrolet", "camaro"), new Car("ford", "gt")) 113 | ); 114 | 115 | //When 116 | noSql.put("/user/florent/", user); 117 | 118 | //Then 119 | assertThat(noSql.get("/user/florent/house/adress").object()).isEqualTo("paris"); 120 | assertThat(noSql.get("/user/florent/favorites/0").object()).isEqualTo(3); 121 | assertThat(noSql.get("/user/florent/favorites/1").object()).isEqualTo(5); 122 | assertThat(noSql.get("/user/florent/cars/0/constructor").object()).isEqualTo("chevrolet"); 123 | assertThat(noSql.get("/user/florent/cars/0/name").object()).isEqualTo("camaro"); 124 | assertThat(noSql.get("/user/florent/cars/1/constructor").object()).isEqualTo("ford"); 125 | assertThat(noSql.get("/user/florent/cars/1/name").object()).isEqualTo("gt"); 126 | } 127 | 128 | @Test 129 | public void testSave() throws Exception { 130 | //Given 131 | final User user = new User("flo"); 132 | noSql.put("/user/florent/", user); 133 | 134 | //When 135 | noSql.save(); 136 | 137 | //Then 138 | assertThat(sharedPreferences.getStringSet(SharedPreferencesDataSaver.NODES, null)) 139 | .containsAllIn(Arrays.asList("/", "/user", "/user/florent", "/user/florent/name")); 140 | assertThat(sharedPreferences.getString("/user/florent/name", null)) 141 | .isEqualTo("flo"); 142 | } 143 | 144 | @Test 145 | public void testSave_incremental() throws Exception { 146 | //Given 147 | noSql.put("/numbers/a", 1); 148 | noSql.save(); 149 | 150 | final DataSaver dataSaver = mock(DataSaver.class); 151 | AndroidNoSql.addDataSaver(dataSaver); 152 | 153 | //When 154 | noSql.put("/numbers/b", 2); 155 | 156 | //Then 157 | 158 | verify(dataSaver, times(2)).saveNodes(eq("/numbers/"), eq(Sets.newHashSet(Arrays.asList("a", "b")))); 159 | verify(dataSaver, times(2)).saveValue(eq("/numbers/a"), eq(1)); 160 | verify(dataSaver, times(2)).saveValue(eq("/numbers/b"), eq(2)); 161 | verifyNoMoreInteractions(dataSaver); 162 | } 163 | 164 | @Test 165 | public void testNotify() throws Exception { 166 | //Given 167 | final User user = new User("flo"); 168 | final Listener listener = spy(new Listener() { 169 | 170 | @Override 171 | public void nodeChanged(String path, NoSql.Value value) { 172 | System.out.println(value); 173 | } 174 | 175 | }); 176 | noSql.notify("/user/", listener); 177 | 178 | //When 179 | noSql.put("/user/florent/", user); 180 | 181 | //Then 182 | verify(listener) 183 | .nodeChanged(eq("/user/florent"), any(NoSql.Value.class)); 184 | verify(listener) 185 | .nodeChanged(eq("/user/florent"), any(NoSql.Value.class)); 186 | } 187 | 188 | @Test 189 | public void testLoad() throws Exception { 190 | //Given 191 | final User user = new User("flo"); 192 | noSql.autoSave = false; 193 | noSql.put("/user/florent/", user); 194 | noSql.put("/numbers/a", 1); 195 | noSql.put("/numbers/b", 2); 196 | noSql.save(); 197 | noSql.remove("/"); 198 | 199 | //When 200 | noSql.load(); 201 | noSql.autoSave = true; 202 | 203 | //Then 204 | assertThat(noSql.node("/numbers/").keys()) 205 | .containsAllIn(Arrays.asList("a", "b")); 206 | 207 | assertThat(noSql.get("/user/florent/name").string()) 208 | .isEqualTo("flo"); 209 | 210 | assertThat(noSql.get("/numbers/a").object()) 211 | .isEqualTo(1); 212 | assertThat(noSql.get("/numbers/b").object()) 213 | .isEqualTo(2); 214 | } 215 | 216 | @Test 217 | public void test_delete_recursive() throws Exception { 218 | //Given 219 | noSql.put("/numbers/a", 1); 220 | noSql.put("/numbers/b", 2); 221 | 222 | //When 223 | noSql.remove("/"); 224 | 225 | //Then 226 | verify(dataSaver, atLeastOnce()).remove(eq("/")); //reset force to add 1 227 | assertThat(dataSaver.getNodes()).isEmpty(); 228 | } 229 | 230 | @Test 231 | public void test_delete_recursive_number() throws Exception { 232 | //Given 233 | noSql.put("/users/", "flo"); 234 | noSql.put("/numbers/a", 1); 235 | noSql.put("/numbers/b", 2); 236 | 237 | 238 | //When 239 | noSql.remove("/numbers/"); 240 | 241 | //Then 242 | verify(dataSaver).remove("/numbers/"); 243 | 244 | assertThat(dataSaver.getNodes()).containsAllIn(Arrays.asList("/", "/users")); 245 | } 246 | 247 | public static class ValueWith implements ArgumentMatcher { 248 | 249 | private final Object value; 250 | 251 | public ValueWith(Object value) { 252 | this.value = value; 253 | } 254 | 255 | @Override 256 | public boolean matches(NoSql.Value argument) { 257 | return argument.object().equals(value); 258 | } 259 | 260 | @Override 261 | public String toString() { 262 | return "ValueWith{" + 263 | "value=" + value + 264 | '}'; 265 | } 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:2.3.2' 7 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1' 8 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | jcenter() 15 | } 16 | } 17 | 18 | ext{ 19 | COMPILE_SDK=25 20 | TARGET_SDK=25 21 | BUILD_TOOL = "25.0.0" 22 | minSdkVersion = 14 23 | sourceCompatibilityVersion = JavaVersion.VERSION_1_7 24 | targetCompatibilityVersion = JavaVersion.VERSION_1_7 25 | supportVersion = "25.0.0" 26 | 27 | libraryVersion = "1.0.0" 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/bintray-android-v1.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = libraryVersion 4 | 5 | task sourcesJar(type: Jar) { 6 | from android.sourceSets.main.java.srcDirs 7 | classifier = 'sources' 8 | } 9 | 10 | task javadoc(type: Javadoc) { 11 | source = android.sourceSets.main.java.srcDirs 12 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 13 | } 14 | 15 | task javadocJar(type: Jar, dependsOn: javadoc) { 16 | classifier = 'javadoc' 17 | from javadoc.destinationDir 18 | } 19 | artifacts { 20 | archives javadocJar 21 | archives sourcesJar 22 | } 23 | 24 | def _user = System.getenv("BINTRAY_USER") 25 | def _key = System.getenv("BINTRAY_API_KEY") 26 | def _passphrase = System.getenv("BINTRAY_PASSPHRASE") 27 | 28 | if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){ 29 | Properties properties = new Properties() 30 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 31 | 32 | _user = properties.getProperty("bintray.user") 33 | _key = properties.getProperty("bintray.apikey"); 34 | _passphrase = properties.getProperty("bintray.gpg.password") 35 | } 36 | 37 | // Bintray 38 | 39 | bintray { 40 | user = _user 41 | key = _key 42 | override = true 43 | configurations = ['archives'] 44 | pkg { 45 | repo = bintrayRepo 46 | name = bintrayName 47 | desc = libraryDescription 48 | userOrg = orgName 49 | websiteUrl = siteUrl 50 | vcsUrl = gitUrl 51 | licenses = allLicenses 52 | publish = true 53 | publicDownloadNumbers = true 54 | version { 55 | desc = libraryDescription 56 | gpg { 57 | sign = true //Determines whether to GPG sign the files. The default is false 58 | passphrase = _passphrase 59 | //Optional. The passphrase for GPG signing' 60 | } 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /gradle/bintray-java-v1.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.jfrog.bintray' 2 | 3 | version = libraryVersion 4 | 5 | task sourcesJar(type: Jar) { 6 | from sourceSets.main.allSource 7 | classifier = 'sources' 8 | } 9 | 10 | task javadocJar(type: Jar, dependsOn: javadoc) { 11 | classifier = 'javadoc' 12 | from javadoc.destinationDir 13 | } 14 | artifacts { 15 | archives javadocJar 16 | archives sourcesJar 17 | } 18 | 19 | // Bintray 20 | 21 | def _user = System.getenv("BINTRAY_USER") 22 | def _key = System.getenv("BINTRAY_API_KEY") 23 | def _passphrase = System.getenv("BINTRAY_PASSPHRASE") 24 | 25 | if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){ 26 | Properties properties = new Properties() 27 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 28 | 29 | _user = properties.getProperty("bintray.user") 30 | _key = properties.getProperty("bintray.apikey"); 31 | _passphrase = properties.getProperty("bintray.gpg.password") 32 | } 33 | 34 | bintray { 35 | user = _user 36 | key = _key 37 | 38 | configurations = ['archives'] 39 | pkg { 40 | repo = bintrayRepo 41 | name = bintrayName 42 | desc = libraryDescription 43 | userOrg = orgName 44 | websiteUrl = siteUrl 45 | vcsUrl = gitUrl 46 | licenses = ['Apache-2.0'] 47 | publish = true 48 | publicDownloadNumbers = true 49 | version { 50 | desc = libraryDescription 51 | gpg { 52 | sign = true //Determines whether to GPG sign the files. The default is false 53 | passphrase = _passphrase 54 | //Optional. The passphrase for GPG signing' 55 | } 56 | } 57 | } 58 | } 59 | 60 | //from https://github.com/workarounds/bundler/blob/master/gradle/bintray-java-v1.gradle -------------------------------------------------------------------------------- /gradle/install-v1.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.github.dcendents.android-maven' 2 | 3 | group = publishedGroupId // Maven Group ID for the artifact 4 | 5 | install { 6 | repositories.mavenInstaller { 7 | // This generates POM.xml with proper parameters 8 | pom { 9 | project { 10 | packaging 'aar' 11 | groupId publishedGroupId 12 | artifactId artifact 13 | 14 | // Add your description here 15 | name libraryName 16 | description libraryDescription 17 | url siteUrl 18 | 19 | // Set your license 20 | licenses { 21 | license { 22 | name licenseName 23 | url licenseUrl 24 | } 25 | } 26 | developers { 27 | developer { 28 | id developerId 29 | name developerName 30 | email developerEmail 31 | } 32 | } 33 | scm { 34 | connection gitUrl 35 | developerConnection gitUrl 36 | url siteUrl 37 | 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | //from https://github.com/workarounds/bundler/blob/master/gradle/install-v1.gradle -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/florent37/Android-NoSql/c1eac03a853a28b0605a53a54e91c3ca5e34f3ff/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed May 24 12:25:28 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /publish.sh: -------------------------------------------------------------------------------- 1 | ./gradlew clean install 2 | ./gradlew bintrayUpload -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':android-nosql', ':android-nosql-paper' 2 | --------------------------------------------------------------------------------