forked from EaniaHuui/android_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
287 additions
and
311 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:android_tool/page/common/app.dart'; | ||
import 'package:android_tool/page/common/base_view_model.dart'; | ||
import 'package:android_tool/widget/list_filter_dialog.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:process_run/shell.dart'; | ||
|
||
mixin PackageHelpMixin implements BaseViewModel { | ||
String packageName = ""; | ||
|
||
ListFilterController<ListFilterItem> packageNameController = | ||
ListFilterController(); | ||
|
||
List<ListFilterItem> packageNameList = []; | ||
|
||
/// 选择调试应用 | ||
Future<String> showPackageSelect(BuildContext context, String deviceId) async { | ||
if (packageNameList.isEmpty) { | ||
return ""; | ||
} | ||
var value = await packageNameController.show( | ||
context, | ||
packageNameList, | ||
ListFilterItem(packageName), | ||
refreshCallback: () { | ||
getInstalledApp(deviceId); | ||
}, | ||
); | ||
if (value != null) { | ||
return value.itemTitle; | ||
} | ||
return ""; | ||
} | ||
|
||
/// 获取已安装的应用 | ||
Future<void> getInstalledApp(String deviceId) async { | ||
var installedApp = await execAdb( | ||
['-s', deviceId, 'shell', 'pm', 'list', 'packages', '-3']); | ||
if (installedApp == null) { | ||
resetPackage(); | ||
return; | ||
} | ||
var outLines = installedApp.outLines; | ||
packageNameList = outLines.map((e) { | ||
return ListFilterItem(e.replaceAll("package:", "")); | ||
}).toList(); | ||
packageNameList.sort((a, b) => a.itemTitle.compareTo(b.itemTitle)); | ||
packageNameController.setData(packageNameList); | ||
if (packageNameList.isNotEmpty) { | ||
var package = await App().getPackageName(); | ||
if (package.isNotEmpty) { | ||
packageName = packageNameList | ||
.firstWhere((element) => element.itemTitle == package, | ||
orElse: () => packageNameList.first) | ||
.itemTitle; | ||
} else { | ||
packageName = packageNameList.first.itemTitle; | ||
} | ||
} | ||
} | ||
|
||
void resetPackage() { | ||
packageName = ""; | ||
packageNameList.clear(); | ||
notifyListeners(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.