Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- override fun doInBackground(vararg params: Void?): ArrayList<String>? {
- if (!mvpView.checkForPermissions()) return null
- var selection = "address LIKE '%${template.phoneNumb}%'"
- val cursor = context.contentResolver.query(Uri.parse("content://sms/inbox"), null, selection, null, null)
- var count:Int = 0
- var samePhoneNumbers = ArrayList<TemplateItem>()
- if (cursor != null && cursor.moveToFirst()) { // must check the result to prevent exception
- count = cursor.count
- var item:TemplateItem
- for (idx in 1..count) {
- if (cursor.moveToPosition(idx)) {
- item = TemplateItem()
- item.phoneNumb = cursor.getString(cursor.getColumnIndexOrThrow("address"))
- item.name = item.phoneNumb
- item.text = cursor.getString(cursor.getColumnIndexOrThrow("body"))
- samePhoneNumbers.add(item)
- }
- }
- }
- if (samePhoneNumbers.isEmpty()) return null
- sameWordsList = ArrayList<ArrayList<String>>()
- coincidenceCount = 0
- samePhoneNumbers.forEachIndexed { i, spni ->
- Converter.findNotMatching(template.text, spni.text)?.let {
- sameWordsList.add(it)
- if (sameWordsList.size >1) {
- for (k in sameWordsList.size-2..sameWordsList.size - 1) {
- var same = true
- sameWordsList[0].forEachIndexed { i, s ->
- if (sameWordsList[k].size > i && s == sameWordsList[k][i]){
- same = same && true
- } else {
- same = same && false
- }
- }
- if (same && sameWordsList[0].size >0){
- coincidenceCount++
- }
- }
- }
- if(coincidenceCount >=3){
- return sameWordsList[0]
- }
- }
- }
- if (coincidenceCount >0){
- return sameWordsList[0]
- }
- return null
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement