diff --git a/android/src/main/java/org/fossasia/badgemagic/others/BadgeMagicPermission.kt b/android/src/main/java/org/fossasia/badgemagic/others/BadgeMagicPermission.kt index 78f7d0f8..0bff48bb 100644 --- a/android/src/main/java/org/fossasia/badgemagic/others/BadgeMagicPermission.kt +++ b/android/src/main/java/org/fossasia/badgemagic/others/BadgeMagicPermission.kt @@ -5,6 +5,7 @@ import android.app.Activity import android.app.AlertDialog import android.widget.Toast import androidx.core.content.ContextCompat +import org.fossasia.badgemagic.R class BadgeMagicPermission private constructor() { @@ -69,32 +70,32 @@ class BadgeMagicPermission private constructor() { if (listPermissionsNeeded.size > 0) { for (permission in listPermissionsNeeded) { if (permission == Manifest.permission.ACCESS_FINE_LOCATION) { - val builder = AlertDialog.Builder(activity) - builder.setTitle("Location Permission Disclosure") - builder.setMessage("Badge Magic collects location data to enable the transfer of data to LED Badges via Bluetooth LE in the background.") - builder.setCancelable(false) - builder.setPositiveButton("ACCEPT") { _, _ -> - activity.requestPermissions(locationPermissions, REQUEST_PERMISSION_CODE) - } - builder.setNegativeButton("DENY") { _, _ -> - Toast.makeText(activity, "Please grant the permission", Toast.LENGTH_SHORT).show() - activity.requestPermissions(locationPermissions, REQUEST_PERMISSION_CODE) - } - builder.show() + AlertDialog.Builder(activity) + .setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_caution)) + .setTitle(activity.getString(R.string.location_required_title)) + .setMessage(activity.getString(R.string.location_required_message)) + .setPositiveButton("OK") { _, _ -> + activity.requestPermissions(locationPermissions, REQUEST_PERMISSION_CODE) + } + .setNegativeButton("Cancel") { _, _ -> + Toast.makeText(activity, activity.getString(R.string.location_canceled_warning), Toast.LENGTH_SHORT).show() + } + .create() + .show() } else if (permission == Manifest.permission.WRITE_EXTERNAL_STORAGE) { - val builder = AlertDialog.Builder(activity) - builder.setTitle("Storage Permission Disclosure") - builder.setMessage("Badge Magic requires access to storage to enable the storage and import of data.") - builder.setCancelable(false) - builder.setPositiveButton("ACCEPT") { _, _ -> - activity.requestPermissions(storagePermissions, REQUEST_PERMISSION_CODE) - } - builder.setNegativeButton("DENY") { _, _ -> - Toast.makeText(activity, "Please grant the permission", Toast.LENGTH_SHORT).show() - activity.requestPermissions(storagePermissions, REQUEST_PERMISSION_CODE) - } - builder.show() - } else if (permission == Manifest.permission.BLUETOOTH || permission == Manifest.permission.BLUETOOTH_ADMIN || permission == Manifest.permission.BLUETOOTH_PRIVILEGED || permission == Manifest.permission.BLUETOOTH_CONNECT || permission == Manifest.permission.BLUETOOTH_SCAN) { + AlertDialog.Builder(activity) + .setIcon(ContextCompat.getDrawable(activity, R.drawable.ic_caution)) + .setTitle(activity.getString(R.string.storage_required_title)) + .setMessage(activity.getString(R.string.storage_required_message)) + .setPositiveButton("OK") { _, _ -> + activity.requestPermissions(storagePermissions, REQUEST_PERMISSION_CODE) + } + .setNegativeButton("Cancel") { _, _ -> + Toast.makeText(activity, activity.getString(R.string.storage_canceled_warning), Toast.LENGTH_SHORT).show() + } + .create() + .show() + } else if (permission == Manifest.permission.BLUETOOTH_CONNECT || permission == Manifest.permission.BLUETOOTH_SCAN) { activity.requestPermissions(bluetoothPermissions, REQUEST_PERMISSION_CODE) } } diff --git a/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt b/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt index 33007ac6..42d8adb4 100644 --- a/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt +++ b/android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt @@ -1,5 +1,6 @@ package org.fossasia.badgemagic.ui +import android.Manifest import android.app.Activity import android.app.AlertDialog import android.content.DialogInterface @@ -56,8 +57,6 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val permission = BadgeMagicPermission.instance - permission.checkPermissions(this, permission.ALL_PERMISSION) binding = ActivityDrawerBinding.inflate(layoutInflater) setContentView(binding.root) @@ -226,7 +225,7 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi private fun prepareForScan() { if (isBleSupported()) { val permission = BadgeMagicPermission.instance - permission.checkPermissions(this, permission.BLUETOOTH_PERMISSION) + permission.checkPermissions(this, permission.LOCATION_PERMISSION) } else { Toast.makeText(this, "BLE is not supported", Toast.LENGTH_LONG).show() finish() @@ -295,6 +294,15 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Timber.d { "Required Permission Accepted" } } + for (p in permissions) { + if ( + p == Manifest.permission.ACCESS_FINE_LOCATION && + grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED + ) { + val permission = BadgeMagicPermission.instance + permission.checkPermissions(this, permission.BLUETOOTH_PERMISSION) + } + } } else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults) } diff --git a/android/src/main/res/values-zh-rCN/strings.xml b/android/src/main/res/values-zh-rCN/strings.xml index 26783472..2dbc42a7 100644 --- a/android/src/main/res/values-zh-rCN/strings.xml +++ b/android/src/main/res/values-zh-rCN/strings.xml @@ -95,6 +95,19 @@ 保存的教具 找不到GPS,请从设置中启用GPS + 需要位置许可 + + 此应用程序使用蓝牙 LE 服务,需要启用位置权限才能扫描附近的设备。\n\n + 该应用程序不会以任何方式使用用户的任何个人和位置信息。\n\n + 如果您未启用定位服务,此应用程序可能无法找到附近的任何 LED 徽章并且无法正常运行。 + + 请允许位置权限。 蓝牙 LE 需要这个才能工作。 + + + 需要存储权限 + 此应用程序需要访问存储空间才能保存和访问已保存的徽章/剪贴画。 + 请允许存储权限来保存和访问已保存的徽章/剪贴画。 + Badge Magic是一个用于控制LED名称徽章的Android应用。该应用程序提供了在LED徽章上描绘姓名,图形和简单动画的功能。 \n您也可以从下面的链接下载它 https://play.google.com/store/apps/details?id=org.fossasia.badgemagic 分享使用 " 您确定要删除此徽章吗?" diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index e101a16d..b78be990 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -109,6 +109,18 @@ Error in saving Clipart Saved Cliparts No GPS Found, Please Enable GPS from Settings + + Location Permission Required + + This application use Bluetooth LE services which require background location to be enabled to scan and transfer data to nearby devices.\n\n + This application is not using any personal and location information of users in anyway.\n\n + If you are not enabling the location permission, this application might not find any nearby LED Badge and cannot function correctly. + + Please allow Location permissions. Bluetooth LE requires this to work. + + Storage Permission Required + This application requires access to storage to save and access saved Badges/Cliparts. + Please allow Storage permissions to save and access saved Badges/Cliparts. Badge Magic is an Android app to control LED name badges. This app provides features to portray names, graphics and simple animations on LED badges. \nYou can also download it from below link \nhttps://play.google.com/store/apps/details?id=org.fossasia.badgemagic Share Using