Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. override fun doInBackground(vararg params: Void?): ArrayList<String>? {
  2. if (!mvpView.checkForPermissions()) return null
  3. var selection = "address LIKE '%${template.phoneNumb}%'"
  4. val cursor = context.contentResolver.query(Uri.parse("content://sms/inbox"), null, selection, null, null)
  5.  
  6. var count:Int = 0
  7. var samePhoneNumbers = ArrayList<TemplateItem>()
  8. if (cursor != null && cursor.moveToFirst()) { // must check the result to prevent exception
  9. count = cursor.count
  10. var item:TemplateItem
  11. for (idx in 1..count) {
  12. if (cursor.moveToPosition(idx)) {
  13. item = TemplateItem()
  14. item.phoneNumb = cursor.getString(cursor.getColumnIndexOrThrow("address"))
  15. item.name = item.phoneNumb
  16. item.text = cursor.getString(cursor.getColumnIndexOrThrow("body"))
  17. samePhoneNumbers.add(item)
  18. }
  19. }
  20. }
  21. if (samePhoneNumbers.isEmpty()) return null
  22. sameWordsList = ArrayList<ArrayList<String>>()
  23. coincidenceCount = 0
  24. samePhoneNumbers.forEachIndexed { i, spni ->
  25. Converter.findNotMatching(template.text, spni.text)?.let {
  26. sameWordsList.add(it)
  27. if (sameWordsList.size >1) {
  28. for (k in sameWordsList.size-2..sameWordsList.size - 1) {
  29. var same = true
  30. sameWordsList[0].forEachIndexed { i, s ->
  31. if (sameWordsList[k].size > i && s == sameWordsList[k][i]){
  32. same = same && true
  33. } else {
  34. same = same && false
  35. }
  36. }
  37. if (same && sameWordsList[0].size >0){
  38. coincidenceCount++
  39. }
  40. }
  41. }
  42. if(coincidenceCount >=3){
  43. return sameWordsList[0]
  44. }
  45. }
  46. }
  47. if (coincidenceCount >0){
  48. return sameWordsList[0]
  49. }
  50. return null
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement