added contacts/contact activities
This commit is contained in:
@ -35,14 +35,13 @@
|
||||
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
|
||||
|
||||
<application
|
||||
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".MainActivity"
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:launchMode="singleTask" >
|
||||
<intent-filter>
|
||||
@ -50,16 +49,14 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AccountsActivity"
|
||||
android:label="Accounts"
|
||||
android:parentActivityName=".MainActivity">
|
||||
android:parentActivityName=".MainActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AccountActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
@ -69,7 +66,24 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ContactsActivity"
|
||||
android:label="Contacts"
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:parentActivityName=".MainActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ContactActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:label="Contact"
|
||||
android:parentActivityName=".MainActivity" >
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".EditConfigActivity"
|
||||
android:label="Edit Config"
|
||||
@ -78,16 +92,6 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".EditContactsActivity"
|
||||
android:label="Edit Contacts"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".HistoryActivity"
|
||||
android:label="Call History"
|
||||
@ -96,7 +100,6 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".AboutActivity"
|
||||
android:label="About"
|
||||
@ -105,8 +108,6 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.tutpro.baresip.MainActivity" />
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
|
||||
82
app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt
Normal file
82
app/src/main/kotlin/com/tutpro/baresip/ContactActivity.kt
Normal file
@ -0,0 +1,82 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
class ContactActivity : AppCompatActivity() {
|
||||
|
||||
lateinit var nameView: EditText
|
||||
lateinit var uriView: EditText
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_contact)
|
||||
|
||||
index = intent.extras.getInt("index")
|
||||
val name = ContactsActivity.contactNames[index]
|
||||
val uri = ContactsActivity.contactURIs[index]
|
||||
setTitle(name)
|
||||
|
||||
nameView = findViewById(R.id.Name) as EditText
|
||||
nameView.setText(name)
|
||||
|
||||
uriView = findViewById(R.id.Uri) as EditText
|
||||
uriView.setText(uri)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
val inflater = menuInflater
|
||||
inflater.inflate(R.menu.check_icon, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
val i = Intent(this, MainActivity::class.java)
|
||||
|
||||
if (item.itemId == R.id.checkIcon) {
|
||||
|
||||
val name = nameView.text.toString().trim()
|
||||
if (!Utils.checkName(name)) {
|
||||
Utils.alertView(this, "Notice",
|
||||
"Invalid contact name: $name")
|
||||
return false
|
||||
}
|
||||
|
||||
var uri = uriView.text.toString().trim()
|
||||
if (!uri.startsWith("<")) {
|
||||
if (!uri.startsWith("sip:")) uri = "sip:$uri"
|
||||
if (!Utils.checkUri(uri)) {
|
||||
Utils.alertView(this, "Notice","Invalid contact URI: $uri")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
ContactsActivity.contactNames[index] = name
|
||||
ContactsActivity.contactURIs[index] = uri
|
||||
ContactsActivity.saveContacts()
|
||||
setResult(RESULT_OK, i)
|
||||
finish()
|
||||
return true
|
||||
|
||||
} else if (item.itemId == android.R.id.home) {
|
||||
|
||||
Log.d("Baresip", "Back array was pressed at Contact")
|
||||
setResult(RESULT_CANCELED, i)
|
||||
finish()
|
||||
return true
|
||||
|
||||
} else return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
companion object {
|
||||
internal var index = 0
|
||||
}
|
||||
|
||||
}
|
||||
57
app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt
Normal file
57
app/src/main/kotlin/com/tutpro/baresip/ContactListAdapter.kt
Normal file
@ -0,0 +1,57 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
|
||||
import java.util.*
|
||||
|
||||
class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<String>) :
|
||||
ArrayAdapter<String>(cxt, R.layout.contact_row, rows) {
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val row = rows[position]
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
||||
val nameView = rowView.findViewById(R.id.contactName) as TextView
|
||||
nameView.text = row
|
||||
nameView.textSize = 20f
|
||||
nameView.setPadding(6, 6, 0, 6)
|
||||
nameView.setOnClickListener { _ ->
|
||||
val i = Intent(cxt, ContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putInt("index", position)
|
||||
i.putExtras(b)
|
||||
(cxt as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||
}
|
||||
val actionView = rowView.findViewById(R.id.contactAction) as ImageButton
|
||||
actionView.setImageResource(R.drawable.action_remove)
|
||||
actionView.setOnClickListener { _ ->
|
||||
Log.d("Baresip", "Delete button clicked")
|
||||
val deleteDialog = AlertDialog.Builder(cxt)
|
||||
deleteDialog.setMessage("Do you want to delete contact ${row}")
|
||||
deleteDialog.setPositiveButton("Delete") { dialog, _ ->
|
||||
ContactsActivity.contactNames.removeAt(position)
|
||||
ContactsActivity.contactURIs.removeAt(position)
|
||||
ContactsActivity.posAtContacts.removeAt(position)
|
||||
ContactsActivity.saveContacts()
|
||||
this.notifyDataSetChanged()
|
||||
dialog.dismiss()
|
||||
}
|
||||
deleteDialog.setNegativeButton("No") { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}
|
||||
deleteDialog.create().show()
|
||||
}
|
||||
return rowView
|
||||
}
|
||||
}
|
||||
124
app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt
Normal file
124
app/src/main/kotlin/com/tutpro/baresip/ContactsActivity.kt
Normal file
@ -0,0 +1,124 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
import java.io.File
|
||||
import java.util.ArrayList
|
||||
|
||||
class ContactsActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var layout: LinearLayout
|
||||
internal var name: String = ""
|
||||
lateinit var clAdapter: ContactListAdapter
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_contacts)
|
||||
|
||||
val listview = findViewById(R.id.contacts) as ListView
|
||||
Log.d("Baresip", "Got ${contactNames.size} contacts")
|
||||
clAdapter = ContactListAdapter(this, contactNames)
|
||||
listview.adapter = clAdapter
|
||||
|
||||
val addContactButton = findViewById(R.id.addContact) as ImageButton
|
||||
val newNameView = findViewById(R.id.newName) as EditText
|
||||
addContactButton.setOnClickListener{
|
||||
val name = newNameView.text.toString().trim()
|
||||
if (!Utils.checkName(name)) {
|
||||
Log.e("Baresip", "Invalid contact name $name")
|
||||
Utils.alertView(this, "Notice",
|
||||
"Invalid contact name: $name")
|
||||
} else if (contactNames.contains(name)) {
|
||||
Log.e("Baresip", "Contact name $name already exists")
|
||||
Utils.alertView(this, "Notice",
|
||||
"Contact $name already exists")
|
||||
} else {
|
||||
newNameView.setText("")
|
||||
newNameView.hint = "Contact name"
|
||||
newNameView.clearFocus()
|
||||
contactNames.add(name)
|
||||
contactURIs.add("")
|
||||
posAtContacts.add(contactNames.size)
|
||||
clAdapter.notifyDataSetChanged()
|
||||
saveContacts()
|
||||
val i = Intent(this, ContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putInt("index", contactNames.size - 1)
|
||||
i.putExtras(b)
|
||||
startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
Log.d("Baresip", "Back array was pressed at Contacts")
|
||||
val i = Intent()
|
||||
setResult(Activity.RESULT_OK, i)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Log.d("Baresip", "Notifying clAdapter")
|
||||
clAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
var contactNames = ArrayList<String>()
|
||||
var contactURIs = ArrayList<String>()
|
||||
var posAtContacts = ArrayList<Int>()
|
||||
|
||||
fun generateContacts(path: String) {
|
||||
val content = Utils.getFileContents(File(path))
|
||||
MainActivity.contacts_remove()
|
||||
contactNames.clear()
|
||||
contactURIs.clear()
|
||||
posAtContacts.clear()
|
||||
var i = 0
|
||||
content.lines().forEach {
|
||||
val parts = it.split("\"")
|
||||
if (parts.size == 3) {
|
||||
val name = parts[1]
|
||||
var uri = parts[2].trim()
|
||||
MainActivity.contact_add("\"$name\" $uri")
|
||||
contactNames.add(name)
|
||||
contactURIs.add(uri)
|
||||
posAtContacts.add(i++)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun saveContacts() {
|
||||
var contents = ""
|
||||
for (i in contactNames.indices)
|
||||
contents += "\"${contactNames[i]}\" ${contactURIs[i]}\n"
|
||||
val path = MainActivity.filesPath + "/contacts"
|
||||
Utils.putFileContents(File(path), contents)
|
||||
Log.d("Baresip", "Saved contacts '${contents}' to '$path")
|
||||
}
|
||||
|
||||
fun findContactURI(name: String): String {
|
||||
for (i in contactNames.indices)
|
||||
if (contactNames[i] == name)
|
||||
return contactURIs[i].removePrefix("<")
|
||||
.replaceAfter(">", "")
|
||||
.replace(">", "")
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
50
app/src/main/res/layout/activity_contact.xml
Normal file
50
app/src/main/res/layout/activity_contact.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/ContactView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="24dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/NameTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:text="Contact Name" >
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/Name"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPersonName"
|
||||
android:textSize="18sp"
|
||||
android:layout_width="fill_parent">
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/SipUriTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingTop="10dp"
|
||||
android:text="SIP URI" >
|
||||
</TextView>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/Uri"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="SIP URI, telephone number, or userid"
|
||||
android:inputType="textUri"
|
||||
android:textSize="18sp"
|
||||
android:layout_width="fill_parent">
|
||||
</EditText>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
48
app/src/main/res/layout/activity_contacts.xml
Normal file
48
app/src/main/res/layout/activity_contacts.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.tutpro.baresip.ContactsActivity">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/contacts"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<EditText
|
||||
android:id="@+id/newName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:textSize="20sp"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="0dp"
|
||||
android:hint="Name of Contact" >
|
||||
</EditText>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/addContact"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:src="@drawable/action_add"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageButton>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
29
app/src/main/res/layout/contact_row.xml
Normal file
29
app/src/main/res/layout/contact_row.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contactRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contactName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginBottom="6dp">
|
||||
</TextView>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/contactAction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:icon="@android:drawable/ic_menu_delete"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageButton>
|
||||
|
||||
</RelativeLayout>
|
||||
Reference in New Issue
Block a user