Skip to content

Commit

Permalink
Document AppInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Kipruto <[email protected]>
  • Loading branch information
kelvinkipruto committed Jan 30, 2024
1 parent 800f5d9 commit ccf38f7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion example/integration_test/plugin_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void main() {

testWidgets('getPlatformVersion test', (WidgetTester tester) async {
final AppsList plugin = AppsList();
final List<AppInfoByProfile> apps = await plugin.getInstalledApps();
final List<AppInfo> apps = await plugin.getInstalledApps();
expect(apps, isNotNull);
});
}
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
final _appsListPlugin = AppsList();
List<AppInfoByProfile> _apps = [];
List<AppInfo> _apps = [];

@override
void initState() {
Expand All @@ -27,7 +27,7 @@ class _MyAppState extends State<MyApp> {
}

Future<void> initPlatformState() async {
List<AppInfoByProfile> apps = [];
List<AppInfo> apps = [];
try {
apps = await _appsListPlugin.getInstalledApps();
} on PlatformException {
Expand Down
60 changes: 24 additions & 36 deletions lib/app_info.dart
Original file line number Diff line number Diff line change
@@ -1,62 +1,50 @@
/// Dart package for handling app information.
import 'dart:typed_data';

// enum AppProfile {
// Work,
// Personal

// // from string
// }

/// Class representing information about an app.
class AppInfo {
/// The name of the app.
String name;

/// The icon of the app as a list of unsigned 8-bit integers.
Uint8List icon;

/// The package name of the app.
String packageName;

/// A boolean value indicating whether the app is a system app.
bool isSystemApp;

AppInfo(this.name, this.icon, this.packageName, this.isSystemApp);
/// The profile associated with the app.
String profile;

/// The serial number of the app.
int serialNumber;

/// Constructor for the AppInfo class.
AppInfo(this.name, this.icon, this.packageName, this.isSystemApp,
this.profile, this.serialNumber);

/// Factory constructor for creating an instance of AppInfo from dynamic data.
factory AppInfo.create(dynamic data) {
return AppInfo(
data["name"],
data["icon"],
data["package_name"],
data["is_system_app"],
data["profile"],
data["serial_number"],
);
}

/// Method for comparing this AppInfo instance with another based on name.
int compareTo(AppInfo other) {
return name.compareTo(other.name);
}

/// Method for converting this AppInfo instance to a string.
@override
String toString() {
return "AppInfo{name=$name, packageName=$packageName, isSystemApp=$isSystemApp";
}
}

class AppInfoByProfile extends AppInfo {
// profile can only be personal or work
String profile;
int serialNumber;

AppInfoByProfile(String name, Uint8List icon, String packageName,
bool isSystemApp, this.profile, this.serialNumber)
: super(name, icon, packageName, isSystemApp);

factory AppInfoByProfile.create(dynamic data) {
// AppProfile profile = AppProfile.values[data["profile"]];
return AppInfoByProfile(
data["name"],
data["icon"],
data["package_name"],
data["is_system_app"],
data["profile"],
data["serial_number"],
);
}

@override
String toString() {
return "AppInfoByProfile{name=$name, packageName=$packageName, isSystemApp=$isSystemApp, profile=$profile";
return "AppInfo{name=$name, packageName=$packageName, isSystemApp=$isSystemApp, profile=$profile, serialNumber=$serialNumber";
}
}
2 changes: 1 addition & 1 deletion lib/apps_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppsList {
return AppsListPlatform.instance.launchApp(packageName, serialNumber);
}

Future<List<AppInfoByProfile>> getInstalledApps() async {
Future<List<AppInfo>> getInstalledApps() async {
return AppsListPlatform.instance.getInstalledApps();
}
}
6 changes: 3 additions & 3 deletions lib/apps_list_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class MethodChannelAppsList extends AppsListPlatform {

// get installed apps
@override
Future<List<AppInfoByProfile>> getInstalledApps() async {
Future<List<AppInfo>> getInstalledApps() async {
try {
List<Object?> apps = await methodChannel.invokeMethod('getInstalledApps');
List<AppInfoByProfile> appInfoList =
apps.map((app) => AppInfoByProfile.create(app)).toList();
List<AppInfo> appInfoList =
apps.map((app) => AppInfo.create(app)).toList();
return Future.value(appInfoList);
} on PlatformException {
debugPrint("APPS ERROR");
Expand Down
2 changes: 1 addition & 1 deletion lib/apps_list_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AppsListPlatform extends PlatformInterface {
throw UnimplementedError('launchApp() has not been implemented.');
}

Future<List<AppInfoByProfile>> getInstalledApps() async {
Future<List<AppInfo>> getInstalledApps() async {
throw UnimplementedError(
'getInstalledAppsByProfile() has not been implemented.');
}
Expand Down
4 changes: 2 additions & 2 deletions test/apps_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MockAppsListPlatform
Future<String?> getPlatformVersion() => Future.value('42');

@override
Future<List<AppInfoByProfile>> getInstalledApps() {
Future<List<AppInfo>> getInstalledApps() {
return Future.value([]);
}

Expand All @@ -33,7 +33,7 @@ void main() {
MockAppsListPlatform fakePlatform = MockAppsListPlatform();
AppsListPlatform.instance = fakePlatform;

List<AppInfoByProfile> apps = await appsListPlugin.getInstalledApps();
List<AppInfo> apps = await appsListPlugin.getInstalledApps();
expect(apps, isNotNull);
});
}

0 comments on commit ccf38f7

Please sign in to comment.