Skip to content

Commit

Permalink
merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
xcadrik authored and dzlabing committed Apr 24, 2023
2 parents 5307fc0 + 1eafb04 commit caf4617
Show file tree
Hide file tree
Showing 49 changed files with 400 additions and 270 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ dependencies {
implementation "androidx.vectordrawable:vectordrawable:$versions.vectordrawable"
implementation "androidx.navigation:navigation-fragment-ktx:$versions.navigation_fragment"
implementation "androidx.navigation:navigation-ui-ktx:$versions.navigation_ui"
implementation "androidx.lifecycle:lifecycle-extensions:$versions.lifecycle_extensions"
implementation "androidx.navigation:navigation-fragment-ktx:$versions.navigation_fragment"
implementation "androidx.navigation:navigation-ui-ktx:$versions.navigation_fragment"
implementation "com.google.android.gms:play-services-maps:$versions.google_services"
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/at/rtr/rmbt/android/di/ViewModelLazy.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package at.rtr.rmbt.android.di

import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import at.rtr.rmbt.android.ui.activity.BaseActivity
import at.rtr.rmbt.android.ui.fragment.BaseFragment
import at.rtr.rmbt.android.util.listenNonNull
Expand All @@ -14,7 +13,7 @@ inline fun <reified T : BaseViewModel> BaseActivity.viewModelLazy(): Lazy<T> = A
class FragmentViewModelLazy<T : BaseViewModel>(private val fragment: BaseFragment, modelClass: Class<T>) : ViewModelLazy<T>(modelClass) {

override val viewModelProvider: ViewModelProvider
get() = ViewModelProviders.of(fragment, Injector.component.viewModelFactory())
get() = ViewModelProvider(fragment, Injector.component.viewModelFactory())

override fun subscribeOnError(viewModel: BaseViewModel) {
viewModel.errorLiveData.listenNonNull(fragment) {
Expand All @@ -28,7 +27,7 @@ class FragmentViewModelLazy<T : BaseViewModel>(private val fragment: BaseFragmen
class ActivityViewModelLazy<T : BaseViewModel>(private val activity: BaseActivity, modelClass: Class<T>) : ViewModelLazy<T>(modelClass) {

override val viewModelProvider: ViewModelProvider
get() = ViewModelProviders.of(activity, Injector.component.viewModelFactory())
get() = ViewModelProvider(activity, Injector.component.viewModelFactory())

override fun subscribeOnError(viewModel: BaseViewModel) {
viewModel.errorLiveData.listenNonNull(activity) {
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/at/rtr/rmbt/android/ui/activity/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ abstract class BaseActivity : AppCompatActivity() {
fun <T : ViewDataBinding> bindContentView(@LayoutRes layoutRes: Int): T =
DataBindingUtil.setContentView(this, layoutRes)

open fun onHandledException(exception: HandledException) {
val message = if (exception is NoConnectionException) {
getString(R.string.error_no_connection)
} else {
exception.getText(this)
}
open fun onHandledException(exception: HandledException?) {
exception?.let { handledException ->
val message = if (handledException is NoConnectionException) {
getString(R.string.error_no_connection)
} else {
handledException.getText(this)
}

SimpleDialog.Builder()
.messageText(message)
.positiveText(android.R.string.ok)
.cancelable(false)
.show(supportFragmentManager, DIALOG_DEFAULT_OK)
SimpleDialog.Builder()
.messageText(message)
.positiveText(android.R.string.ok)
.cancelable(false)
.show(supportFragmentManager, DIALOG_DEFAULT_OK)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import at.rtr.rmbt.android.R
import at.rtr.rmbt.android.databinding.DialogFiltersBinding
import at.rtr.rmbt.android.di.Injector
Expand All @@ -35,8 +35,8 @@ class MapFiltersDialog : FullscreenDialog(), MapFiltersConfirmationDialog.Callba
super.onCreate(savedInstanceState)

if (savedInstanceState == null || !::viewModel.isInitialized) {
val provider = ViewModelProviders.of(this, Injector.component.viewModelFactory())
viewModel = provider.get(MapFiltersViewModel::class.java)
val provider = ViewModelProvider(this, Injector.component.viewModelFactory())
viewModel = provider[MapFiltersViewModel::class.java]
viewModel.obtain()
} else {
viewModel.onRestoreState(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import at.rtr.rmbt.android.util.showKeyboard
import at.rtr.rmbt.android.viewmodel.SyncDevicesViewModel
import at.specure.util.copyToClipboard
import at.specure.util.toast
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -123,10 +122,12 @@ class SyncDevicesDialog : FullscreenDialog() {
}

viewModel.errorLiveData.listen(this) {
SimpleDialog.Builder()
.messageText(it.getText(requireContext()))
.positiveText(R.string.button_close)
.show(parentFragmentManager, 0)
it?.let {
SimpleDialog.Builder()
.messageText(it.getText(requireContext()))
.positiveText(R.string.button_close)
.show(parentFragmentManager, 0)
}
}
}

Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/at/rtr/rmbt/android/ui/fragment/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ abstract class BaseFragment : Fragment() {
viewModels.forEach { it.onSaveState(outState) }
}

open fun onHandledException(exception: HandledException) {
val message = if (exception is NoConnectionException) {
getString(R.string.error_no_connection)
} else {
exception.getText(requireContext())
open fun onHandledException(exception: HandledException?) {
exception?.let { handledException ->
val message = if (handledException is NoConnectionException) {
getString(R.string.error_no_connection)
} else {
handledException.getText(requireContext())
}

SimpleDialog.Builder()
.messageText(message)
.positiveText(android.R.string.ok)
.cancelable(false)
.show(parentFragmentManager, DIALOG_DEFAULT_OK)
}

SimpleDialog.Builder()
.messageText(message)
.positiveText(android.R.string.ok)
.cancelable(false)
.show(parentFragmentManager, DIALOG_DEFAULT_OK)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,18 @@ class CustomSwitchPreference @JvmOverloads constructor(
view.isChecked = getPersistedBoolean(false)
view.setOnCheckedChangeListener { _, isChecked ->
if (getPersistedBoolean(false) != isChecked) {
if (onPreferenceChangeListener != null)
onPreferenceChangeListener.onPreferenceChange(
this@CustomSwitchPreference,
isChecked
)
onPreferenceChangeListener?.onPreferenceChange(
this@CustomSwitchPreference,
isChecked
)
persistBoolean(isChecked)
}
}
}
}

override fun onBindViewHolder(holder: PreferenceViewHolder?) {
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
holder?.let { bindSwitch(it) }
holder.let { bindSwitch(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations

/**
* Removes all previously registered observers for current lifecycle owner and live data
Expand Down Expand Up @@ -62,8 +61,6 @@ fun <T> LiveData<T>.singleResult(lifecycleOwner: LifecycleOwner, block: (T) -> (
@Keep
private data class LifecycleHolder<T>(var observer: Observer<T>? = null)

fun <X, Y> LiveData<X>.map(transform: (X) -> Y): LiveData<Y> = Transformations.map(this, transform)

fun <T> liveDataOf(block: (liveData: MutableLiveData<T>) -> (Unit)): LiveData<T> = MutableLiveData<T>().also {
block.invoke(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import java.util.concurrent.TimeUnit
open class BaseViewModel : ViewModel(), CoroutineScope {

private val viewStates = mutableSetOf<ViewState>()
private val _errorLiveData = MutableLiveData<HandledException>()
private val _errorLiveData = MutableLiveData<HandledException?>()
val askPermissionsAgainTimesMillis = TimeUnit.DAYS.toMillis(1)

val errorLiveData: LiveData<HandledException>
val errorLiveData: LiveData<HandledException?>
get() = _errorLiveData

fun clearErrorMessages() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import android.os.IBinder
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import at.rmbt.client.control.NewsItem
import at.rtr.rmbt.android.config.AppConfig
import at.rtr.rmbt.android.ui.viewstate.HomeViewState
import at.rtr.rmbt.android.util.map
import at.specure.data.ClientUUID
import at.specure.data.MeasurementServers
import at.specure.data.repository.NewsRepository
Expand All @@ -28,7 +28,6 @@ import at.specure.measurement.signal.SignalMeasurementService
import at.specure.test.SignalMeasurementType
import at.specure.util.permission.PermissionsWatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import timber.log.Timber
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package at.rtr.rmbt.android.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.map
import at.rtr.rmbt.android.config.AppConfig
import at.rtr.rmbt.android.ui.viewstate.LoopConfigurationViewState
import at.rtr.rmbt.android.util.map
import at.specure.info.connectivity.ConnectivityInfoLiveData
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package at.rtr.rmbt.android.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.switchMap
import at.rmbt.client.control.data.MapPresentationType
import at.rtr.rmbt.android.map.wrapper.LatLngW
import at.rtr.rmbt.android.map.wrapper.TileW
Expand Down Expand Up @@ -31,7 +31,7 @@ class MapViewModel @Inject constructor(
var providerLiveData: MutableLiveData<RetrofitTileProvider> = MutableLiveData()

var markersLiveData: LiveData<List<MarkerMeasurementRecord>> =
Transformations.switchMap(state.coordinatesLiveData) { repository.getMarkers(it?.latitude, it?.longitude, state.zoom.toInt()) }
state.coordinatesLiveData.switchMap { repository.getMarkers(it?.latitude, it?.longitude, state.zoom.toInt()) }

init {
addStateSaveHandler(state)
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/at/specure/data/Columns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ object Columns {
const val TEST_DETAILS_TEST_UUID = "testUUID"
const val TEST_DETAILS_TITLE = "title"
const val TEST_DETAILS_VALUE = "value"

const val SIGNAL_MEASUREMENT_ID_PARENT_COLUMN = "id"

}
2 changes: 1 addition & 1 deletion core/src/main/java/at/specure/data/CoreDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import at.specure.data.entity.VoipTestResultRecord
ConnectivityStateRecord::class,
HistoryReference::class],
// Needs to upgraded when schema changes - else: "Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number."
version = 118
version = 119
)
@TypeConverters(TypeConverter::class)
abstract class CoreDatabase : RoomDatabase() {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/at/specure/data/dao/CellInfoDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ abstract class CellInfoDao {
abstract fun removeAllCellInfo(testUUID: String)

@Query("DELETE FROM ${Tables.CELL_INFO} WHERE testUUID=:testUUID AND uuid==:cellInfoUUID")
abstract fun removeSingleCellInfo(testUUID: String, cellInfoUUID: String)
abstract fun removeSingleCellInfo(testUUID: String?, cellInfoUUID: String)

@Transaction
open fun clearInsert(testUUID: String, cellInfo: List<CellInfoRecord>) {
open fun clearInsert(testUUID: String?, cellInfo: List<CellInfoRecord>) {
val filteredCellInfo = cellInfo.filter { it.cellTechnology != null || it.transportType == TransportType.WIFI }
filteredCellInfo.forEach {
if (it.cellTechnology != null || it.transportType == TransportType.WIFI) removeSingleCellInfo(testUUID, it.uuid)
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/at/specure/data/dao/CellLocationDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ interface CellLocationDao {
@Query("DELETE FROM ${Tables.CELL_LOCATION} WHERE testUUID=:testUUID")
fun remove(testUUID: String)

@Query("SELECT * FROM ${Tables.CELL_LOCATION} WHERE testUUID=:testUUID AND scramblingCode==:scramblingCode")
fun getSingleCellLocation(testUUID: String, scramblingCode: Int): List<CellLocationRecord>
@Query("SELECT * FROM ${Tables.CELL_LOCATION} WHERE ((:testUUID!=null AND testUUID=:testUUID) OR (:signalChunkId!=null AND signalChunkId=:signalChunkId)) AND scramblingCode==:scramblingCode")
fun getSingleCellLocation(testUUID: String?, signalChunkId: String?, scramblingCode: Int): List<CellLocationRecord>

@Transaction
fun insertNew(testUUID: String, cellLocationList: List<CellLocationRecord>) {
fun insertNew(testUUID: String?, signalChunkId: String?, cellLocationList: List<CellLocationRecord>) {
val cellLocationListDistinct = cellLocationList.distinct()
cellLocationListDistinct.forEach { newCellLocation ->
val cellLocationsExist = getSingleCellLocation(testUUID, newCellLocation.scramblingCode)
val cellLocationsExist = getSingleCellLocation(testUUID, signalChunkId, newCellLocation.scramblingCode)
val sameCellLocationList = cellLocationsExist.filter { oldCellLocation ->
(oldCellLocation.areaCode == newCellLocation.areaCode && oldCellLocation.locationId == newCellLocation.locationId)
}
if (sameCellLocationList.isEmpty()) {
Timber.d("Inserting cell location true: ${newCellLocation.areaCode}, ${newCellLocation.locationId}, ${newCellLocation.scramblingCode}")
insert(newCellLocation)
} else {

Timber.d("Inserting cell location false: ${newCellLocation.areaCode}, ${newCellLocation.locationId}, ${newCellLocation.scramblingCode}")
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/at/specure/data/dao/HistoryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Upsert
import at.specure.data.Tables
import at.specure.data.entity.History
import at.specure.data.entity.HistoryContainer
Expand All @@ -24,7 +25,7 @@ abstract class HistoryDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun saveHistory(history: List<History>)

@Insert(onConflict = OnConflictStrategy.IGNORE)
@Upsert
abstract fun saveReferences(history: List<HistoryReference>)

@Transaction
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/at/specure/data/dao/QosTestItemDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package at.specure.data.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Upsert
import at.specure.data.Tables
import at.specure.data.entity.QosTestItemRecord
import at.specure.result.QoSCategory
Expand All @@ -16,7 +15,7 @@ abstract class QosTestItemDao {
@Query("SELECT * from ${Tables.QOS_TEST_RESULT_ITEM} WHERE testUUID == :testUUID AND category == :category ORDER BY testNumber")
abstract fun get(testUUID: String, category: QoSCategory): LiveData<List<QosTestItemRecord>>

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Upsert
abstract fun insert(qosTestItems: List<QosTestItemRecord>)

@Query("DELETE FROM ${Tables.QOS_TEST_RESULT_ITEM} WHERE testUUID == :testUUID")
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/at/specure/data/dao/TestDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import androidx.room.Upsert
import at.specure.data.Tables
import at.specure.data.entity.LoopModeRecord
import at.specure.data.entity.QoSResultRecord
Expand All @@ -17,13 +18,13 @@ import at.specure.data.entity.TestWlanRecord
@Dao
interface TestDao {

@Insert(onConflict = OnConflictStrategy.IGNORE)
@Upsert
fun insert(test: TestRecord)

@Insert(onConflict = OnConflictStrategy.REPLACE)
@Upsert
fun insert(test: TestTelephonyRecord)

@Insert(onConflict = OnConflictStrategy.IGNORE)
@Upsert
fun insert(test: TestWlanRecord)

@Insert(onConflict = OnConflictStrategy.REPLACE)
Expand Down
18 changes: 11 additions & 7 deletions core/src/main/java/at/specure/data/entity/CapabilitiesRecord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import androidx.room.PrimaryKey
import at.specure.data.Columns
import at.specure.data.Tables

@Entity(tableName = Tables.CAPABILITIES)
@Entity(
tableName = Tables.CAPABILITIES,
foreignKeys = [
ForeignKey(
entity = TestRecord::class,
parentColumns = [Columns.TEST_UUID_PARENT_COLUMN],
childColumns = ["testUUID"],
onDelete = ForeignKey.CASCADE
)
]
)
data class CapabilitiesRecord(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
@ForeignKey(
entity = TestRecord::class,
parentColumns = [Columns.TEST_UUID_PARENT_COLUMN],
childColumns = ["testUUID"],
onDelete = ForeignKey.CASCADE
)
val testUUID: String,
val classificationCount: Int,
val qosSupportInfo: Boolean,
Expand Down

0 comments on commit caf4617

Please sign in to comment.