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
commit 4d809a3cd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 41 additions and 44 deletions

View file

@ -172,8 +172,6 @@ dependencies {
implementation 'com.google.android.gms:play-services-location:19.0.1'
// For Google Sign-In (owner name accesss)
implementation 'com.google.android.gms:play-services-auth:20.2.0'
// ML Kit barcode scanning
implementation 'com.google.android.gms:play-services-code-scanner:16.0.0-beta2'
// Add the Firebase SDK for Crashlytics.
implementation 'com.google.firebase:firebase-crashlytics:18.2.6'

View file

@ -97,9 +97,6 @@
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode_ui"/>
<!-- we need bind job service for oreo -->
<service

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

View file

@ -88,4 +88,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/shutdownButton"
app:layout_constraintTop_toTopOf="@id/shutdownButton" />
<com.google.android.material.button.MaterialButton
android:id="@+id/factoryResetButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/factory_reset"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/shutdownButton" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -153,4 +153,7 @@
<string name="mode_append">Append to message</string>
<string name="mode_instant">Instantly send</string>
<string name="warning_default_psk">Empty channel names use the default encryption key (any device on %s can read your messages).</string>
<string name="factory_reset">Factory reset</string>
<string name="are_you_sure_factory_reset">Are you sure you want to factory reset?</string>
<string name="factory_reset_description">This will clear all device configuration you have done.</string>
</resources>