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

fix: #4025 translate the offline data page #4055

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 71 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2073,5 +2073,76 @@
"page_not_found_button": "Go back to the homepage",
"@page_not_found_button": {
"description": "Button to go back to the homepage"
},
"download_data": "Download Data",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@download_data": {
"description": "App bar title for the download data page"
},
"download_top_products": "Download the top 1000 products in your country for instant scanning",
"@download_top_products": {
"description": "Download the top 1000 products in your country for instant scanning"
},
"download_in_progress": "Downloading data\nThis may take a while",
"@download_in_progress": {
"description": "Download in progress"
},
"downloaded_products": "{num} products added",
"@downloaded_products": {
"description": "text to show when products added",
"placeholders": {
"num": {
"type": "int"
}
}
},
"update_offline_data": "Update Offline Product Data",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@update_offline_data": {
"description": "List tile title for the update offline data page"
},
"update_local_database_sub": "Update the local product database with the latest data from server",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@update_local_database_sub": {
"description": "Update the local product database with the latest data from server"
},
"clear_local_database": "Clear Offline Product Data",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@clear_local_database": {
"description": "List tile title for the clear local database page"
},
"clear_local_database_sub": "Clear all local product data from your app to free up space",
"@clear_local_database_sub": {
"description": "Clear all local product data from your app to free up space"
},
"deleted_products": "{num} products deleted",
"@deleted_products": {
"description": "text to show when products are deleted from local databse",
"placeholders": {
"num": {
"type": "int"
}
}
},
"loading": "Loading...",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@loading": {
"description": "Loading..."
teolemon marked this conversation as resolved.
Show resolved Hide resolved
},
"know_more": "Know More",
"@know_more": {
"description": "Know More"
},
"offline_data_desc": "Click to know more about offline data",
"@offline_data_desc": {
"description": "Click to know more about offline data"
},
"offline_product_data_title": "Offline Product Data",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@offline_product_data_title": {
"description": "Offline Product Data"
},
"available_for_download": "{num} products available for immediate scaning",
"@available_for_download": {
"description": "text to show details of products available for download",
"placeholders": {
"num": {
"type": "int"
}
}
}
}
42 changes: 23 additions & 19 deletions packages/smooth_app/lib/pages/offline_data_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
daoProduct: daoProduct,
),
_OfflinePageListTile(
title: 'Download Data',
subtitle:
'Download the top 1000 products in your country for instant scanning',
title: appLocalizations.download_data,
subtitle: appLocalizations.download_top_products,
onTap: () async {
final LocalDatabase localDatabase =
context.read<LocalDatabase>();
final DaoProduct daoProduct = DaoProduct(localDatabase);
final int newlyAddedProducts = await LoadingDialog.run<int>(
title: 'Downloading data\nThis may take a while',
title: appLocalizations.download_in_progress,
context: context,
future:
PreloadDataHelper(daoProduct).downloadTopProducts(),
Expand All @@ -140,21 +139,22 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$newlyAddedProducts products added'),
content: Text(
appLocalizations.downloaded_products(newlyAddedProducts),
),
),
);
localDatabase.notifyListeners();
},
trailing: const Icon(Icons.download),
),
_OfflinePageListTile(
title: 'Update Offline Product Data',
subtitle:
'Update the local product database with the latest data from server',
title: appLocalizations.update_offline_data,
subtitle: appLocalizations.update_local_database_sub,
trailing: const Icon(Icons.refresh),
onTap: () async {
final int newlyAddedProducts = await LoadingDialog.run<int>(
title: 'Downloading data\nThis may take a while',
title: appLocalizations.download_in_progress,
context: context,
future: updateLocalDatabaseFromServer(context),
) ??
Expand All @@ -164,7 +164,8 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'$newlyAddedProducts products updated',
appLocalizations
.downloaded_products(newlyAddedProducts),
),
duration: SnackBarDuration.brief,
),
Expand All @@ -173,16 +174,17 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
},
),
_OfflinePageListTile(
title: 'Clear Offline Product Data',
subtitle:
'Clear all local product data from your app to free up space',
title: appLocalizations.clear_local_database,
subtitle: appLocalizations.clear_local_database_sub,
trailing: const Icon(Icons.delete),
onTap: () async {
final int totalProductsDeleted = await daoProduct.deleteAll();
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('$totalProductsDeleted products deleted'),
content: Text(
appLocalizations.deleted_products(totalProductsDeleted),
),
duration: SnackBarDuration.brief,
),
);
Expand All @@ -191,8 +193,8 @@ class _OfflineDataPageState extends State<OfflineDataPage> {
},
),
_OfflinePageListTile(
title: 'Know More',
subtitle: 'Click to know more about offline data',
title: appLocalizations.know_more,
subtitle: appLocalizations.offline_data_desc,
trailing: const Icon(Icons.info),
// ignore: avoid_returning_null_for_void
onTap: () => null,
Expand All @@ -215,18 +217,20 @@ class _StatsWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final AppLocalizations applocalizations = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE),
child: ListTile(
title: const Text('Offline Product Data'),
title: Text(applocalizations.offline_product_data_title),
subtitle: FutureBuilder<int>(
future: daoProduct.getTotalNoOfProducts(),
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
if (snapshot.hasData) {
return Text(
'${snapshot.data} products available for immediate scaning');
applocalizations.available_for_download(snapshot.data!),
);
} else {
return const Text('Loading...');
return Text(applocalizations.loading);
}
},
),
Expand Down