diff --git a/kitx_mobile/lib/pages/controls/home_page_drawer.dart b/kitx_mobile/lib/pages/controls/home_page_drawer.dart index ed02f67..eac4269 100644 --- a/kitx_mobile/lib/pages/controls/home_page_drawer.dart +++ b/kitx_mobile/lib/pages/controls/home_page_drawer.dart @@ -4,6 +4,7 @@ import 'package:kitx_mobile/pages/pages.dart'; import 'package:kitx_mobile/pages/plugins_page.dart'; import 'package:kitx_mobile/utils/config.dart'; import 'package:kitx_mobile/utils/handlers/tasks/delayed_task.dart'; +import 'package:kitx_mobile/utils/handlers/vibration_handler.dart'; /// [HomePageDrawer] class class HomePageDrawer extends StatelessWidget { @@ -35,50 +36,50 @@ class HomePageDrawer extends StatelessWidget { ListTile( leading: const Icon(Icons.devices), title: Text('Drawer_Devices'.tr), - onTap: () { + onTap: () => () { Get.back(); Get.toNamed(DevicesPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ListTile( leading: const Icon(Icons.layers), title: Text('Drawer_Plugins'.tr), - onTap: () { + onTap: () => () { Get.back(); Get.toNamed(PluginsPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ListTile( leading: const Icon(Icons.alternate_email), title: Text('Drawer_Account'.tr), - onTap: () { + onTap: () => () { Get.back(); Get.toNamed(AccountPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), const Divider(), Row( children: [ const SizedBox(width: 5), IconButton( - onPressed: () { + onPressed: () => () { Get.back(); Get.toNamed(SettingsPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), icon: const Icon(Icons.settings), ), IconButton( - onPressed: () { + onPressed: () => () { Get.back(); Get.toNamed(AboutPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), icon: const Icon(Icons.info_outline_rounded), ), IconButton( - onPressed: () { + onPressed: () => () { Get.back(); Get.toNamed(TestPage.getRoute()); - }.delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute, + }.tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), icon: const Icon(Icons.bug_report), ), ], diff --git a/kitx_mobile/lib/pages/devices_page.dart b/kitx_mobile/lib/pages/devices_page.dart index c7e0b42..6de893c 100644 --- a/kitx_mobile/lib/pages/devices_page.dart +++ b/kitx_mobile/lib/pages/devices_page.dart @@ -7,6 +7,7 @@ import 'package:kitx_mobile/pages/controls/device_status_icon.dart'; import 'package:kitx_mobile/pages/controls/device_status_label.dart'; import 'package:kitx_mobile/pages/pages.dart'; import 'package:kitx_mobile/pages/sub_pages/device_chat_page.dart'; +import 'package:kitx_mobile/utils/handlers/vibration_handler.dart'; import 'package:kitx_shared_dart/kitx_shared_dart.dart'; import 'package:sliding_up_panel/sliding_up_panel.dart'; @@ -67,11 +68,15 @@ class _DevicesPage extends State { itemBuilder: (context) => [ PopupMenuItem( child: const Text('2'), - onTap: () => deviceCardHorizontalScale = 0.5, + onTap: () => () { + deviceCardHorizontalScale = 0.5; + }.tryVibrate().call(), ), PopupMenuItem( child: const Text('3'), - onTap: () => deviceCardHorizontalScale = 1.0 / 3, + onTap: () => () { + deviceCardHorizontalScale = 1.0 / 3; + }.tryVibrate().call(), ), ], ) @@ -85,11 +90,11 @@ class _DevicesPage extends State { itemBuilder: (context) => [ PopupMenuItem( child: Text('Option_RestartDevicesServer'.tr), - onTap: instances.restartDevicesServer, + onTap: () => instances.restartDevicesServer.tryVibrate().call(), ), PopupMenuItem( child: Text('Option_ShutdownDevicesServer'.tr), - onTap: instances.shutdownDevicesServer, + onTap: () => instances.shutdownDevicesServer.tryVibrate().call(), ), ], ), @@ -102,11 +107,13 @@ class _DevicesPage extends State { curve: Curves.easeInOutCubicEmphasized, opacity: backToTopButtonVisibility.value ? 1 : 0, child: FloatingActionButton( - onPressed: () => _scrollController.animateTo( - 0.0, - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOutCubicEmphasized, - ), + onPressed: () => () { + _scrollController.animateTo( + 0.0, + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOutCubicEmphasized, + ); + }.tryVibrate().call(), child: const Icon(Icons.arrow_upward), ), ), diff --git a/kitx_mobile/lib/pages/home_page.dart b/kitx_mobile/lib/pages/home_page.dart index 9bb1268..161fbf1 100644 --- a/kitx_mobile/lib/pages/home_page.dart +++ b/kitx_mobile/lib/pages/home_page.dart @@ -7,6 +7,7 @@ import 'package:kitx_mobile/pages/pages.dart'; import 'package:kitx_mobile/pages/plugins_page.dart'; import 'package:kitx_mobile/utils/config.dart'; import 'package:kitx_mobile/utils/handlers/tasks/delayed_task.dart'; +import 'package:kitx_mobile/utils/handlers/vibration_handler.dart'; /// HomePage class HomePage extends StatelessWidget implements ConstantPage { @@ -31,11 +32,11 @@ class HomePage extends StatelessWidget implements ConstantPage { body: Padding( padding: EdgeInsets.all(20), child: ListView( - children: [ - OrientationBuilder( - builder: (context, _) => MediaQuery.of(context).orientation == Orientation.portrait - ? ListView( - shrinkWrap: true, + children: [ + OrientationBuilder( + builder: (context, _) => MediaQuery.of(context).orientation == Orientation.portrait + ? ListView( + shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), children: getContent( context, @@ -78,7 +79,7 @@ class HomePage extends StatelessWidget implements ConstantPage { ), trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => (() => Get.toNamed(DevicesPage.getRoute())).delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), + onTap: () => (() => Get.toNamed(DevicesPage.getRoute())).tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), onLongPress: () { showMenu( context: context, @@ -107,7 +108,7 @@ class HomePage extends StatelessWidget implements ConstantPage { subtitle: isLandscape ? const Text('developing ...') : null, trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => (() => Get.toNamed(PluginsPage.getRoute())).delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), + onTap: () => (() => Get.toNamed(PluginsPage.getRoute())).tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ), const SizedBox(height: tilesPadding), @@ -119,7 +120,7 @@ class HomePage extends StatelessWidget implements ConstantPage { subtitle: isLandscape ? const Text('developing ...') : null, trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => (() => Get.toNamed(AccountPage.getRoute())).delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), + onTap: () => (() => Get.toNamed(AccountPage.getRoute())).tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ), const SizedBox(height: tilesPadding), @@ -131,7 +132,7 @@ class HomePage extends StatelessWidget implements ConstantPage { subtitle: isLandscape ? const Text('no notifications') : null, trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => (() => Get.toNamed(SettingsPage.getRoute())).delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), + onTap: () => (() => Get.toNamed(SettingsPage.getRoute())).tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ), const SizedBox(height: tilesPadding), @@ -144,7 +145,7 @@ class HomePage extends StatelessWidget implements ConstantPage { subtitle: Text(instances.appInfo.versionString.value), trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => (() => Get.toNamed(AboutPage.getRoute())).delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), + onTap: () => (() => Get.toNamed(AboutPage.getRoute())).tryVibrate().delay(milliseconds: config.delayOpenPageInHomePage.value ? pageOpenDelay : 0).execute(), ), ), ), diff --git a/kitx_mobile/lib/pages/plugins_page.dart b/kitx_mobile/lib/pages/plugins_page.dart index 7506ce9..f534400 100644 --- a/kitx_mobile/lib/pages/plugins_page.dart +++ b/kitx_mobile/lib/pages/plugins_page.dart @@ -1,11 +1,11 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; import 'package:kitx_mobile/pages/pages.dart'; +import 'package:kitx_mobile/utils/handlers/vibration_handler.dart'; import 'package:kitx_mobile_internal_plugins/kitx_mobile_internal_plugins.dart'; -import 'package:sound_mode/sound_mode.dart'; -import 'package:sound_mode/utils/ringer_mode_statuses.dart'; -import 'package:vibration/vibration.dart'; /// Plugins Page class PluginsPage extends StatefulWidget implements ConstantPage { @@ -27,32 +27,11 @@ class _PluginsPageState extends State { @override Widget build(BuildContext context) { - InternalPluginsManager.instance().onPluginAbilityChanged((ability) { - SoundMode.ringerModeStatus.then((ringer) { - if (ringer == RingerModeStatus.silent) { - return; - } - - Vibration.hasVibrator().then((value) { - Vibration.hasCustomVibrationsSupport().then( - (value) => { - if (value ?? false) - { - Vibration.vibrate(duration: ability ? 50 : 100), - } - else - { - Vibration.hasVibrator().then( - (value) => { - if (value ?? false) Vibration.vibrate(), - }, - ), - } - }, - ); - }); - }); - }); + InternalPluginsManager.instance().onPluginAbilityChanged( + (ability) => VibrationHandler.tryVibrate( + milliseconds: ability ? 50 : 100, + ), + ); return Scaffold( appBar: AppBar( @@ -69,9 +48,11 @@ class _PluginsPageState extends State { const SizedBox(height: 10), const Divider(), const SizedBox(height: 10), - ListView( - shrinkWrap: true, - children: InternalPluginsManager.instance().getList(shape: tileRadius), + Column( + children: InternalPluginsManager.instance().getList( + shape: tileRadius, + vibrator: () => VibrationHandler.tryVibrate(), + ), ), const SizedBox(height: 50), Text( @@ -81,8 +62,7 @@ class _PluginsPageState extends State { const SizedBox(height: 10), const Divider(), const SizedBox(height: 10), - ListView( - shrinkWrap: true, + Column( children: [ const ListTile( title: Text('Nothing here yet!'), diff --git a/kitx_mobile/lib/pages/settings_page.dart b/kitx_mobile/lib/pages/settings_page.dart index a440734..627aafe 100644 --- a/kitx_mobile/lib/pages/settings_page.dart +++ b/kitx_mobile/lib/pages/settings_page.dart @@ -13,6 +13,7 @@ import 'package:kitx_mobile/utils/composer.dart'; import 'package:kitx_mobile/utils/config.dart'; import 'package:kitx_mobile/utils/converters/size_converter.dart'; import 'package:kitx_mobile/utils/handlers/tasks/delayed_task.dart'; +import 'package:kitx_mobile/utils/handlers/vibration_handler.dart'; /// Settings Group Title class SettingsGroupTitle extends StatelessWidget { @@ -152,7 +153,7 @@ class _SettingsPageState extends State { title: Text('SettingsPage_Theme'.tr), trailing: const Icon(Icons.keyboard_arrow_right), shape: tileRadius, - onTap: () => Get.toNamed(ExteriorSettingsPage.getRoute()), + onTap: () => (() => Get.toNamed(ExteriorSettingsPage.getRoute())).tryVibrate().call(), ), ), const Divider(), diff --git a/kitx_mobile/lib/utils/handlers/vibration_handler.dart b/kitx_mobile/lib/utils/handlers/vibration_handler.dart new file mode 100644 index 0000000..060fdf0 --- /dev/null +++ b/kitx_mobile/lib/utils/handlers/vibration_handler.dart @@ -0,0 +1,40 @@ +import 'package:sound_mode/sound_mode.dart'; +import 'package:sound_mode/utils/ringer_mode_statuses.dart'; +import 'package:vibration/vibration.dart'; + +/// [VibrationHandler] +class VibrationHandler { + /// [tryVibrate] + static void tryVibrate({int milliseconds = 50}) { + SoundMode.ringerModeStatus.then((ringer) { + if (ringer == RingerModeStatus.silent) { + return; + } + + Vibration.hasVibrator().then((value) { + Vibration.hasCustomVibrationsSupport().then( + (value) { + if (value ?? false) { + Vibration.vibrate(duration: milliseconds); + } else { + Vibration.hasVibrator().then( + (value) { + if (value ?? false) Vibration.vibrate(); + }, + ); + } + }, + ); + }); + }); + } +} + +/// [VibrationHandlerExtensions] +extension VibrationHandlerExtensions on Function { + /// [tryVibrate] + Function tryVibrate({int milliseconds = 50}) { + VibrationHandler.tryVibrate(milliseconds: milliseconds); + return this; + } +} diff --git a/kitx_mobile_internal_plugins/lib/kitx_mobile_internal_plugins.dart b/kitx_mobile_internal_plugins/lib/kitx_mobile_internal_plugins.dart index 1969b2f..eb6e411 100644 --- a/kitx_mobile_internal_plugins/lib/kitx_mobile_internal_plugins.dart +++ b/kitx_mobile_internal_plugins/lib/kitx_mobile_internal_plugins.dart @@ -28,7 +28,7 @@ class InternalPluginsManager { int get enabledLength => plugins.where((plugin) => plugin.isEnabled.value).length; - List getList({ShapeBorder? shape}) { + List getList({ShapeBorder? shape, Function? vibrator}) { return plugins .map( (plugin) => ListTile( @@ -44,7 +44,10 @@ class InternalPluginsManager { ), ), shape: shape, - onTap: () => Get.to(plugin.getSettings()), + onTap: () { + vibrator?.call(); + Get.to(plugin.getSettings()); + }, ), ) .toList();