Minor code cleanup

This commit is contained in:
Juha Heinanen
2022-02-18 10:11:22 +02:00
parent 9ff543fd6d
commit 7d943362c6
3 changed files with 11 additions and 15 deletions
@@ -208,14 +208,14 @@ sealed class Contact {
BaresipService.contactUpdate.postValue(System.nanoTime()) BaresipService.contactUpdate.postValue(System.nanoTime())
} }
fun sortContacts() { private fun sortContacts() {
BaresipService.contacts.sortBy{ when (it) { BaresipService.contacts.sortBy{ when (it) {
is BaresipContact -> it.name is BaresipContact -> it.name
is AndroidContact -> it.name is AndroidContact -> it.name
}} }}
} }
fun generateContactNames () { private fun generateContactNames () {
BaresipService.contactNames.clear() BaresipService.contactNames.clear()
BaresipService.contactNames.addAll( BaresipService.contactNames.addAll(
BaresipService.contacts.map { BaresipService.contacts.map {
@@ -494,16 +494,4 @@ class ContactActivity : AppCompatActivity() {
} }
} }
companion object {
var contact: Contact? = null
fun deleteAndroidContact(ctx: Context, name: String): Int {
return ctx.contentResolver.delete(ContactsContract.RawContacts.CONTENT_URI,
ContactsContract.Contacts.DISPLAY_NAME + "='" + name + "'",
null)
}
}
} }
@@ -6,6 +6,7 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.SystemClock import android.os.SystemClock
import android.provider.ContactsContract
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@@ -176,7 +177,7 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
this.notifyDataSetChanged() this.notifyDataSetChanged()
} }
is Contact.AndroidContact -> { is Contact.AndroidContact -> {
ContactActivity.deleteAndroidContact(ctx, contact.name) deleteAndroidContact(ctx, contact.name)
} }
} }
} }
@@ -202,4 +203,11 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
return rowView return rowView
} }
private fun deleteAndroidContact(ctx: Context, name: String): Int {
return ctx.contentResolver.delete(ContactsContract.RawContacts.CONTENT_URI,
ContactsContract.Contacts.DISPLAY_NAME + "='" + name + "'",
null)
}
} }