#编程
##创建新的模块
build文件的配置,采用和root项目相同配置,需要引用基础库,服务库(不需要服务库,也可不引入)示例:
apply plugin: 'com.android.library' apply plugin: 'com.jakewharton.butterknife' android { compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion } compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':common') implementation project(':service') annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT' }声明服务
- 在service模块中的component包中,创建相模块服务
- 服务接口需要继承基类ComponentService
- 在constant包中的ComponentConstant下,记录下服务相应的实现类路径
- 在IntentParamsConstants类下,声明Intent带参数跳转的key(命名规则:TNTENT-PARAM-模块名称-业务)
- 在服务接口中,务必写清注释,参数含义及方法业务
注册服务到Application,示例:
Route.getInstance().registerComponent(ComponentConstant.USER);- 其他命名:
- 所以命名:包括页面,布局,图片,资源文件,请在开头增加模块名称
- 公共资源图片:请放入common库中,并已common开头
- 控件id命名:模块-控件类型-业务 eg:news-tv-list-title
开发细节
- Acticity继承com.gtmc.common.base.BaseActivity
- bindLayout()方法设置布局ID,自动实现初始化
- widgetClick()实现点击时间
- initParms()可获取Intent传入参数
- initView()实现控件初始化
- doBusiness()实现业务操作
- 加载中loading,直接使用loading()方法 取消使用loaded()
- showToast()展示简短提示
- Fragment继承同com.gtmc.common.base.BaseFragment
- 列表控件
- com.yonyou.common.widget.ListView 整合下拉刷新及加载更多
- RecyclerView
- 请舍弃XListView的使用
- 定位
- com.gtmc.common.utils.Location
Location.getLocation(mContext, location -> { //do something });
- com.gtmc.common.utils.Location
- 图片加载
- com.yonyou.common.image.ImageLoad
ImageLoad.loadUrlFitCenter(mContext,view, url);
- com.yonyou.common.image.ImageLoad
- 日志系统
com.yonyou.common.log.Log - Json解析
- com.yonyou.common.utils.JsonUtils:适用于单独获取某个字节
- com.yonyou.common.utils.GsonUtils:适用于bean及list转换
网络请求
com.yonyou.common.net.self.BaseHttp
new BaseHttp(HttpFactory.HttpType.OKHTTP) .post() .url(InterfaceNames.GETNEWSINFORMATION) .addParam("code", params.code)//是否专属店0:是 1:不是 .addParam("lat", params.lat) .addParam("lng", params.lon) .addParam("pageSize", Constants.PAGE_SIZE) .addParam("pageNo", params.pageNo) .addParam("cityName", params.cityName) .addParam("type", params.type) .send(callBack);
- 架构
- mvp模式
- Model:网络请求,数据提取,提供增删改查方法
- Presenter:绑定model及view,删选处理数据,通知view刷新
- View:页面刷新样式,控件初始化,事件下发给Presenter
Dialog
com.afollestad.materialdialogs.MaterialDialog
new MaterialDialog.Builder(mContext) .cancelable(false) .progress(true, 0) .progressIndeterminateStyle(false) .content(msg) .build();
- Acticity继承com.gtmc.common.base.BaseActivity
- 工具插件
- GsonFormat json转为bean的java文件
- MVPHelper 生成MVP包
- Android ButterKnife Zelezny 初始化控件
- 由于组件包都使用的library,所以初始化时,请使用R2来索引ID
##组件交互
例如:首页模块提供两个页面,并且首页组件调取需要车生活组件的页面
首页提供服务
public interface HomeService extends ComponentService { /** * @return 首页页面 */ Fragment getHomePage(); /** * @return 车生活页面 */ Fragment getCarLife(); }车生活提供页面
public interface CarLifeService extends ComponentService { /** * @return 新闻资讯页面 */ Fragment getNewListPage(); /** * 进入新闻资讯详情页面 * * @param context 上下文 * @param newsId 新闻ID */ void goNewDetailsPage(Context context, String newsId); }MainActivity中获取首页组件, 并加载其页面
mHomeService= (HomeService) Route.getInstance().getComponentService(HOME); mHomeService.getHomePage(); mHomeService.getCarLife();车生活页面获取
mCarLifeService = (CarLifeService) Route.getInstance().getComponentService(ComponentConstant.CARLIFE);
##提交规范
- 以bug、需求、优化等为一个点做提交准则
提交已增加前缀
【需求】+【编号】xxxxxxxx 【BUG】+【编号】xxxxxxxx 【优化】+【模块】xxxxxxxx 【资源】+【替换、新增、删除】xxxxxxxx 【配置】+【升级、新增、删除】(如第三方库,build文件)xxxxxxxx