Skip to content

Commit

Permalink
Improve: Update dialog is more informative now
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Dec 20, 2023
1 parent b3dfdca commit 001842f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/services/update_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import 'package:musify/API/version.dart';
import 'package:musify/extensions/l10n.dart';
import 'package:musify/main.dart';
import 'package:musify/utilities/flutter_toast.dart';
import 'package:musify/widgets/auto_format_text.dart';
import 'package:permission_handler/permission_handler.dart';

const String checkUrl =
'https://raw.githubusercontent.com/gokadzev/Musify/update/check.json';
const String releasesUrl =
'https://api.github.com/repos/gokadzev/Musify/releases/latest';
const String downloadUrlKey = 'url';
const String downloadUrlArm64Key = 'arm64url';
const String downloadFilename = 'Musify.apk';
Expand All @@ -23,6 +26,9 @@ Future<void> checkAppUpdates(BuildContext context) async {
final map = json.decode(response.body) as Map<String, dynamic>;
final latestVersion = map['version'].toString();
if (isLatestVersionHigher(appVersion, latestVersion)) {
final releasesRequest = await http.get(Uri.parse(releasesUrl));
final releasesResponse =
json.decode(releasesRequest.body) as Map<String, dynamic>;
await showDialog(
context: context,
builder: (BuildContext context) {
Expand All @@ -33,14 +39,26 @@ Future<void> checkAppUpdates(BuildContext context) async {
Text(
context.l10n!.appUpdateIsAvailable,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Text(
'V$latestVersion',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16),
),
const SizedBox(height: 10),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height / 2.14,
),
child: SingleChildScrollView(
child: AutoFormatText(text: releasesResponse['body']),
),
),
],
),
actions: <Widget>[
Expand Down
46 changes: 46 additions & 0 deletions lib/widgets/auto_format_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';

class AutoFormatText extends StatelessWidget {
AutoFormatText({required this.text});
final String text;

@override
Widget build(BuildContext context) {
final spans = <TextSpan>[];

final exp = RegExp(r'\*\*(.*?)\*\*');
final matches = exp.allMatches(text);

var currentTextIndex = 0;

for (final match in matches) {
spans.add(
TextSpan(
text: text.substring(currentTextIndex, match.start),
style: const TextStyle(fontSize: 16),
),
);

spans.add(
TextSpan(
text: match.group(1),
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
);

currentTextIndex = match.end;
}

spans.add(
TextSpan(
text: text.substring(currentTextIndex),
style: const TextStyle(fontSize: 16),
),
);

return RichText(
textAlign: TextAlign.center,
text: TextSpan(children: spans),
);
}
}

0 comments on commit 001842f

Please sign in to comment.