Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to search query for suggested version #1151

Merged
merged 23 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@

"currentVersion": "Current",
"suggestedVersion": "Suggested",
"allVersions": "All versions"
"allVersions": "All versions",
"search": "search",
"apk": "apk",
"version": "version"
},
"patchSelectorCard": {
"widgetTitle": "Select patches",
Expand Down
10 changes: 10 additions & 0 deletions lib/ui/views/app_selector/app_selector_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class _AppSelectorViewState extends State<AppSelectorView> {
context,
app.packageName,
),
onLinkTap: () => model.searchSuggestedVersionOnWeb(
context,
packageName: app.packageName,
appName: app.appName,
),
),
)
.toList(),
Expand All @@ -130,6 +135,11 @@ class _AppSelectorViewState extends State<AppSelectorView> {
onTap: () {
model.showDownloadToast();
},
onLinkTap: () => model.searchSuggestedVersionOnWeb(
context,
packageName: app,
appName: app,
),
),
)
.toList(),
Expand Down
23 changes: 23 additions & 0 deletions lib/ui/views/app_selector/app_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart';
import 'package:url_launcher/url_launcher.dart';

class AppSelectorViewModel extends BaseViewModel {
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
Expand Down Expand Up @@ -69,6 +70,28 @@ class AppSelectorViewModel extends BaseViewModel {
return true;
}

Future<void> searchSuggestedVersionOnWeb(BuildContext context,
{required String packageName, required String appName}) async {
final String search = FlutterI18n.translate(
context,
'appSelectorCard.search',
);
final String apk = FlutterI18n.translate(
context,
'appSelectorCard.apk',
);
final String version = FlutterI18n.translate(
context,
'appSelectorCard.version',
);
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved
final String suggestedVersion = getSuggestedVersion(packageName);
final Uri url = Uri.parse('https://www.google.com/$search?q=$appName'
'+$apk+$version+v+$suggestedVersion');
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
}

Future<void> selectApp(ApplicationWithIcon application) async {
locator<PatcherViewModel>().selectedApp = PatchedApplication(
name: application.appName,
Expand Down
45 changes: 39 additions & 6 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:revanced_manager/utils/about_info.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
import 'package:url_launcher/url_launcher.dart';

@lazySingleton
class PatcherViewModel extends BaseViewModel {
Expand Down Expand Up @@ -161,6 +162,40 @@ class PatcherViewModel extends BaseViewModel {
return text;
}

String getCurrentVersionString(BuildContext context) {
return '${FlutterI18n.translate(
context,
'appSelectorCard.currentVersion',
)}: v${selectedApp!.version}';
}

Future<void> searchSuggestedVersionOnWeb(BuildContext context) async {
final String search = FlutterI18n.translate(
context,
'appSelectorCard.search',
);
final String apk = FlutterI18n.translate(
context,
'appSelectorCard.apk',
);
final String version = FlutterI18n.translate(
context,
'appSelectorCard.version',
);
final String suggestedVersion =
_patcherAPI.getSuggestedVersion(selectedApp!.packageName);
Ushie marked this conversation as resolved.
Show resolved Hide resolved
final Uri url =
Uri.parse('https://www.google.com/$search?q=${selectedApp!.name}'
'+$apk+$version+v+$suggestedVersion');
if (!await launchUrl(url, mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $url');
}
}

String getSuggestedVersion() {
return _patcherAPI.getSuggestedVersion(selectedApp!.packageName);
}

String getSuggestedVersionString(BuildContext context) {
String suggestedVersion =
_patcherAPI.getSuggestedVersion(selectedApp!.packageName);
Expand All @@ -173,9 +208,6 @@ class PatcherViewModel extends BaseViewModel {
suggestedVersion = 'v$suggestedVersion';
}
return '${FlutterI18n.translate(
context,
'appSelectorCard.currentVersion',
)}: v${selectedApp!.version}\n${FlutterI18n.translate(
context,
'appSelectorCard.suggestedVersion',
)}: $suggestedVersion';
Expand Down Expand Up @@ -203,9 +235,10 @@ class PatcherViewModel extends BaseViewModel {
.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
final usedPatches = _managerAPI.getUsedPatches(selectedApp!.originalPackageName);
for (final patch in usedPatches){
if (!patches.any((p) => p.name == patch.name)){
final usedPatches =
_managerAPI.getUsedPatches(selectedApp!.originalPackageName);
for (final patch in usedPatches) {
if (!patches.any((p) => p.name == patch.name)) {
removedPatches.add('\u2022 ${patch.name}');
}
}
Expand Down
45 changes: 35 additions & 10 deletions lib/ui/widgets/appSelectorView/installed_app_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InstalledAppItem extends StatefulWidget {
required this.suggestedVersion,
required this.installedVersion,
this.onTap,
this.onLinkTap,
}) : super(key: key);
final String name;
final String pkgName;
Expand All @@ -21,6 +22,7 @@ class InstalledAppItem extends StatefulWidget {
final String suggestedVersion;
final String installedVersion;
final Function()? onTap;
final Function()? onLinkTap;

@override
State<InstalledAppItem> createState() => _InstalledAppItemState();
Expand Down Expand Up @@ -72,16 +74,39 @@ class _InstalledAppItemState extends State<InstalledAppItem> {
),
Wrap(
children: [
I18nText(
'suggested',
translationParams: {
'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(
context,
'appSelectorCard.allVersions',
)
: 'v${widget.suggestedVersion}',
},
GestureDetector(
onTap: widget.onLinkTap,
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade800,
borderRadius:
const BorderRadius.all(Radius.circular(7)),
),
padding: const EdgeInsets.symmetric(horizontal: 3),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
I18nText(
'suggested',
translationParams: {
'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(
context,
'appSelectorCard.allVersions',
)
: 'v${widget.suggestedVersion}',
},
),
// if(widget.suggestedVersion.isNotEmpty)
Ushie marked this conversation as resolved.
Show resolved Hide resolved
const SizedBox(width: 4),
// if(widget.suggestedVersion.isNotEmpty)
Ushie marked this conversation as resolved.
Show resolved Hide resolved
const Icon(
Icons.link,
Ushie marked this conversation as resolved.
Show resolved Hide resolved
size: 17,
),
],
),
),
),
const SizedBox(width: 4),
Text(
Expand Down
44 changes: 34 additions & 10 deletions lib/ui/widgets/appSelectorView/not_installed_app_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ class NotInstalledAppItem extends StatefulWidget {
required this.patchesCount,
required this.suggestedVersion,
this.onTap,
this.onLinkTap,
}) : super(key: key);
final String name;
final int patchesCount;
final String suggestedVersion;
final Function()? onTap;
final Function()? onLinkTap;

@override
State<NotInstalledAppItem> createState() => _NotInstalledAppItem();
Expand Down Expand Up @@ -66,16 +68,38 @@ class _NotInstalledAppItem extends State<NotInstalledAppItem> {
),
Wrap(
children: [
I18nText(
'suggested',
translationParams: {
'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(
context,
'appSelectorCard.allVersions',
)
: 'v${widget.suggestedVersion}',
},
GestureDetector(
onTap: widget.onLinkTap,
child: Container(
decoration: BoxDecoration(
color: Colors.grey.shade800,
borderRadius:
const BorderRadius.all(Radius.circular(7)),
),
padding: const EdgeInsets.symmetric(horizontal: 3),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
I18nText(
'suggested',
translationParams: {
'version': widget.suggestedVersion.isEmpty
? FlutterI18n.translate(
context,
'appSelectorCard.allVersions',
)
: 'v${widget.suggestedVersion}',
},
),
const SizedBox(width: 4),
// if(widget.suggestedVersion.isNotEmpty)
Ushie marked this conversation as resolved.
Show resolved Hide resolved
const Icon(
Icons.link,
size: 17,
),
],
),
),
),
const SizedBox(width: 4),
Text(
Expand Down
20 changes: 19 additions & 1 deletion lib/ui/widgets/patcherView/app_selector_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,29 @@ class AppSelectorCard extends StatelessWidget {
Container()
else
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 4),
Text(
locator<PatcherViewModel>()
.getSuggestedVersionString(context),
.getCurrentVersionString(context),
),
Row(
children: [
Text(
locator<PatcherViewModel>()
.getSuggestedVersionString(context),
),
const SizedBox(width: 20,),
if(locator<PatcherViewModel>().getSuggestedVersion().isNotEmpty)
InkWell(
onTap: (){
locator<PatcherViewModel>()
.searchSuggestedVersionOnWeb(context);
},
child: const Icon(Icons.link),
),
],
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/shared/custom_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CustomCard extends StatelessWidget {
onTap: onTap,
borderRadius: BorderRadius.circular(16),
child: Padding(
padding: padding ?? const EdgeInsets.all(20.0),
padding: padding ?? const EdgeInsets.only(top: 20.0, bottom: 20, left: 10),
child: child,
),
),
Expand Down