我17年底开始使用kotlin开发,那叫一个难受,各种不习惯,当用上一个月之后才发现kotlin这么的香,什么New对象什么extends什么implements统统不需要,只需要一个 ,(逗号)就搞定了,当时项目中一直使用的MVP模式,和原生一样的写法,启初用MVP还感觉有那么一点的逻辑清晰,后面就越发感觉好臃肿,我走一步怎么需要考虑这么多,心想我一定要给简化了,不然强迫症好难受,我有强烈的极简主义,后来换公司了我就抛弃了kotlin的MVP模式,因为kotiln的极简在加上高阶函数非常的强大了,代码已经非常的精简了完全可以应对项目需求了。
我使用的AndroidViewModel组合
-
下面展示我的写法贴图
页面很简单展示地址,一个标题和RecyclerVIew
AndroidViewModel使用到的Gradle库展示
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
把我新项目使用到的gradle库都展示出来:
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.9.0"
//超过65536
implementation 'com.android.support:multidex:1.0.3'
//图片加载
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
//EventBus
implementation 'org.greenrobot:eventbus:3.1.1'
//网络请求
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
//知乎图片、拍照选择器
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
//日期选择器控件 仿ios https://github.com/Bigkoo/Android-PickerView
implementation 'com.contrarywind:Android-PickerView:4.1.9'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.android.material:material:1.1.0'
//圆形头像 image使用 https://github.com/hdodenhof/CircleImageView
implementation 'de.hdodenhof:circleimageview:3.1.0'
//鲁班压缩
implementation 'top.zibin:Luban:1.1.8'
// 注意:分包之后不会有默认的Header和Footer需要手动添加!还是原来的三种方法!
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1'
//核心必须依赖
implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1'
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1'
写到最后:
我Android开发6年+比不上大牛,代码有些粗糙忘见谅,每个人的对代码的追求是不一样的,在加上我们的项目也没多么复杂,所以我采用的对应的模式,仅供学习交流。
网友评论