feat: add demo mode for testing and review purposes

- Activates by tapping "None (disable)" 7 times.
- Displays a confirmation message when `Demo Mode` is enabled.
- Simulates a connection to a Meshtastic device and allows the app to function without requiring real hardware.
This commit is contained in:
andrekir 2024-10-02 19:58:11 -03:00
parent 16e91c0ebf
commit ffb402acde
4 changed files with 36 additions and 17 deletions

View file

@ -1,15 +1,11 @@
package com.geeksville.mesh.repository.radio
import android.app.Application
import com.geeksville.mesh.android.BuildUtils
import com.geeksville.mesh.android.GeeksvilleApplication
import javax.inject.Inject
/**
* Mock interface backend implementation.
*/
class MockInterfaceSpec @Inject constructor(
private val application: Application,
private val factory: MockInterfaceFactory
): InterfaceSpec<MockInterface> {
override fun createInterface(rest: String): MockInterface {
@ -17,6 +13,5 @@ class MockInterfaceSpec @Inject constructor(
}
/** Return true if this address is still acceptable. For BLE that means, still bonded */
override fun addressValid(rest: String): Boolean =
BuildUtils.isEmulator || ((application as GeeksvilleApplication).isInTestLab)
}
override fun addressValid(rest: String): Boolean = true
}

View file

@ -7,6 +7,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.coroutineScope
import com.geeksville.mesh.CoroutineDispatchers
import com.geeksville.mesh.android.BinaryLogFile
import com.geeksville.mesh.android.BuildUtils
import com.geeksville.mesh.android.GeeksvilleApplication
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.concurrent.handledLaunch
@ -104,8 +105,8 @@ class RadioInterfaceService @Inject constructor(
return interfaceFactory.toInterfaceAddress(interfaceId, rest)
}
fun isAddressValid(address: String?): Boolean {
return interfaceFactory.addressValid(address)
val isMockInterface: Boolean by lazy {
BuildUtils.isEmulator || (context as GeeksvilleApplication).isInTestLab
}
/** Return the device we are configured to use, or null for none
@ -121,7 +122,7 @@ class RadioInterfaceService @Inject constructor(
var address = prefs.getString(DEVADDR_KEY, null)
// If we are running on the emulator we default to the mock interface, so we can have some data to show to the user
if (address == null && isAddressValid(mockInterfaceAddress)) {
if (address == null && isMockInterface) {
address = mockInterfaceAddress
}