Skip to content

Commit

Permalink
feat: disabling quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
orl0pl committed Oct 19, 2024
1 parent 0c44c51 commit 4c6e2fc
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 27 deletions.
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,7 @@
"unknown_location": "Unknown location",
"weeks_num_plural": "{weeksNum, plural, =0{weeks} =1{week} =2{weeks} few{weeks} many{weeks} other{weeks}}",
"wind_speed_unit": "Wind speed unit",
"years_num_plural": "{yearsNum, plural, =0{years} =1{year} =2{years} few{years} many{years} other{years}}"
"years_num_plural": "{yearsNum, plural, =0{years} =1{year} =2{years} few{years} many{years} other{years}}",
"enable_quotes": "Enable quotes",
"@enable_quotes": {}
}
3 changes: 2 additions & 1 deletion lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@
"unknown_location": "Nieznana lokalizacja",
"weeks_num_plural": "{weeksNum, plural, =0{tygodnie} =1{tydzień} =2{tygodnie} few{tygodnie} many{tygodnie} other{tygodnie}}",
"wind_speed_unit": "Jednostka prędkości wiatru",
"years_num_plural": "{yearsNum, plural, =0{lata} =1{rok} =2{lata} few{lata} many{lat} other{lat}}"
"years_num_plural": "{yearsNum, plural, =0{lata} =1{rok} =2{lata} few{lata} many{lat} other{lat}}",
"enable_quotes": "Włącz cytaty"
}
39 changes: 28 additions & 11 deletions lib/screens/settings/manage_quotes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ManageQuotesScreen extends StatefulWidget {

class _ManageQuotesScreenState extends State<ManageQuotesScreen> {
SharedPreferences? prefs;
bool? quotesEnabled;
bool? dywlQuotesEnabled;

@override
Expand All @@ -24,30 +25,46 @@ class _ManageQuotesScreenState extends State<ManageQuotesScreen> {

setState(() {
dywlQuotesEnabled = prefs?.getBool('dywlQuotesEnabled') ?? false;
quotesEnabled = prefs?.getBool('quotesEnabled') ?? false;
});
}

void savePrefs() async {
prefs?.setBool('dywlQuotesEnabled', dywlQuotesEnabled ?? false);
}

bool get loading => quotesEnabled == null || dywlQuotesEnabled == null;

@override
Widget build(BuildContext context) {
AppLocalizations l = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(l.manage_quotes),
),
body: ListView(children: [
SwitchListTile(
title: Text(l.api_enabled("dywl/quotes")),
value: dywlQuotesEnabled ?? false,
onChanged: (value) {
setState(() {
dywlQuotesEnabled = value;
});
savePrefs();
}),
]));
body: loading
? const Center(child: CircularProgressIndicator())
: ListView(children: [
SwitchListTile(
title: Text(l.enable_quotes),
value: quotesEnabled!,
onChanged: (value) {
setState(() {
quotesEnabled = value;
});
savePrefs();
}),
SwitchListTile(
title: Text(l.api_enabled("dywl/quotes")),
value: dywlQuotesEnabled!,
onChanged: quotesEnabled!
? (value) {
setState(() {
dywlQuotesEnabled = value;
});
savePrefs();
}
: null),
]));
}
}
26 changes: 24 additions & 2 deletions lib/widgets/start_subscreen/inspiration.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:maximum/utils/quotesy.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Inspiration extends StatefulWidget {
const Inspiration({
Expand All @@ -14,6 +15,13 @@ class _InspirationState extends State<Inspiration> {
String _quote =
'„Tutaj być postawiony cytat, powitanie, cel długoterminowy, że zmienia się co jakiś czas.”';
String _author = '– designer aplikacji';
bool? dywlQuotesEnabled;

void fetchPrefs() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
dywlQuotesEnabled = prefs.getBool('dywlQuotesEnabled');
print(dywlQuotesEnabled);
}

void loadDywlQuote() async {
var quote = await Quotes.random();
Expand All @@ -26,13 +34,27 @@ class _InspirationState extends State<Inspiration> {
@override
void initState() {
super.initState();
loadDywlQuote();
loadQuote();
}

void loadQuote() async {
fetchPrefs();
if (dywlQuotesEnabled == true) {
loadDywlQuote();
} else {
var quote = 'No quotes available';
var author = 'No quotes available';
setState(() {
_quote = quote;
_author = author;
});
}
}

@override
Widget build(BuildContext context) {
return InkWell(
onLongPress: loadDywlQuote,
onLongPress: loadQuote,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand Down
64 changes: 57 additions & 7 deletions lib/widgets/subscreens/apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:maximum/data/database_helper.dart';
import 'package:maximum/data/models/note.dart';
import 'package:intl/intl.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:skeletonizer/skeletonizer.dart';

enum ElementType { app, note }

Expand Down Expand Up @@ -177,6 +176,46 @@ class AppsWidgetState extends State<AppsWidget> {
}
}

enum AppCategory {
accessibility,
audio,
game,
image,
maps,
news,
productivity,
social,
undefined,
video
}

AppCategory appCategoryFromInt(int i) {
switch (i) {
case -1:
return AppCategory.undefined;
case 8:
return AppCategory.accessibility;
case 1:
return AppCategory.audio;
case 0:
return AppCategory.game;
case 3:
return AppCategory.image;
case 6:
return AppCategory.maps;
case 5:
return AppCategory.news;
case 7:
return AppCategory.productivity;
case 4:
return AppCategory.social;
case 2:
return AppCategory.video;
default:
return AppCategory.undefined;
}
}

class AppListEntry extends StatelessWidget {
const AppListEntry({
super.key,
Expand Down Expand Up @@ -210,22 +249,33 @@ class AppListEntry extends StatelessWidget {
},
);
} else {
return const CircularProgressIndicator(); // or some other loading indicator
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
);
}
},
),
subtitle: Text(app.flags.toString()),
//subtitle: Text(appCategoryFromInt(app.category ?? -1).toString()),
trailing: highlight ? const Icon(Icons.chevron_right) : null,
title: FutureBuilder<String?>(
future: app.getAppLabel(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(snapshot.data!);
} else {
return Skeletonizer(
enabled: !snapshot.hasData,
child: Text(
"${app.packageName}")); // or some other loading indicator
return Container(
width: app.packageName!.length * 8,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(16),
),
height: 16,
);
}
},
),
Expand Down
14 changes: 9 additions & 5 deletions lib/widgets/subscreens/start.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _StartWidgetState extends State<StartWidget> {
int? rankTune1;
int? rankTune2;
bool? showDebugScores;
bool? quotesEnabled;

@override
void initState() {
Expand All @@ -41,6 +42,7 @@ class _StartWidgetState extends State<StartWidget> {
int? rankTune1Memory = prefs.getInt('rankTune1');
int? rankTune2Memory = prefs.getInt('rankTune2');
bool? showDebugScoresMemory = prefs.getBool('showDebugScores');
bool? quotesEnabledMemory = prefs.getBool('quotesEnabled');
if (showDebugScoresMemory == null) {
prefs.setBool('showDebugScores', false);
}
Expand All @@ -52,9 +54,15 @@ class _StartWidgetState extends State<StartWidget> {
prefs.setInt('rankTune2', defaultRankTune2);
}

if (quotesEnabledMemory == null) {
prefs.setBool('quotesEnabled', true);
}

showDebugScores = showDebugScoresMemory ?? false;
rankTune1 = rankTune1Memory ?? defaultRankTune1;
rankTune2 = rankTune2Memory ?? defaultRankTune2;

quotesEnabled = quotesEnabledMemory ?? true;
}

void fetchTasks() {
Expand Down Expand Up @@ -124,10 +132,6 @@ class _StartWidgetState extends State<StartWidget> {
builder: (context, constraints) {
int? tasksThatFit;
try {
if (kDebugMode) {
print(
"${constraints.maxHeight} ${constraints.minHeight}");
}
tasksThatFit =
((constraints.maxHeight - 24) / 64).floor();
} on UnsupportedError catch (e) {
Expand Down Expand Up @@ -174,7 +178,7 @@ class _StartWidgetState extends State<StartWidget> {
),
),
const Spacer(),
const Inspiration()
if (quotesEnabled == true) const Inspiration()
],
),
),
Expand Down

0 comments on commit 4c6e2fc

Please sign in to comment.