|
@@ -91,40 +91,38 @@ class ContactAddressBookWorker(val context: Context, workerParameters: WorkerPar
|
|
|
// collect all contacts with phone number
|
|
|
val contactsWithNumbers = collectPhoneNumbers()
|
|
|
|
|
|
- val currentLocale = ConfigurationCompat.getLocales(context.resources.configuration)[0].country
|
|
|
-
|
|
|
- val map = mutableMapOf<String, Any>()
|
|
|
- map["location"] = currentLocale
|
|
|
- map["search"] = contactsWithNumbers
|
|
|
-
|
|
|
- val json = Gson().toJson(map)
|
|
|
-
|
|
|
- ncApi.searchContactsByPhoneNumber(
|
|
|
- ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
|
|
- ApiUtils.getUrlForSearchByNumber(currentUser.baseUrl),
|
|
|
- RequestBody.create(MediaType.parse("application/json"), json))
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribe(object : Observer<ContactsByNumberOverall> {
|
|
|
- override fun onComplete() {
|
|
|
- }
|
|
|
-
|
|
|
- override fun onSubscribe(d: Disposable) {
|
|
|
- }
|
|
|
+ if(contactsWithNumbers.isNotEmpty()){
|
|
|
+ val currentLocale = ConfigurationCompat.getLocales(context.resources.configuration)[0].country
|
|
|
+
|
|
|
+ val map = mutableMapOf<String, Any>()
|
|
|
+ map["location"] = currentLocale
|
|
|
+ map["search"] = contactsWithNumbers
|
|
|
+
|
|
|
+ val json = Gson().toJson(map)
|
|
|
+
|
|
|
+ ncApi.searchContactsByPhoneNumber(
|
|
|
+ ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
|
|
+ ApiUtils.getUrlForSearchByNumber(currentUser.baseUrl),
|
|
|
+ RequestBody.create(MediaType.parse("application/json"), json))
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(object : Observer<ContactsByNumberOverall> {
|
|
|
+ override fun onComplete() {
|
|
|
+ }
|
|
|
|
|
|
- override fun onNext(foundContacts: ContactsByNumberOverall) {
|
|
|
- Log.d(javaClass.simpleName, "next")
|
|
|
+ override fun onSubscribe(d: Disposable) {
|
|
|
+ }
|
|
|
|
|
|
- // todo update
|
|
|
- up(foundContacts)
|
|
|
- }
|
|
|
+ override fun onNext(foundContacts: ContactsByNumberOverall) {
|
|
|
+ up(foundContacts)
|
|
|
+ }
|
|
|
|
|
|
- override fun onError(e: Throwable) {
|
|
|
- // TODO error handling
|
|
|
- Log.d(javaClass.simpleName, "error")
|
|
|
- }
|
|
|
+ override fun onError(e: Throwable) {
|
|
|
+ Log.e(javaClass.simpleName, "Failed to searchContactsByPhoneNumber", e)
|
|
|
+ }
|
|
|
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
// store timestamp
|
|
|
appPreferences.setPhoneBookIntegrationLastRun(System.currentTimeMillis())
|