Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tooseriuz committed Mar 8, 2022
2 parents 0951bea + 1c601a7 commit af1958d
Show file tree
Hide file tree
Showing 117 changed files with 4,749 additions and 2,699 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ build/
captures/
.navigation/

# Google service file
google-services.json

# Intellij IDEA
.idea/*
!.idea/codeStyles
Expand Down
4 changes: 2 additions & 2 deletions .idea/gradle.xml

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

1 change: 0 additions & 1 deletion .idea/vcs.xml

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

9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ apply plugin: 'com.google.firebase.crashlytics'

android {
compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "org.rfcx.companion"
manifestPlaceholders = [auth0Domain: "@string/auth0_domain", auth0Scheme: "@string/auth0_scheme"]
minSdkVersion 19
targetSdkVersion 30
versionCode 61
versionName "1.3.6"
versionCode 73
versionName "1.4.1"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -73,7 +72,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.work:work-runtime-ktx:2.4.0'
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'
Expand Down Expand Up @@ -102,7 +101,7 @@ dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-scalebar-v9:0.5.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'

implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation 'com.google.android.material:material:1.4.0'

//Preference
implementation "androidx.preference:preference-ktx:1.1.1"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
android:name=".view.project.ProjectSelectActivity"
android:screenOrientation="portrait" />

<activity
android:name=".view.profile.guardiansoftware.GuardianSoftwareActivity"
android:screenOrientation="portrait"/>

<service
android:name=".service.LocationTrackerService"
android:exported="false"
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/java/org/rfcx/companion/CompanionApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package org.rfcx.companion
import android.app.Application
import io.realm.Realm
import io.realm.exceptions.RealmMigrationNeededException
import org.rfcx.companion.connection.socket.SocketManager
import org.rfcx.companion.connection.socket.AdminSocketManager
import org.rfcx.companion.connection.socket.AudioCastSocketManager
import org.rfcx.companion.connection.socket.FileSocketManager
import org.rfcx.companion.connection.socket.GuardianSocketManager
import org.rfcx.companion.service.DeploymentCleanupWorker
import org.rfcx.companion.util.LocationTracking
import org.rfcx.companion.util.Preferences
import org.rfcx.companion.util.RealmHelper
import org.rfcx.companion.util.SocketUtils

class CompanionApplication : Application() {
override fun onCreate() {
Expand All @@ -22,6 +26,13 @@ class CompanionApplication : Application() {
if (state) {
LocationTracking.set(this, true)
}

val defaultHandler = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler { thread, throwable ->
defaultHandler?.uncaughtException(thread, throwable)

SocketUtils.stopAllConnections()
}
}

private fun setupRealm() {
Expand All @@ -46,6 +57,6 @@ class CompanionApplication : Application() {

override fun onTerminate() {
super.onTerminate()
SocketManager.stopConnection()
SocketUtils.stopAllConnections()
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/rfcx/companion/CompanionRealmMigration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class CompanionRealmMigration : RealmMigration {
if (oldVersion < 18L && newVersion >= 18L) {
migrateToV18(realm)
}

if (oldVersion < 19L && newVersion >= 19L) {
migrateToV19(realm)
}
}

private fun migrateToV2(realm: DynamicRealm) {
Expand Down Expand Up @@ -385,6 +389,13 @@ class CompanionRealmMigration : RealmMigration {
}
}

private fun migrateToV19(realm: DynamicRealm) {
val deployment = realm.schema.get(Deployment.TABLE_NAME)
deployment?.apply {
addField(Deployment.FIELD_DEVICE_PARAMETERS, String::class.java)
}
}

override fun hashCode(): Int {
return 1
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/rfcx/companion/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import kotlinx.android.synthetic.main.layout_search_view.*
import org.rfcx.companion.base.ViewModelFactory
import org.rfcx.companion.entity.Locate
import org.rfcx.companion.entity.isGuest
import org.rfcx.companion.repo.api.CoreApiHelper
import org.rfcx.companion.repo.api.CoreApiServiceImpl
import org.rfcx.companion.repo.api.DeviceApiHelper
import org.rfcx.companion.repo.api.DeviceApiServiceImpl
import org.rfcx.companion.repo.local.LocalDataHelper
Expand Down Expand Up @@ -62,6 +64,7 @@ class MainActivity : AppCompatActivity(), MainActivityListener {
ViewModelFactory(
application,
DeviceApiHelper(DeviceApiServiceImpl()),
CoreApiHelper(CoreApiServiceImpl()),
LocalDataHelper()
)
).get(MainViewModel::class.java)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/rfcx/companion/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class MainViewModel(
val projectName = getProjectName()
if (projectName != context.getString(R.string.none)) {
filteredShowLocations =
filteredShowLocations.filter { it.locationGroup?.name == projectName }
filteredShowLocations.filter { it.locationGroup?.name == projectName && it.lastDeploymentId == 0 }
deploymentsForShow =
deploymentsForShow.filter { it.stream?.project?.name == projectName }
}
Expand Down
54 changes: 38 additions & 16 deletions app/src/main/java/org/rfcx/companion/base/ViewModelFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import org.rfcx.companion.MainRepository
import org.rfcx.companion.MainViewModel
import org.rfcx.companion.repo.api.CoreApiHelper
import org.rfcx.companion.repo.api.DeviceApiHelper
import org.rfcx.companion.repo.local.LocalDataHelper
import org.rfcx.companion.view.profile.guardiansoftware.repository.GuardianSoftwareRepository
import org.rfcx.companion.view.profile.guardiansoftware.viewmodel.GuardianSoftwareViewModel
import org.rfcx.companion.view.deployment.AudioMothDeploymentRepository
import org.rfcx.companion.view.deployment.AudioMothDeploymentViewModel
import org.rfcx.companion.view.LoginRepository
Expand All @@ -20,23 +23,42 @@ import org.rfcx.companion.view.profile.offlinemap.ProjectOfflineMapViewModel
import org.rfcx.companion.view.project.repository.ProjectSelectRepository
import org.rfcx.companion.view.project.viewmodel.ProjectSelectViewModel

class ViewModelFactory(private val application: Application, private val deviceApiHelper: DeviceApiHelper, private val localDataHelper: LocalDataHelper): ViewModelProvider.Factory {
class ViewModelFactory(
private val application: Application,
private val deviceApiHelper: DeviceApiHelper,
private val coreApiHelper: CoreApiHelper,
private val localDataHelper: LocalDataHelper
) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(ProjectSelectViewModel::class.java)) {
return ProjectSelectViewModel(application, ProjectSelectRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
return MainViewModel(application, MainRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(LoginViewModel::class.java)) {
return LoginViewModel(application, LoginRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(ProjectOfflineMapViewModel::class.java)) {
return ProjectOfflineMapViewModel(application, ProjectOfflineMapRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(AudioMothDeploymentViewModel::class.java)) {
return AudioMothDeploymentViewModel(application, AudioMothDeploymentRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(EditLocationViewModel::class.java)) {
return EditLocationViewModel(application, EditLocationRepository(deviceApiHelper, localDataHelper)) as T
} else if (modelClass.isAssignableFrom(DeploymentDetailViewModel::class.java)) {
return DeploymentDetailViewModel(application, DeploymentDetailRepository(deviceApiHelper, localDataHelper)) as T
when {
modelClass.isAssignableFrom(ProjectSelectViewModel::class.java) -> {
return ProjectSelectViewModel(
application,
ProjectSelectRepository(deviceApiHelper, localDataHelper)
) as T
}
modelClass.isAssignableFrom(MainViewModel::class.java) -> {
return MainViewModel(application, MainRepository(deviceApiHelper, localDataHelper)) as T
}
modelClass.isAssignableFrom(ProjectOfflineMapViewModel::class.java) -> {
return ProjectOfflineMapViewModel(
application,
ProjectOfflineMapRepository(deviceApiHelper, localDataHelper)
) as T
}
modelClass.isAssignableFrom(GuardianSoftwareViewModel::class.java) -> {
return GuardianSoftwareViewModel(application, GuardianSoftwareRepository(coreApiHelper)) as T
}
modelClass.isAssignableFrom(LoginViewModel::class.java) -> {
return LoginViewModel(application, LoginRepository(deviceApiHelper, localDataHelper)) as T
}
modelClass.isAssignableFrom(AudioMothDeploymentViewModel::class.java) -> {
return AudioMothDeploymentViewModel(application, AudioMothDeploymentRepository(deviceApiHelper, localDataHelper)) as T
}
modelClass.isAssignableFrom(DeploymentDetailViewModel::class.java) -> {
return DeploymentDetailViewModel(application, DeploymentDetailRepository(deviceApiHelper, localDataHelper)) as T
}
else -> throw IllegalArgumentException("Unknown class name")
}
throw IllegalArgumentException("Unknown class name")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.rfcx.companion.connection.socket

import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import org.rfcx.companion.entity.socket.response.AdminPing
import java.io.DataInputStream
import java.io.DataOutputStream
import java.net.Socket
import java.net.SocketTimeoutException

object AdminSocketManager {

private var socket: Socket? = null
private var outputStream: DataOutputStream? = null
private var inputStream: DataInputStream? = null
private var clientThread: Thread? = null // Thread for socket communication

private lateinit var inComingMessageThread: Thread

private val gson = Gson()

val pingBlob = MutableLiveData<AdminPing>()

//just to connect to server
fun connect() {
sendMessage("")
}

private fun sendMessage(message: String) {
clientThread = Thread {
try {
socket = Socket("192.168.43.1", 9997)
socket?.keepAlive = true
socket?.soTimeout = 10000
startInComingMessageThread()
outputStream = DataOutputStream(socket?.getOutputStream())
outputStream?.writeUTF(message)
outputStream?.flush()
} catch (e: Exception) {
e.printStackTrace()
}
}
clientThread?.start()
}

private fun startInComingMessageThread() {
inComingMessageThread = Thread {
try {
while (true) {
inputStream = DataInputStream(socket!!.getInputStream())
val dataInput = inputStream?.readUTF()
if (!dataInput.isNullOrBlank()) {

val ping = gson.fromJson(dataInput, AdminPing::class.java)
pingBlob.postValue(ping)

}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
inComingMessageThread.start()
}

fun clearValue() {
pingBlob.value = AdminPing()
}

fun stopConnection() {
// stop incoming message thread
if (::inComingMessageThread.isInitialized) {
inComingMessageThread.interrupt()
}

// stop server thread
clientThread?.interrupt()

outputStream?.flush()
outputStream?.close()

inputStream?.close()

outputStream?.close()
socket?.close()
}
}
Loading

0 comments on commit af1958d

Please sign in to comment.