This repository was archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathScanAppUtils.kt
More file actions
71 lines (56 loc) · 1.88 KB
/
ScanAppUtils.kt
File metadata and controls
71 lines (56 loc) · 1.88 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package scan
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.observers.DisposableObserver
import io.reactivex.schedulers.Schedulers
import scan.listener.ScanListener
/**
* by y on 2016/10/20.
*/
class ScanAppUtils {
companion object {
const val ALL_APP = 1 //全部app
const val SYSTEM_APP = 2 //系统app
const val NO_SYSTEM_APP = 3 //第三方app
val instance by lazy { ScanAppUtils() }
}
private lateinit var subscription: Disposable
/**
* true:系统app更新后也算在第三方app里面
* false:只记录用户安装的app
*/
private var isNoSystem = false
fun setNoSystem(noSystem: Boolean): ScanAppUtils {
isNoSystem = noSystem
return this
}
fun start(@ScanTypeMode type: Int, scanListener: ScanListener) {
unsubscribe()
subscription = Observable
.create(ScanObservable(type, scanListener, isNoSystem))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver<List<AppModel>>() {
override fun onStart() {
super.onStart()
scanListener.onScanStart()
}
override fun onComplete() {
unsubscribe()
}
override fun onError(e: Throwable) {
unsubscribe()
scanListener.onScanError(e)
}
override fun onNext(list: List<AppModel>) {
scanListener.onScanSuccess(list)
}
})
}
private fun unsubscribe() {
if (::subscription.isInitialized && !subscription.isDisposed) {
subscription.dispose()
}
}
}