Skip to content

Commit

Permalink
Option for revoking internet access
Browse files Browse the repository at this point in the history
  • Loading branch information
ferraridamiano committed Feb 4, 2024
1 parent 4f4b8d3 commit 2f55ae8
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final isEverythingLoadedProvider = Provider<bool>((ref) =>
ref.watch(SignificantFigures.provider).hasValue &&
ref.watch(RemoveTrailingZeros.provider).hasValue &&
ref.watch(IsDarkAmoled.provider).hasValue &&
ref.watch(RevokeInternetNotifier.provider).hasValue &&
ref.watch(CurrentThemeMode.provider).hasValue &&
ref.watch(CurrentLocale.provider).hasValue &&
ref.watch(PropertiesOrderNotifier.provider).hasValue &&
Expand Down
3 changes: 2 additions & 1 deletion lib/models/currencies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ final currenciesProvider = FutureProvider<Currencies>((ref) async {
String? lastUpdate = pref.getString("lastUpdateCurrencies");
// if I have never updated the conversions or if I have updated before today
// I have to update
if (lastUpdate == null || lastUpdate != now) {
if (!(ref.read(RevokeInternetNotifier.provider).valueOrNull ?? false) &&
(lastUpdate == null || lastUpdate != now)) {
return downloadCurrencies();
}
// If I already have the data of today I just use it, no need of read them
Expand Down
17 changes: 17 additions & 0 deletions lib/models/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ class IsDarkAmoled extends AsyncNotifier<bool> {
}
}

class RevokeInternetNotifier extends AsyncNotifier<bool> {
static const _prefKey = 'revokeInternet';
static final provider = AsyncNotifierProvider<RevokeInternetNotifier, bool>(
RevokeInternetNotifier.new);

@override
Future<bool> build() async {
var pref = await ref.watch(sharedPref.future);
return pref.getBool(_prefKey) ?? false;
}

void set(bool value) {
state = AsyncData(value);
ref.read(sharedPref.future).then((pref) => pref.setBool(_prefKey, value));
}
}

class CurrentThemeMode extends AsyncNotifier<ThemeMode> {
static const _prefKey = 'currentThemeMode';
static final provider =
Expand Down
55 changes: 54 additions & 1 deletion lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,59 @@ class SettingsPage extends ConsumerWidget {
},
shape: const RoundedRectangleBorder(borderRadius: borderRadius),
),
if (!kIsWeb)
SwitchListTile(
secondary: Icon(Icons.public_off, color: iconColor),
title: Text(
AppLocalizations.of(context)!.revokeInternetAccess,
style: textStyle,
),
value:
ref.watch(RevokeInternetNotifier.provider).valueOrNull ?? false,
activeColor: Theme.of(context).colorScheme.secondary,
onChanged: (bool val) {
if (val) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(
AppLocalizations.of(context)!.revokeInternetAccess,
),
content: SizedBox(
width: 500,
child: Text(
AppLocalizations.of(context)!
.revokeInternetExplanation,
style: Theme.of(context).textTheme.bodyLarge,
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
// Introduce a tiny delay to let the user see the
// switch to turn on
Future.delayed(
const Duration(milliseconds: 200),
() => ref
.read(
RevokeInternetNotifier.provider.notifier)
.set(val),
);
},
child: Text(AppLocalizations.of(context)!.ok),
),
],
);
},
);
} else {
ref.read(RevokeInternetNotifier.provider.notifier).set(val);
}
},
shape: const RoundedRectangleBorder(borderRadius: borderRadius),
),
SwitchListTile(
secondary: SvgPicture(
const AssetBytesLoader(
Expand Down Expand Up @@ -280,7 +333,7 @@ class SettingsPage extends ConsumerWidget {
width: 500,
child: Text(
AppLocalizations.of(context)!.donationDialog,
style: const TextStyle(fontSize: 18),
style: Theme.of(context).textTheme.bodyLarge,
),
),
actions: <Widget>[
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "تراجُع",
"routeError1": "هذه الصفحة غير موجودة",
"routeError2": "الروجوع إلى الصفحة الأولى",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "الطول",
"area": "المساحة",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_ca.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Desfés",
"routeError1": "Aquesta pàgina no existeix",
"routeError2": "Torna a la primera pàgina",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Longitud",
"area": "Àrea",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Rückgängig machen",
"routeError1": "Diese Seite existiert nicht.",
"routeError2": "Zurück zur ersten Seite gehen",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Länge",
"area": "Fläche",
Expand Down
3 changes: 3 additions & 0 deletions packages/translations/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"undo": "Undo",
"routeError1": "This page doesn't exist",
"routeError2": "Go back to the first page",
"ok": "Ok",
"revokeInternetAccess": "Revoke internet access",
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",

"length": "Length",
"area": "Area",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@
"@routeError2": {
"description": "Not yet translated. Once done, remove this comment"
},
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Longitud",
"area": "Área",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Annuler",
"routeError1": "Cette page n'existe pas",
"routeError2": "Revenir à la première page",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Distance",
"area": "Superficie",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_hr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Poništi",
"routeError1": "Ova stranica ne postoji",
"routeError2": "Vrati se na prvu stranicu",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Duljina",
"area": "Površina",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_id.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Urung",
"routeError1": "Halaman ini tidak ada",
"routeError2": "Kembali ke beranda",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Panjang",
"area": "Luas",
Expand Down
3 changes: 3 additions & 0 deletions packages/translations/lib/l10n/app_it.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"undo": "Annulla",
"routeError1": "Questa pagina non esiste",
"routeError2": "Ritorna alla prima pagina",
"ok": "Ok",
"revokeInternetAccess": "Revoca l'accesso a internet",
"revokeInternetExplanation": "Questa app utilizza internet per aggiornare i tassi di cambio delle valute una volta al giorno (quando viene aperta). Si tratta di pochi chilobyte di download, ma se non hai bisogno di questa funzionalità puoi prevenire che la app acceda ad intenet abilitando questa opzione.",

"length": "Lunghezza",
"area": "Superficie",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_ja.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "元に戻す",
"routeError1": "このページは存在しません。",
"routeError2": "先頭ページに戻る",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "長さ",
"area": "面積",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_nb.arb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@
"undo": "Angre",
"routeError1": "Denne siden finnes ikke",
"routeError2": "Gå tilbake til den første siden",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Lengde",
"area": "Areal",
Expand Down
14 changes: 13 additions & 1 deletion packages/translations/lib/l10n/app_nl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"placeholders": {
"property": {
"type": "String",
"voorbeeld": "Lengte"
"example": "Lengte"
}
}
},
Expand All @@ -53,6 +53,18 @@
"undo": "Ongedaan maken",
"routeError1": "Deze pagina lijkt niet te bestaan",
"routeError2": "Ga terug naar de eerste pagina",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Lengte",
"area": "Oppervlak",
Expand Down
14 changes: 13 additions & 1 deletion packages/translations/lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@reorderProperty":{
"placeholders": {
"property": {
"type": "Ciąg",
"type": "String",
"example": "Długość"
}
}
Expand All @@ -53,6 +53,18 @@
"undo": "Cofnij",
"routeError1": "Ta strona nie istnieje",
"routeError2": "Wróć do pierwszej strony",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Długość",
"area": "Powierzchnia",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_pt.arb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
"@routeError2": {
"description": "Not yet translated. Once done, remove this comment"
},
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Comprimento",
"area": "Área",
Expand Down
12 changes: 12 additions & 0 deletions packages/translations/lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@
"undo": "Отмена",
"routeError1": "Этой страницы не существует",
"routeError2": "Вернутся на первую страницу",
"ok": "Ok",
"@ok": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetAccess": "Revoke internet access",
"@revokeInternetAccess": {
"description": "Not yet translated. Once done, remove this comment"
},
"revokeInternetExplanation": "This app uses the internet to update currency exchange rates once a day (when opened). It is a few kilobytes of download, but if you do not need this feature you can prevent the app from accessing the intenet by enabling this option.",
"@revokeInternetExplanation": {
"description": "Not yet translated. Once done, remove this comment"
},

"length": "Длина",
"area": "Площадь",
Expand Down
Loading

0 comments on commit 2f55ae8

Please sign in to comment.