{"id":19915753,"url":"https://github.com/maoruibin/viewcontroller","last_synced_at":"2025-05-03T05:32:35.318Z","repository":{"id":91596904,"uuid":"72980207","full_name":"maoruibin/ViewController","owner":"maoruibin","description":":pushpin: A view controller manages a set of views that make up a portion of your app’s user interface,it aims to make ui develop change more clear and flexible.(ViewControler 是一种界面开发组件化实现方式,利用它可以将一些复杂的 UI 界面开发组件化.)","archived":false,"fork":false,"pushed_at":"2021-01-31T03:05:55.000Z","size":482,"stargazers_count":122,"open_issues_count":1,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2023-10-26T12:03:08.493Z","etag":null,"topics":["android","components","flexible","viewcontroller"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maoruibin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-11-06T09:10:32.000Z","updated_at":"2023-08-03T07:09:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"cf7444b0-eb97-4138-9b7c-fc3dba035a86","html_url":"https://github.com/maoruibin/ViewController","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maoruibin%2FViewController","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maoruibin%2FViewController/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maoruibin%2FViewController/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maoruibin%2FViewController/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maoruibin","download_url":"https://codeload.github.com/maoruibin/ViewController/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224354838,"owners_count":17297409,"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":["android","components","flexible","viewcontroller"],"created_at":"2024-11-12T21:42:18.488Z","updated_at":"2024-11-12T21:42:19.083Z","avatar_url":"https://github.com/maoruibin.png","language":"Java","readme":"# ViewController\n[![](https://jitpack.io/v/maoruibin/ViewController.svg)](https://jitpack.io/#maoruibin/ViewController)\n[![](https://img.shields.io/hexpm/l/plug.svg)](https://github.com/maoruibin/ViewController/blob/master/LICENSE.txt)\n\nA view controller manages a set of views that make up a portion of your app’s user interface, it aims to make ui develop change more clear and flexible.\n\nEnglish | [中文](./README_CN.md) | [Android 复杂界面开发实践之 ViewController: 介绍](http://gudong.site/2016/11/06/viewcontroler-introduce.html)\n\n## demo\n\n\u003cimg src=\"http://7xr9gx.com1.z0.glb.clouddn.com/practice-demo.png\"\u003e\n\n## Advantage\n\n* Make UI development components,resolve problem of code bloated.\n* flexible, one component can used in more place. \n* easy use, easy develop. \n\n\n## Usage \n\nAs a good practice, I recommend you run or watch demo code directly.\n\n### import dependency\n\nyou can import dependency or copy source file to your project directly, so far, only one file in this lib.\n\nAdd the JitPack repository to your build file\n```groovy\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url \"https://jitpack.io\" }\n\t}\n}\n```\n\nAdd the dependency\n```groovy\ndependencies {\n\t compile 'com.github.maoruibin:ViewController:0.9.1'\n}\n```\n## develop component\n\njust like this demo image, we should develop four component. \n\n\u003cimg src=\"http://7xr9gx.com1.z0.glb.clouddn.com/practice-demo.png\"\u003e\n\n \nnow I want to develop comment component as a demo, i will introduce the point by code annotation.\n\n```java\n// 1、every component mast extends ViewController\npublic class HouseCommentViewController extends ViewController\u003cList\u003cString\u003e\u003e \n\n// 2、indicate layout id for this component  \n@Override\nprotected int resLayoutId() {\n    return R.layout.detail_comment_layout;\n}\n\n// init this component's view element \n@Override\nprotected void onCreatedView(View view) {\n    mLlContainer = view.findViewById(R.id.ll_container);\n    ...\n}\n\n// bind data to this view component \n@Override\nprotected void onBindView(List\u003cString\u003e comments) {\n    for (String comment:comments) {\n        TextView view = new TextView(getContext());\n        view.setBackgroundResource(R.color.bk_item);\n        view.setText(comment);\n        int padding = Utils.dp2px(16);\n        view.setPadding(padding,padding,padding,padding);\n        mLlContainer.addView(view);\n    }\n}\n```\n\nNow, we have finished a simple view component, and you can watch left components implement by demo code. \n\n## Assemble Component in Activity\n\nWe have finished four components for house detail UI.\n\n```java\nHousePhotoViewController    //House picture component \nHouseParamViewController    //House param info component\nHouseDescViewController     //House description component\nHouseCommentViewController  //House comment component\n```\n  \nthe left job is assemble. the core of assemble is\n  \n\u003e every view controller support a way to attach owner's view to root layout,so activity should have a root layout use to\n fill all views.\n\nThe java code is like this\n\n```java\n// 1、define ViewController instance\nprivate ViewController\u003cList\u003cString\u003e\u003e mHousePhotoViewController;\nprivate ViewController\u003cHouseDetail.Param\u003e mHouseParamViewController;\nprivate ViewController\u003cList\u003cString\u003e\u003e mHouseCommentViewController;\nprivate ViewController\u003cString\u003e mHouseDescViewController;\n\n// 2、init instance \nmHousePhotoViewController = new HousePhotoViewController(this);\nmHouseParamViewController = new HouseParamViewController(this);\nmHouseDescViewController = new HouseDescViewController(this);\nmHouseCommentViewController = new HouseCommentViewController(this);\n\n// 3、attach view controller to activity root, usually the best choose for root is a vertical LinearLayout. \nmHousePhotoViewController.attachRoot(mLlContainer);\nmHouseParamViewControler.attachRoot(mLlContainer);\nmHouseDescViewControler.attachRoot(mLlContainer);\nmHouseCommentViewControler.attachRoot(mLlContainer);\n\n// 4 、mock get data \ngetData();\n\n// 5、fill data to UI \n\nfillData();\n\n// 6、fill data to different view controller\nprivate void fillData(HouseDetail detail) {\n    mHousePhotoViewController.fillData(detail.photos);\n    mHouseParamViewController.fillData(detail.param);\n    mHouseDescViewController.fillData(detail.desc);\n    mHouseCommentViewController.fillData(detail.comments);\n}\n```\n\nand now, a complex ui had split four components, by this way, every components only deal with owner logic.\n\nAnd if other activity or fragment have a same component need implement, you can reuse code directly, nice!\n\n## TODO\n\n- [ ] Manage lifecycle \n- [ ] Support a AndroidStudio Templete for generate ViewController frame\n\n## Author\n\n[http://gudong.name](http://gudong.name)\n\n[https://github.com/maoruibin](https://github.com/maoruibin)\n\n\n## License\n\n    Copyright 2016 咕咚\n    \n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n    \n        http://www.apache.org/licenses/LICENSE-2.0\n    \n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaoruibin%2Fviewcontroller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaoruibin%2Fviewcontroller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaoruibin%2Fviewcontroller/lists"}