mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-02-02 20:02:26 -05:00
add ClassicScan button, timer & permissions check
This commit is contained in:
@@ -289,6 +289,9 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
return getMissingPermissions(perms)
|
||||
}
|
||||
|
||||
/** Ask the user to grant camera permission */
|
||||
fun requestBTScanPermission() = requestPermission(getCameraPermissions(), false)
|
||||
|
||||
/** Ask the user to grant camera permission */
|
||||
fun requestCameraPermission() = requestPermission(getCameraPermissions(), false)
|
||||
|
||||
@@ -331,7 +334,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
*
|
||||
* @return true if we already have the needed permissions
|
||||
*/
|
||||
private fun requestPermission(
|
||||
fun requestPermission(
|
||||
missingPerms: List<String> = getMinimumPermissions(),
|
||||
shouldShowDialog: Boolean = true
|
||||
): Boolean =
|
||||
@@ -534,9 +537,6 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
handleIntent(intent)
|
||||
|
||||
askToRate()
|
||||
|
||||
// if (!isInTestLab) - very important - even in test lab we must request permissions because we need location perms for some of our tests to pass
|
||||
requestPermission()
|
||||
}
|
||||
|
||||
private fun initToolbar() {
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.content.pm.PackageManager
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbManager
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.RemoteException
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -811,12 +813,32 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||
|
||||
private fun initClassicScan() {
|
||||
|
||||
model.bluetoothEnabled.observe(viewLifecycleOwner, Observer { enabled ->
|
||||
if (enabled)
|
||||
scanModel.startScan()
|
||||
else
|
||||
binding.changeRadioButton.setOnClickListener {
|
||||
if (myActivity.warnMissingPermissions()) {
|
||||
myActivity.requestPermission()
|
||||
} else scanLeDevice()
|
||||
}
|
||||
}
|
||||
|
||||
// per https://developer.android.com/guide/topics/connectivity/bluetooth/find-ble-devices
|
||||
private fun scanLeDevice() {
|
||||
var scanning = false
|
||||
val SCAN_PERIOD: Long = 5000 // Stops scanning after 5 seconds
|
||||
|
||||
if (!scanning) { // Stops scanning after a pre-defined scan period.
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
scanning = false
|
||||
binding.scanProgressBar.visibility = View.GONE
|
||||
scanModel.stopScan()
|
||||
})
|
||||
}, SCAN_PERIOD)
|
||||
scanning = true
|
||||
binding.scanProgressBar.visibility = View.VISIBLE
|
||||
scanModel.startScan()
|
||||
} else {
|
||||
scanning = false
|
||||
binding.scanProgressBar.visibility = View.GONE
|
||||
scanModel.stopScan()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initModernScan() {
|
||||
|
||||
Reference in New Issue
Block a user