Skip to content

Commit

Permalink
Merge pull request #27 from Bablo-AD/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
prasannan-robots authored Nov 26, 2023
2 parents 4968f58 + f530208 commit 49903a2
Show file tree
Hide file tree
Showing 15 changed files with 598 additions and 221 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand Down
3 changes: 3 additions & 0 deletions lib/core/data.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'loader.dart';
import 'package:device_apps/device_apps.dart';

class Data {
Loader load = Loader();
static String? userId = FirebaseAuth.instance.currentUser?.uid;
static List<Application> apps = [];
static List<Application> selected_apps = [];
static String response = "";
static String interest = "";
static List<Messages> messages_data = [];
Expand Down
34 changes: 33 additions & 1 deletion lib/core/loader.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:convert';

import 'package:device_apps/device_apps.dart';
import 'data.dart';

class SessionManager {
Expand All @@ -21,6 +21,38 @@ class SessionManager {
class Loader {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();

static Future<List<Application>> loadApps() async {
List<Application> loaded_apps = await DeviceApps.getInstalledApplications(
includeSystemApps: true,
onlyAppsWithLaunchIntent: true,
);
List<Application> sortedApps = List<Application>.from(loaded_apps);
sortedApps.sort((a, b) => a.appName.compareTo(b.appName));
Data.apps = sortedApps;
return sortedApps;
}

Future<List<Application>> loadSelectedApps() async {
await Loader.loadApps();
final SharedPreferences prefs = await _prefs;
List<String>? selectedAppNames =
await prefs.getStringList('selectedApps') ?? [];

List<Application> selectedApps = Data.apps
.where((app) => selectedAppNames.contains(app.appName))
.toList();

Data.selected_apps = selectedApps;
return selectedApps;
}

Future<void> saveSelectedApps() async {
final SharedPreferences prefs = await _prefs;
List<String> selectedAppNames =
Data.selected_apps.map((app) => app.appName).toList();
await prefs.setStringList('selectedApps', selectedAppNames);
}

void saveScheduleTime(String selectedTime) async {
SharedPreferences prefs = await SharedPreferences.getInstance();

Expand Down
85 changes: 85 additions & 0 deletions lib/home/apps_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import '../core/loader.dart';
import '../core/data.dart';

class AppsPage extends StatefulWidget {
const AppsPage({super.key});

@override
State<AppsPage> createState() => _AppsPageState();
}

class _AppsPageState extends State<AppsPage> {
List<Application> filteredApps = Data.apps;
@override
void initState() {
super.initState();
Loader.loadApps();
}

void _filterApps(String query) {
setState(() {
filteredApps = Data.apps
.where(
(app) => app.appName.toLowerCase().contains(query.toLowerCase()))
.toList();
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Mentor/Apps',
),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
onChanged: _filterApps, // Call _filterApps when the text changes
decoration: InputDecoration(
labelText: 'Search',
prefixIcon: Icon(
Icons.search,
),
filled: true,
),
),
),
Expanded(
child: ListView.builder(
itemCount: filteredApps.length,
itemBuilder: (context, index) {
final Application app = filteredApps[index];
return Column(
children: [
ListTile(
onTap: () async {
bool isInstalled =
await DeviceApps.isAppInstalled(app.packageName);
if (isInstalled) {
DeviceApps.openApp(app.packageName);
}
},
title: Text(
app.appName,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 5),
],
);
},
),
),
],
),
);
}
}
52 changes: 51 additions & 1 deletion lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import '../core/loader.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:intl/intl.dart';
import 'package:usage_stats/usage_stats.dart';
import 'package:device_apps/device_apps.dart';
import 'apps_page.dart';
import '../settings/apps_selection_page.dart';

class MentorPage extends StatefulWidget {
const MentorPage({super.key});
Expand All @@ -26,6 +29,11 @@ class _MentorPageState extends State<MentorPage> {
List<Messages> messages_data = [];
List<Video> videos = [];
Loader loader = Loader();
List<Application> selected_apps_data = Data.selected_apps;
String serverurl = '';

List<Application> loadedApps = [];

//Gets user's usage data
void _Makerequest(String interest) async {
setState(() {
Expand Down Expand Up @@ -53,7 +61,9 @@ class _MentorPageState extends State<MentorPage> {
@override
void initState() {
super.initState();

loader.loadSelectedApps().then((value) {
selected_apps_data = Data.selected_apps;
});
check_permissions();

loader.loadcompletion().then((completionMessage) {
Expand Down Expand Up @@ -83,6 +93,46 @@ class _MentorPageState extends State<MentorPage> {
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Card(
child: ListTile(
onLongPress: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AppSelectionPage()),
);
},
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AppsPage()),
);
},
title: const Text("Apps"),
subtitle: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: selected_apps_data.length,
itemBuilder: (context, index) {
final Application app = selected_apps_data[index];
return ListTile(
onTap: () async {
bool isInstalled = await DeviceApps.isAppInstalled(
app.packageName);
if (isInstalled) {
DeviceApps.openApp(app.packageName);
}
},
title: Text(
app.appName,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
);
}),
)),
const SizedBox(height: 16.0),
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('users')
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'journal/journal_page.dart';
import 'firebase_options.dart';
import 'setup/authentication_page.dart';
import 'settings/habitica_integration_page.dart';

import 'settings/apps_selection_page.dart';
import 'core/loader.dart';
import 'color_schemes.g.dart';

Expand Down Expand Up @@ -40,6 +40,8 @@ class MyApp extends StatelessWidget {
'/mentor': (context) => const MentorPage(),

//Settings Subroute

'/appsSelection': (context) => const AppSelectionPage(),
'/habiticaIntegrationPage': (context) =>
const HabiticaIntegrationPage(),
'/knowingthestudent': (context) => const Knowingthestudent()
Expand Down
75 changes: 75 additions & 0 deletions lib/settings/apps_selection_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import '../core/data.dart';
import '../core/loader.dart';

class AppSelectionPage extends StatefulWidget {
const AppSelectionPage({super.key});

@override
_AppSelectionPageState createState() => _AppSelectionPageState();
}

class _AppSelectionPageState extends State<AppSelectionPage> {
Loader _loader = Loader();

@override
void initState() {
super.initState();
_loader.loadSelectedApps();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Mentor/Apps/Selection',
),
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: Data.apps.length,
itemBuilder: (context, index) {
final Application app = Data.apps[index];
return Column(
children: [
CheckboxListTile(
activeColor: const Color.fromARGB(255, 50, 204, 102),
checkColor: const Color.fromARGB(255, 19, 19, 19),
tileColor: const Color.fromARGB(255, 19, 19, 19),
title: Text(
app.appName,
),
value: Data.selected_apps.contains(app),
onChanged: (bool? value) {
setState(() {
if (value != null && value) {
Data.selected_apps.add(app);
} else {
Data.selected_apps.remove(app);
}
});
},
),
const SizedBox(height: 10),
],
);
},
),
),
],
),
floatingActionButton: FloatingActionButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: const Icon(Icons.check),
onPressed: () async {
await _loader.saveSelectedApps();
Navigator.of(context).pop();
},
),
);
}
}
Loading

0 comments on commit 49903a2

Please sign in to comment.