From 5b07ecab2364ae8e8fa291ec073cb5ebf56193c7 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 30 Jan 2015 02:32:54 +0100 Subject: [PATCH] Open chat after adding a new contact. Currently, you have to press back twice in the ContactsFragment after this to exit the app. --- .../ensichat/activities/AddContactsActivity.scala | 14 +++++++++----- .../nutomic/ensichat/activities/MainActivity.scala | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/src/main/scala/com/nutomic/ensichat/activities/AddContactsActivity.scala b/app/src/main/scala/com/nutomic/ensichat/activities/AddContactsActivity.scala index e6579c7..f125063 100644 --- a/app/src/main/scala/com/nutomic/ensichat/activities/AddContactsActivity.scala +++ b/app/src/main/scala/com/nutomic/ensichat/activities/AddContactsActivity.scala @@ -2,7 +2,7 @@ package com.nutomic.ensichat.activities import android.app.AlertDialog import android.content.DialogInterface.OnClickListener -import android.content.{Context, DialogInterface} +import android.content.{Intent, Context, DialogInterface} import android.os.Bundle import android.support.v4.app.NavUtils import android.util.Log @@ -129,19 +129,23 @@ class AddContactsActivity extends EnsiChatActivity with ChatService.OnConnection case _: RequestAddContact => 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) - case _: ResultAddContact => + case m: ResultAddContact => 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") currentlyAdding += (contact -> new AddContactInfo(true, currentlyAdding(contact).remoteConfirmed)) 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 { Log.i(Tag, contact.toString + " denied us as a contact, showing toast") Toast.makeText(this, R.string.contact_not_added, Toast.LENGTH_LONG).show() currentlyAdding -= contact - } - ) + }) case _ => } } diff --git a/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala b/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala index 9b05838..74a3af8 100644 --- a/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala +++ b/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala @@ -10,6 +10,13 @@ import com.nutomic.ensichat.R import com.nutomic.ensichat.fragments.{ChatFragment, ContactsFragment} import com.nutomic.ensichat.protocol.Address +object MainActivity { + + val ActionOpenChat = "open_chat" + + val ExtraAddress = "address" +} + /** * Main activity, entry point for app start. */ @@ -47,6 +54,9 @@ class MainActivity extends EnsiChatActivity { .add(android.R.id.content, ContactsFragment) .commit() } + + if (getIntent.getAction == MainActivity.ActionOpenChat) + openChat(new Address(getIntent.getStringExtra(MainActivity.ExtraAddress))) } /**