├── .gitignore ├── README.md ├── SyncAdapterExample ├── .gitignore ├── AndroidManifest.xml ├── ic_launcher-web.png ├── libs │ ├── ActiveAndroid.jar │ └── android-support-v4.jar ├── lint.xml ├── proguard-project.txt ├── project.properties ├── readme.md ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ ├── activity_account_authenticator.xml │ │ └── activity_main.xml │ ├── menu │ │ ├── account_authenticator.xml │ │ └── main.xml │ ├── values-large │ │ └── styles.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ ├── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ ├── strings_activity_account_authenticator.xml │ │ └── styles.xml │ └── xml │ │ ├── authenticator.xml │ │ └── sync_adapter.xml └── src │ └── com │ └── example │ └── syncadapterexample │ ├── App.java │ ├── MainActivity.java │ ├── Post.java │ ├── Tag.java │ └── example │ ├── AccountGeneral.java │ ├── Authenticator.java │ ├── AuthenticatorActivity.java │ ├── AuthenticatorService.java │ ├── SyncAdapter.java │ └── SyncService.java ├── dist ├── ActiveAndroid-Loaders-0.1.jar └── ActiveAndroid-Loaders-0.2.jar ├── libs ├── ActiveAndroid.jar ├── android-support-v4.jar └── android.jar └── src └── com └── activeandroid └── loaders └── ModelLoader.java /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Intellij project files 26 | *.iml 27 | *.ipr 28 | *.iws 29 | .idea/ 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ActiveAndroid-Loaders 2 | ==================== 3 | 4 | About 5 | ----- 6 | This library extends [ActiveAndroid](https://github.com/pardom/ActiveAndroid) to add support for fetcing results 7 | using a [Loader](http://developer.android.com/reference/android/content/Loader.html). 8 | 9 | It adds one class, `ModelLoader`. 10 | 11 | Also see [this pull request](https://github.com/pardom/ActiveAndroid/pull/35). 12 | 13 | Example 14 | ------- 15 | 16 | Say we have a model named `Post`. We can create a loader for this class which loads its results into an 17 | `ArrayAdapter` (which could be used to back a `ListView`) and keeps it up-to-date like so: 18 | 19 | ```java 20 | ArrayAdapter mAdapter; 21 | 22 | class PostLoader implements LoaderManager.LoaderCallbacks> 23 | { 24 | @Override 25 | public Loader> onCreateLoader(int id, Bundle args) 26 | { 27 | return new ModelLoader(MainActivity.this, Post.class, true); 28 | } 29 | 30 | @Override 31 | public void onLoadFinished(Loader> loader, List data) 32 | { 33 | mAdapter.clear(); 34 | mAdapter.addAll(data); 35 | mAdapter.notifyDataSetChanged(); 36 | } 37 | 38 | @Override 39 | public void onLoaderReset(Loader> loader) 40 | { 41 | mAdapter.clear(); 42 | mAdapter.notifyDataSetChanged(); 43 | } 44 | } 45 | ``` 46 | This loader will query the database for all `Post` records and add them to the adapter. By using a `ContentObserver` 47 | the `Loader` is updated whenever a change occurs to the `Model` table. 48 | 49 | There are 3 constructors available for creating your `ModelLoader`. 50 | 51 | ```java 52 | /** 53 | * Instantiates a new model loader. Will retrieve all models of the specified subclass. Will not 54 | * be reloaded on relationship changes. 55 | * 56 | * @param context 57 | * the model subclass you wish to query 58 | * @param clazz 59 | * the clazz 60 | */ 61 | public ModelLoader(Context context, Class clazz); 62 | ``` 63 | ```java 64 | /** 65 | * Instantiates a new model loader. Will retrieve all models of the specified subclass. 66 | * 67 | * @param context 68 | * the context 69 | * @param clazz 70 | * the model subclass you wish to query 71 | * @param updateOnRelationshipChanges 72 | * if true, loader will updated when tables related to the one detected are changed 73 | */ 74 | public ModelLoader(Context context, Class clazz, boolean updateOnRelationshipChanges); 75 | ``` 76 | ```java 77 | /** 78 | * Instantiates a new model loader. 79 | * 80 | * @param context 81 | * the context 82 | * @param clazz 83 | * the model subclass you wish to query 84 | * @param from 85 | * a select/from statement that will be executed to retrieve the objects 86 | * @param updateOnRelationshipChanges 87 | * if true, loader will updated when tables related to the one detected are changed 88 | */ 89 | public ModelLoader(Context context, Class clazz, From from, boolean updateOnRelationshipChanges); 90 | ``` 91 | 92 | Sor for example you could create a loader that would only load `Posts` where a member `needsSync` was `true` like so: 93 | 94 | ```java 95 | return new ModelLoader(MainActivity.this, 96 | Post.class, 97 | new Select() 98 | .from(Post.class) 99 | .where("needsSync == true"), 100 | false); 101 | ``` 102 | 103 | By setting `updateOnRelationshipChanges` to `true`, the loader will also be updated if a table that the main class has 104 | a reference to is updated - for instance, if `Post` had a 1-M relationship with a table `Tag`, the model would be updated 105 | when members of the `Tag` class are changed. This adds some overhead, so leave it off unless you need it. 106 | 107 | 108 | 109 | Example Project 110 | ------- 111 | 112 | An example project is included that shows the use of `ModelLoaders` with a custom `SyncAdpater` to keep a list of data up-to-date and syncronised with a fake webservice (no network stuff occurs for real). The credentials are included in the code - you can login with: 113 | ''' 114 | email: foo@example.com 115 | password: hello 116 | ''' 117 | 118 | License 119 | ======= 120 | This project made available under the MIT License. 121 | 122 | Copyright (C) 2013 3Squared Ltd. 123 | 124 | 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: 125 | 126 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 127 | 128 | 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. 129 | -------------------------------------------------------------------------------- /SyncAdapterExample/.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Intellij project files 26 | *.iml 27 | *.ipr 28 | *.iws 29 | .idea/ 30 | -------------------------------------------------------------------------------- /SyncAdapterExample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 62 | 63 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /SyncAdapterExample/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/ic_launcher-web.png -------------------------------------------------------------------------------- /SyncAdapterExample/libs/ActiveAndroid.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/libs/ActiveAndroid.jar -------------------------------------------------------------------------------- /SyncAdapterExample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /SyncAdapterExample/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /SyncAdapterExample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /SyncAdapterExample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-16 15 | -------------------------------------------------------------------------------- /SyncAdapterExample/readme.md: -------------------------------------------------------------------------------- 1 | # SyncAdapter+ActiveAndroid Example 2 | 3 | An example project which demonstrates how ActiveAndroid (+Extras) can be used along with a SyncAdapter to create a client-server app which keeps itself in sync while keeping the UI up-to-date. -------------------------------------------------------------------------------- /SyncAdapterExample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /SyncAdapterExample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /SyncAdapterExample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SyncAdapterExample/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3Squared/ActiveAndroid-Loaders/d72836eff475edc1cc914e0e0f1da4a656af2592/SyncAdapterExample/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /SyncAdapterExample/res/layout/activity_account_authenticator.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 15 | 16 | 21 | 22 | 30 | 31 | 32 | 33 | 34 | 38 | 39 | 42 | 43 | 51 | 52 | 63 | 64 |