Skip to content

Commit

Permalink
Reword how android permissions are asked, once again
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Jun 29, 2022
1 parent e2e3819 commit 2c107a2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 63 deletions.
93 changes: 38 additions & 55 deletions qml/DeviceList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,33 @@ Item {
property bool bluetoothPermissionsAvailable: deviceManager.bluetoothPermissions

Component.onCompleted: checkStatus()

onBluetoothAvailableChanged: checkStatus()
onBluetoothPermissionsAvailableChanged: checkStatus()
onDeviceAvailableChanged: {
checkStatus()
exitSelectionMode()
}
onDeviceAvailableChanged: { checkStatus(); exitSelectionMode(); }

function checkStatus() {

if (!utilsApp.checkMobileBleLocationPermission()) {
utilsApp.getMobileBleLocationPermission()
//utilsApp.getMobileBleLocationPermission()
}

if (deviceManager.hasDevices) {
// The device list is shown
itemStatus.source = ""

if (!deviceManager.bluetooth) {
rectangleStatus.setBluetoothWarning()
rectangleBluetoothStatus.setBluetoothWarning()
} else if (!deviceManager.bluetoothPermissions) {
rectangleStatus.setPermissionWarning()
rectangleBluetoothStatus.setPermissionWarning()
} else {
rectangleStatus.hide()
rectangleBluetoothStatus.hide()
}
} else {
// The device list is not populated
rectangleStatus.hide()
rectangleBluetoothStatus.hide()

if (!deviceManager.bluetooth) {
itemStatus.source = "ItemNoBluetooth.qml"
} else if (!deviceManager.bluetoothPermissions) {
itemStatus.source = "ItemNoPermission.qml"
} else {
itemStatus.source = "ItemNoDevice.qml"
}
Expand Down Expand Up @@ -135,7 +129,7 @@ Item {
////////////////

Rectangle {
id: rectangleStatus
id: rectangleBluetoothStatus
anchors.left: parent.left
anchors.right: parent.right

Expand All @@ -150,7 +144,7 @@ Item {
MouseArea { anchors.fill: parent; acceptedButtons: Qt.AllButtons; }

Text {
id: textStatus
id: textBluetoothStatus
anchors.fill: parent
anchors.leftMargin: 16
anchors.rightMargin: 16
Expand All @@ -162,65 +156,54 @@ Item {
font.pixelSize: Theme.fontSizeComponent
}

Row {
ButtonWireframe {
id: buttonBluetoothStatus
height: 32
anchors.right: parent.right
anchors.rightMargin: 16
anchors.verticalCenter: parent.verticalCenter
spacing: 16

ButtonWireframe {
id: buttonBluetoothAbout
height: 32
anchors.verticalCenter: parent.verticalCenter

visible: !deviceManager.bluetoothPermissions
fullColor: true
primaryColor: Theme.colorActionbarHighlight
fullColor: true
primaryColor: Theme.colorActionbarHighlight

text: qsTr("About")
onClicked: screenPermissions.loadScreenFrom("DeviceList")
}

ButtonWireframe {
id: buttonBluetoothRetry
height: 32
anchors.verticalCenter: parent.verticalCenter

visible: false
fullColor: true
primaryColor: Theme.colorActionbarHighlight

text: {
if (Qt.platform.os === "android") {
if (!deviceManager.bluetooth) qsTr("Enable")
else qsTr("Retry")
} else {
qsTr("Retry")
}
text: {
if (Qt.platform.os === "android") {
if (!deviceManager.bluetoothEnabled) qsTr("Enable")
else if (!deviceManager.bluetoothPermissions) qsTr("About")
else qsTr("Retry")
} else {
qsTr("Retry")
}
onClicked: {
if (Qt.platform.os === "android") {
if (!deviceManager.bluetooth) deviceManager.enableBluetooth()
if (!deviceManager.bluetoothPermissions) deviceManager.checkBluetoothPermissions()
}
onClicked: {
if (Qt.platform.os === "android") {
if (!deviceManager.bluetooth) {
deviceManager.enableBluetooth()
} else if (!deviceManager.bluetoothPermissions) {
//utilsApp.getMobileBleLocationPermission()
//deviceManager.checkBluetoothPermissions()

// someone clicked 'never ask again'?
screenPermissions.loadScreenFrom("DeviceList")
} else {
deviceManager.checkBluetooth()
}
} else {
deviceManager.checkBluetooth()
}
}
}

function hide() {
rectangleStatus.height = 0
rectangleBluetoothStatus.height = 0
}
function setBluetoothWarning() {
textStatus.text = qsTr("Bluetooth is disabled...")
rectangleStatus.height = 48
buttonBluetoothRetry.visible = true
textBluetoothStatus.text = qsTr("Bluetooth is disabled...")
rectangleBluetoothStatus.height = 48
}
function setPermissionWarning() {
textStatus.text = qsTr("Bluetooth permission is missing...")
rectangleStatus.height = 48
buttonBluetoothRetry.visible = false
textBluetoothStatus.text = qsTr("Bluetooth permission is missing...")
rectangleBluetoothStatus.height = 48
}
}

Expand Down
36 changes: 30 additions & 6 deletions qml/components/ItemNoDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,31 @@ import QtQuick 2.15
import ThemeEngine 1.0

Item {
id: itemNoDevice
anchors.fill: parent

////////////////////////////////////////////////////////////////////////////

Timer {
id: retryScan
interval: 333
running: false
repeat: false
onTriggered: scan()
}

function scan() {
if (!deviceManager.updating) {
if (deviceManager.scanning) {
deviceManager.scanDevices_stop()
} else {
deviceManager.scanDevices_start()
}
}
}

////////////////////////////////////////////////////////////////////////////

Column {
id: column
anchors.left: parent.left
Expand Down Expand Up @@ -144,12 +167,11 @@ Item {
primaryColor: Theme.colorPrimary

onClicked: {
if (!deviceManager.updating) {
if (deviceManager.scanning) {
deviceManager.scanDevices_stop()
} else {
deviceManager.scanDevices_start()
}
if (utilsApp.checkMobileBleLocationPermission()) {
scan()
} else {
utilsApp.getMobileBleLocationPermission()
retryScan.start()
}
}
}
Expand All @@ -171,6 +193,8 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignBottom
}

////////
}
}
}
5 changes: 3 additions & 2 deletions qml/components/ItemNoPermission.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ThemeEngine 1.0

Item {
id: itemNoPermission
anchors.fill: parent

Rectangle {
anchors.centerIn: parent
Expand Down Expand Up @@ -44,8 +45,8 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter

fullColor: true
text: (Qt.platform.os === "android") ? qsTr("Enable") : qsTr("Retry")
onClicked: (Qt.platform.os === "android") ? deviceManager.enableBluetooth() : deviceManager.checkBluetooth()
text: (Qt.platform.os === "android") ? qsTr("Get permission") : qsTr("Check permission")
onClicked: (Qt.platform.os === "android") ? utilsApp.getMobileBleLocationPermission() : deviceManager.checkBluetooth()
}
}
}
Expand Down

0 comments on commit 2c107a2

Please sign in to comment.