Don't show existing contacts in AddContactsActivity.
This commit is contained in:
parent
2f08ec0124
commit
b1f59eaaff
3 changed files with 18 additions and 23 deletions
|
@ -42,9 +42,6 @@
|
|||
<!-- Empty text for devices list -->
|
||||
<string name="no_devices_nearby">No nearby devices found</string>
|
||||
|
||||
<!-- Toast shown when trying to add a contact again -->
|
||||
<string name="contact_already_added">You already added this contact</string>
|
||||
|
||||
<!-- Toast shown when a new contact was added. Parameter is contact name -->
|
||||
<string name="contact_added">%1$s was added as a contact</string>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import android.widget._
|
|||
import com.nutomic.ensichat.R
|
||||
import com.nutomic.ensichat.protocol.messages.{Message, RequestAddContact, ResultAddContact}
|
||||
import com.nutomic.ensichat.protocol.{User, Address, ChatService, Crypto}
|
||||
import com.nutomic.ensichat.util.{UsersAdapter, IdenticonGenerator}
|
||||
import com.nutomic.ensichat.util.{Database, UsersAdapter, IdenticonGenerator}
|
||||
|
||||
import scala.collection.SortedSet
|
||||
|
||||
|
@ -62,31 +62,17 @@ class AddContactsActivity extends EnsiChatActivity with ChatService.OnConnection
|
|||
runOnServiceConnected(() => {
|
||||
service.registerConnectionListener(AddContactsActivity.this)
|
||||
service.registerMessageListener(this)
|
||||
Database.runOnContactsUpdated(updateList)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays newly connected devices in the list.
|
||||
*/
|
||||
override def onConnectionsChanged(contacts: Set[User]): Unit = {
|
||||
runOnUiThread(new Runnable {
|
||||
override def run(): Unit = {
|
||||
Adapter.clear()
|
||||
contacts.foreach(Adapter.add)
|
||||
}
|
||||
})
|
||||
}
|
||||
override def onConnectionsChanged() = updateList()
|
||||
|
||||
/**
|
||||
* Initiates adding the device as contact if it hasn't been added yet.
|
||||
*/
|
||||
override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long): Unit = {
|
||||
val contact = Adapter.getItem(position)
|
||||
if (Database.getContact(contact.Address).nonEmpty) {
|
||||
Toast.makeText(this, R.string.contact_already_added, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
service.sendTo(contact.Address, new RequestAddContact())
|
||||
addDeviceDialog(contact)
|
||||
}
|
||||
|
@ -181,4 +167,16 @@ class AddContactsActivity extends EnsiChatActivity with ChatService.OnConnection
|
|||
super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches connections and displays them (excluding contacts).
|
||||
*/
|
||||
private def updateList(): Unit ={
|
||||
runOnUiThread(new Runnable {
|
||||
override def run(): Unit = {
|
||||
Adapter.clear()
|
||||
(service.getConnections -- service.Database.getContacts).foreach(Adapter.add)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ object ChatService {
|
|||
* connects or disconnects
|
||||
*/
|
||||
trait OnConnectionsChangedListener {
|
||||
def onConnectionsChanged(contacts: Set[User]): Unit
|
||||
def onConnectionsChanged(): Unit
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ class ChatService extends Service {
|
|||
*/
|
||||
def registerConnectionListener(listener: OnConnectionsChangedListener): Unit = {
|
||||
connectionListeners += new WeakReference[OnConnectionsChangedListener](listener)
|
||||
listener.onConnectionsChanged(getConnections)
|
||||
listener.onConnectionsChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +212,7 @@ class ChatService extends Service {
|
|||
def callConnectionListeners(): Unit = {
|
||||
connectionListeners
|
||||
.filter(_.get.nonEmpty)
|
||||
.foreach(_.apply().onConnectionsChanged(getConnections))
|
||||
.foreach(_.apply().onConnectionsChanged())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue