Skip to content

Commit 4712a94

Browse files
authored
Merge pull request #23 from CoderJava/feature/tampilkan-penanda-ketika-ada-app-versi-terbaru
Feature - Tampilkan info dalam bentuk banner ketika ada app versi terbaru di halaman home
2 parents 2316fdf + 237d8fb commit 4712a94

File tree

3 files changed

+99
-5
lines changed

3 files changed

+99
-5
lines changed

assets/translations/en-US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,7 @@
265265
"set_start_and_finish_time": "Set start and finish time",
266266
"duration": "Duration",
267267
"please_set_start_time": "Please set start time",
268-
"please_set_finish_time": "Please set finish time"
268+
"please_set_finish_time": "Please set finish time",
269+
"title_new_update_available": "New update available",
270+
"description_new_update_available": "Click here to download latest version"
269271
}

lib/core/util/widget_helper.dart

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22
import 'dart:math';
33

4+
import 'package:dio/dio.dart';
45
import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart';
56
import 'package:dipantau_desktop_client/core/util/helper.dart';
67
import 'package:dipantau_desktop_client/core/util/shared_preferences_manager.dart';
@@ -11,6 +12,7 @@ import 'package:flutter/material.dart';
1112
import 'package:flutter/services.dart';
1213
import 'package:go_router/go_router.dart';
1314
import 'package:path_provider/path_provider.dart';
15+
import 'package:xml/xml.dart';
1416

1517
class WidgetHelper {
1618
void showSnackBar(BuildContext context, String message) {
@@ -168,9 +170,9 @@ class WidgetHelper {
168170
],
169171
),
170172
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
171-
fontStyle: FontStyle.italic,
172-
fontWeight: FontWeight.w500,
173-
),
173+
fontStyle: FontStyle.italic,
174+
fontWeight: FontWeight.w500,
175+
),
174176
),
175177
],
176178
),
@@ -209,4 +211,25 @@ class WidgetHelper {
209211

210212
return file;
211213
}
214+
215+
Future<bool> isNewUpdateAvailable() async {
216+
final response =
217+
await Dio().get('https://raw.githubusercontent.com/CoderJava/dipantau-desktop/main/dist/appcast.xml');
218+
final data = response.data;
219+
final document = XmlDocument.parse(data);
220+
final sparkleVersion = document.findAllElements('sparkle:version');
221+
if (sparkleVersion.isNotEmpty) {
222+
final element = sparkleVersion.first;
223+
final versionText = element.innerText;
224+
final newVersion = int.tryParse(versionText);
225+
if (newVersion != null) {
226+
final strBuildNumberLocal = packageInfo.buildNumber;
227+
final buildNumberLocal = int.tryParse(strBuildNumberLocal);
228+
if (buildNumberLocal != null) {
229+
return newVersion > buildNumberLocal;
230+
}
231+
}
232+
}
233+
return false;
234+
}
212235
}

lib/feature/presentation/page/home/home_page.dart

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22
import 'dart:io';
33

4+
import 'package:auto_updater/auto_updater.dart';
45
import 'package:dipantau_desktop_client/core/network/network_info.dart';
56
import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart';
67
import 'package:dipantau_desktop_client/core/util/helper.dart';
@@ -76,6 +77,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
7677
final listTrackLocal = <Track>[];
7778
final listPathStartScreenshots = <String?>[];
7879
final networkInfo = sl<NetworkInfo>();
80+
final valueNotifierShowBannerUpdate = ValueNotifier(false);
7981

8082
var isWindowVisible = true;
8183
var userId = '';
@@ -130,6 +132,8 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
130132
}
131133
setupCronTimer();
132134
doLoadDataTask();
135+
final isNewUpdateAvailable = await widgetHelper.isNewUpdateAvailable();
136+
valueNotifierShowBannerUpdate.value = isNewUpdateAvailable;
133137
});
134138
super.initState();
135139
}
@@ -506,7 +510,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
506510
),
507511
),
508512
floatingActionButton: FloatingActionButton(
509-
onPressed: () {
513+
onPressed: () async {
510514
context.pushNamed(ManualTrackingPage.routeName).then((value) {
511515
// TODO: refresh data home jika add manual tracking-nya pada hari ini dan di project yang sama
512516
});
@@ -555,6 +559,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
555559
child: Column(
556560
crossAxisAlignment: CrossAxisAlignment.center,
557561
children: [
562+
buildWidgetBannerUpdate(),
558563
buildWidgetFieldProject(),
559564
const SizedBox(height: 24),
560565
buildWidgetTimer(),
@@ -1487,4 +1492,68 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
14871492
);
14881493
}
14891494
}
1495+
1496+
Widget buildWidgetBannerUpdate() {
1497+
return ValueListenableBuilder(
1498+
valueListenable: valueNotifierShowBannerUpdate,
1499+
builder: (BuildContext context, bool isShow, _) {
1500+
if (!isShow) {
1501+
return Container();
1502+
}
1503+
return Column(
1504+
children: [
1505+
Material(
1506+
borderRadius: BorderRadius.circular(8),
1507+
color: Theme.of(context).colorScheme.primaryContainer,
1508+
child: InkWell(
1509+
borderRadius: BorderRadius.circular(8),
1510+
onTap: () {
1511+
const feedURL = autoUpdaterUrl;
1512+
autoUpdater.setFeedURL(feedURL);
1513+
autoUpdater.checkForUpdates();
1514+
valueNotifierShowBannerUpdate.value = false;
1515+
},
1516+
child: Container(
1517+
width: double.infinity,
1518+
padding: const EdgeInsets.all(8),
1519+
decoration: BoxDecoration(
1520+
borderRadius: BorderRadius.circular(8),
1521+
),
1522+
child: Row(
1523+
children: [
1524+
Expanded(
1525+
child: Padding(
1526+
padding: const EdgeInsets.only(left: 8.0),
1527+
child: Column(
1528+
crossAxisAlignment: CrossAxisAlignment.start,
1529+
children: [
1530+
Text(
1531+
'title_new_update_available'.tr(),
1532+
style: Theme.of(context).textTheme.bodyLarge,
1533+
),
1534+
Text(
1535+
'description_new_update_available'.tr(),
1536+
style: Theme.of(context).textTheme.bodySmall,
1537+
),
1538+
],
1539+
),
1540+
),
1541+
),
1542+
IconButton(
1543+
onPressed: () {
1544+
valueNotifierShowBannerUpdate.value = false;
1545+
},
1546+
icon: const Icon(Icons.clear),
1547+
),
1548+
],
1549+
),
1550+
),
1551+
),
1552+
),
1553+
const SizedBox(height: 16),
1554+
],
1555+
);
1556+
},
1557+
);
1558+
}
14901559
}

0 commit comments

Comments
 (0)