Moved exit button to ContactsFragment so it isn't shown when chat is open.
This commit is contained in:
parent
c1c4239499
commit
2129107684
2 changed files with 18 additions and 17 deletions
|
@ -59,11 +59,6 @@ class MainActivity extends Activity {
|
||||||
currentChat.collect{case c => outState.putString("current_chat", c.toString)}
|
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,
|
* 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.
|
* Opens a chat fragment for the given device, creating the fragment if needed.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.nutomic.ensichat.fragments
|
||||||
import android.app.ListFragment
|
import android.app.ListFragment
|
||||||
import android.content.{ComponentName, Context, Intent, ServiceConnection}
|
import android.content.{ComponentName, Context, Intent, ServiceConnection}
|
||||||
import android.os.{Bundle, IBinder}
|
import android.os.{Bundle, IBinder}
|
||||||
import android.view.{LayoutInflater, View, ViewGroup}
|
import android.view._
|
||||||
import android.widget.{ArrayAdapter, ListView}
|
import android.widget.{ArrayAdapter, ListView}
|
||||||
import com.nutomic.ensichat.R
|
import com.nutomic.ensichat.R
|
||||||
import com.nutomic.ensichat.activities.MainActivity
|
import com.nutomic.ensichat.activities.MainActivity
|
||||||
|
@ -44,6 +44,7 @@ class ContactsFragment extends ListFragment with ChatService.OnDeviceConnectedLi
|
||||||
setListAdapter(adapter)
|
setListAdapter(adapter)
|
||||||
getActivity.bindService(new Intent(getActivity, classOf[ChatService]),
|
getActivity.bindService(new Intent(getActivity, classOf[ChatService]),
|
||||||
ChatServiceConnection, Context.BIND_AUTO_CREATE)
|
ChatServiceConnection, Context.BIND_AUTO_CREATE)
|
||||||
|
setHasOptionsMenu(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onDestroy(): Unit = {
|
override def onDestroy(): Unit = {
|
||||||
|
@ -51,6 +52,22 @@ class ContactsFragment extends ListFragment with ChatService.OnDeviceConnectedLi
|
||||||
getActivity.unbindService(ChatServiceConnection)
|
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.
|
* Displays newly connected devices in the list.
|
||||||
*/
|
*/
|
||||||
|
|
Reference in a new issue