Files
lunasea/lib/core/utilities/changelog.dart
Jagandeep Brar d4bd52832f (feat): [Radarr] Ability to view and manage the queue (#414)
* (queue): Ability to view basic queue, delete queue record
* (fix): [UI] Show mouse cursor on ListTile when onTap or onLongPress are not null
* (fix): [UI] Fix height/width of sorting/filtering buttons, ensure consistent fixed-height for input bars
* (fix): [Lists] Remove default drag handles from ReorderableListView
* (fix): Further safe-guarded with platform checks
* (fix): Hide settings options on incompatible platforms
* (chore): Update CHANGELOG.md
* (fix): Switch from package_info to package_info_plus to support MacOS and other platforms
* (chore): Update packages
* (chore): Update Podfile
* (tweak): [Icons] Add font_awesome_flutter, change Icon() usages to FaIcon() to prepare
* (tweak): [Sonarr/Queue] Utilize a cleaner messages dialog view
* (feat): [Radarr/Queue] Add movie name and quality profile to collapsed tile
* (fix): [UI/AppBar] Back button was top-left aligned instead of centered
* (feat): [Icons] Add FontAwesome Pro icons
* (tweak): [Icons] Rollback to FontAwesome 5
* (tweak): [Icons] Rollback to FontAwesome 5
* (fix): [Icons] Revert back to system icons for now
* (fix): [Icons] Revert from FaIcon to Icon
* (tweak): [UI/Expandable Tile] Show two buttons per line, wrapping to a new line when necessary
* (feat): [Radarr] Queue implementation finished
* (fix): [Queue] Safe-guard some data model usages
* (chore): Update CHANGELOG.md
2021-04-09 11:13:16 -05:00

117 lines
5.8 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
import 'package:package_info_plus/package_info_plus.dart';
class LunaChangelog {
/// Check if the current build number is not equal to the stored build number.
///
/// If they are not the same, stores the current build number and shows the changelog.
Future<void> checkAndShowChangelog() async {
PackageInfo.fromPlatform()
.then((package) {
if(package != null && AlertsDatabaseValue.CHANGELOG.data != package.buildNumber) {
AlertsDatabaseValue.CHANGELOG.put(package.buildNumber);
showChangelog(package.version, package.buildNumber);
}
})
.catchError((error, stack) {
LunaLogger().error('Failed to fetch platform information', error, stack);
});
}
/// Load the changelog asset and show a bottom modal sheet with the changelog.
Future<void> showChangelog(String version, String buildNumber) async {
await DefaultAssetBundle.of(LunaState.navigatorKey.currentContext).loadString('assets/changelog.json')
.then((data) {
_Changelog changelog = _Changelog.fromJson(json.decode(data));
LunaBottomModalSheet().showModal(
context: LunaState.navigatorKey.currentContext,
builder: (context) => LunaScaffold(
scaffoldKey: null,
body: LunaListViewModal(
shrinkWrap: false,
children: [
if(version != null && buildNumber != null) LunaHeader(text: '$version ($buildNumber)', subtitle: changelog.motd),
if(version == null || buildNumber == null) LunaHeader(text: 'LunaSea', subtitle: changelog.motd),
if((changelog.changesNew?.length ?? 0) != 0) LunaHeader(text: 'New'),
if((changelog.changesNew?.length ?? 0) != 0) LunaTableCard(
content: List<LunaTableContent>.generate(
changelog.changesNew.length,
(index) => LunaTableContent(
title: changelog.changesNew[index].module,
body: changelog.changesNew[index].changes.fold('', (data, object) => data += '${LunaUI.TEXT_BULLET}\t$object\n').trim(),
),
),
),
if((changelog.changesTweaks?.length ?? 0) != 0) LunaHeader(text: 'Tweaks'),
if((changelog.changesTweaks?.length ?? 0) != 0) LunaTableCard(
content: List<LunaTableContent>.generate(
changelog.changesTweaks.length,
(index) => LunaTableContent(
title: changelog.changesTweaks[index].module,
body: changelog.changesTweaks[index].changes.fold('', (data, object) => data += '${LunaUI.TEXT_BULLET}\t$object\n').trim(),
),
),
),
if((changelog.changesFixes?.length ?? 0) != 0) LunaHeader(text: 'Fixes'),
if((changelog.changesFixes?.length ?? 0) != 0) LunaTableCard(
content: List<LunaTableContent>.generate(
changelog.changesFixes.length,
(index) => LunaTableContent(
title: changelog.changesFixes[index].module,
body: changelog.changesFixes[index].changes.fold('', (data, object) => data += '${LunaUI.TEXT_BULLET}\t$object\n').trim(),
),
),
),
],
),
bottomNavigationBar: LunaBottomActionBar(
actions: [
LunaButton.text(
text: 'Full Changelog',
icon: Icons.track_changes_rounded,
onTap: LunaLinks.CHANGELOG.launch,
),
],
),
),
);
})
.catchError((error, stack) {
LunaLogger().error('Failed to fetched changelog asset', error, stack);
showLunaErrorSnackBar(title: 'Failed to Load Changelog', error: error);
});
}
}
class _Changelog {
String motd;
String version;
List<_Change> changesNew;
List<_Change> changesTweaks;
List<_Change> changesFixes;
static _Changelog fromJson(Map<String, dynamic> json) {
_Changelog changelog = _Changelog();
changelog.motd = json['motd'] ?? '';
changelog.version = json['version'] ?? '';
changelog.changesNew = json['new'] == null ? [] : (json['new'] as List).map<_Change>((change) => _Change.fromJson(change)).toList();
changelog.changesTweaks = json['tweaks'] == null ? [] : (json['tweaks'] as List).map<_Change>((change) => _Change.fromJson(change)).toList();
changelog.changesFixes = json['fixes'] == null ? [] : (json['fixes'] as List).map<_Change>((change) => _Change.fromJson(change)).toList();
return changelog;
}
}
class _Change {
String module;
List<String> changes;
static _Change fromJson(Map<String, dynamic> json) {
_Change change = _Change();
change.module = json['module'] ?? '';
change.changes = (json['changes'] as List)?.cast<String>() ?? [];
return change;
}
}