Skip to content

Commit

Permalink
Merge pull request #3 from srnunio/emartins-fixes
Browse files Browse the repository at this point in the history
emartins-fixes-improvements
  • Loading branch information
srnunio authored Aug 21, 2023
2 parents 4a0ea90 + e28965a commit 63ac915
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 199 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@
* Intercept events
* Change in the name of methods
* Check active monitoring

## 1.0.2
* Fix initialize monitoring
* Fix ```stop``` monitoring
* Fix ```start``` monitoring
* Fix ```reset``` monitoring
* Rename methods
* Other fixes

## 1.0.3
* Remove time limitation
* Update example
* Other fixes
35 changes: 12 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,17 @@ reacts when there are no user activities in your application

```yaml
dependencies:
activsy: ^1.0.1
activsy: ^1.0.3
```
# Usage
```dart
void main() {
Activsy.config(seconds: 10, noActivity: () async {
Activsy.initialize(waiTime: 10, onTimeOut: () {
/// perform operation
/// call the start to continue monitoring
});
runApp(const MyApp());
}

or

void main() {
Activsy.config(seconds: 10, noActivity: () async {
/// perform operation
/// call the start to continue monitoring
}).init();
});
runApp(const MyApp());
}
```
Expand All @@ -53,19 +43,18 @@ ActivsyWidget(
)
```

After the ```onActivity``` method call the monitoring is terminated
After the ```onTimeOut``` method call the monitoring is terminated

<img src="/demo.gif" width="240" height="480">

| Functions And Attributes | Description |
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| init | Starts monitoring after setting up. Uses the method `start()` |
| start | To monitor user interaction with the application just call `Activsy.start()`. Can be called multiple times but if monitoring is already active nothing happens |
| cancel | Ends monitoring `Activsy.reset()`. Can be called multiple times |
| reset | Restart monitoring `Activsy.reset()`, he calls `start()` and then `cancel()`. This method also to modify the waiting time: `Activsy.reset(seconds: 60)` |
| trigger | Triggers the onActivity method at any point in the application `Activsy.trigger()`. There are several reasons to trigger the noActivity method before the stipulated timer |
| isInitialized | true returns if the setup was made |
| isActive | true returns if monitoring this active |
| Functions And Attributes | Description |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| start | To monitor user interaction with the application just call `Activsy.start()`. Can be called multiple times but if monitoring is already active nothing happens |
| stop | Ends monitoring `Activsy.reset()`. Can be called multiple times |
| reset | Restart monitoring `Activsy.reset()`, he calls `start()` and then `stop()`. This method also to modify the waiting time: `Activsy.updateTime(waiTime: 60)` |
| forceTimeOut | Triggers the onTimeOut method at any point in the application `Activsy.forceTimeOut()`. There are several reasons to trigger the noActivity method before the stipulated timer |
| isInitialized | true returns if the setup was made |
| isActive | true returns if monitoring this active |

**Note**: call the functions after the **config** method otherwise you will throw an exception

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
5 changes: 4 additions & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -171,10 +171,12 @@
/* Begin PBXShellScriptBuildPhase section */
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -185,6 +187,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down
4 changes: 4 additions & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
20 changes: 9 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ class App extends StatefulWidget {

class _AppState extends State<App> {
final GlobalKey<NavigatorState> _globalKey = GlobalKey<NavigatorState>();
final int _seconds = 10;
final int _waiTime = 3;

void onEvent(dynamic _) {
print('onEvent');
debugPrint('onEvent');
}

void noActivity() async {
print('noActivity called :)');
void onTimeOut() async {
debugPrint('onTimeOut :)');
await _globalKey.currentState!.pushNamed(AuthenticationPage.route);
Activsy.start();
}

@override
void initState() {
super.initState();
Activsy.config(seconds: _seconds, noActivity: noActivity).init();
Activsy.initialize(waiTime: _waiTime, onTimeOut: onTimeOut);
Activsy.start();
}

@override
Widget build(BuildContext context) {
return ActivsyWidget(
detectedMouseAction: false,
withMouse: true,
onEvent: onEvent,
builder: (ctx) {
return MaterialApp(
Expand All @@ -45,9 +46,8 @@ class _AppState extends State<App> {
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: TransactionsPage.route,
initialRoute: '/',
onGenerateRoute: AppRouter.route,
home: TransactionsPage(),
);
},
);
Expand All @@ -56,10 +56,8 @@ class _AppState extends State<App> {

abstract class AppRouter {
static Route<dynamic> route(RouteSettings settings) {
debugPrint("route:: ${settings.name}");
switch (settings.name) {
case TransactionsPage.route:
return MaterialPageRoute(builder: (_) => TransactionsPage());

case AuthenticationPage.route:
return MaterialPageRoute(builder: (_) => AuthenticationPage());
default:
Expand Down
44 changes: 17 additions & 27 deletions example/lib/src/transactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TransactionsPage extends StatefulWidget {
}

class _TransactionsPageState extends State<TransactionsPage> {
ScrollController _controller = ScrollController();
final ScrollController _controller = ScrollController();

List<Map<String, dynamic>> _items = [];

Expand All @@ -23,7 +23,7 @@ class _TransactionsPageState extends State<TransactionsPage> {
}

void fetchData() async {
await Future.delayed(Duration(milliseconds: 300));
await Future.delayed(const Duration(milliseconds: 300));

var list = List.generate(15, (index) => createItem()).toList();
setState(() => _items.addAll(list));
Expand All @@ -33,16 +33,12 @@ class _TransactionsPageState extends State<TransactionsPage> {
return ListView.separated(
controller: _controller,
itemCount: _items.length,
separatorBuilder: (ctx, index) {
return SizedBox(
height: 10.0,
);
},
separatorBuilder: (ctx, index) => const SizedBox(height: 10.0),
itemBuilder: (ctx, index) {
var item = _items[index];
return Container(
margin: EdgeInsets.only(left: 10.0, right: 10.0),
padding: EdgeInsets.all(8.0),
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(4.0)),
child: Row(
Expand All @@ -52,30 +48,26 @@ class _TransactionsPageState extends State<TransactionsPage> {
color: item['color'],
size: 32.0,
),
SizedBox(
width: 8.0,
),
const SizedBox(width: 8.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'Payment n°:${index + 1}',
style: TextStyle(fontSize: 18.0),
),
SizedBox(
height: 2.0,
style: const TextStyle(fontSize: 18.0),
),
const SizedBox(height: 2.0),
Text.rich(TextSpan(children: [
TextSpan(
text: "\$${item['amount']}",
style: TextStyle(fontSize: 14.0, color: Colors.grey)),
TextSpan(
style: const TextStyle(fontSize: 14.0, color: Colors.grey)),
const TextSpan(
text: " • ",
style: TextStyle(fontSize: 14.0, color: Colors.grey)),
TextSpan(
text: "${item['status']}",
style: TextStyle(fontSize: 14.0, color: Colors.grey))
style: const TextStyle(fontSize: 14.0, color: Colors.grey))
]))
],
)
Expand All @@ -90,10 +82,10 @@ class _TransactionsPageState extends State<TransactionsPage> {
// TODO: implement initState
super.initState();

Future.delayed(Duration(seconds: 1), () {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'This application will be blocked after 10 seconds without user interaction ')));
Future.delayed(const Duration(milliseconds: 300), () {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('This application will be blocked after 3 '
'seconds without user interaction ')));
});

_controller.addListener(() {
Expand All @@ -110,13 +102,11 @@ class _TransactionsPageState extends State<TransactionsPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Transactions'),
title: const Text('Transactions'),
),
body: Column(
children: [
SizedBox(
height: 10,
),
const SizedBox(height: 10),
Expanded(child: _bodyList())
],
),
Expand Down
Loading

0 comments on commit 63ac915

Please sign in to comment.