Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davixdedem committed Dec 8, 2023
1 parent 2b1e859 commit 996a82e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.magix.atcommand"
minSdk = 30
targetSdk = 33
versionCode = 5
versionName = "0.0.4"
versionCode = 6
versionName = "0.0.5"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -47,6 +47,7 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("com.github.mik3y:usb-serial-for-android:3.7.0")
implementation("com.google.android.gms:play-services-location:21.0.1")
implementation("androidx.webkit:webkit:1.9.0")
}


12 changes: 10 additions & 2 deletions app/src/main/assets/assets/js/custom-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function receiveJsonUserChat(jsonString, newMessage="false") {
message.timestamp,
message.favourite,
`./../assets/media/avatar/${message.senderUUID}.png`,
index === 0 ? needDivider : false
index === 0 ? needDivider : false,
message.rssi
);
});
if(newMessage != "false"){
Expand Down Expand Up @@ -56,6 +57,7 @@ function receiveGroupJsonUserChat(jsonString,newMessage = "false"){
message.favourite,
`./../assets/media/avatar/${message.senderUUID}.png`,
index === 0 ? needDivider : false,
message.rssi,
true
);
});
Expand Down Expand Up @@ -92,7 +94,8 @@ function addMessageDivider() {
}

// Genera il contenuto della chat
function insertMessagesIntoContainer(messageID, myUUID, senderUUID, receiverUUID, messageText, messageDate, favourite, avatarSrc, needDivider, isGroup=false) {
function insertMessagesIntoContainer(messageID, myUUID, senderUUID, receiverUUID, messageText, messageDate, favourite, avatarSrc, needDivider, rssi, isGroup=false) {
console.log(rssi);
const isSelf = myUUID === senderUUID;
const messageClass = isSelf ? 'message self' : 'message';
let messageContent = '';
Expand All @@ -110,6 +113,11 @@ function insertMessagesIntoContainer(messageID, myUUID, senderUUID, receiverUUID
<div class="message-content">
${isGroup && senderUUID !== myUUID ? `<h6 class="text-dark">${senderUUID}</h6>` : ''}
<span>${messageText}</span>
${!isSelf ? `
<div class="contacts-info">
<span class="rssi" style="opacity: 0.3;">rssi: ${rssi}dB</span>
</div>
` : ''}
</div>
</div>
<div class="message-options">
Expand Down
50 changes: 47 additions & 3 deletions app/src/main/java/com/magix/atcommand/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.core.content.ContextCompat
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.hoho.android.usbserial.driver.UsbSerialDriver
import java.net.URLEncoder
import java.util.Timer
import java.util.TimerTask
import kotlin.concurrent.timerTask
Expand Down Expand Up @@ -197,7 +198,6 @@ class MainActivity : AppCompatActivity() {
val webAppInterface = WebAppInterface(this)
webView.addJavascriptInterface(webAppInterface, "Android")
webView.loadUrl("file:///android_asset/dark-skin/index.html")

}

webView.webViewClient = object : WebViewClient() {
Expand All @@ -209,6 +209,11 @@ class MainActivity : AppCompatActivity() {
disableTextareaAndLoadingIndicator()
}
}
if (currentPage == "Homepage"){
if (!isDeviceConnected) {
addOverlayDeviceDisconnected()
}
}
}
}

Expand All @@ -221,6 +226,7 @@ class MainActivity : AppCompatActivity() {
createTableUsers(db)
createTableMessage(db)
createTableGroups(db)
createTableCoordinates(db)

/*
Creo il gruppo Multicast se non esiste
Expand Down Expand Up @@ -611,6 +617,21 @@ class MainActivity : AppCompatActivity() {
}
}

/*
Carica Google Maps
*/
fun loadMap(){
val latitude = 40.7128
val longitude = -74.0060
val zoomLevel = 15

val markerUrl = "https://www.openstreetmap.org/?mlat=$latitude&mlon=$longitude#map=$zoomLevel/$latitude/$longitude"
val encodedUrl = URLEncoder.encode(markerUrl, "UTF-8")

val mapUrl = "https://www.openstreetmap.org/export/embed.html"
webView.loadUrl(mapUrl)
}

/*
Funzione che controlla ogni 3 secondi lo stato della funzione readSerial()
*/
Expand Down Expand Up @@ -833,6 +854,24 @@ class MainActivity : AppCompatActivity() {
db.execSQL(query)
}

/*
Creo la tabella 'coordinates'
*/
private fun createTableCoordinates(db: SQLiteDatabase) {
val query = """
CREATE TABLE IF NOT EXISTS coordinates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
receiverUUID TEXT,
latitude INTEGER DEFAULT NULL,
longitude INTEGER DEFAULT NULL,
rssi INTEGER DEFAULT NULL,
snr INTEGER DEFAULT NULL,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""".trimIndent()
db.execSQL(query)
}

fun deleteMessageById(db: SQLiteDatabase, messageId: Int) {
val whereClause = "id = ?"
val whereArgs = arrayOf(messageId.toString())
Expand Down Expand Up @@ -1486,7 +1525,7 @@ class MainActivity : AppCompatActivity() {
val jsonArray = JSONArray()

val query = (
"SELECT id, senderUUID, receiverUUID, content, timestamp, favourite FROM messages " +
"SELECT id, senderUUID, receiverUUID, content, timestamp, favourite, rssi FROM messages " +
"WHERE (senderUUID = '$userUUID' OR receiverUUID = '$userUUID') " +
"AND hasGroup != 1 " + // Aggiunta della condizione per escludere hasGroup = 1
"ORDER BY timestamp DESC LIMIT 50"
Expand All @@ -1503,6 +1542,7 @@ class MainActivity : AppCompatActivity() {
val content = cursor.getString(3)
val timestamp = cursor.getString(4)
val favourite = cursor.getInt(5)
val rssi = cursor.getInt(6)

val jsonObject = JSONObject()
jsonObject.put("id", messageId)
Expand All @@ -1512,6 +1552,7 @@ class MainActivity : AppCompatActivity() {
jsonObject.put("timestamp", timestamp)
jsonObject.put("favourite", favourite)
jsonObject.put("myUUID", myUUID)
jsonObject.put("rssi", rssi)
jsonArray.put(jsonObject)
cursor.moveToPrevious()
}
Expand Down Expand Up @@ -1550,7 +1591,7 @@ class MainActivity : AppCompatActivity() {
val jsonArray = JSONArray()

val query = (
"SELECT id, senderUUID, receiverUUID, content, timestamp, favourite FROM messages " +
"SELECT id, senderUUID, receiverUUID, content, timestamp, favourite, rssi FROM messages " +
"WHERE hasGroup = 1 AND IDGroup = $groupID " +
"ORDER BY timestamp DESC LIMIT 50"
)
Expand All @@ -1565,6 +1606,7 @@ class MainActivity : AppCompatActivity() {
val content = cursor.getString(3)
val timestamp = cursor.getString(4)
val favourite = cursor.getInt(5)
val rssi = cursor.getInt(6)

val jsonObject = JSONObject()
jsonObject.put("id", messageId)
Expand All @@ -1574,6 +1616,8 @@ class MainActivity : AppCompatActivity() {
jsonObject.put("timestamp", timestamp)
jsonObject.put("favourite", favourite)
jsonObject.put("myUUID", myUUID)
jsonObject.put("rssi", rssi)

jsonArray.put(jsonObject)
} while (cursor.moveToPrevious())
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
<string name="lora_retry_number">3</string>
<string name="lora_question">\u003F</string>
<string name="lora_prefix">AT+</string>
<string name="google_maps_key">AIzaSyAaLoeuhYn-pCwhKyQ1AUPsu9rcsSxOodc</string>
</resources>

0 comments on commit 996a82e

Please sign in to comment.