Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
cleaner settings, added languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Incr3dible committed Jul 13, 2020
1 parent 5016e93 commit e7aaa76
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ buildscript {
ext.kotlin_version = '1.3.72'
repositories {
google()
mavenCentral()
jcenter()
}

Expand Down
Binary file added src/assets/de.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/uk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 74 additions & 57 deletions src/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MyAppState extends State<MyApp> {
primarySwatch: themeColor,
accentColor: themeColor,
toggleableActiveColor: themeColor,
appBarTheme: AppBarTheme(color: themeColor),
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.dark),
themeMode: themeMode,
Expand Down Expand Up @@ -84,7 +85,6 @@ class MainPageState extends State<MainPage>
with SingleTickerProviderStateMixin {
GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();
TabController controller;
PackageInfo packageInfo;
List<ApplicationWithIcon> games;
bool isLoading = true;
Resources resources;
Expand Down Expand Up @@ -127,8 +127,6 @@ class MainPageState extends State<MainPage>
}

void prepare() async {
packageInfo = await PackageInfo.fromPlatform();

await initRootRequest();
await Permission.storage.request();
await RootUtils.grantStoragePermissions();
Expand Down Expand Up @@ -205,80 +203,98 @@ class MainPageState extends State<MainPage>
],
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
child: Column(
children: <Widget>[
UserAccountsDrawerHeader(
accountName: Text(title),
decoration: BoxDecoration(
color: Colors.blueGrey[900],
),
accountEmail: packageInfo != null
? Text("Version: " +
packageInfo.version +
", Build: " +
packageInfo.buildNumber)
: Text(""),
),
ListTile(
enabled: _rootStatus,
title: Text('CR Event Images (ROOT)'),
leading: Icon(
Icons.image,
Flexible(
fit: FlexFit.tight,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(
color: Colors.blueGrey[900],
),
accountEmail: Text("an open source project"),
accountName: Text(title),
),
ListTile(
enabled: _rootStatus,
title: Text('CR Event Images (ROOT)'),
leading: Icon(
Icons.image,
),
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new EventPage("Clash Royale",
"com.supercell.clashroyale", "events"),
));
},
),
ListTile(
enabled: _rootStatus,
title: Text(
'COC Event Images (ROOT)',
),
leading: Icon(
Icons.image,
),
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) =>
new EventPage(
"Clash of Clans",
"com.supercell.clashofclans",
"events-coc"),
));
},
),
ListTile(
title: Text(
'Settings',
),
leading: Icon(
Icons.settings,
),
onTap: () {
Navigator.pushNamed(context, '/settings');
},
enabled: true,
),
],
),
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new EventPage(
"Clash Royale",
"com.supercell.clashroyale",
"events"),
));
},
),
ListTile(
enabled: _rootStatus,
title: Text(
'COC Event Images (ROOT)',
),
leading: Icon(
Icons.image,
),
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (BuildContext context) => new EventPage(
"Clash of Clans",
"com.supercell.clashofclans",
"events-coc"),
));
},
leading: Icon(Icons.open_in_new),
title: Text("More"),
subtitle: Text(
"looking for help or want to take a look at the code of this app?"),
),
Divider(),
ListTile(
title: Text(
'Settings',
'Discord',
),
leading: Icon(
Icons.settings,
Icons.chat,
),
onTap: () {
Navigator.pushNamed(context, '/settings');
launchURL('https://discord.gg/XdTw2PZ');
},
enabled: true,
),
Divider(),
ListTile(
title: Text(
'Discord',
'Github',
),
leading: Icon(
Icons.chat,
Icons.code,
),
onTap: () {
launchURL('https://discord.gg/XdTw2PZ');
launchURL('https://github.com/Incr3dible/sc-utility');
},
)
],
Expand Down Expand Up @@ -312,6 +328,7 @@ class MainPageState extends State<MainPage>
widgets.addAll(buildGames());

return ListView.builder(
padding: EdgeInsets.only(top: 8, left: 5, right: 5),
itemCount: widgets.length,
itemBuilder: (BuildContext ctx, int index) {
return widgets[index];
Expand Down
88 changes: 79 additions & 9 deletions src/lib/pages/settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../resources.dart';
import '../translationProvider.dart';

class SettingsPage extends StatefulWidget {
@override
Expand All @@ -13,12 +14,14 @@ class SettingsState extends State<SettingsPage> {
bool notificationsOn = false;
bool nightModeOn = false;
int nightModeState = 2;
int language = 0;

@override
void initState() {
resources = Resources.getInstance();
nightModeState = resources.prefs.getInt("themeMode") ?? 2;
notificationsOn = resources.prefs.getBool("notifications") ?? true;
language = resources.language();

super.initState();
}
Expand All @@ -33,6 +36,13 @@ class SettingsState extends State<SettingsPage> {
}
}

void onLanguageChanged(int value) {
setState(() {
language = value;
resources.prefs.setInt("language", value);
});
}

void handleRadioValueChanged(int value) {
setState(() {
nightModeState = value;
Expand Down Expand Up @@ -62,10 +72,12 @@ class SettingsState extends State<SettingsPage> {

@override
Widget build(BuildContext context) {
var version = resources.packageInfo.version;
var build = resources.packageInfo.buildNumber;

return Scaffold(
appBar: AppBar(
title: Text("Settings"),
backgroundColor: Colors.blueGrey[900],
title: Text(TranslationProvider.get("TID_SETTINGS")),
),
body: Column(
children: [
Expand All @@ -74,7 +86,7 @@ class SettingsState extends State<SettingsPage> {
child: ListView(
children: <Widget>[
ListTile(
title: Text("Notifications"),
title: Text(TranslationProvider.get("TID_NOTIFICATIONS")),
),
Container(
child: ListTile(
Expand All @@ -88,8 +100,9 @@ class SettingsState extends State<SettingsPage> {
? Icon(Icons.notifications_active)
: Icon(Icons.notifications_off),
title: Text(
"Maintenance Notifications",
TranslationProvider.get("TID_MAINTENANCE_NOTIFICATIONS"),
),
subtitle: Text(TranslationProvider.get("TID_MAINTENANCE_NOTIFICATION_DESC")),
trailing: Switch(
value: notificationsOn,
onChanged: (value) {
Expand All @@ -105,9 +118,10 @@ class SettingsState extends State<SettingsPage> {
),
Divider(),
ListTile(
leading: Icon(Icons.style),
title: Text(
"Theme",
)),
TranslationProvider.get("TID_THEME"),
)),
Center(
child: Row(
mainAxisSize: MainAxisSize.min,
Expand All @@ -117,13 +131,13 @@ class SettingsState extends State<SettingsPage> {
groupValue: nightModeState,
onChanged: handleRadioValueChanged,
),
Text("Light"),
Text(TranslationProvider.get("TID_LIGHT")),
Radio<int>(
value: 1,
groupValue: nightModeState,
onChanged: handleRadioValueChanged,
),
Text("Dark"),
Text(TranslationProvider.get("TID_DARK")),
Radio<int>(
value: 2,
groupValue: nightModeState,
Expand All @@ -133,7 +147,25 @@ class SettingsState extends State<SettingsPage> {
],
),
),
Divider()
Divider(),
ListTile(
leading: Icon(Icons.language),
title: Text(TranslationProvider.get("TID_LANGUAGE"))),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
flagButton(0, "assets/uk.png", language == 0),
flagButton(1, "assets/de.png", language == 1),
],
),
Divider(),
ListTile(
leading: Icon(Icons.info),
title: Text(
"Info",
),
subtitle: Text("Version: $version Build: $build"),
),
],
),
),
Expand All @@ -148,4 +180,42 @@ class SettingsState extends State<SettingsPage> {
],
));
}

Widget flagButton(int index, String assetImage, bool selected) {
return Stack(
children: <Widget>[
Container(
child: GestureDetector(
onTap: () {
onLanguageChanged(index);
},
),
margin: EdgeInsets.only(left: 10, right: 10, bottom: 10),
width: 45,
height: 30,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(assetImage), fit: BoxFit.fill),
borderRadius: BorderRadius.circular(6)),
),
selected
? Positioned.fill(
child: Align(
alignment: Alignment.bottomRight,
child: Container(
child: Icon(
Icons.done,
size: 20,
color: Colors.white,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).accentColor,
),
),
))
: SizedBox.shrink()
],
);
}
}
8 changes: 8 additions & 0 deletions src/lib/resources.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sc_utility/network/Client.dart';

Expand All @@ -24,6 +25,7 @@ class Resources {
MainPageState mainPage;
MyAppState myApp;
CrClientPageState clientPageState;
PackageInfo packageInfo;

bool isPopupOpen = false;
FirebaseMessaging firebaseMessaging;
Expand All @@ -43,6 +45,8 @@ class Resources {
firebaseMessaging.subscribeToTopic("everyone");
}

packageInfo = await PackageInfo.fromPlatform();

print("Initialized resources.");

initialized = true;
Expand All @@ -67,6 +71,10 @@ class Resources {
return ThemeMode.system;
}

int language(){
return prefs?.getInt("language") ?? 0;
}

String fingerprintSha() {
return prefs.getString("sha") ?? "unknown";
}
Expand Down
Loading

0 comments on commit e7aaa76

Please sign in to comment.