mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-07-29 20:20:14 +02:00
Added App pinning
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import 'package:html/parser.dart';
|
import 'package:html/parser.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:obtainium/components/generated_form.dart';
|
|
||||||
import 'package:obtainium/custom_errors.dart';
|
import 'package:obtainium/custom_errors.dart';
|
||||||
import 'package:obtainium/providers/source_provider.dart';
|
import 'package:obtainium/providers/source_provider.dart';
|
||||||
|
|
||||||
|
@@ -143,7 +143,8 @@ class _ObtainiumState extends State<Obtainium> {
|
|||||||
[],
|
[],
|
||||||
0,
|
0,
|
||||||
['true'],
|
['true'],
|
||||||
null)
|
null,
|
||||||
|
false)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// Register the background update task according to the user's setting
|
// Register the background update task according to the user's setting
|
||||||
|
@@ -23,24 +23,24 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
AppsFilter? filter;
|
AppsFilter? filter;
|
||||||
var updatesOnlyFilter =
|
var updatesOnlyFilter =
|
||||||
AppsFilter(includeUptodate: false, includeNonInstalled: false);
|
AppsFilter(includeUptodate: false, includeNonInstalled: false);
|
||||||
Set<String> selectedIds = {};
|
Set<App> selectedApps = {};
|
||||||
DateTime? refreshingSince;
|
DateTime? refreshingSince;
|
||||||
|
|
||||||
clearSelected() {
|
clearSelected() {
|
||||||
if (selectedIds.isNotEmpty) {
|
if (selectedApps.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedIds.clear();
|
selectedApps.clear();
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectThese(List<String> appIds) {
|
selectThese(List<App> apps) {
|
||||||
if (selectedIds.isEmpty) {
|
if (selectedApps.isEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
for (var a in appIds) {
|
for (var a in apps) {
|
||||||
selectedIds.add(a);
|
selectedApps.add(a);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -54,16 +54,16 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
var currentFilterIsUpdatesOnly =
|
var currentFilterIsUpdatesOnly =
|
||||||
filter?.isIdenticalTo(updatesOnlyFilter) ?? false;
|
filter?.isIdenticalTo(updatesOnlyFilter) ?? false;
|
||||||
|
|
||||||
selectedIds = selectedIds
|
selectedApps = selectedApps
|
||||||
.where((element) => sortedApps.map((e) => e.app.id).contains(element))
|
.where((element) => sortedApps.map((e) => e.app).contains(element))
|
||||||
.toSet();
|
.toSet();
|
||||||
|
|
||||||
toggleAppSelected(String appId) {
|
toggleAppSelected(App app) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (selectedIds.contains(appId)) {
|
if (selectedApps.contains(app)) {
|
||||||
selectedIds.remove(appId);
|
selectedApps.remove(app);
|
||||||
} else {
|
} else {
|
||||||
selectedIds.add(appId);
|
selectedApps.add(app);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -124,15 +124,15 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
var existingUpdates = appsProvider.findExistingUpdates(installedOnly: true);
|
var existingUpdates = appsProvider.findExistingUpdates(installedOnly: true);
|
||||||
|
|
||||||
var existingUpdateIdsAllOrSelected = existingUpdates
|
var existingUpdateIdsAllOrSelected = existingUpdates
|
||||||
.where((element) => selectedIds.isEmpty
|
.where((element) => selectedApps.isEmpty
|
||||||
? sortedApps.where((a) => a.app.id == element).isNotEmpty
|
? sortedApps.where((a) => a.app.id == element).isNotEmpty
|
||||||
: selectedIds.contains(element))
|
: selectedApps.map((e) => e.id).contains(element))
|
||||||
.toList();
|
.toList();
|
||||||
var newInstallIdsAllOrSelected = appsProvider
|
var newInstallIdsAllOrSelected = appsProvider
|
||||||
.findExistingUpdates(nonInstalledOnly: true)
|
.findExistingUpdates(nonInstalledOnly: true)
|
||||||
.where((element) => selectedIds.isEmpty
|
.where((element) => selectedApps.isEmpty
|
||||||
? sortedApps.where((a) => a.app.id == element).isNotEmpty
|
? sortedApps.where((a) => a.app.id == element).isNotEmpty
|
||||||
: selectedIds.contains(element))
|
: selectedApps.map((e) => e.id).contains(element))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (settingsProvider.pinUpdates) {
|
if (settingsProvider.pinUpdates) {
|
||||||
@@ -147,6 +147,17 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
sortedApps = [...temp, ...sortedApps];
|
sortedApps = [...temp, ...sortedApps];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tempPinned = [];
|
||||||
|
var tempNotPinned = [];
|
||||||
|
for (var a in sortedApps) {
|
||||||
|
if (a.app.pinned) {
|
||||||
|
tempPinned.add(a);
|
||||||
|
} else {
|
||||||
|
tempNotPinned.add(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortedApps = [...tempPinned, ...tempNotPinned];
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
@@ -192,11 +203,16 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
delegate: SliverChildBuilderDelegate(
|
delegate: SliverChildBuilderDelegate(
|
||||||
(BuildContext context, int index) {
|
(BuildContext context, int index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
selectedTileColor:
|
tileColor: sortedApps[index].app.pinned
|
||||||
Theme.of(context).colorScheme.primary.withOpacity(0.1),
|
? Colors.grey.withOpacity(0.1)
|
||||||
selected: selectedIds.contains(sortedApps[index].app.id),
|
: Colors.transparent,
|
||||||
|
selectedTileColor: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary
|
||||||
|
.withOpacity(sortedApps[index].app.pinned ? 0.2 : 0.1),
|
||||||
|
selected: selectedApps.contains(sortedApps[index].app),
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
toggleAppSelected(sortedApps[index].app.id);
|
toggleAppSelected(sortedApps[index].app);
|
||||||
},
|
},
|
||||||
leading: sortedApps[index].installedInfo != null
|
leading: sortedApps[index].installedInfo != null
|
||||||
? Image.memory(
|
? Image.memory(
|
||||||
@@ -204,9 +220,19 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
gaplessPlayback: true,
|
gaplessPlayback: true,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
title: Text(sortedApps[index].installedInfo?.name ??
|
title: Text(
|
||||||
sortedApps[index].app.name),
|
sortedApps[index].installedInfo?.name ??
|
||||||
subtitle: Text('By ${sortedApps[index].app.author}'),
|
sortedApps[index].app.name,
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: sortedApps[index].app.pinned
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal),
|
||||||
|
),
|
||||||
|
subtitle: Text('By ${sortedApps[index].app.author}',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: sortedApps[index].app.pinned
|
||||||
|
? FontWeight.bold
|
||||||
|
: FontWeight.normal)),
|
||||||
trailing: sortedApps[index].downloadProgress != null
|
trailing: sortedApps[index].downloadProgress != null
|
||||||
? Text(
|
? Text(
|
||||||
'Downloading - ${sortedApps[index].downloadProgress?.toInt()}%')
|
'Downloading - ${sortedApps[index].downloadProgress?.toInt()}%')
|
||||||
@@ -256,8 +282,8 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
textAlign: TextAlign.end,
|
textAlign: TextAlign.end,
|
||||||
)))),
|
)))),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (selectedIds.isNotEmpty) {
|
if (selectedApps.isNotEmpty) {
|
||||||
toggleAppSelected(sortedApps[index].app.id);
|
toggleAppSelected(sortedApps[index].app);
|
||||||
} else {
|
} else {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
@@ -275,25 +301,25 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
selectedIds.isEmpty
|
selectedApps.isEmpty
|
||||||
? selectThese(sortedApps.map((e) => e.app.id).toList())
|
? selectThese(sortedApps.map((e) => e.app).toList())
|
||||||
: clearSelected();
|
: clearSelected();
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
selectedIds.isEmpty
|
selectedApps.isEmpty
|
||||||
? Icons.select_all_outlined
|
? Icons.select_all_outlined
|
||||||
: Icons.deselect_outlined,
|
: Icons.deselect_outlined,
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.primary,
|
||||||
),
|
),
|
||||||
tooltip: selectedIds.isEmpty
|
tooltip: selectedApps.isEmpty
|
||||||
? 'Select All'
|
? 'Select All'
|
||||||
: 'Deselect ${selectedIds.length.toString()}'),
|
: 'Deselect ${selectedApps.length.toString()}'),
|
||||||
const VerticalDivider(),
|
const VerticalDivider(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
selectedIds.isEmpty
|
selectedApps.isEmpty
|
||||||
? const SizedBox()
|
? const SizedBox()
|
||||||
: IconButton(
|
: IconButton(
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
@@ -307,11 +333,12 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
defaultValues: const [],
|
defaultValues: const [],
|
||||||
initValid: true,
|
initValid: true,
|
||||||
message:
|
message:
|
||||||
'${selectedIds.length} App${selectedIds.length == 1 ? '' : 's'} will be removed from Obtainium but remain installed. You still need to uninstall ${selectedIds.length == 1 ? 'it' : 'them'} manually.',
|
'${selectedApps.length} App${selectedApps.length == 1 ? '' : 's'} will be removed from Obtainium but remain installed. You still need to uninstall ${selectedApps.length == 1 ? 'it' : 'them'} manually.',
|
||||||
);
|
);
|
||||||
}).then((values) {
|
}).then((values) {
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
appsProvider.removeApps(selectedIds.toList());
|
appsProvider.removeApps(
|
||||||
|
selectedApps.map((e) => e.id).toList());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -347,7 +374,7 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
builder: (BuildContext ctx) {
|
builder: (BuildContext ctx) {
|
||||||
return GeneratedFormModal(
|
return GeneratedFormModal(
|
||||||
title:
|
title:
|
||||||
'Install${selectedIds.isEmpty ? ' ' : ' Selected '}Apps?',
|
'Install${selectedApps.isEmpty ? ' ' : ' Selected '}Apps?',
|
||||||
message:
|
message:
|
||||||
'${existingUpdateIdsAllOrSelected.length} update${existingUpdateIdsAllOrSelected.length == 1 ? '' : 's'} and ${newInstallIdsAllOrSelected.length} new install${newInstallIdsAllOrSelected.length == 1 ? '' : 's'}.',
|
'${existingUpdateIdsAllOrSelected.length} update${existingUpdateIdsAllOrSelected.length == 1 ? '' : 's'} and ${newInstallIdsAllOrSelected.length} new install${newInstallIdsAllOrSelected.length == 1 ? '' : 's'}.',
|
||||||
items: formInputs,
|
items: formInputs,
|
||||||
@@ -386,11 +413,11 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
tooltip:
|
tooltip:
|
||||||
'Install/Update${selectedIds.isEmpty ? ' ' : ' Selected '}Apps',
|
'Install/Update${selectedApps.isEmpty ? ' ' : ' Selected '}Apps',
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.file_download_outlined,
|
Icons.file_download_outlined,
|
||||||
)),
|
)),
|
||||||
selectedIds.isEmpty
|
selectedApps.isEmpty
|
||||||
? const SizedBox()
|
? const SizedBox()
|
||||||
: IconButton(
|
: IconButton(
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
@@ -419,7 +446,7 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
ctx) {
|
ctx) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: Text(
|
title: Text(
|
||||||
'Mark ${selectedIds.length} Selected Apps as Updated?'),
|
'Mark ${selectedApps.length} Selected Apps as Updated?'),
|
||||||
content:
|
content:
|
||||||
const Text(
|
const Text(
|
||||||
'Only applies to installed but out of date Apps.'),
|
'Only applies to installed but out of date Apps.'),
|
||||||
@@ -438,9 +465,7 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
HapticFeedback
|
HapticFeedback
|
||||||
.selectionClick();
|
.selectionClick();
|
||||||
appsProvider
|
appsProvider
|
||||||
.saveApps(selectedIds.map((e) {
|
.saveApps(selectedApps.map((a) {
|
||||||
var a =
|
|
||||||
appsProvider.apps[e]!.app;
|
|
||||||
if (a.installedVersion !=
|
if (a.installedVersion !=
|
||||||
null) {
|
null) {
|
||||||
a.installedVersion = a.latestVersion;
|
a.installedVersion = a.latestVersion;
|
||||||
@@ -455,23 +480,50 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
'Yes'))
|
'Yes'))
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
}).whenComplete(() {
|
||||||
|
Navigator.of(
|
||||||
|
context)
|
||||||
|
.pop();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tooltip:
|
tooltip:
|
||||||
'Mark Selected Apps as Updated',
|
'Mark Selected Apps as Updated',
|
||||||
icon: const Icon(Icons.done)),
|
icon: const Icon(Icons.done)),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
var pinStatus = selectedApps
|
||||||
|
.where((element) =>
|
||||||
|
element.pinned)
|
||||||
|
.isEmpty;
|
||||||
|
appsProvider.saveApps(
|
||||||
|
selectedApps.map((e) {
|
||||||
|
e.pinned = pinStatus;
|
||||||
|
return e;
|
||||||
|
}).toList());
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
tooltip:
|
||||||
|
'${selectedApps.where((element) => element.pinned).isEmpty ? 'Pin to' : 'Unpin from'} top',
|
||||||
|
icon: Icon(selectedApps
|
||||||
|
.where((element) =>
|
||||||
|
element.pinned)
|
||||||
|
.isEmpty
|
||||||
|
? Icons.bookmark_outline_rounded
|
||||||
|
: Icons
|
||||||
|
.bookmark_remove_outlined),
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
String urls = '';
|
String urls = '';
|
||||||
for (var id in selectedIds) {
|
for (var a in selectedApps) {
|
||||||
urls +=
|
urls += '${a.url}\n';
|
||||||
'${appsProvider.apps[id]!.app.url}\n';
|
|
||||||
}
|
}
|
||||||
urls = urls.substring(
|
urls = urls.substring(
|
||||||
0, urls.length - 1);
|
0, urls.length - 1);
|
||||||
Share.share(urls,
|
Share.share(urls,
|
||||||
subject:
|
subject:
|
||||||
'${selectedIds.length} Selected App URLs from Obtainium');
|
'${selectedApps.length} Selected App URLs from Obtainium');
|
||||||
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
tooltip: 'Share Selected App URLs',
|
tooltip: 'Share Selected App URLs',
|
||||||
icon: const Icon(Icons.share),
|
icon: const Icon(Icons.share),
|
||||||
|
@@ -490,7 +490,8 @@ class AppsProvider with ChangeNotifier {
|
|||||||
currentApp.url,
|
currentApp.url,
|
||||||
currentApp.additionalData,
|
currentApp.additionalData,
|
||||||
name: currentApp.name,
|
name: currentApp.name,
|
||||||
id: currentApp.id);
|
id: currentApp.id,
|
||||||
|
pinned: currentApp.pinned);
|
||||||
newApp.installedVersion = currentApp.installedVersion;
|
newApp.installedVersion = currentApp.installedVersion;
|
||||||
if (currentApp.preferredApkIndex < newApp.apkUrls.length) {
|
if (currentApp.preferredApkIndex < newApp.apkUrls.length) {
|
||||||
newApp.preferredApkIndex = currentApp.preferredApkIndex;
|
newApp.preferredApkIndex = currentApp.preferredApkIndex;
|
||||||
|
@@ -40,6 +40,7 @@ class App {
|
|||||||
late int preferredApkIndex;
|
late int preferredApkIndex;
|
||||||
late List<String> additionalData;
|
late List<String> additionalData;
|
||||||
late DateTime? lastUpdateCheck;
|
late DateTime? lastUpdateCheck;
|
||||||
|
bool pinned = false;
|
||||||
App(
|
App(
|
||||||
this.id,
|
this.id,
|
||||||
this.url,
|
this.url,
|
||||||
@@ -50,11 +51,12 @@ class App {
|
|||||||
this.apkUrls,
|
this.apkUrls,
|
||||||
this.preferredApkIndex,
|
this.preferredApkIndex,
|
||||||
this.additionalData,
|
this.additionalData,
|
||||||
this.lastUpdateCheck);
|
this.lastUpdateCheck,
|
||||||
|
this.pinned);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ID: $id URL: $url INSTALLED: $installedVersion LATEST: $latestVersion APK: $apkUrls PREFERREDAPK: $preferredApkIndex ADDITIONALDATA: ${additionalData.toString()} LASTCHECK: ${lastUpdateCheck.toString()}';
|
return 'ID: $id URL: $url INSTALLED: $installedVersion LATEST: $latestVersion APK: $apkUrls PREFERREDAPK: $preferredApkIndex ADDITIONALDATA: ${additionalData.toString()} LASTCHECK: ${lastUpdateCheck.toString()} PINNED $pinned';
|
||||||
}
|
}
|
||||||
|
|
||||||
factory App.fromJson(Map<String, dynamic> json) => App(
|
factory App.fromJson(Map<String, dynamic> json) => App(
|
||||||
@@ -75,7 +77,8 @@ class App {
|
|||||||
: List<String>.from(jsonDecode(json['additionalData'])),
|
: List<String>.from(jsonDecode(json['additionalData'])),
|
||||||
json['lastUpdateCheck'] == null
|
json['lastUpdateCheck'] == null
|
||||||
? null
|
? null
|
||||||
: DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']));
|
: DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']),
|
||||||
|
json['pinned'] ?? false);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'id': id,
|
'id': id,
|
||||||
@@ -87,7 +90,8 @@ class App {
|
|||||||
'apkUrls': jsonEncode(apkUrls),
|
'apkUrls': jsonEncode(apkUrls),
|
||||||
'preferredApkIndex': preferredApkIndex,
|
'preferredApkIndex': preferredApkIndex,
|
||||||
'additionalData': jsonEncode(additionalData),
|
'additionalData': jsonEncode(additionalData),
|
||||||
'lastUpdateCheck': lastUpdateCheck?.microsecondsSinceEpoch
|
'lastUpdateCheck': lastUpdateCheck?.microsecondsSinceEpoch,
|
||||||
|
'pinned': pinned
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +228,7 @@ class SourceProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<App> getApp(AppSource source, String url, List<String> additionalData,
|
Future<App> getApp(AppSource source, String url, List<String> additionalData,
|
||||||
{String name = '', String? id}) async {
|
{String name = '', String? id, bool pinned = false}) async {
|
||||||
String standardUrl = source.standardizeURL(preStandardizeUrl(url));
|
String standardUrl = source.standardizeURL(preStandardizeUrl(url));
|
||||||
AppNames names = source.getAppNames(standardUrl);
|
AppNames names = source.getAppNames(standardUrl);
|
||||||
APKDetails apk =
|
APKDetails apk =
|
||||||
@@ -241,7 +245,8 @@ class SourceProvider {
|
|||||||
apk.apkUrls,
|
apk.apkUrls,
|
||||||
apk.apkUrls.length - 1,
|
apk.apkUrls.length - 1,
|
||||||
additionalData,
|
additionalData,
|
||||||
DateTime.now());
|
DateTime.now(),
|
||||||
|
pinned);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns errors in [results, errors] instead of throwing them
|
// Returns errors in [results, errors] instead of throwing them
|
||||||
|
Reference in New Issue
Block a user