diff --git a/app/src/main/java/science/apolline/view/activity/MainActivity.kt b/app/src/main/java/science/apolline/view/activity/MainActivity.kt index 9a24baa..de2a417 100644 --- a/app/src/main/java/science/apolline/view/activity/MainActivity.kt +++ b/app/src/main/java/science/apolline/view/activity/MainActivity.kt @@ -231,17 +231,17 @@ class MainActivity : RootActivity(), NavigationView.OnNavigationItemSelectedList request.send() request.listeners { - onAccepted { permissions -> + onAccepted { Toasty.success(applicationContext, "READ_PHONE_STATE and ACCESS_FINE_LOCATION permissions granted.", Toast.LENGTH_SHORT, true).show() stopService(Intent(applicationContext, IOIOService::class.java)) startService(Intent(applicationContext, IOIOService::class.java)) } - onDenied { permissions -> + onDenied { Toasty.error(applicationContext, "READ_PHONE_STATE and ACCESS_FINE_LOCATION permissions denied.", Toast.LENGTH_LONG, true).show() } - onPermanentlyDenied { permissions -> + onPermanentlyDenied { Toasty.error(applicationContext, "READ_PHONE_STATE and ACCESS_FINE_LOCATION permissions permanently denied, please grant it manually, Apolline will close in 10 seconds", Toast.LENGTH_LONG, true).show() object : CountDownTimer(10000, 1000) { override fun onTick(millisUntilFinished: Long) { @@ -254,7 +254,7 @@ class MainActivity : RootActivity(), NavigationView.OnNavigationItemSelectedList }.start() } - onShouldShowRationale { permissions, nonce -> + onShouldShowRationale { _, _ -> alert("Apolline will not work, please grant READ_PHONE_STATE and ACCESS_FINE_LOCATION permissions.", "Request read phone state and location permissions") { yesButton { diff --git a/app/src/main/java/science/apolline/view/activity/SplashScreen.kt b/app/src/main/java/science/apolline/view/activity/SplashScreen.kt index e92a63f..bb22066 100644 --- a/app/src/main/java/science/apolline/view/activity/SplashScreen.kt +++ b/app/src/main/java/science/apolline/view/activity/SplashScreen.kt @@ -31,6 +31,7 @@ import com.github.ivbaranov.rxbluetooth.predicates.BtPredicate import com.fondesa.kpermissions.extension.permissionsBuilder import com.fondesa.kpermissions.request.PermissionRequest import org.jetbrains.anko.* +import science.apolline.utils.CheckUtility class SplashScreen : RootActivity(), AnkoLogger { @@ -56,6 +57,8 @@ class SplashScreen : RootActivity(), AnkoLogger { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter() mDisposable = CompositeDisposable() + mIsLocationPermissionGranted = CheckUtility.isWifiNetworkConnected(applicationContext) + setContentView(R.layout.activity_splash_screen) ripple_scan_view.clipToOutline = true circle_layout.setOnItemSelectedListener { @@ -65,7 +68,7 @@ class SplashScreen : RootActivity(), AnkoLogger { pairCurrentDevice() } circle_layout.setOnCenterClickListener { - if(!mIsLocationPermissionGranted){ + if (!mIsLocationPermissionGranted) { checkFineLocationPermission(mRequestLocationPermission) } else { checkBlueToothState() @@ -179,9 +182,8 @@ class SplashScreen : RootActivity(), AnkoLogger { // if (circle_layout.tag != null) { val view = circle_layout.selectedItem if (view is CircleImageView) { - + Toasty.info(applicationContext, "Default PIN code for IOIO sensor is: 4545", Toast.LENGTH_LONG, true).show() mBluetoothAdapter!!.cancelDiscovery() - selected_device_name_textview.text = view.name val deviceName = view.name val device = mDetectedDevices[deviceName] @@ -203,14 +205,17 @@ class SplashScreen : RootActivity(), AnkoLogger { private fun addDeviceToCircleView(device: BluetoothDevice?) { - + var isCompatible = false if (device != null) { info("device: $device") - - val nameOrcode = if (device.name == null) { - device.address.toString() + val nameOrcode: String + if (device.name == null) { + nameOrcode = device.address.toString() } else { - device.name.toString() + nameOrcode = device.name.toString() + if (nameOrcode.toLowerCase().contains(regex = "^ioio.".toRegex())) { + isCompatible = true + } } mDetectedDevices[nameOrcode] = device @@ -218,45 +223,45 @@ class SplashScreen : RootActivity(), AnkoLogger { when (device.bluetoothClass.majorDeviceClass) { BluetoothClass.Device.Major.AUDIO_VIDEO -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_audio_video) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_audio_video, isCompatible) } BluetoothClass.Device.Major.COMPUTER -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_computer) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_computer, isCompatible) } BluetoothClass.Device.Major.HEALTH -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_health) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_health, isCompatible) } BluetoothClass.Device.Major.IMAGING -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_imaging) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_imaging, isCompatible) } BluetoothClass.Device.Major.MISC -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_misc) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_misc, isCompatible) } BluetoothClass.Device.Major.NETWORKING -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_netwoking) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_netwoking, isCompatible) } BluetoothClass.Device.Major.PERIPHERAL -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_peripheral) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_peripheral, isCompatible) } BluetoothClass.Device.Major.TOY -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_toy) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_toy, isCompatible) } BluetoothClass.Device.Major.PHONE -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_phone) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_phone, isCompatible) } BluetoothClass.Device.Major.WEARABLE -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_wear) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_wear, isCompatible) } else -> { - onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_uncategorized) + onAddClick(circle_layout, nameOrcode, R.drawable.ic_device_bluetooth_uncategorized, isCompatible) } } @@ -295,17 +300,20 @@ class SplashScreen : RootActivity(), AnkoLogger { } - private fun onAddClick(view: View, name: String, drawableId: Int) { + private fun onAddClick(view: View, name: String, drawableId: Int, compatible: Boolean) { val newMenu = CircleImageView(this) val currentDrawable = ContextCompat.getDrawable(this, drawableId) val willBeWhite = currentDrawable!!.constantState.newDrawable() newMenu.setBackgroundResource(R.drawable.circle_menu_shape_item) willBeWhite.mutate().setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP) - newMenu.setPadding(20, 20, 20, 20) newMenu.setImageDrawable(willBeWhite) - newMenu.name = name + + if (compatible) { + newMenu.setBackgroundResource(R.color.colorPrimary) + } + circle_layout.addView(newMenu) } @@ -322,17 +330,17 @@ class SplashScreen : RootActivity(), AnkoLogger { request.send() request.listeners { - onAccepted { permissions -> + onAccepted { mIsLocationPermissionGranted = true Toasty.success(applicationContext, "ACCESS_FINE_LOCATION granted.", Toast.LENGTH_SHORT, true).show() } - onDenied { permissions -> + onDenied { mIsLocationPermissionGranted = false Toasty.warning(applicationContext, "ACCESS_FINE_LOCATION denied.", Toast.LENGTH_SHORT, true).show() } - onPermanentlyDenied { permissions -> + onPermanentlyDenied { mIsLocationPermissionGranted = false Toasty.error(applicationContext, "ACCESS_FINE_LOCATION permission permanently denied, please grant it manually, Apolline will close in 10 seconds", Toast.LENGTH_LONG, true).show() object : CountDownTimer(10000, 1000) { @@ -341,12 +349,12 @@ class SplashScreen : RootActivity(), AnkoLogger { } override fun onFinish() { - finish() + finish() } }.start() } - onShouldShowRationale { permissions, nonce -> + onShouldShowRationale { _, _ -> mIsLocationPermissionGranted = false alert("Apolline will not work, please grant ACCESS_FINE_LOCATION permission.", "Request location permission") { yesButton { diff --git a/app/src/main/java/science/apolline/view/fragment/ChartFragment.kt b/app/src/main/java/science/apolline/view/fragment/ChartFragment.kt index ae9d3bb..2741150 100644 --- a/app/src/main/java/science/apolline/view/fragment/ChartFragment.kt +++ b/app/src/main/java/science/apolline/view/fragment/ChartFragment.kt @@ -337,22 +337,22 @@ class ChartFragment : RootFragment(), OnChartValueSelectedListener, FragmentLife request.send() request.listeners { - onAccepted { permissions -> + onAccepted { mIsWriteToExternalStoragePermissionGranted = true Toasty.success(activity!!.applicationContext, "WRITE_EXTERNAL_STORAGE permission granted.", Toast.LENGTH_SHORT, true).show() } - onDenied { permissions -> + onDenied { mIsWriteToExternalStoragePermissionGranted = false Toasty.error(activity!!.applicationContext, "WRITE_EXTERNAL_STORAGE permission denied.", Toast.LENGTH_SHORT, true).show() } - onPermanentlyDenied { permissions -> + onPermanentlyDenied { mIsWriteToExternalStoragePermissionGranted = false Toasty.error(activity!!.applicationContext, "Fatal error, WRITE_EXTERNAL_STORAGE permission permanently denied, please grant it manually", Toast.LENGTH_LONG, true).show() } - onShouldShowRationale { permissions, nonce -> + onShouldShowRationale { _, _ -> mIsWriteToExternalStoragePermissionGranted = false activity!!.alert("Apolline couldn't export any file, please grant WRITE_EXTERNAL_STORAGE permission.", "Request write permission") { diff --git a/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt b/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt index 7fb8c76..c3a7251 100644 --- a/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt +++ b/app/src/main/java/science/apolline/view/fragment/IOIOFragment.kt @@ -217,22 +217,22 @@ class IOIOFragment : RootFragment(), FragmentLifecycle, AnkoLogger { request.send() request.listeners { - onAccepted { permissions -> + onAccepted { mIsWriteToExternalStoragePermissionGranted = true Toasty.success(activity!!.applicationContext, "WRITE_EXTERNAL_STORAGE permission granted.", Toast.LENGTH_SHORT, true).show() } - onDenied { permissions -> + onDenied { mIsWriteToExternalStoragePermissionGranted = false Toasty.error(activity!!.applicationContext, "WRITE_EXTERNAL_STORAGE permission denied.", Toast.LENGTH_SHORT, true).show() } - onPermanentlyDenied { permissions -> + onPermanentlyDenied { mIsWriteToExternalStoragePermissionGranted = false Toasty.error(activity!!.applicationContext, "Fatal error, WRITE_EXTERNAL_STORAGE permission permanently denied, please grant it manually", Toast.LENGTH_LONG, true).show() } - onShouldShowRationale { permissions, nonce -> + onShouldShowRationale { _, _ -> mIsWriteToExternalStoragePermissionGranted = false activity!!.alert("Apolline couldn't export any file, please grant WRITE_EXTERNAL_STORAGE permission.", "Request write permission") {