From 2129107684dc9e5a68e7e16a9473d8242adff426 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 7 Nov 2014 17:20:29 +0200 Subject: [PATCH] Moved exit button to ContactsFragment so it isn't shown when chat is open. --- .../ensichat/activities/MainActivity.scala | 16 ---------------- .../ensichat/fragments/ContactsFragment.scala | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 17 deletions(-) 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 ddbbec0..cd2d781 100644 --- a/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala +++ b/app/src/main/scala/com/nutomic/ensichat/activities/MainActivity.scala @@ -59,11 +59,6 @@ class MainActivity extends Activity { currentChat.collect{case c => outState.putString("current_chat", c.toString)} } - override def onCreateOptionsMenu(menu: Menu): Boolean = { - getMenuInflater.inflate(R.menu.main, menu) - true - } - /** * Exits with error if bluetooth was not enabled/not set discoverable, */ @@ -77,17 +72,6 @@ class MainActivity extends Activity { } } - override def onOptionsItemSelected(item: MenuItem): Boolean = { - item.getItemId match { - case R.id.exit => - stopService(new Intent(this, classOf[ChatService])) - finish() - true - case _ => - false - } - } - /** * Opens a chat fragment for the given device, creating the fragment if needed. */ diff --git a/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala b/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala index f8b101e..cb44a95 100644 --- a/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala +++ b/app/src/main/scala/com/nutomic/ensichat/fragments/ContactsFragment.scala @@ -3,7 +3,7 @@ package com.nutomic.ensichat.fragments import android.app.ListFragment import android.content.{ComponentName, Context, Intent, ServiceConnection} import android.os.{Bundle, IBinder} -import android.view.{LayoutInflater, View, ViewGroup} +import android.view._ import android.widget.{ArrayAdapter, ListView} import com.nutomic.ensichat.R import com.nutomic.ensichat.activities.MainActivity @@ -44,6 +44,7 @@ class ContactsFragment extends ListFragment with ChatService.OnDeviceConnectedLi setListAdapter(adapter) getActivity.bindService(new Intent(getActivity, classOf[ChatService]), ChatServiceConnection, Context.BIND_AUTO_CREATE) + setHasOptionsMenu(true) } override def onDestroy(): Unit = { @@ -51,6 +52,22 @@ class ContactsFragment extends ListFragment with ChatService.OnDeviceConnectedLi getActivity.unbindService(ChatServiceConnection) } + override def onCreateOptionsMenu(menu: Menu, inflater: MenuInflater): Unit = { + super.onCreateOptionsMenu(menu, inflater) + inflater.inflate(R.menu.main, menu) + } + + override def onOptionsItemSelected(item: MenuItem): Boolean = { + item.getItemId match { + case R.id.exit => + getActivity.stopService(new Intent(getActivity, classOf[ChatService])) + getActivity.finish() + true + case _ => + super.onOptionsItemSelected(item) + } + } + /** * Displays newly connected devices in the list. */