Added share option, saveApp -> saveApps

This commit is contained in:
Imran Remtulla
2022-09-25 01:41:50 -04:00
parent 9a4b0301be
commit 428c208de4
8 changed files with 98 additions and 26 deletions

View File

@@ -109,7 +109,8 @@ class MyApp extends StatelessWidget {
if (isFirstRun) {
// If this is the first run, ask for notification permissions and add Obtainium to the Apps list
Permission.notification.request();
appsProvider.saveApp(App(
appsProvider.saveApps([
App(
'imranr98_obtainium_${GitHub().host}',
'https://github.com/ImranR98/Obtainium',
'ImranR98',
@@ -118,7 +119,8 @@ class MyApp extends StatelessWidget {
currentReleaseTag,
[],
0,
['true']));
['true'])
]);
}
}

View File

@@ -113,7 +113,8 @@ class _AddAppPageState extends State<AddAppPage> {
settingsProvider
.getInstallPermission()
.then((_) {
appsProvider.saveApp(app).then((_) {
appsProvider
.saveApps([app]).then((_) {
Navigator.push(
context,
MaterialPageRoute(

View File

@@ -126,8 +126,8 @@ class _AppPageState extends State<AppPage> {
.installedVersion =
updatedApp
.latestVersion;
appsProvider.saveApp(
updatedApp);
appsProvider.saveApps(
[updatedApp]);
}
Navigator.of(context)
.pop();
@@ -167,8 +167,8 @@ class _AppPageState extends State<AppPage> {
updatedApp
.installedVersion =
null;
appsProvider.saveApp(
updatedApp);
appsProvider.saveApps(
[updatedApp]);
}
Navigator.of(context)
.pop();
@@ -202,7 +202,7 @@ class _AppPageState extends State<AppPage> {
if (app != null && values != null) {
var changedApp = app.app;
changedApp.additionalData = values;
appsProvider.saveApp(changedApp);
appsProvider.saveApps([changedApp]);
}
});
},

View File

@@ -7,6 +7,7 @@ import 'package:obtainium/pages/app.dart';
import 'package:obtainium/providers/apps_provider.dart';
import 'package:obtainium/providers/settings_provider.dart';
import 'package:provider/provider.dart';
import 'package:share_plus/share_plus.dart';
class AppsPage extends StatefulWidget {
const AppsPage({super.key});
@@ -194,6 +195,7 @@ class AppsPageState extends State<AppsPage> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
visualDensity: VisualDensity.compact,
onPressed: () {
showDialog<List<String>?>(
context: context,
@@ -215,6 +217,7 @@ class AppsPageState extends State<AppsPage> {
icon: const Icon(Icons.delete_outline_outlined),
),
IconButton(
visualDensity: VisualDensity.compact,
onPressed: appsProvider.areDownloadsRunning() ||
selectedIds
.where((id) =>
@@ -301,6 +304,19 @@ class AppsPageState extends State<AppsPage> {
icon: const Icon(
Icons.file_download_outlined,
)),
IconButton(
visualDensity: VisualDensity.compact,
onPressed: () {
String urls = '';
for (var id in selectedIds) {
urls += '${appsProvider.apps[id]!.app.url}\n';
}
urls = urls.substring(0, urls.length - 1);
Share.share(urls,
subject: 'Selected App URLs from Obtainium');
},
icon: const Icon(Icons.share),
),
],
)),
const VerticalDivider(),

View File

@@ -47,7 +47,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
if (appsProvider.apps.containsKey(app.id)) {
errorsMap.addAll({app.id: 'App already added'});
} else {
await appsProvider.saveApp(app);
await appsProvider.saveApps([app]);
}
}
List<List<String>> errors =

View File

@@ -124,7 +124,7 @@ class AppsProvider with ChangeNotifier {
await AppInstaller.installApk(file.file.path, actionRequired: false);
apps[file.appId]!.app.installedVersion =
apps[file.appId]!.app.latestVersion;
await saveApp(apps[file.appId]!.app);
await saveApps([apps[file.appId]!.app]);
}
// Given a list of AppIds, uses stored info about the apps to download APKs and install them
@@ -171,7 +171,7 @@ class AppsProvider with ChangeNotifier {
int urlInd = apps[id]!.app.apkUrls.indexOf(apkUrl);
if (urlInd != apps[id]!.app.preferredApkIndex) {
apps[id]!.app.preferredApkIndex = urlInd;
await saveApp(apps[id]!.app);
await saveApps([apps[id]!.app]);
}
if (context != null ||
(await canInstallSilently(apps[id]!.app) &&
@@ -247,11 +247,14 @@ class AppsProvider with ChangeNotifier {
notifyListeners();
}
Future<void> saveApp(App app) async {
Future<void> saveApps(List<App> apps) async {
for (var app in apps) {
File('${(await getAppsDir()).path}/${app.id}.json')
.writeAsStringSync(jsonEncode(app.toJson()));
apps.update(app.id, (value) => AppInMemory(app, value.downloadProgress),
this.apps.update(
app.id, (value) => AppInMemory(app, value.downloadProgress),
ifAbsent: () => AppInMemory(app, null));
}
notifyListeners();
}
@@ -289,7 +292,7 @@ class AppsProvider with ChangeNotifier {
if (currentApp.preferredApkIndex < newApp.apkUrls.length) {
newApp.preferredApkIndex = currentApp.preferredApkIndex;
}
await saveApp(newApp);
await saveApps([newApp]);
return newApp;
}
return null;
@@ -353,7 +356,7 @@ class AppsProvider with ChangeNotifier {
for (App a in importedApps) {
a.installedVersion =
apps.containsKey(a.id) ? apps[a]?.app.installedVersion : null;
await saveApp(a);
await saveApps([a]);
}
notifyListeners();
return importedApps.length;

View File

@@ -324,6 +324,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
mime:
dependency: transitive
description:
name: mime
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
nested:
dependency: transitive
description:
@@ -457,6 +464,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.3"
share_plus:
dependency: "direct main"
description:
name: share_plus
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0"
share_plus_linux:
dependency: transitive
description:
name: share_plus_linux
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
share_plus_macos:
dependency: transitive
description:
name: share_plus_macos
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.3"
share_plus_web:
dependency: transitive
description:
name: share_plus_web
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
share_plus_windows:
dependency: transitive
description:
name: share_plus_windows
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
shared_preferences:
dependency: "direct main"
description:

View File

@@ -53,6 +53,7 @@ dependencies:
file_picker: ^5.1.0
animations: ^2.0.4
flutter_install_app: ^1.3.0
share_plus: ^4.4.0
dev_dependencies: