override fun doWork(): Result { // Do the work here--in this case, upload the images. uploadImages() // Indicate whether the task finished successfully with the Result return Result.success() } }
// 2)配置运行任务的方式和时间 val uploadWorkRequest = OneTimeWorkRequestBuilder<UploadWorker>() .build() // 3)将任务提交给系统 WorkManager.getInstance(myContext).enqueue(uploadWorkRequest)
那如何从中获得所有修改的文件列表呢?可以使用 git diff 命令,这里可以对比相对当前 HEAD 的前 N 个提交的文件修改记录,前面为 D 的表示删除,我们不需要关注。利用上面得到的提交个数,我们就可以得到未入库的所有提交的文件修改列表。
1 2 3 4 5 6
$ git diff --name-status HEAD~3 HEAD M app/src/main/java/.../abc.kt M app/src/main/java/.../def.kt A app/src/main/res/drawable-xxhdpi/xyz.png A app/src/main/res/drawable-xxhdpi/wallpaper01.jpg D app/src/main/res/drawable/aaa.png
这里获取修改的提交数目有个坑,直接用 wc 输出行数的话,输出结果前有空格,导致后面用的时候出错,最后是用 sed 处理了下:
1 2 3 4 5 6 7
HEAD~ 3 fatal: ambiguous argument '3': unknown revision or path not in the working tree. $ git cherry -v | wc -l 3 $ git cherry -v | wc -l | sed 's/ //g' 3
上面提到的“不满足现有的答案”需要付出很多努力去思考,需要耗费精力。这样做需要真正的动力,诺贝尔奖得主 William Shockley 谈过 “the will to think”,这是他从物理学家费米那学到的一个终生难忘的短语。除非坚信某些事情值得努力去完成,否则很难有 “the will to think”。
[Fermi] distilled the essence of a very significant insight: A competent thinker will be reluctant to commit himself to the effort that tedious and precise thinking demands – he will lack ‘the will to think’ – unless he has the conviction that something worthwhile will be done with the results of his efforts.
有动力花费这么多精力,意味着不理解某些事情或者在思考中存在 bug 会让你很困扰,这个时候就会有 “the will to know”。与之相关的特质就是诚实。费曼曾说过做科学的第一条规则就是不要糊弄自己,因为自己是最好糊弄的那个人。
class ProfileUseCase( private val userRepository: UserRepository, private val tracksRepository: TracksRepository, private val playlistRepository: PlaylistRepository, )