Changed AddContactsActivity to ConnectionsActivity.
This means all neighbors are shown, not just non-contacts. Also fixed a bug where the list would not be refreshed when first opened.
This commit is contained in:
parent
123c56c322
commit
b11bf85d90
5 changed files with 34 additions and 16 deletions
|
@ -34,8 +34,8 @@
|
|||
android:theme="@style/AppTheme.NoActionBar"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.AddContactsActivity"
|
||||
android:label="@string/add_contacts"
|
||||
android:name=".activities.ConnectionsActivity"
|
||||
android:label="@string/connections"
|
||||
android:parentActivityName=".activities.MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/devices_empty"
|
||||
android:text="@string/no_connections"
|
||||
android:gravity="center" />
|
||||
|
||||
</LinearLayout>
|
|
@ -43,13 +43,13 @@
|
|||
<string name="exit">Exit</string>
|
||||
|
||||
|
||||
<!-- AddContactsActivity -->
|
||||
<!-- ConnectionsActivity -->
|
||||
|
||||
<!-- Activity title -->
|
||||
<string name="add_contacts">Add Contacts</string>
|
||||
<string name="connections">Connections</string>
|
||||
|
||||
<!-- Empty text for devices list -->
|
||||
<string name="devices_empty">Searching for Users\nRange: ~10m</string>
|
||||
<string name="no_connections">Searching for Users\nRange: ~10m</string>
|
||||
|
||||
<!-- Alertdialog message to add new contact -->
|
||||
<string name="dialog_add_contact">Do you want to add %1$s as contact?</string>
|
||||
|
@ -57,6 +57,9 @@
|
|||
<!-- Toast shown after contact has been added -->
|
||||
<string name="toast_contact_added">Contact added</string>
|
||||
|
||||
<!-- Toast shown when clicking a user that is already a contact -->
|
||||
<string name="contact_already_added">You have already added %1$s as a contact</string>
|
||||
|
||||
|
||||
<!-- SettingsActivity -->
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.nutomic.ensichat.views.UsersAdapter
|
|||
/**
|
||||
* Lists all nearby, connected devices and allows adding them to be added as contacts.
|
||||
*/
|
||||
class AddContactsActivity extends EnsichatActivity with OnItemClickListener {
|
||||
class ConnectionsActivity extends EnsichatActivity with OnItemClickListener {
|
||||
|
||||
private val Tag = "AddContactsActivity"
|
||||
|
||||
|
@ -32,7 +32,7 @@ class AddContactsActivity extends EnsichatActivity with OnItemClickListener {
|
|||
super.onCreate(savedInstanceState)
|
||||
getSupportActionBar.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
setContentView(R.layout.activity_add_contacts)
|
||||
setContentView(R.layout.activity_connections)
|
||||
val list = findViewById(android.R.id.list).asInstanceOf[ListView]
|
||||
list.setAdapter(adapter)
|
||||
list.setOnItemClickListener(this)
|
||||
|
@ -45,6 +45,13 @@ class AddContactsActivity extends EnsichatActivity with OnItemClickListener {
|
|||
.registerReceiver(onContactsUpdatedReceiver, filter)
|
||||
}
|
||||
|
||||
override def onResume(): Unit = {
|
||||
super.onResume()
|
||||
runOnServiceConnected(() => {
|
||||
updateConnections()
|
||||
})
|
||||
}
|
||||
|
||||
override def onDestroy(): Unit = {
|
||||
super.onDestroy()
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onContactsUpdatedReceiver)
|
||||
|
@ -55,12 +62,18 @@ class AddContactsActivity extends EnsichatActivity with OnItemClickListener {
|
|||
*/
|
||||
override def onItemClick(parent: AdapterView[_], view: View, position: Int, id: Long): Unit = {
|
||||
val contact = adapter.getItem(position)
|
||||
if (database.getContacts.contains(contact)) {
|
||||
val text = getString(R.string.contact_already_added, contact.name)
|
||||
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
new Builder(this)
|
||||
.setMessage(getString(R.string.dialog_add_contact, contact.name))
|
||||
.setPositiveButton(android.R.string.yes, new OnClickListener {
|
||||
override def onClick(dialog: DialogInterface, which: Int): Unit = {
|
||||
database.addContact(contact)
|
||||
Toast.makeText(AddContactsActivity.this, R.string.toast_contact_added, Toast.LENGTH_SHORT)
|
||||
Toast.makeText(ConnectionsActivity.this, R.string.toast_contact_added, Toast.LENGTH_SHORT)
|
||||
.show()
|
||||
}
|
||||
})
|
||||
|
@ -82,13 +95,15 @@ class AddContactsActivity extends EnsichatActivity with OnItemClickListener {
|
|||
private val onContactsUpdatedReceiver = new BroadcastReceiver() {
|
||||
override def onReceive(context: Context, intent: Intent): Unit = {
|
||||
runOnUiThread(new Runnable {
|
||||
override def run(): Unit = {
|
||||
adapter.clear()
|
||||
(service.get.connections().map(a => service.get.getUser(a)) -- database.getContacts)
|
||||
.foreach(adapter.add)
|
||||
}
|
||||
override def run(): Unit = updateConnections()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private def updateConnections(): Unit = {
|
||||
adapter.clear()
|
||||
service.get.connections().map(a => service.get.getUser(a))
|
||||
.foreach(adapter.add)
|
||||
}
|
||||
|
||||
}
|
|
@ -14,7 +14,7 @@ import android.view.View.OnClickListener
|
|||
import android.view._
|
||||
import android.widget.{ListView, TextView, Toast}
|
||||
import com.nutomic.ensichat.R
|
||||
import com.nutomic.ensichat.activities.{AddContactsActivity, EnsichatActivity, MainActivity, SettingsActivity}
|
||||
import com.nutomic.ensichat.activities.{ConnectionsActivity, EnsichatActivity, MainActivity, SettingsActivity}
|
||||
import com.nutomic.ensichat.protocol.{ChatService, Crypto}
|
||||
import com.nutomic.ensichat.util.Database
|
||||
import com.nutomic.ensichat.views.UsersAdapter
|
||||
|
@ -80,7 +80,7 @@ class ContactsFragment extends ListFragment with OnClickListener {
|
|||
}
|
||||
|
||||
override def onClick(v: View): Unit =
|
||||
startActivity(new Intent(getActivity, classOf[AddContactsActivity]))
|
||||
startActivity(new Intent(getActivity, classOf[ConnectionsActivity]))
|
||||
|
||||
override def onOptionsItemSelected(item: MenuItem): Boolean = item.getItemId match {
|
||||
case R.id.share_app =>
|
||||
|
|
Reference in a new issue