Skip to content

Commit

Permalink
feat: Add Logs screen + Rework UI + Update presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cestef committed Jan 13, 2023
1 parent 2a04c47 commit 5ef0389
Show file tree
Hide file tree
Showing 33 changed files with 725 additions and 406 deletions.
3 changes: 2 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

31 changes: 19 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId "com.cstef.meshlink"
minSdk 26
targetSdk 33
versionCode 29
versionName "1.2.2"
versionCode 30
versionName "1.2.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -44,7 +44,7 @@ android {

dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation('com.daveanthonythomas.moshipack:moshipack:1.0.1') {
Expand All @@ -53,40 +53,47 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.10"

implementation "androidx.compose.compiler:compiler:$compose_version"
implementation "androidx.compose.runtime:runtime:1.3.2"
implementation 'androidx.compose.material3:material3:1.1.0-alpha03'
implementation "androidx.compose.runtime:runtime:1.3.3"
implementation 'androidx.compose.material3:material3:1.1.0-alpha04'

implementation 'androidx.compose.ui:ui-tooling-preview:1.4.0-alpha03'
debugImplementation 'androidx.compose.ui:ui-tooling:1.4.0-alpha03'
implementation 'androidx.compose.ui:ui-tooling-preview:1.4.0-alpha04'
debugImplementation 'androidx.compose.ui:ui-tooling:1.4.0-alpha04'
implementation 'androidx.activity:activity-compose:1.6.1'
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.28.0'
implementation "com.google.accompanist:accompanist-permissions:0.28.0"
// material-icons-extended
implementation 'androidx.compose.material:material-icons-extended:1.4.0-alpha03'
implementation 'androidx.compose.material:material-icons-extended:1.4.0-alpha04'
// Navigation
implementation 'androidx.navigation:navigation-compose:2.6.0-alpha04'
implementation "com.google.accompanist:accompanist-navigation-animation:0.28.0"
//AndroidSVG
implementation 'com.caverock:androidsvg-aar:1.4'
def room_version = "2.4.3"

// Room
def room_version = "2.5.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

kapt "androidx.room:room-compiler:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-paging:$room_version"
implementation "androidx.room:room-ktx:$room_version"

implementation "androidx.compose.runtime:runtime-livedata:1.3.2"
implementation "androidx.compose.runtime:runtime-livedata:1.3.3"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'

// Database
implementation "net.zetetic:android-database-sqlcipher:4.5.2"
implementation "androidx.sqlite:sqlite:2.2.0"
implementation "androidx.sqlite:sqlite:2.3.0"

// QR Code
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'

// Easter egg
implementation 'nl.dionsegijn:konfetti-compose:2.0.2'

// Charts
implementation "com.patrykandpatrick.vico:compose:1.6.2"
implementation "com.patrykandpatrick.vico:compose-m3:1.6.2"
}
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.Meshlinkkotlin">

<activity
Expand Down
48 changes: 40 additions & 8 deletions app/src/main/java/com/cstef/meshlink/BleService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.cstef.meshlink.db.AppDatabase
import com.cstef.meshlink.db.entities.Device
import com.cstef.meshlink.managers.BleManager
import com.cstef.meshlink.managers.EncryptionManager
import com.cstef.meshlink.managers.LogcatMessage
import com.cstef.meshlink.managers.LogsManager
import com.cstef.meshlink.repositories.DeviceRepository
import com.cstef.meshlink.repositories.MessageRepository
import com.cstef.meshlink.util.struct.Chunk
Expand All @@ -39,6 +41,8 @@ class BleService : Service() {
}

inner class BleServiceBinder : Binder() {
val logcatLogs: MutableLiveData<List<LogcatMessage>>
get() = logsManager.logcatMessages
val isAdvertising
get() = bleManager.isAdvertising
val service: BleService
Expand All @@ -59,10 +63,15 @@ class BleService : Service() {
bleManager.setUserId(id)
}

fun sendMessage(recipientId: String, message: String, type: String = Message.Type.TEXT) {
fun sendMessage(
recipientId: String,
message: String,
type: String = Message.Type.TEXT
): String {
val id = UUID.randomUUID().toString()
this@BleService.sendMessage(
Message(
UUID.randomUUID().toString(),
id,
userId,
recipientId,
message,
Expand All @@ -71,6 +80,7 @@ class BleService : Service() {
true
)
)
return id
}

fun addDevice(userId: String) {
Expand Down Expand Up @@ -177,6 +187,7 @@ class BleService : Service() {
val messagesHashes: MutableMap<String, MutableList<String>> = mutableMapOf()
val chunks: MutableMap<String, MutableMap<Int, MutableList<Chunk>>> =
mutableMapOf() // userId -> messageId -> chunks
val sentMessages: MutableMap<String, MutableList<String>> = mutableMapOf()

private val bleDataExchangeManager = object : BleManager.BleDataExchangeManager {
override fun connect(address: String) {
Expand Down Expand Up @@ -218,7 +229,8 @@ class BleService : Service() {
name = null,
blocked = false,
publicKey = publicKey?.encoded?.let { Base64.encodeToString(it, Base64.DEFAULT) },
added = false
added = false,
txPower = 0
)
)
} else {
Expand All @@ -241,10 +253,15 @@ class BleService : Service() {
}
}

override fun onMessageSent(userId: String) {
override fun onMessageSent(userId: String, messageId: String) {
val sharedPreferences = getSharedPreferences("USER_STATS", MODE_PRIVATE)
val sentMessages = sharedPreferences.getInt("TOTAL_MESSAGES_DELIVERED", 0)
sharedPreferences.edit().putInt("TOTAL_MESSAGES_DELIVERED", sentMessages + 1).apply()
val deliveredMessages = sharedPreferences.getInt("TOTAL_MESSAGES_DELIVERED", 0)
sharedPreferences.edit().putInt("TOTAL_MESSAGES_DELIVERED", deliveredMessages + 1).apply()
// Add the message to the sent messages list
val sentMessagesForUser = sentMessages[userId] ?: mutableListOf()
sentMessagesForUser.add(messageId)
sentMessages[userId] = sentMessagesForUser
// Remove the message from the chunks list
Log.d("BleService", "onMessageSent: $userId")
}

Expand All @@ -258,9 +275,11 @@ class BleService : Service() {
if (!bleManager.isConnected(address) && !bleManager.isConnecting(address)) {
bleManager.connect(address)
}
// is user blocked?
val devices = allDevices?.value ?: emptyList()
val device = devices.find { it.userId == getUserIdForAddress(address) }
if (device?.connected == false && bleManager.isConnected(address)) {
deviceRepository?.update(device.copy(connected = true))
}
if (device != null && device.blocked) {
Log.d("BleService", "onChunkReceived: user is blocked")
return
Expand Down Expand Up @@ -387,7 +406,18 @@ class BleService : Service() {
if (devices.isNotEmpty()) {
devices.find { it.userId == userId }?.let { device ->
if (device.rssi != rssi) {
deviceRepository?.update(device.copy(rssi = rssi))
deviceRepository?.update(device.copy(rssi = rssi, connected = true))
}
}
}
}

override fun onUserTxPowerReceived(userId: String, txPower: Int) {
val devices = allDevices?.value ?: return
if (devices.isNotEmpty()) {
devices.find { it.userId == userId }?.let { device ->
if (device.txPower != txPower) {
deviceRepository?.update(device.copy(txPower = txPower, connected = true))
}
}
}
Expand Down Expand Up @@ -415,6 +445,7 @@ class BleService : Service() {
}
lateinit var bleManager: BleManager
private lateinit var encryptionManager: EncryptionManager
lateinit var logsManager: LogsManager

var allMessages: LiveData<List<com.cstef.meshlink.db.entities.Message>>? = null
var allDevices: LiveData<List<Device>>? = null
Expand All @@ -433,6 +464,7 @@ class BleService : Service() {
super.onCreate()
handlerThread.start()
handler = Handler(handlerThread.looper)
logsManager = LogsManager()
encryptionManager = EncryptionManager()
bleManager = BleManager(applicationContext, bleDataExchangeManager, encryptionManager, handler)
}
Expand Down
Loading

0 comments on commit 5ef0389

Please sign in to comment.