@@ -148,34 +148,35 @@ class CallsHistoryModule(private val reactContext: ReactApplicationContext) : Re
148148 val nameColumnIndex = cursor.getColumnIndex(CallLog .Calls .CACHED_NAME )
149149
150150 while (cursor.moveToNext()) {
151- val phoneNumber = cursor.getString(numberColumnIndex)
152- val timestampStr = cursor.getString(dateColumnIndex)
153- val type = resolveCallType(cursor.getInt(typeColumnIndex))
154- val duration = cursor.getInt(durationColumnIndex)
155- var name = cursor.getString(nameColumnIndex)
156-
157- var photoUri: String? = null
158- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
159- val photoUriColumnIndex = cursor.getColumnIndex(CallLog .Calls .CACHED_PHOTO_URI )
160- photoUri = cursor.getString(photoUriColumnIndex)
161- }
151+ val phoneNumber = cursor.getString(numberColumnIndex)?.trim()
152+ if (phoneNumber != null && phoneNumber.isNotEmpty()) {
153+ val timestampStr = cursor.getString(dateColumnIndex)
154+ val type = resolveCallType(cursor.getInt(typeColumnIndex))
155+ val duration = cursor.getInt(durationColumnIndex)
156+ var name = cursor.getString(nameColumnIndex)
157+
158+ var photoUri: String? = null
159+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
160+ val photoUriColumnIndex = cursor.getColumnIndex(CallLog .Calls .CACHED_PHOTO_URI )
161+ photoUri = cursor.getString(photoUriColumnIndex)
162+ }
162163
163- if (name == null || photoUri == null ) {
164- val contact = getContactByPhoneNumber(phoneNumber)
165- if (contact != null ) {
166- name = contact.name ? : name
167- photoUri = contact.photoUri ? : photoUri
164+ if (name == null || photoUri == null ) {
165+ val contact = getContactByPhoneNumber(phoneNumber)
166+ if (contact != null ) {
167+ name = contact.name ? : name
168+ photoUri = contact.photoUri ? : photoUri
169+ }
168170 }
169- }
170171
171- val cursorJSON = JSONObject ()
172- cursorJSON.put(" timestamp" , timestampStr)
173- val itemCursor = Base64 .encodeToString(cursorJSON.toString().toByteArray(), Base64 .DEFAULT )
172+ val cursorJSON = JSONObject ()
173+ cursorJSON.put(" timestamp" , timestampStr)
174+ val itemCursor = Base64 .encodeToString(cursorJSON.toString().toByteArray(), Base64 .DEFAULT )
174175
175- val df = SimpleDateFormat (" HH:mm" , Locale .getDefault())
176- val time = df.format(Date (timestampStr.toLong()))
176+ val df = SimpleDateFormat (" HH:mm" , Locale .getDefault())
177+ val time = df.format(Date (timestampStr.toLong()))
177178
178- val item = CallLogItem (
179+ val item = CallLogItem (
179180 phoneNumber = phoneNumber,
180181 duration = duration,
181182 name = name,
@@ -184,19 +185,20 @@ class CallsHistoryModule(private val reactContext: ReactApplicationContext) : Re
184185 time = time,
185186 type = type,
186187 cursor = itemCursor
187- )
188- result.items.add(item)
189- if (cursor.isLast) {
190- val afterCursorJSON = JSONObject ()
191- afterCursorJSON.put(" timestamp" , timestampStr)
192- afterCursorJSON.put(" direction" , Direction .AFTER )
193- result.pagination.after = Base64 .encodeToString(afterCursorJSON.toString().toByteArray(), Base64 .DEFAULT )
194- }
195- if (cursor.isFirst) {
196- val beforeCursorJSON = JSONObject ()
197- beforeCursorJSON.put(" timestamp" , timestampStr)
198- beforeCursorJSON.put(" direction" , Direction .BEFORE )
199- result.pagination.before = Base64 .encodeToString(beforeCursorJSON.toString().toByteArray(), Base64 .DEFAULT )
188+ )
189+ result.items.add(item)
190+ if (cursor.isLast) {
191+ val afterCursorJSON = JSONObject ()
192+ afterCursorJSON.put(" timestamp" , timestampStr)
193+ afterCursorJSON.put(" direction" , Direction .AFTER )
194+ result.pagination.after = Base64 .encodeToString(afterCursorJSON.toString().toByteArray(), Base64 .DEFAULT )
195+ }
196+ if (cursor.isFirst) {
197+ val beforeCursorJSON = JSONObject ()
198+ beforeCursorJSON.put(" timestamp" , timestampStr)
199+ beforeCursorJSON.put(" direction" , Direction .BEFORE )
200+ result.pagination.before = Base64 .encodeToString(beforeCursorJSON.toString().toByteArray(), Base64 .DEFAULT )
201+ }
200202 }
201203 }
202204 cursor.close()
0 commit comments