Open chat after adding a new contact.
Currently, you have to press back twice in the ContactsFragment after this to exit the app.
This commit is contained in:
parent
64e8b06543
commit
5b07ecab23
2 changed files with 19 additions and 5 deletions
|
@ -2,7 +2,7 @@ package com.nutomic.ensichat.activities
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
import android.content.DialogInterface.OnClickListener
|
import android.content.DialogInterface.OnClickListener
|
||||||
import android.content.{Context, DialogInterface}
|
import android.content.{Intent, Context, DialogInterface}
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.NavUtils
|
import android.support.v4.app.NavUtils
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -129,19 +129,23 @@ class AddContactsActivity extends EnsiChatActivity with ChatService.OnConnection
|
||||||
case _: RequestAddContact =>
|
case _: RequestAddContact =>
|
||||||
Log.i(Tag, "Remote device " + msg.Header.Origin + " wants to add us as a contact, showing dialog")
|
Log.i(Tag, "Remote device " + msg.Header.Origin + " wants to add us as a contact, showing dialog")
|
||||||
service.getConnections.find(_.Address == msg.Header.Origin).foreach(addDeviceDialog)
|
service.getConnections.find(_.Address == msg.Header.Origin).foreach(addDeviceDialog)
|
||||||
case _: ResultAddContact =>
|
case m: ResultAddContact =>
|
||||||
currentlyAdding.keys.find(_.Address == msg.Header.Origin).foreach(contact =>
|
currentlyAdding.keys.find(_.Address == msg.Header.Origin).foreach(contact =>
|
||||||
if (msg.Body.asInstanceOf[ResultAddContact].Accepted) {
|
if (m.Accepted) {
|
||||||
Log.i(Tag, contact.toString + " accepted us as a contact, updating state")
|
Log.i(Tag, contact.toString + " accepted us as a contact, updating state")
|
||||||
currentlyAdding += (contact ->
|
currentlyAdding += (contact ->
|
||||||
new AddContactInfo(true, currentlyAdding(contact).remoteConfirmed))
|
new AddContactInfo(true, currentlyAdding(contact).remoteConfirmed))
|
||||||
addContactIfBothConfirmed(contact)
|
addContactIfBothConfirmed(contact)
|
||||||
|
val intent = new Intent(this, classOf[MainActivity])
|
||||||
|
intent.setAction(MainActivity.ActionOpenChat)
|
||||||
|
intent.putExtra(MainActivity.ExtraAddress, msg.Header.Origin.toString)
|
||||||
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
} else {
|
} else {
|
||||||
Log.i(Tag, contact.toString + " denied us as a contact, showing toast")
|
Log.i(Tag, contact.toString + " denied us as a contact, showing toast")
|
||||||
Toast.makeText(this, R.string.contact_not_added, Toast.LENGTH_LONG).show()
|
Toast.makeText(this, R.string.contact_not_added, Toast.LENGTH_LONG).show()
|
||||||
currentlyAdding -= contact
|
currentlyAdding -= contact
|
||||||
}
|
})
|
||||||
)
|
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,13 @@ import com.nutomic.ensichat.R
|
||||||
import com.nutomic.ensichat.fragments.{ChatFragment, ContactsFragment}
|
import com.nutomic.ensichat.fragments.{ChatFragment, ContactsFragment}
|
||||||
import com.nutomic.ensichat.protocol.Address
|
import com.nutomic.ensichat.protocol.Address
|
||||||
|
|
||||||
|
object MainActivity {
|
||||||
|
|
||||||
|
val ActionOpenChat = "open_chat"
|
||||||
|
|
||||||
|
val ExtraAddress = "address"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main activity, entry point for app start.
|
* Main activity, entry point for app start.
|
||||||
*/
|
*/
|
||||||
|
@ -47,6 +54,9 @@ class MainActivity extends EnsiChatActivity {
|
||||||
.add(android.R.id.content, ContactsFragment)
|
.add(android.R.id.content, ContactsFragment)
|
||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getIntent.getAction == MainActivity.ActionOpenChat)
|
||||||
|
openChat(new Address(getIntent.getStringExtra(MainActivity.ExtraAddress)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue