{"id":19011922,"url":"https://github.com/3squared/activeandroid-loaders","last_synced_at":"2025-04-22T23:28:21.081Z","repository":{"id":9729707,"uuid":"11688262","full_name":"3Squared/ActiveAndroid-Loaders","owner":"3Squared","description":"This library extends ActiveAndroid to add support for fetcing results using a Loader.","archived":false,"fork":false,"pushed_at":"2014-10-17T09:58:56.000Z","size":13218,"stargazers_count":37,"open_issues_count":2,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-17T16:03:26.695Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://3squared.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3Squared.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-26T15:03:18.000Z","updated_at":"2023-09-02T02:40:04.000Z","dependencies_parsed_at":"2022-09-21T13:41:26.416Z","dependency_job_id":null,"html_url":"https://github.com/3Squared/ActiveAndroid-Loaders","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Squared%2FActiveAndroid-Loaders","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Squared%2FActiveAndroid-Loaders/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Squared%2FActiveAndroid-Loaders/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3Squared%2FActiveAndroid-Loaders/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3Squared","download_url":"https://codeload.github.com/3Squared/ActiveAndroid-Loaders/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250339531,"owners_count":21414373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T19:16:07.504Z","updated_at":"2025-04-22T23:28:21.064Z","avatar_url":"https://github.com/3Squared.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"ActiveAndroid-Loaders\n====================\n\nAbout\n-----\nThis library extends [ActiveAndroid](https://github.com/pardom/ActiveAndroid) to add support for fetcing results \nusing a [Loader](http://developer.android.com/reference/android/content/Loader.html). \n\nIt adds one class, `ModelLoader`.\n\nAlso see [this pull request](https://github.com/pardom/ActiveAndroid/pull/35).\n\nExample\n-------\n\nSay we have a model named `Post`. We can create a loader for this class which loads its results into an \n`ArrayAdapter` (which could be used to back a `ListView`) and keeps it up-to-date like so:\n\n```java\nArrayAdapter\u003cPost\u003e mAdapter;\n\nclass PostLoader implements LoaderManager.LoaderCallbacks\u003cList\u003cPost\u003e\u003e\n{\n\t@Override\n\tpublic Loader\u003cList\u003cPost\u003e\u003e onCreateLoader(int id, Bundle args)\n\t{\n\t\treturn new ModelLoader\u003cPost\u003e(MainActivity.this, Post.class, true);\n\t}\n\t\n\t@Override\n\tpublic void onLoadFinished(Loader\u003cList\u003cPost\u003e\u003e loader, List\u003cPost\u003e data)\n\t{\n\t\tmAdapter.clear();\n\t\tmAdapter.addAll(data);\n\t\tmAdapter.notifyDataSetChanged();\n\t}\n\n\t@Override\n\tpublic void onLoaderReset(Loader\u003cList\u003cPost\u003e\u003e loader)\n\t{\n\t  mAdapter.clear();\n\t\tmAdapter.notifyDataSetChanged();\n\t}\n}\n```\nThis loader will query the database for all `Post` records and add them to the adapter. By using a `ContentObserver`\nthe `Loader` is updated whenever a change occurs to the `Model` table.\n\nThere are 3 constructors available for creating your `ModelLoader`.\n\n```java\n/**\n * Instantiates a new model loader. Will retrieve all models of the specified subclass. Will not\n * be reloaded on relationship changes.\n * \n * @param context\n *            the model subclass you wish to query\n * @param clazz\n *            the clazz\n */\npublic ModelLoader(Context context, Class\u003cT\u003e clazz);\n```\n```java\n/**\n * Instantiates a new model loader. Will retrieve all models of the specified subclass.\n * \n * @param context\n *            the context\n * @param clazz\n *            the model subclass you wish to query\n * @param updateOnRelationshipChanges\n *            if true, loader will updated when tables related to the one detected are changed\n */\npublic ModelLoader(Context context, Class\u003cT\u003e clazz, boolean updateOnRelationshipChanges);\n```\n```java\n/**\n* Instantiates a new model loader.\n* \n* @param context\n*            the context\n* @param clazz\n*            the model subclass you wish to query\n* @param from\n*            a select/from statement that will be executed to retrieve the objects\n* @param updateOnRelationshipChanges\n*            if true, loader will updated when tables related to the one detected are changed\n*/\npublic ModelLoader(Context context, Class\u003cT\u003e clazz, From from, boolean updateOnRelationshipChanges);\n```\n\nSor for example you could create a loader that would only load `Posts` where a member `needsSync` was `true` like so:\n\n```java\nreturn new ModelLoader\u003cPost\u003e(MainActivity.this, \n  Post.class, \n  new Select()\n    .from(Post.class)\n    .where(\"needsSync == true\"), \n  false);\n```\n\nBy setting `updateOnRelationshipChanges` to `true`, the loader will also be updated if a table that the main class has\na reference to is updated - for instance, if `Post` had a 1-M relationship with a table `Tag`, the model would be updated\nwhen members of the `Tag` class are changed. This adds some overhead, so leave it off unless you need it.\n\n\n\nExample Project\n-------\n\nAn 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:\n'''\nemail: foo@example.com \npassword: hello\n'''\n\nLicense\n=======\nThis project made available under the MIT License.\n\nCopyright (C) 2013 3Squared Ltd.\n\nPermission 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:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3squared%2Factiveandroid-loaders","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3squared%2Factiveandroid-loaders","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3squared%2Factiveandroid-loaders/lists"}