mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-16 19:58:09 +02:00
Add changelog button to app page (#1474)
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:obtainium/components/generated_form_modal.dart';
|
import 'package:obtainium/components/generated_form_modal.dart';
|
||||||
import 'package:obtainium/custom_errors.dart';
|
import 'package:obtainium/custom_errors.dart';
|
||||||
import 'package:obtainium/main.dart';
|
import 'package:obtainium/main.dart';
|
||||||
|
import 'package:obtainium/pages/apps.dart';
|
||||||
import 'package:obtainium/pages/settings.dart';
|
import 'package:obtainium/pages/settings.dart';
|
||||||
import 'package:obtainium/providers/apps_provider.dart';
|
import 'package:obtainium/providers/apps_provider.dart';
|
||||||
import 'package:obtainium/providers/settings_provider.dart';
|
import 'package:obtainium/providers/settings_provider.dart';
|
||||||
@@ -108,6 +109,7 @@ class _AppPageState extends State<AppPage> {
|
|||||||
infoLines =
|
infoLines =
|
||||||
'$infoLines\n${app?.app.apkUrls.length == 1 ? app?.app.apkUrls[0].key : plural('apk', app?.app.apkUrls.length ?? 0)}';
|
'$infoLines\n${app?.app.apkUrls.length == 1 ? app?.app.apkUrls[0].key : plural('apk', app?.app.apkUrls.length ?? 0)}';
|
||||||
}
|
}
|
||||||
|
var changeLogFn = app != null ? getChangeLogFn(context, app.app) : null;
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
@@ -125,13 +127,26 @@ class _AppPageState extends State<AppPage> {
|
|||||||
.textTheme
|
.textTheme
|
||||||
.bodyLarge!
|
.bodyLarge!
|
||||||
.copyWith(fontWeight: FontWeight.bold)),
|
.copyWith(fontWeight: FontWeight.bold)),
|
||||||
app?.app.releaseDate == null
|
changeLogFn != null || app?.app.releaseDate != null
|
||||||
? const SizedBox.shrink()
|
? GestureDetector(
|
||||||
: Text(
|
onTap: changeLogFn,
|
||||||
app!.app.releaseDate.toString(),
|
child: Text(
|
||||||
textAlign: TextAlign.center,
|
app?.app.releaseDate == null
|
||||||
style: Theme.of(context).textTheme.labelSmall,
|
? tr('changes')
|
||||||
),
|
: app!.app.releaseDate.toString(),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style:
|
||||||
|
Theme.of(context).textTheme.labelSmall!.copyWith(
|
||||||
|
decoration: changeLogFn != null
|
||||||
|
? TextDecoration.underline
|
||||||
|
: null,
|
||||||
|
fontStyle: changeLogFn != null
|
||||||
|
? FontStyle.italic
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
|
@@ -26,6 +26,92 @@ class AppsPage extends StatefulWidget {
|
|||||||
State<AppsPage> createState() => AppsPageState();
|
State<AppsPage> createState() => AppsPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showChangeLogDialog(BuildContext context, App app, String? changesUrl,
|
||||||
|
AppSource appSource, String changeLog) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return GeneratedFormModal(
|
||||||
|
title: tr('changes'),
|
||||||
|
items: const [],
|
||||||
|
message: app.latestVersion,
|
||||||
|
additionalWidgets: [
|
||||||
|
changesUrl != null
|
||||||
|
? GestureDetector(
|
||||||
|
child: Text(
|
||||||
|
changesUrl,
|
||||||
|
style: const TextStyle(
|
||||||
|
decoration: TextDecoration.underline,
|
||||||
|
fontStyle: FontStyle.italic),
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
launchUrlString(changesUrl,
|
||||||
|
mode: LaunchMode.externalApplication);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
|
changesUrl != null
|
||||||
|
? const SizedBox(
|
||||||
|
height: 16,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
|
appSource.changeLogIfAnyIsMarkDown
|
||||||
|
? SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width,
|
||||||
|
height: MediaQuery.of(context).size.height - 350,
|
||||||
|
child: Markdown(
|
||||||
|
data: changeLog,
|
||||||
|
onTapLink: (text, href, title) {
|
||||||
|
if (href != null) {
|
||||||
|
launchUrlString(
|
||||||
|
href.startsWith('http://') ||
|
||||||
|
href.startsWith('https://')
|
||||||
|
? href
|
||||||
|
: '${Uri.parse(app.url).origin}/$href',
|
||||||
|
mode: LaunchMode.externalApplication);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
extensionSet: md.ExtensionSet(
|
||||||
|
md.ExtensionSet.gitHubFlavored.blockSyntaxes,
|
||||||
|
[
|
||||||
|
md.EmojiSyntax(),
|
||||||
|
...md.ExtensionSet.gitHubFlavored.inlineSyntaxes
|
||||||
|
],
|
||||||
|
),
|
||||||
|
))
|
||||||
|
: Text(changeLog),
|
||||||
|
],
|
||||||
|
singleNullReturnButton: tr('ok'),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getChangeLogFn(BuildContext context, App app) {
|
||||||
|
AppSource appSource =
|
||||||
|
SourceProvider().getSource(app.url, overrideSource: app.overrideSource);
|
||||||
|
String? changesUrl = appSource.changeLogPageFromStandardUrl(app.url);
|
||||||
|
String? changeLog = app.changeLog;
|
||||||
|
if (changeLog?.split('\n').length == 1) {
|
||||||
|
if (RegExp(
|
||||||
|
'(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?')
|
||||||
|
.hasMatch(changeLog!)) {
|
||||||
|
if (changesUrl == null) {
|
||||||
|
changesUrl = changeLog;
|
||||||
|
changeLog = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (changeLog == null && changesUrl == null)
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
if (changeLog != null) {
|
||||||
|
showChangeLogDialog(context, app, changesUrl, appSource, changeLog);
|
||||||
|
} else {
|
||||||
|
launchUrlString(changesUrl!, mode: LaunchMode.externalApplication);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class AppsPageState extends State<AppsPage> {
|
class AppsPageState extends State<AppsPage> {
|
||||||
AppsFilter filter = AppsFilter();
|
AppsFilter filter = AppsFilter();
|
||||||
final AppsFilter neutralFilter = AppsFilter();
|
final AppsFilter neutralFilter = AppsFilter();
|
||||||
@@ -262,66 +348,6 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
.where((a) => selectedAppIds.contains(a.id))
|
.where((a) => selectedAppIds.contains(a.id))
|
||||||
.toSet();
|
.toSet();
|
||||||
|
|
||||||
showChangeLogDialog(
|
|
||||||
String? changesUrl, AppSource appSource, String changeLog, int index) {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return GeneratedFormModal(
|
|
||||||
title: tr('changes'),
|
|
||||||
items: const [],
|
|
||||||
message: listedApps[index].app.latestVersion,
|
|
||||||
additionalWidgets: [
|
|
||||||
changesUrl != null
|
|
||||||
? GestureDetector(
|
|
||||||
child: Text(
|
|
||||||
changesUrl,
|
|
||||||
style: const TextStyle(
|
|
||||||
decoration: TextDecoration.underline,
|
|
||||||
fontStyle: FontStyle.italic),
|
|
||||||
),
|
|
||||||
onTap: () {
|
|
||||||
launchUrlString(changesUrl,
|
|
||||||
mode: LaunchMode.externalApplication);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: const SizedBox.shrink(),
|
|
||||||
changesUrl != null
|
|
||||||
? const SizedBox(
|
|
||||||
height: 16,
|
|
||||||
)
|
|
||||||
: const SizedBox.shrink(),
|
|
||||||
appSource.changeLogIfAnyIsMarkDown
|
|
||||||
? SizedBox(
|
|
||||||
width: MediaQuery.of(context).size.width,
|
|
||||||
height: MediaQuery.of(context).size.height - 350,
|
|
||||||
child: Markdown(
|
|
||||||
data: changeLog,
|
|
||||||
onTapLink: (text, href, title) {
|
|
||||||
if (href != null) {
|
|
||||||
launchUrlString(
|
|
||||||
href.startsWith('http://') ||
|
|
||||||
href.startsWith('https://')
|
|
||||||
? href
|
|
||||||
: '${Uri.parse(listedApps[index].app.url).origin}/$href',
|
|
||||||
mode: LaunchMode.externalApplication);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
extensionSet: md.ExtensionSet(
|
|
||||||
md.ExtensionSet.gitHubFlavored.blockSyntaxes,
|
|
||||||
[
|
|
||||||
md.EmojiSyntax(),
|
|
||||||
...md.ExtensionSet.gitHubFlavored.inlineSyntaxes
|
|
||||||
],
|
|
||||||
),
|
|
||||||
))
|
|
||||||
: Text(changeLog),
|
|
||||||
],
|
|
||||||
singleNullReturnButton: tr('ok'),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getLoadingWidgets() {
|
getLoadingWidgets() {
|
||||||
return [
|
return [
|
||||||
if (listedApps.isEmpty)
|
if (listedApps.isEmpty)
|
||||||
@@ -351,35 +377,6 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
getChangeLogFn(int appIndex) {
|
|
||||||
AppSource appSource = SourceProvider().getSource(
|
|
||||||
listedApps[appIndex].app.url,
|
|
||||||
overrideSource: listedApps[appIndex].app.overrideSource);
|
|
||||||
String? changesUrl =
|
|
||||||
appSource.changeLogPageFromStandardUrl(listedApps[appIndex].app.url);
|
|
||||||
String? changeLog = listedApps[appIndex].app.changeLog;
|
|
||||||
if (changeLog?.split('\n').length == 1) {
|
|
||||||
if (RegExp(
|
|
||||||
'(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?')
|
|
||||||
.hasMatch(changeLog!)) {
|
|
||||||
if (changesUrl == null) {
|
|
||||||
changesUrl = changeLog;
|
|
||||||
changeLog = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (changeLog == null && changesUrl == null)
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
if (changeLog != null) {
|
|
||||||
showChangeLogDialog(changesUrl, appSource, changeLog, appIndex);
|
|
||||||
} else {
|
|
||||||
launchUrlString(changesUrl!,
|
|
||||||
mode: LaunchMode.externalApplication);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
getUpdateButton(int appIndex) {
|
getUpdateButton(int appIndex) {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
visualDensity: VisualDensity.compact,
|
visualDensity: VisualDensity.compact,
|
||||||
@@ -444,7 +441,7 @@ class AppsPageState extends State<AppsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSingleAppHorizTile(int index) {
|
getSingleAppHorizTile(int index) {
|
||||||
var showChangesFn = getChangeLogFn(index);
|
var showChangesFn = getChangeLogFn(context, listedApps[index].app);
|
||||||
var hasUpdate = listedApps[index].app.installedVersion != null &&
|
var hasUpdate = listedApps[index].app.installedVersion != null &&
|
||||||
listedApps[index].app.installedVersion !=
|
listedApps[index].app.installedVersion !=
|
||||||
listedApps[index].app.latestVersion;
|
listedApps[index].app.latestVersion;
|
||||||
|
Reference in New Issue
Block a user