Skip to content

Commit

Permalink
File transfer fixes and localization
Browse files Browse the repository at this point in the history
  • Loading branch information
glodanif committed Jan 25, 2018
1 parent 9cdfd82 commit 9f83abb
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class Message() {
}

fun createAcceptConnectionMessage(name: String, @ColorInt color: Int): Message {
return Message("0", "$name#$color", true, Type.CONNECTION_RESPONSE)
return Message("0", "$name#$color#$MESSAGE_CONTRACT_VERSION", true, Type.CONNECTION_RESPONSE)
}

fun createRejectConnectionMessage(name: String, @ColorInt color: Int): Message {
return Message("0", "$name#$color", false, Type.CONNECTION_RESPONSE)
return Message("0", "$name#$color#$MESSAGE_CONTRACT_VERSION", false, Type.CONNECTION_RESPONSE)
}

fun createFileStartMessage(file: File, type: MessageType): Message {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.os.*
import com.glodanif.bluetoothchat.data.entity.*
import com.glodanif.bluetoothchat.data.entity.Message


class BluetoothConnectionService : Service() {

private val TAG = "BCS"
Expand Down Expand Up @@ -500,6 +499,7 @@ class BluetoothConnectionService : Service() {

fun cancelFileTransfer() {
dataTransferThread?.cancelFileTransfer()
notificationView.dismissFileTransferNotification()
}

private fun onMessageSent(messageBody: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ class ChatActivity : SkeletonActivity(), ChatView {
textSendingHolder.visibility = View.GONE
imageSendingHolder.visibility = View.VISIBLE

transferringImageHeader.text = if (transferType == ChatView.FileTransferType.SENDING)
"Sending image" else "Receiving image"
transferringImageHeader.text = getString(if (transferType == ChatView.FileTransferType.SENDING)
R.string.chat__sending_image else R.string.chat__receiving_images)

if (fileAddress != null) {
Picasso.with(this)
Expand Down Expand Up @@ -394,11 +394,21 @@ class ChatActivity : SkeletonActivity(), ChatView {
}

override fun showImageTransferCanceled() {
Toast.makeText(this, "Your partner has canceled image transfer", Toast.LENGTH_LONG).show()
Toast.makeText(this, R.string.chat__partner_canceled_image_transfer, Toast.LENGTH_LONG).show()
}

override fun showImageTransferFailure() {
Toast.makeText(this, "Problem during image transfer", Toast.LENGTH_LONG).show()
Toast.makeText(this, R.string.chat__problem_during_file_transfer, Toast.LENGTH_LONG).show()
}

override fun showReceiverUnableToReceiveImages() {

if (!isStarted()) return

AlertDialog.Builder(this)
.setMessage(R.string.chat__partner_unable_to_receive_images)
.setPositiveButton(R.string.general__ok, null)
.show()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glodanif.bluetoothchat.ui.presenter

import android.bluetooth.BluetoothDevice
import android.util.Log
import com.glodanif.bluetoothchat.data.entity.ChatMessage
import com.glodanif.bluetoothchat.data.entity.Conversation
import com.glodanif.bluetoothchat.data.entity.TransferringFile
Expand Down Expand Up @@ -285,20 +286,22 @@ class ChatPresenter(private val deviceAddress: String, private val view: ChatVie

if (!connectionModel.isConnected()) {
view.showNotConnectedToSend()
return
} else {
fileToSend = file
}

fileToSend = file
}

fun pickImage() {

val currentConversation: Conversation? = connectionModel.getCurrentConversation()

if (!connectionModel.isConnected()) {
view.showNotConnectedToSend()
return
} else if (currentConversation != null && currentConversation.messageContractVersion < 1) {
view.showReceiverUnableToReceiveImages()
} else {
view.pickImage()
}

view.pickImage()
}

fun cancelFileTransfer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ChatView {
fun showNotConnectedToThisDevice(currentDevice: String)
fun showNotValidMessage()
fun showNotConnectedToSend()
fun showReceiverUnableToReceiveImages()
fun showDeviceIsNotAvailable()
fun showWainingForOpponent()
fun hideActions()
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<resources>

<string name="app_name">Bluetooth Chat</string>

<string name="general__ok">ОК</string>
<string name="general__cancel">Отмена</string>
<string name="general__try_again">Попробовать еще</string>
Expand Down Expand Up @@ -75,6 +73,11 @@
<string name="chat__chat">Чат</string>
<string name="chat__removed_image">Изображение удалено</string>
<string name="chat__missing_image">Изображение не найдено</string>
<string name="chat__partner_canceled_image_transfer">Ваш партнер отменил передачу файла</string>
<string name="chat__problem_during_file_transfer">Произошла ошибка во время передачи файла</string>
<string name="chat__sending_image">Отправка изображения</string>
<string name="chat__receiving_images">Прием изображения</string>
<string name="chat__partner_unable_to_receive_images">Ваш партнер изпользует старую версию Bluetooth Chat, которая не может принимать изображения.</string>

<string name="conversations__no_conversations">У вас пока что нет ни одного разговора\nНачните сканирование чтобы найти вашего партнера</string>
<string name="conversations__scan">Сканировать</string>
Expand Down Expand Up @@ -138,6 +141,7 @@
<string name="images__remove">Удалить</string>
<string name="images__received_images">Полученые изображения</string>

<string name="image__cd__image_preview">Вид изображения</string>
<string name="profile__cd__avatar_preview">Вид аватара</string>
<string name="scan__cd__share_apk_file_button">Кнопка отправки .apk файла</string>
<string name="conversations__cd__settings_button">Кнопка настроек</string>
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<resources>

<string name="app_name">Bluetooth Chat</string>

<string name="general__ok">ОК</string>
<string name="general__cancel">Скасувати</string>
<string name="general__try_again">Спробувати ще</string>
Expand Down Expand Up @@ -75,6 +73,11 @@
<string name="chat__chat">Чат</string>
<string name="chat__removed_image">Зображення видалено</string>
<string name="chat__missing_image">Зображення не знайдено</string>
<string name="chat__partner_canceled_image_transfer">Ваш партнер відмінив передачу файлу</string>
<string name="chat__problem_during_file_transfer">Сталася помилка під час передачі файлу</string>
<string name="chat__sending_image">Відправлення зображення</string>
<string name="chat__receiving_images">Прийом зображення</string>
<string name="chat__partner_unable_to_receive_images">Ваш партнер використовує стару версію Bluetooth Chat, яка не може приймати зображення.</string>

<string name="conversations__no_conversations">У вас пока что нет ни одного разговора\nНачните сканирование чтобы найти вашего партнера</string>
<string name="conversations__scan">Сканувати</string>
Expand Down Expand Up @@ -136,15 +139,15 @@
<string name="images__no_images">Ви ще не прийняли жодного зображення</string>
<string name="images__image">Зображення</string>
<string name="images__remove">Видалити</string>
<string name="images__received_images">Отримані зображення</string>

<string name="profile__cd__avatar_preview">Вид аватара</string>
<string name="scan__cd__share_apk_file_button">Кнопка відправки .apk файла</string>
<string name="conversations__cd__settings_button">Кнопка налаштувань</string>
<string name="conversations__cd__partners_avatar">Аватар партнера</string>
<string name="conversations__cd__connected_indicator">Індикатор з\'єднання</string>
<string name="conversations__cd__users_avatar">Аватар користувача</string>

<string name="images__received_images">Отримані зображення</string>
<string name="image__cd__image_preview">Вид зображення</string>
<string name="chat__cd__send_text_button">Кнопка відправки тексту</string>
<string name="chat__cd__send_image_button">Кнопка відправки зображення</string>
<string name="chat__too_big_image">Це зображення надто велике. Максимальний розмір файлу, який ви можете відправити за допомогою Blooetooth Chat складає %s.</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<string name="chat__too_big_image">This image it too big. Max file size which you can send via Bluetooth Chat is %s</string>
<string name="chat__removed_image">Removed image</string>
<string name="chat__missing_image">Missing image</string>
<string name="chat__partner_canceled_image_transfer">Your partner has canceled image transfer</string>
<string name="chat__problem_during_file_transfer">Problem during image transfer</string>
<string name="chat__sending_image">Sending image</string>
<string name="chat__receiving_images">Receiving image</string>
<string name="chat__partner_unable_to_receive_images">Your partner uses an old version of Bluetooth Chat which is not able to receive images.</string>

<string name="conversations__no_conversations">You don\'t have any conversationsStorage yet\nScan for devices to find your partner</string>
<string name="conversations__scan">Scan</string>
Expand Down
Binary file modified graphics/screenshots/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9f83abb

Please sign in to comment.