Merge branch 'meshtastic:master' into feature/osmand-migration

This commit is contained in:
PWRxPSYCHO
2022-08-26 13:44:48 +00:00
committed by GitHub
8 changed files with 41 additions and 44 deletions

View File

@@ -44,16 +44,6 @@ fun Context.hasCompanionDeviceApi(): Boolean =
fun Context.hasGps(): Boolean =
packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)
/**
* return app install source (play store = com.android.vending)
*/
fun Context.installSource(): String? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
packageManager.getInstallSourceInfo(packageName).installingPackageName
else
packageManager.getInstallerPackageName(packageName)
}
/**
* return a list of the permissions we don't have
*/

View File

@@ -346,6 +346,17 @@ class UIViewModel @Inject constructor(
meshService?.requestReboot(DataPacket.ID_LOCAL)
}
fun requestFactoryReset() {
val config = _localConfig.value
if (config != null) {
val builder = config.device.toBuilder()
builder.factoryReset = true
val newConfig = ConfigProtos.Config.newBuilder()
newConfig.device = builder.build()
setDeviceConfig(newConfig.build())
}
}
/**
* Write the persisted packet data out to a CSV file in the specified location.
*/

View File

@@ -55,6 +55,7 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.lsSleepSwitch.isEnabled = connected && model.isESP32()
binding.shutdownButton.isEnabled = connected && model.hasAXP()
binding.rebootButton.isEnabled = connected
binding.factoryResetButton.isEnabled = connected
}
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
@@ -132,5 +133,17 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
}
.show()
}
binding.factoryResetButton.setOnClickListener {
MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.are_you_sure_factory_reset)
.setMessage(R.string.factory_reset_description)
.setNeutralButton(R.string.cancel) { _, _ ->
}
.setPositiveButton(R.string.okay) { _, _ ->
model.requestFactoryReset()
}
.show()
}
}
}

View File

@@ -25,7 +25,6 @@ import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.R
import com.geeksville.mesh.android.getCameraPermissions
import com.geeksville.mesh.android.hasCameraPermission
import com.geeksville.mesh.android.installSource
import com.geeksville.mesh.databinding.ChannelFragmentBinding
import com.geeksville.mesh.model.Channel
import com.geeksville.mesh.model.ChannelOption
@@ -33,9 +32,6 @@ import com.geeksville.mesh.model.ChannelSet
import com.geeksville.mesh.model.UIViewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.mlkit.vision.barcode.common.Barcode
import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions
import com.google.mlkit.vision.codescanner.GmsBarcodeScanning
import com.google.protobuf.ByteString
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanOptions
@@ -238,24 +234,6 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
.show()
}
fun mlkitScan() {
debug("Starting ML Kit code scanner")
val options = GmsBarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
.build()
val scanner = GmsBarcodeScanning.getClient(requireContext(), options)
scanner.startScan()
.addOnSuccessListener { barcode ->
if (barcode.rawValue != null)
model.setRequestChannelUrl(Uri.parse(barcode.rawValue))
}
.addOnFailureListener { ex ->
errormsg("code scanner failed: ${ex.message}")
if (requireContext().hasCameraPermission()) zxingScan()
else requestPermissionAndScan()
}
}
binding.channelNameEdit.on(EditorInfo.IME_ACTION_DONE) {
requireActivity().hideKeyboard()
}
@@ -279,13 +257,8 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
}
binding.scanButton.setOnClickListener {
// only use ML Kit for play store installs
if (requireContext().installSource() == "com.android.vending") {
mlkitScan()
} else {
if (requireContext().hasCameraPermission()) zxingScan()
else requestPermissionAndScan()
}
if (requireContext().hasCameraPermission()) zxingScan()
else requestPermissionAndScan()
}
// Note: Do not use setOnCheckedChanged here because we don't want to be called when we programmatically disable editing