Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'de.mobilej.unmock'
apply plugin: 'net.ltgt.errorprone'

Expand Down Expand Up @@ -30,6 +31,7 @@ android {
versionCode 49
versionName "2.9.1"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments disableAnalytics: 'true'
Expand Down Expand Up @@ -62,6 +64,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

buildFeatures {
viewBinding = true
buildConfig true
Expand All @@ -75,12 +81,14 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.squareup:otto:1.3.8'
implementation 'org.osmdroid:osmdroid-android:6.1.8'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'androidx.core:core:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.annotation:annotation:1.9.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.exifinterface:exifinterface:1.3.7'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.stephanlindauer.criticalmaps.model

import de.stephanlindauer.criticalmaps.model.chat.ReceivedChatMessage
import de.stephanlindauer.criticalmaps.utils.AeSimpleSHA1
import okhttp3.internal.Util
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import timber.log.Timber
import java.io.UnsupportedEncodingException
import java.net.URLDecoder
import java.net.URLEncoder
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ChatModel @Inject constructor(
private val userModel: UserModel
) {

private var receivedChatMessages = mutableListOf<ReceivedChatMessage>()

fun getReceivedChatMessages(): List<ReceivedChatMessage> {
return receivedChatMessages
}

@Throws(JSONException::class, UnsupportedEncodingException::class)
fun setFromJson(jsonArray: JSONArray) {
receivedChatMessages = mutableListOf()

for (i in 0 until jsonArray.length()) {
val jsonObject = jsonArray.getJSONObject(i)

val message = URLDecoder.decode(jsonObject.getString("message"), Util.UTF_8.name())
val timestamp = Date(jsonObject.getString("timestamp").toLong() * 1000)

receivedChatMessages.add(ReceivedChatMessage(message, timestamp))
}

receivedChatMessages.sortBy { it.timestamp }
}

fun createNewOutgoingMessage(message: String): JSONObject {
val messageObject = JSONObject()
try {
messageObject.put("text", urlEncodeMessage(message))
messageObject.put("identifier", AeSimpleSHA1.SHA1(message + Math.random()))
messageObject.put("device", userModel.changingDeviceToken)
} catch (e: JSONException) {
Timber.d(e)
}
return messageObject
}

private fun urlEncodeMessage(messageToEncode: String): String {
return try {
URLEncoder.encode(messageToEncode, Util.UTF_8.name())
} catch (e: UnsupportedEncodingException) {
""
}
}

companion object {
const val MESSAGE_MAX_LENGTH = 255
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.stephanlindauer.criticalmaps.model

import org.json.JSONArray
import org.json.JSONException
import org.osmdroid.util.GeoPoint
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class OtherUsersLocationModel @Inject constructor(
private val userModel: UserModel
) {

private var otherUsersLocations = ArrayList<GeoPoint>()

@Throws(JSONException::class)
fun setFromJson(jsonArray: JSONArray) {
otherUsersLocations = ArrayList(jsonArray.length())
for (i in 0 until jsonArray.length()) {
val locationObject = jsonArray.getJSONObject(i)
if (locationObject.getString("device") == userModel.changingDeviceToken) {
continue // Ignore own location
}
val latitudeE6 = locationObject.getString("latitude").toInt()
val longitudeE6 = locationObject.getString("longitude").toInt()

otherUsersLocations.add(
GeoPoint(latitudeE6 / 1000000.0, longitudeE6 / 1000000.0)
)
}
}

fun getOtherUsersLocations(): ArrayList<GeoPoint> {
return otherUsersLocations
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.stephanlindauer.criticalmaps.model

import org.json.JSONException
import org.json.JSONObject
import org.osmdroid.util.GeoPoint
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class OwnLocationModel @Inject constructor() {

@JvmField
var ownLocation: GeoPoint? = null
private var isLocationPrecise: Boolean = false

fun setLocation(location: GeoPoint, accuracy: Float) {
ownLocation = location
isLocationPrecise = accuracy < ACCURACY_PRECISE_THRESHOLD
}

fun hasPreciseLocation(): Boolean {
return ownLocation != null && isLocationPrecise
}

fun getLocationJson(): JSONObject {
val locationObject = JSONObject()
try {
val location = ownLocation ?: throw NullPointerException("ownLocation is null")
locationObject.put("longitude", (location.longitude * 1000000.0).toInt().toString())
locationObject.put("latitude", (location.latitude * 1000000.0).toInt().toString())
} catch (e: JSONException) {
Timber.e(e)
}
return locationObject
}

companion object {
private const val ACCURACY_PRECISE_THRESHOLD = 50.0f // meters
}
}
Loading