Skip to content

Commit

Permalink
fix(#17) : implemented appIcons
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyHers committed Jun 22, 2023
1 parent 3db2bbc commit 1471378
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 61 deletions.
4 changes: 3 additions & 1 deletion lib/app/helpers/parsing_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ Duration calculateAverage(List<Duration> durations) {
double calculatePercentage(Duration duration) {
var value = duration.toString().replaceAll('.000000', '');
var parts = value.split(':');
var days = int.parse(parts[0]);
var hours = int.parse(parts[1]);
var minutes = int.parse(parts[2]);
var parsedDuration = Duration(
days: days,
hours: hours,
minutes: minutes,
);

final totalDuration = Duration(hours: 2);
final totalDuration = Duration(days: 30, hours: 2);
final milliseconds = parsedDuration.inMilliseconds;
final totalMilliseconds = totalDuration.inMilliseconds;

Expand Down
17 changes: 7 additions & 10 deletions lib/app/landing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,18 @@ class _LandingPageState extends State<LandingPage> {
);
}

Provider<AuthBase> _buildChildSide(
Provider<Database> _buildChildSide(
AuthBase auth,
User user,
GeoLocatorService geoService,
BuildContext context,
) {
return Provider<AuthBase>(
create: (_) => Auth(),
child: Provider<Database>(
create: (_) => FireStoreDatabase(auth: auth, uid: user.uid),
child: FutureProvider(
initialData: geoService.getCurrentLocation,
create: (context) => geoService.getInitialLocation(),
child: SetChildPage.create(context),
),
return Provider<Database>(
create: (_) => FireStoreDatabase(auth: auth, uid: user.uid),
child: FutureProvider(
initialData: geoService.getCurrentLocation,
create: (context) => geoService.getInitialLocation(),
child: SetChildPage.create(context),
),
);
}
Expand Down
25 changes: 25 additions & 0 deletions lib/app/lifecycle/life_cycle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:parental_control/common_widgets/show_logger.dart';

class JHAppLifeCycleObserver extends WidgetsBindingObserver {
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);

switch (state) {
case AppLifecycleState.resumed:
JHLogger.$.d(state.name);
break;
case AppLifecycleState.inactive:
JHLogger.$.d(state.name);
break;
case AppLifecycleState.paused:
JHLogger.$.d(state.name);
break;
case AppLifecycleState.detached:
JHLogger.$.d(state.name);
// App is detached from the view hierarchy
break;
}
}
}
9 changes: 7 additions & 2 deletions lib/app/pages/child_details_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:line_awesome_flutter/line_awesome_flutter.dart';
import 'package:parental_control/app/helpers/parsing_extension.dart';
import 'package:parental_control/common_widgets/jh_bar_chart.dart';
import 'package:parental_control/common_widgets/jh_custom_button.dart';
Expand Down Expand Up @@ -360,7 +359,13 @@ class _AppUsedList extends StatelessWidget {
mainAxisSize: MainAxisSize.max,
children: [
ListTile(
leading: Icon(LineAwesomeIcons.android),
leading:
model.appsUsageModel[index].appIcon != null
? Image.memory(
model.appsUsageModel[index].appIcon!,
height: 35,
)
: Icon(Icons.android),
title: Text(
'${model.appsUsageModel[index].appName}',
style: TextStyle(
Expand Down
9 changes: 5 additions & 4 deletions lib/app/pages/child_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChildPage extends StatefulWidget {
_ChildPageState createState() => _ChildPageState();
}

class _ChildPageState extends State<ChildPage> {
class _ChildPageState extends State<ChildPage> with WidgetsBindingObserver {
void sendLocalToBloCNotification(BuildContext context) {
var childSideBloc = context.read<ChildSideBloc>();
childSideBloc.add(GetNotifications());
Expand All @@ -51,11 +51,11 @@ class _ChildPageState extends State<ChildPage> {
}

@override
void initState() {
Timer.periodic(const Duration(seconds: 15), (timer) {
void didChangeAppLifecycleState(AppLifecycleState state) {
Timer.periodic(const Duration(minutes: 5), (timer) {
widget.database?.liveUpdateChild(widget.child!, timer.tick);
});
super.initState();
super.didChangeAppLifecycleState(state);
}

@override
Expand Down Expand Up @@ -267,6 +267,7 @@ class _ChildPageState extends State<ChildPage> {
itemCount: appUsage.info.length,
itemBuilder: (context, index) {
return ListTile(
leading: Image.memory(appUsage.info[index].appIcon),
title: JHDisplayText(
text: appUsage.info[index].appName,
style: TextStyle(fontSize: 15),
Expand Down
27 changes: 18 additions & 9 deletions lib/app/pages/parent_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:parental_control/app/pages/setting_page.dart';
import 'package:parental_control/common_widgets/child_horizontal_view.dart';
import 'package:parental_control/common_widgets/jh_display_text.dart';
import 'package:parental_control/common_widgets/jh_empty_content.dart';
import 'package:parental_control/common_widgets/jh_feature_widget.dart';
import 'package:parental_control/common_widgets/jh_header.dart';
import 'package:parental_control/common_widgets/jh_header_widget.dart';
import 'package:parental_control/common_widgets/jh_info_row_widget.dart';
Expand Down Expand Up @@ -232,14 +231,24 @@ class _ParentPageState extends State<ParentPage>
text_1: MockData.text_3,
text_2: MockData.text_4,
).p4,
JHFeatureWidget(
child: Png.google,
icon: Icons.timelapse_sharp,
),
JHFeatureWidget(
child: Png.facebook,
icon: Icons.timelapse_sharp,
),
// SizedBox(
// height: double.maxFinite,
// child: ListView.builder(
// physics: BouncingScrollPhysics(),
// scrollDirection: Axis.vertical,
// itemCount: data![1]?.appsUsageModel.length,
// itemBuilder: (context, index) {
// return JHFeatureWidget(
// title:
// data[1]?.appsUsageModel[index].packageName,
// child: Image.memory(
// (data[1]?.appsUsageModel[index].appIcon)!,
// height: 30,
// ).p4,
// );
// },
// ),
// ),
],
),
),
Expand Down
51 changes: 27 additions & 24 deletions lib/common_widgets/jh_feature_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JHFeatureWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.07,
height: 80,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(5)),
Expand All @@ -29,29 +29,32 @@ class JHFeatureWidget extends StatelessWidget {
),
padding: EdgeInsets.all(15.0),
margin: EdgeInsets.symmetric(horizontal: 15.0, vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: 10),
if (child != null) child ?? SizedBox.shrink(),
title != null
? JHDisplayText(
text: title!,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w800,
color: CustomColors.indigoLight,
),
)
: SizedBox.shrink(),
Spacer(),
if (icon != null)
Icon(
icon,
size: 22,
),
SizedBox.shrink(),
],
child: SizedBox(
width: 200,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(width: 10),
if (child != null) child ?? SizedBox.shrink(),
title != null
? JHDisplayText(
text: title!,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w800,
color: CustomColors.indigoLight,
),
)
: SizedBox.shrink(),
Spacer(),
if (icon != null)
Icon(
icon,
size: 22,
),
SizedBox.shrink(),
],
),
),
);
}
Expand Down
28 changes: 21 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:parental_control/app/config/screencontroller_config.dart';
import 'package:parental_control/app/lifecycle/life_cycle.dart';
import 'package:parental_control/services/app_usage_service.dart';
import 'package:parental_control/services/auth.dart';
import 'package:parental_control/services/geo_locator_service.dart';
Expand All @@ -18,7 +19,9 @@ void main() {
providers: [
Provider<AuthBase>(create: (context) => Auth()),
Provider<AppUsageService>(create: (context) => AppUsageService()),
Provider<GeoLocatorService>(create: (context) => GeoLocatorService()),
Provider<GeoLocatorService>(
create: (context) => GeoLocatorService()..getInitialLocation(),
),
Provider<NotificationService>(
create: (context) => NotificationService(),
),
Expand All @@ -33,19 +36,30 @@ class TimesUpApp extends StatefulWidget {
State<TimesUpApp> createState() => _TimesUpAppState();
}

class _TimesUpAppState extends State<TimesUpApp> {
class _TimesUpAppState extends State<TimesUpApp> with WidgetsBindingObserver {
late JHAppLifeCycleObserver appLifeCycleObserver;

@override
void initState() {
super.initState();
appLifeCycleObserver = JHAppLifeCycleObserver();
WidgetsBinding.instance.addObserver(appLifeCycleObserver);
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(appLifeCycleObserver);
super.dispose();
}

@override
Widget build(BuildContext context) {
final geoService = Provider.of<GeoLocatorService>(context, listen: false);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: Strings.appName,
theme: AppTheme.lightTheme,
darkTheme: AppTheme.darkTheme,
home: FutureBuilder(
future: geoService.getInitialLocation(),
builder: (context, _) => ScreensController(),
),
home: ScreensController(),
);
}
}
4 changes: 3 additions & 1 deletion lib/services/app_usage_local_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io' show Platform;

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/services.dart';
import 'package:installed_apps/installed_apps.dart';
import 'package:parental_control/app/helpers/parsing_extension.dart';
Expand Down Expand Up @@ -68,7 +69,8 @@ class AppUsageInfo {
@override
String toString() {
return 'App Usage: $packageName - $appName, '
'duration: $usage [${startDate}, $endDate]';
'duration: $usage [${Timestamp.fromDate(startDate)},'
' ${Timestamp.fromDate(endDate)}]';
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/services/app_usage_service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/cupertino.dart';
import 'package:installed_apps/app_info.dart';
import 'package:parental_control/app/helpers/parsing_extension.dart';
import 'package:parental_control/common_widgets/show_logger.dart';
import 'package:parental_control/models/child_model/child_model.dart';
Expand All @@ -13,9 +14,11 @@ abstract class AppService {

class AppUsageService implements AppService {
List<AppUsageInfo> _info = <AppUsageInfo>[];
List<AppInfo> _appInfo = <AppInfo>[];
Duration _averageDuration = Duration(minutes: 1);

List<AppUsageInfo> get info => _info;
List<AppInfo> get appInfo => _appInfo;
Duration get averageDuration => _averageDuration;

@override
Expand Down
7 changes: 4 additions & 3 deletions lib/services/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ class FireStoreDatabase implements Database {
@override
Future<void> liveUpdateChild(ChildModel model, value) async {
await apps.getAppUsageService();
var point = await geo.getInitialLocation();
var currentLocation = GeoPoint(point.latitude, point.longitude);
//TODO: UNCOMMENT THIS TO UPDATE LOCATION
//var point = await geo.getInitialLocation();
//var currentLocation = GeoPoint(point.latitude, point.longitude);

_child = ChildModel(
id: model.id,
name: model.name,
email: model.email,
token: model.token,
position: currentLocation,
position: model.position,
appsUsageModel: apps.info,
image: model.image,
);
Expand Down
3 changes: 3 additions & 0 deletions lib/services/device_info_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
abstract class DeviceInfoServiceInterface {}

class DeviceInfoService implements DeviceInfoServiceInterface {}
Loading

0 comments on commit 1471378

Please sign in to comment.