Skip to content

Commit

Permalink
Added extra logging for imvalid messages format
Browse files Browse the repository at this point in the history
  • Loading branch information
glodanif committed Feb 6, 2018
1 parent b0e0000 commit 8d3ca08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def final VERSION_CODE = 9
def final VERSION_NAME = '1.0.0-beta4'
def final VERSION_CODE = 10
def final VERSION_NAME = '1.0.0-beta5'

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
Expand Down Expand Up @@ -74,6 +74,7 @@ dependencies {

def final SUPPORT_VERSION = '27.0.2'
def final ARCH_VERSION = '1.0.0'
def final DAGGER_VERSION = '2.4'

compile fileTree(dir: 'libs', include: ['*.jar'])

Expand Down Expand Up @@ -101,8 +102,8 @@ dependencies {

compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$KOTLIN_VERSION"

compile 'com.google.dagger:dagger:2.4'
kapt 'com.google.dagger:dagger-compiler:2.4'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

testCompile "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.glodanif.bluetoothchat.data.entity

import android.support.annotation.ColorInt
import com.crashlytics.android.Crashlytics
import com.glodanif.bluetoothchat.extension.isNumber
import io.fabric.sdk.android.Fabric
import java.io.File

class Message() {
Expand Down Expand Up @@ -33,6 +36,11 @@ class Message() {

var messageText = message

if (!messageText.substring(0, messageText.indexOf(DIVIDER)).isNumber() && Fabric.isInitialized()) {
val ex = IllegalArgumentException("Incorrect message format: $message")
Crashlytics.getInstance().core.logException(ex)
}

type = Type.from(messageText.substring(0, messageText.indexOf(DIVIDER)).toInt())
messageText = messageText.substring(messageText.indexOf(DIVIDER) + 1, messageText.length)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Handler
import com.glodanif.bluetoothchat.data.database.Storage
import com.glodanif.bluetoothchat.data.database.MessagesDao
import com.glodanif.bluetoothchat.data.entity.ChatMessage
import java.io.File
import kotlin.concurrent.thread

class MessagesStorageImpl(val context: Context) : MessagesStorage {
Expand All @@ -28,6 +29,7 @@ class MessagesStorageImpl(val context: Context) : MessagesStorage {
val messages: List<ChatMessage> = (if (address != null)
dao.getFilesMessagesByDevice(address) else dao.getAllFilesMessages())
.filter { !it.filePath.isNullOrEmpty() }
.filter { File(it.filePath).exists() }
handler.post { listener.invoke(messages) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ abstract class DataTransferThread(private val socket: BluetoothSocket,
if (len > 0) {
timeOut = 0
it.write(buffer, 0, len)
it.flush()
bytesRead += len.toLong()

fileListener.onFileReceivingProgress(transferringFile, bytesRead)
Expand All @@ -302,7 +303,6 @@ abstract class DataTransferThread(private val socket: BluetoothSocket,
Thread.sleep(250)

if (!isCanceled && !isFileTransferCanceledByMe && !isFileTransferCanceledByPartner) {
it.flush()
fileListener.onFileReceivingFinished(file.absolutePath)
}

Expand Down

0 comments on commit 8d3ca08

Please sign in to comment.