Show warning toast if message can't be sent.
This commit is contained in:
parent
02f7d87929
commit
0eab785e96
3 changed files with 13 additions and 6 deletions
|
@ -115,4 +115,6 @@
|
|||
<!-- Notification text for incoming message -->
|
||||
<string name="notification_message">New message!</string>
|
||||
|
||||
<string name="toast_user_not_connected">User is not connected. Cannot send message.</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -109,8 +109,9 @@ class ChatFragment extends ListFragment with OnClickListener {
|
|||
val text = messageText.getText.toString.trim
|
||||
if (!text.isEmpty) {
|
||||
val message = new Text(text.toString)
|
||||
chatService.sendTo(address, message)
|
||||
messageText.getText.clear()
|
||||
val success = chatService.sendTo(address, message)
|
||||
if (success)
|
||||
messageText.getText.clear()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.preference.PreferenceManager
|
|||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.nutomic.ensichat.R
|
||||
import com.nutomic.ensichat.activities.MainActivity
|
||||
import com.nutomic.ensichat.bluetooth.BluetoothInterface
|
||||
|
@ -118,11 +119,13 @@ class ChatService extends Service {
|
|||
/**
|
||||
* Sends a new message to the given target address.
|
||||
*/
|
||||
def sendTo(target: Address, body: MessageBody): Unit = {
|
||||
Future {
|
||||
if (!btInterface.getConnections.contains(target))
|
||||
return
|
||||
def sendTo(target: Address, body: MessageBody): Boolean = {
|
||||
if (!btInterface.getConnections.contains(target)) {
|
||||
Toast.makeText(this, R.string.toast_user_not_connected, Toast.LENGTH_SHORT).show()
|
||||
return false
|
||||
}
|
||||
|
||||
Future {
|
||||
val messageId = preferences.getLong("message_id", 0)
|
||||
val header = new ContentHeader(crypto.localAddress, target, seqNumGenerator.next(),
|
||||
body.contentType, Some(messageId), Some(new Date()))
|
||||
|
@ -133,6 +136,7 @@ class ChatService extends Service {
|
|||
router.onReceive(encrypted)
|
||||
onNewMessage(msg)
|
||||
}.onFailure {case e => throw e}
|
||||
true
|
||||
}
|
||||
|
||||
private def sendVia(nextHop: Address, msg: Message) =
|
||||
|
|
Reference in a new issue