mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: app listing on Home View
This commit is contained in:
parent
d351b86f41
commit
750f035104
@ -28,11 +28,13 @@
|
||||
},
|
||||
"appSelectorCard": {
|
||||
"widgetTitle": "Select application",
|
||||
"widgetTitleSelected": "Selected application",
|
||||
"widgetSubtitle": "No application selected.",
|
||||
"noAppsLabel": "No apps found."
|
||||
},
|
||||
"patchSelectorCard": {
|
||||
"widgetTitle": "Select patches",
|
||||
"widgetTitleSelected": "Selected patches",
|
||||
"widgetSubtitle": "Select an application first.",
|
||||
"widgetEmptySubtitle": "No patches selected."
|
||||
},
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
@ -10,8 +11,8 @@ class PatchedApplication {
|
||||
final String version;
|
||||
final String apkFilePath;
|
||||
@JsonKey(
|
||||
fromJson: bytesFromString,
|
||||
toJson: bytesToString,
|
||||
fromJson: decodeBase64,
|
||||
toJson: encodeBase64,
|
||||
)
|
||||
final Uint8List icon;
|
||||
final DateTime patchDate;
|
||||
@ -36,8 +37,7 @@ class PatchedApplication {
|
||||
|
||||
Map toJson() => _$PatchedApplicationToJson(this);
|
||||
|
||||
static Uint8List bytesFromString(String icon) =>
|
||||
Uint8List.fromList(icon.codeUnits);
|
||||
static Uint8List decodeBase64(String icon) => base64.decode(icon);
|
||||
|
||||
static String bytesToString(Uint8List bytes) => String.fromCharCodes(bytes);
|
||||
static String encodeBase64(Uint8List bytes) => base64.encode(bytes);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:github/github.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:timeago/timeago.dart';
|
||||
|
||||
@lazySingleton
|
||||
@ -7,12 +8,11 @@ class GithubAPI {
|
||||
var github = GitHub();
|
||||
|
||||
Future<String?> latestRelease(String org, repoName) async {
|
||||
String? dlurl = '';
|
||||
try {
|
||||
var latestRelease = await github.repositories.getLatestRelease(
|
||||
RepositorySlug(org, repoName),
|
||||
);
|
||||
dlurl = latestRelease.assets
|
||||
return latestRelease.assets
|
||||
?.firstWhere((asset) =>
|
||||
asset.name != null &&
|
||||
(asset.name!.endsWith('.dex') || asset.name!.endsWith('.apk')) &&
|
||||
@ -20,24 +20,21 @@ class GithubAPI {
|
||||
!asset.name!.contains('-javadoc'))
|
||||
.browserDownloadUrl;
|
||||
} on Exception {
|
||||
dlurl = '';
|
||||
return '';
|
||||
}
|
||||
return dlurl;
|
||||
}
|
||||
|
||||
Future<String> latestCommitTime(String org, repoName) async {
|
||||
String pushedAt = '';
|
||||
try {
|
||||
var repo = await github.repositories.getRepository(
|
||||
RepositorySlug(org, repoName),
|
||||
);
|
||||
pushedAt = repo.pushedAt != null
|
||||
return repo.pushedAt != null
|
||||
? format(repo.pushedAt!, locale: 'en_short')
|
||||
: '';
|
||||
} on Exception {
|
||||
pushedAt = '';
|
||||
return '';
|
||||
}
|
||||
return pushedAt;
|
||||
}
|
||||
|
||||
Future<List<Contributor>> getContributors(String org, repoName) async {
|
||||
@ -50,4 +47,15 @@ class GithubAPI {
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> hasUpdates(PatchedApplication app, String org, repoName) async {
|
||||
// TODO: get status based on last update time on the folder of this app?
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<String> getChangelog(
|
||||
PatchedApplication app, String org, repoName) async {
|
||||
// TODO: get changelog based on last commits on the folder of this app?
|
||||
return 'fix: incorrect fingerprint version';
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class PatcherAPI {
|
||||
);
|
||||
} else {
|
||||
await AppInstaller.installApk(_outFile!.path);
|
||||
return true;
|
||||
return await DeviceApps.isAppInstalled(patchedApp.packageName);
|
||||
}
|
||||
} on Exception {
|
||||
return false;
|
||||
|
@ -90,8 +90,8 @@ class HomeView extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
model.showUpdatableApps
|
||||
? const AvailableUpdatesCard()
|
||||
: const InstalledAppsCard()
|
||||
? AvailableUpdatesCard()
|
||||
: InstalledAppsCard()
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -2,12 +2,14 @@ import 'dart:convert';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@lazySingleton
|
||||
class HomeViewModel extends BaseViewModel {
|
||||
final GithubAPI githubAPI = GithubAPI();
|
||||
bool showUpdatableApps = true;
|
||||
|
||||
void toggleUpdatableApps(bool value) {
|
||||
@ -19,10 +21,20 @@ class HomeViewModel extends BaseViewModel {
|
||||
Future downloadIntegrations() => locator<ManagerAPI>().downloadIntegrations();
|
||||
|
||||
Future<List<PatchedApplication>> getPatchedApps(bool isUpdatable) async {
|
||||
List<PatchedApplication> list = [];
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
List<String> patchedApps = prefs.getStringList('patchedApps') ?? [];
|
||||
return patchedApps
|
||||
.map((app) => PatchedApplication.fromJson(json.decode(app)))
|
||||
.toList();
|
||||
for (String str in patchedApps) {
|
||||
PatchedApplication app = PatchedApplication.fromJson(json.decode(str));
|
||||
bool hasUpdates = await githubAPI.hasUpdates(
|
||||
app,
|
||||
'revanced',
|
||||
'revanced-patches',
|
||||
);
|
||||
if (hasUpdates == isUpdatable) {
|
||||
list.add(app);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart';
|
||||
@ -84,7 +83,7 @@ class InstallerView extends StatelessWidget {
|
||||
child: SelectableText(
|
||||
model.logs,
|
||||
style: GoogleFonts.jetBrainsMono(
|
||||
fontSize: 12,
|
||||
fontSize: 13,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:device_apps/device_apps.dart';
|
||||
import 'package:flutter_background/flutter_background.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
@ -151,7 +152,7 @@ class InstallerViewModel extends BaseViewModel {
|
||||
Future<void> saveApp(PatchedApplication selectedApp) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
List<String> patchedApps = prefs.getStringList('patchedApps') ?? [];
|
||||
String app = selectedApp.toJson().toString();
|
||||
String app = json.encode(selectedApp.toJson());
|
||||
if (!patchedApps.contains(app)) {
|
||||
patchedApps.add(app);
|
||||
prefs.setStringList('patchedApps', patchedApps);
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
@ -32,8 +34,11 @@ class AppSelectorCard extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
I18nText(
|
||||
'appSelectorCard.widgetTitle',
|
||||
locator<AppSelectorViewModel>().selectedApp == null
|
||||
? 'appSelectorCard.widgetTitle'
|
||||
: 'appSelectorCard.widgetTitleSelected',
|
||||
child: Text(
|
||||
'',
|
||||
style: GoogleFonts.roboto(
|
||||
@ -43,17 +48,35 @@ class AppSelectorCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
locator<AppSelectorViewModel>().selectedApp != null
|
||||
? Text(
|
||||
_getAppSelection(),
|
||||
style: robotoTextStyle,
|
||||
)
|
||||
: I18nText(
|
||||
locator<AppSelectorViewModel>().selectedApp == null
|
||||
? I18nText(
|
||||
'appSelectorCard.widgetSubtitle',
|
||||
child: Text(
|
||||
'',
|
||||
style: robotoTextStyle,
|
||||
),
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 16.0,
|
||||
child: ClipOval(
|
||||
child: Image.memory(
|
||||
locator<AppSelectorViewModel>().selectedApp == null
|
||||
? Uint8List(0)
|
||||
: locator<AppSelectorViewModel>()
|
||||
.selectedApp!
|
||||
.icon,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
_getAppSelection(),
|
||||
style: robotoTextStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -12,7 +12,7 @@ class ApplicationItem extends StatelessWidget {
|
||||
final Uint8List icon;
|
||||
final String name;
|
||||
final DateTime patchDate;
|
||||
final String? changelog;
|
||||
final String changelog;
|
||||
final bool isUpdatableApp;
|
||||
final Function()? onPressed;
|
||||
|
||||
@ -21,7 +21,7 @@ class ApplicationItem extends StatelessWidget {
|
||||
required this.icon,
|
||||
required this.name,
|
||||
required this.patchDate,
|
||||
this.changelog = '',
|
||||
required this.changelog,
|
||||
required this.isUpdatableApp,
|
||||
required this.onPressed,
|
||||
}) : super(key: key);
|
||||
@ -66,7 +66,7 @@ class ApplicationItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
format(patchDate),
|
||||
format(patchDate, locale: 'en_short'),
|
||||
style: robotoTextStyle.copyWith(
|
||||
color: Theme.of(context).colorScheme.tertiary,
|
||||
),
|
||||
@ -104,7 +104,7 @@ class ApplicationItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
changelog!,
|
||||
changelog,
|
||||
style: robotoTextStyle,
|
||||
),
|
||||
],
|
||||
|
@ -1,14 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/application_item.dart';
|
||||
|
||||
class AvailableUpdatesCard extends StatelessWidget {
|
||||
const AvailableUpdatesCard({
|
||||
AvailableUpdatesCard({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
final GithubAPI githubAPI = GithubAPI();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@ -18,14 +21,26 @@ class AvailableUpdatesCard extends StatelessWidget {
|
||||
FutureBuilder<List<PatchedApplication>>(
|
||||
future: locator<HomeViewModel>().getPatchedApps(true),
|
||||
builder: (context, snapshot) =>
|
||||
snapshot.hasData && snapshot.data!.length > 1
|
||||
snapshot.hasData && snapshot.data!.isNotEmpty
|
||||
? ListView.builder(
|
||||
itemBuilder: (context, index) => ApplicationItem(
|
||||
icon: snapshot.data![index].icon,
|
||||
name: snapshot.data![index].name,
|
||||
patchDate: snapshot.data![index].patchDate,
|
||||
isUpdatableApp: true,
|
||||
onPressed: () => {},
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) => FutureBuilder<String>(
|
||||
future: githubAPI.getChangelog(
|
||||
snapshot.data![index],
|
||||
'revanced',
|
||||
'revanced-patches',
|
||||
),
|
||||
initialData: '',
|
||||
builder: (context, snapshot2) => ApplicationItem(
|
||||
icon: snapshot.data![index].icon,
|
||||
name: snapshot.data![index].name,
|
||||
patchDate: snapshot.data![index].patchDate,
|
||||
changelog: snapshot2.data!,
|
||||
isUpdatableApp: true,
|
||||
onPressed: () => {},
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
|
@ -1,14 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/application_item.dart';
|
||||
|
||||
class InstalledAppsCard extends StatelessWidget {
|
||||
const InstalledAppsCard({
|
||||
InstalledAppsCard({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
final GithubAPI githubAPI = GithubAPI();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
@ -18,14 +21,26 @@ class InstalledAppsCard extends StatelessWidget {
|
||||
FutureBuilder<List<PatchedApplication>>(
|
||||
future: locator<HomeViewModel>().getPatchedApps(false),
|
||||
builder: (context, snapshot) =>
|
||||
snapshot.hasData && snapshot.data!.length > 1
|
||||
snapshot.hasData && snapshot.data!.isNotEmpty
|
||||
? ListView.builder(
|
||||
itemBuilder: (context, index) => ApplicationItem(
|
||||
icon: snapshot.data![index].icon,
|
||||
name: snapshot.data![index].name,
|
||||
patchDate: snapshot.data![index].patchDate,
|
||||
isUpdatableApp: false,
|
||||
onPressed: () => {},
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) => FutureBuilder<String>(
|
||||
future: githubAPI.getChangelog(
|
||||
snapshot.data![index],
|
||||
'revanced',
|
||||
'revanced-patches',
|
||||
),
|
||||
initialData: '',
|
||||
builder: (context, snapshot2) => ApplicationItem(
|
||||
icon: snapshot.data![index].icon,
|
||||
name: snapshot.data![index].name,
|
||||
patchDate: snapshot.data![index].patchDate,
|
||||
changelog: snapshot2.data!,
|
||||
isUpdatableApp: false,
|
||||
onPressed: () => {},
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
|
@ -32,7 +32,9 @@ class PatchSelectorCard extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
I18nText(
|
||||
'patchSelectorCard.widgetTitle',
|
||||
locator<PatchesSelectorViewModel>().selectedPatches.isEmpty
|
||||
? 'patchSelectorCard.widgetTitle'
|
||||
: 'patchSelectorCard.widgetTitleSelected',
|
||||
child: Text(
|
||||
'',
|
||||
style: GoogleFonts.roboto(
|
||||
|
Loading…
Reference in New Issue
Block a user