1.本地数据源
/**
* 书籍本地数据源
*/
object BookLocalDataSource : BookDataSource {
private val appExecutors: AppExecutors = AppExecutors()
private val bookDao: BookDao = AppDatabase.getDatabase(MyApplication.context).bookDao()
/**
* 获取书籍列表
*/
override fun getBooks(callback: CommonCallback<List<Book>>) {
appExecutors.diskIO.execute {
callback.onSuccess(bookDao.getBooks())
}
}
/**
* 更新书籍
*/
override fun updateBook(book: Book, callback: CommonCallback<Book>) {
appExecutors.diskIO.execute {
bookDao.updateBook(book)
callback.onSuccess(book)
}
}
/**
* 删除所有书籍
*/
fun deleteAllBook(callback: CommonCallback<Boolean>) {
appExecutors.diskIO.execute {
bookDao.deleteAllBook()
callback.onSuccess(true)
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
2.远程数据源
/**
* 书籍远程数据源
*/
object BookRemoteDataSource : BookDataSource {
/**
* 书籍服务
*/
private val bookService: BookService = ServiceCreator.create<BookService>()
/**
* 获取书籍列表
*/
override fun getBooks(callback: CommonCallback<List<Book>>) {
bookService.getBooks().enqueue(object : Callback<Result<List<Book>>> {
override fun onResponse(
call: Call<Result<List<Book>>>,
response: Response<Result<List<Book>>>
) {
response.body()?.also {
if (it.status == 0) {
callback.onSuccess(it.data)
} else {
callback.onFailure(R.string.error_net)
}
}
}
override fun onFailure(call: Call<Result<List<Book>>>, t: Throwable) {
callback.onFailure(R.string.error_net)
}
})
}
/**
* 更新书籍
*/
override fun updateBook(book: Book, callback: CommonCallback<Book>) {
bookService.updateBook(book.id, book).enqueue(object : Callback<Result<Book>> {
override fun onResponse(call: Call<Result<Book>>, response: Response<Result<Book>>) {
response.body()?.also {
if (it.status == 0) {
callback.onSuccess(it.data)
} else {
callback.onFailure(R.string.error_net)
}
}
}
override fun onFailure(call: Call<Result<Book>>, t: Throwable) {
callback.onFailure(R.string.error_net)
}
})
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
最后
如果想要成为架构师或想突破20~30K薪资范畴,那就不要局限在编码,业务,要会选型、扩展,提升编程思维。此外,良好的职业规划也很重要,学习的习惯很重要,但是最重要的还是要能持之以恒,任何不能坚持落实的计划都是空谈。
如果你没有方向,这里给大家分享一套由阿里高级架构师编写的《Android八大模块进阶笔记》,帮大家将杂乱、零散、碎片化的知识进行体系化的整理,让大家系统而高效地掌握Android开发的各个知识点。