Avoid warnings in ContactActivity
This commit is contained in:
@@ -20,6 +20,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.cardview.widget.CardView
|
import androidx.cardview.widget.CardView
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
@@ -29,8 +30,6 @@ import java.io.File
|
|||||||
|
|
||||||
class ContactActivity : AppCompatActivity() {
|
class ContactActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private val READ_REQUEST_CODE = 42
|
|
||||||
|
|
||||||
private lateinit var binding: ActivityContactBinding
|
private lateinit var binding: ActivityContactBinding
|
||||||
private lateinit var textAvatarView: TextView
|
private lateinit var textAvatarView: TextView
|
||||||
private lateinit var cardAvatarView: CardView
|
private lateinit var cardAvatarView: CardView
|
||||||
@@ -101,13 +100,36 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
oldAndroid = androidCheck.isChecked
|
oldAndroid = androidCheck.isChecked
|
||||||
|
|
||||||
|
val avatarRequest =
|
||||||
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
|
if (it.resultCode == Activity.RESULT_OK) {
|
||||||
|
it.data?.data?.also { uri ->
|
||||||
|
try {
|
||||||
|
val inputStream = baseContext.contentResolver.openInputStream(uri)
|
||||||
|
val avatarBitmap = BitmapFactory.decodeStream(inputStream)
|
||||||
|
inputStream?.close()
|
||||||
|
val scaledBitmap = Bitmap.createScaledBitmap(avatarBitmap, 192, 192, true)
|
||||||
|
val exif = ExifInterface(baseContext.contentResolver.openInputStream(uri)!!)
|
||||||
|
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
|
||||||
|
ExifInterface.ORIENTATION_NORMAL)
|
||||||
|
val rotatedBitmap = rotateBitmap(scaledBitmap, orientation)
|
||||||
|
showImageAvatar(rotatedBitmap)
|
||||||
|
if (Utils.saveBitmap(rotatedBitmap, File(BaresipService.filesPath, "tmp.png")))
|
||||||
|
newAvatar = "image"
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Could not read avatar image: $e")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
textAvatarView.setOnClickListener {
|
textAvatarView.setOnClickListener {
|
||||||
|
|
||||||
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
val intent = Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||||
addCategory(Intent.CATEGORY_OPENABLE)
|
addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
type = "image/*"
|
type = "image/*"
|
||||||
}
|
}
|
||||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
avatarRequest.launch(intent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +148,7 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
addCategory(Intent.CATEGORY_OPENABLE)
|
addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
type = "image/*"
|
type = "image/*"
|
||||||
}
|
}
|
||||||
startActivityForResult(intent, READ_REQUEST_CODE)
|
avatarRequest.launch(intent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,32 +165,6 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
|
||||||
|
|
||||||
super.onActivityResult(requestCode, resultCode, resultData)
|
|
||||||
|
|
||||||
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
|
||||||
resultData?.data?.also { uri ->
|
|
||||||
try {
|
|
||||||
val inputStream = baseContext.contentResolver.openInputStream(uri)
|
|
||||||
val avatarBitmap = BitmapFactory.decodeStream(inputStream)
|
|
||||||
inputStream?.close()
|
|
||||||
val scaledBitmap = Bitmap.createScaledBitmap(avatarBitmap, 192, 192, true)
|
|
||||||
val exif = ExifInterface(baseContext.contentResolver.openInputStream(uri)!!)
|
|
||||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
|
|
||||||
ExifInterface.ORIENTATION_NORMAL)
|
|
||||||
val rotatedBitmap = rotateBitmap(scaledBitmap, orientation)
|
|
||||||
showImageAvatar(rotatedBitmap)
|
|
||||||
if (Utils.saveBitmap(rotatedBitmap, File(BaresipService.filesPath, "tmp.png")))
|
|
||||||
newAvatar = "image"
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Could not read avatar image: $e")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(optionsMenu: Menu): Boolean {
|
override fun onCreateOptionsMenu(optionsMenu: Menu): Boolean {
|
||||||
|
|
||||||
super.onCreateOptionsMenu(optionsMenu)
|
super.onCreateOptionsMenu(optionsMenu)
|
||||||
@@ -198,11 +194,10 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
String.format(getString(R.string.invalid_contact), newName))
|
String.format(getString(R.string.invalid_contact), newName))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
val alert: Boolean
|
val alert: Boolean = if (newContact)
|
||||||
if (newContact)
|
ContactsActivity.nameExists(newName, true)
|
||||||
alert = ContactsActivity.nameExists(newName, true)
|
|
||||||
else
|
else
|
||||||
alert = (Contact.contacts()[index].name != newName) &&
|
(Contact.contacts()[index].name != newName) &&
|
||||||
ContactsActivity.nameExists(newName, false)
|
ContactsActivity.nameExists(newName, false)
|
||||||
if (alert) {
|
if (alert) {
|
||||||
Utils.alertView(this, getString(R.string.notice),
|
Utils.alertView(this, getString(R.string.notice),
|
||||||
@@ -211,11 +206,10 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!newUri.startsWith("sip:")) {
|
if (!newUri.startsWith("sip:")) {
|
||||||
if (newUri.contains("@") || (BaresipService.uas.size != 1)) {
|
newUri = if (newUri.contains("@") || (BaresipService.uas.size != 1))
|
||||||
newUri = "sip:$newUri"
|
"sip:$newUri"
|
||||||
} else {
|
else
|
||||||
newUri = "sip:$newUri@${Utils.aorDomain(BaresipService.uas[0].account.aor)}"
|
"sip:$newUri@${Utils.aorDomain(BaresipService.uas[0].account.aor)}"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!Utils.checkSipUri(newUri)) {
|
if (!Utils.checkSipUri(newUri)) {
|
||||||
Utils.alertView(this, getString(R.string.notice),
|
Utils.alertView(this, getString(R.string.notice),
|
||||||
@@ -302,6 +296,7 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>,
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>,
|
||||||
grantResults: IntArray) {
|
grantResults: IntArray) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
|
|
||||||
@@ -522,6 +517,7 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
null)
|
null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNUSED")
|
||||||
fun logAndroidSipContacts(ctx: Context): HashMap<Long, MutableList<String>> {
|
fun logAndroidSipContacts(ctx: Context): HashMap<Long, MutableList<String>> {
|
||||||
val contacts = HashMap<Long, MutableList<String>>()
|
val contacts = HashMap<Long, MutableList<String>>()
|
||||||
val projection = arrayOf(ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME,
|
val projection = arrayOf(ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME,
|
||||||
|
|||||||
Reference in New Issue
Block a user