From ee081de0abeae8b1a0a877a292438abec76b40d5 Mon Sep 17 00:00:00 2001 From: zoe Date: Sun, 3 Jul 2022 15:47:24 +0200 Subject: [PATCH] scaling the timeline --- lib/business_logic/settings.dart | 20 ++++++ lib/business_logic/timeline/timeline.dart | 1 + lib/global.dart | 3 + lib/i18n/de.json | 14 ++++ lib/i18n/de_DE.json | 13 ---- lib/i18n/en.json | 14 ++++ lib/i18n/en_US.json | 13 ---- lib/main.dart | 15 +++-- lib/pages/login.dart | 25 ++----- lib/pages/timeline/timeline.dart | 14 ++-- lib/partials/main_scaffold.dart | 14 ++-- lib/partials/post.dart | 82 +++++++++++++++++++++++ lib/partials/thread.dart | 35 ++++++++++ pubspec.yaml | 2 - 14 files changed, 202 insertions(+), 63 deletions(-) create mode 100644 lib/business_logic/timeline/timeline.dart create mode 100644 lib/i18n/de.json delete mode 100644 lib/i18n/de_DE.json create mode 100644 lib/i18n/en.json delete mode 100644 lib/i18n/en_US.json create mode 100644 lib/partials/post.dart create mode 100644 lib/partials/thread.dart diff --git a/lib/business_logic/settings.dart b/lib/business_logic/settings.dart index 759d177..2f5cde5 100644 --- a/lib/business_logic/settings.dart +++ b/lib/business_logic/settings.dart @@ -1,4 +1,7 @@ +import 'package:flutter/painting.dart'; +import 'package:intl/intl.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import '../global.dart' as global; enum Settings { instanceUrl, @@ -38,3 +41,20 @@ Future loadAuthCode() async { } return code; } + +Future saveLocale(String locale) async { + final prefs = await SharedPreferences.getInstance(); + return await prefs.setString("active-locale", locale); +} + +Future loadLocale() async { + final prefs = await SharedPreferences.getInstance(); + String? locale = prefs.getString("active-locale"); + if (locale == null) { + if (global.availableLocales.contains(Locale(Intl.systemLocale))) { + return Locale(Intl.systemLocale); + } + return const Locale("en"); + } + return Locale(locale); +} diff --git a/lib/business_logic/timeline/timeline.dart b/lib/business_logic/timeline/timeline.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/business_logic/timeline/timeline.dart @@ -0,0 +1 @@ + diff --git a/lib/global.dart b/lib/global.dart index 92c91f5..27cef8f 100644 --- a/lib/global.dart +++ b/lib/global.dart @@ -1,3 +1,5 @@ +import 'package:flutter/painting.dart'; + const String name = "slothmu"; const String version = "v0.1 'not even alpha'"; const String useragent = "$name/$version"; @@ -8,3 +10,4 @@ const Map defaultHeaders = { "Content-Type": "application/json" }; const List bad = ["gab.com", "spinster.xyz", "truthsocial.com"]; +const List availableLocales = [Locale("en"), Locale("de")]; diff --git a/lib/i18n/de.json b/lib/i18n/de.json new file mode 100644 index 0000000..01145a9 --- /dev/null +++ b/lib/i18n/de.json @@ -0,0 +1,14 @@ +{ + "greeting": "hallo!", + "instance-url": "anbieter url", + "instance-url-example": "beispiel.de", + "authorize-in-browser": "im browser autorisieren", + "login-failed-snackbar-text": "login fehlgeschlagen!", + "back-button": "zurück", + "confirm-button": "bestätigen", + "timeline" : "timeline", + "chat": "chat", + "notifications": "benachrichtigungen", + "settings": "einstellungen" +} + \ No newline at end of file diff --git a/lib/i18n/de_DE.json b/lib/i18n/de_DE.json deleted file mode 100644 index d9ed071..0000000 --- a/lib/i18n/de_DE.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "greeting": "hallo!", - "user-id-not-valid": "hmm... die id sieht nicht ganz richtig aus...", - "user-id": "nutzer id", - "user-id-example": "nutzer@beispiel.de", - "authorize-in-browser": "im browser autorisieren", - "login-failed-snackbar-text": "login fehlgeschlagen!", - "back-button": "zurück", - "confirm-button": "bestätigen", - "copy-code-from-browser": "bitte den code aus dem browser hierhin kopieren.", - "code-hint": "code" -} - \ No newline at end of file diff --git a/lib/i18n/en.json b/lib/i18n/en.json new file mode 100644 index 0000000..73e68cf --- /dev/null +++ b/lib/i18n/en.json @@ -0,0 +1,14 @@ +{ + "greeting": "hello!", + "instance-url": "instance url", + "instance-url-example": "example.com", + "authorize-in-browser": "authorize in browser", + "login-failed-snackbar-text": "login failed!", + "back-button": "back", + "confirm-button": "confirm", + "timeline" : "timeline", + "chat": "chat", + "notifications": "notifications", + "settings": "settings" +} + \ No newline at end of file diff --git a/lib/i18n/en_US.json b/lib/i18n/en_US.json deleted file mode 100644 index 5dc5fab..0000000 --- a/lib/i18n/en_US.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "greeting": "hello!", - "user-id-not-valid": "sorry, this user id doesn't look quite right... ", - "user-id": "user id", - "user-id-example": "user@example.com", - "authorize-in-browser": "authorize in browser", - "login-failed-snackbar-text": "login failed!", - "back-button": "back", - "confirm-button": "confirm", - "copy-code-from-browser": "please copy the code from your browser here!", - "code-hint": "code" -} - \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index ccc0671..7408759 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,16 +6,20 @@ import 'pages/login.dart'; import 'business_logic/settings.dart' as settings; import 'package:flutter_localizations/flutter_localizations.dart'; import 'themes/themes.dart' as themes; +import 'global.dart' as global; String _initRoute = "/"; ThemeData theme = themes.getTheme(themes.available[0]); +Locale activeLocale = const Locale("en"); void main() async { - Intl.defaultLocale = 'en_US'; + Intl.defaultLocale = "en"; + await settings.saveLocale("en"); + activeLocale = await settings.loadLocale(); // check if all information is available if (await settings.loadAuthCode() == "") { - _initRoute = "/login"; + _initRoute = "/"; } runApp(const Slothmu()); } @@ -28,16 +32,13 @@ class Slothmu extends StatefulWidget { } class _SlothmuState extends State { - List supported = const [ - Locale("en", "US"), - Locale("de", "DE"), - ]; @override Widget build(BuildContext context) { LocalJsonLocalization.delegate.directories = ['lib/i18n']; return MaterialApp( theme: theme, - supportedLocales: supported, + locale: activeLocale, + supportedLocales: global.availableLocales, localizationsDelegates: [ GlobalCupertinoLocalizations.delegate, GlobalWidgetsLocalizations.delegate, diff --git a/lib/pages/login.dart b/lib/pages/login.dart index 5948d02..0693034 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; -import 'package:slothmu/business_logic/user.dart'; import 'package:localization/localization.dart'; import '../business_logic/auth/oauth.dart' as oauth; import '../business_logic/settings.dart' as settings; -import '../business_logic/user.dart' as user; class Login extends StatefulWidget { const Login({Key? key}) : super(key: key); @@ -47,23 +45,15 @@ class _LoginFormState extends State { Text("greeting".i18n(), style: Theme.of(context).textTheme.headline1), TextFormField( onSaved: (value) async { - await settings - .saveInstanceUrl(user.urlFromUsername(name: value!)); - await settings.saveUsername(user.userFromUsername(name: value)); + await settings.saveInstanceUrl(value!); }, decoration: InputDecoration( - labelText: "user-id".i18n(), - hintText: "user-id-example".i18n(), - icon: const Icon(Icons.person), - prefixText: "@", + labelText: "instance-url".i18n(), + hintText: "instance-url-example".i18n(), + icon: const Icon(Icons.home), + prefixText: "https://", ), autofocus: true, - validator: (value) { - if (value!.isEmpty || !isValidUsername(name: value)) { - return "user-id-not-valid".i18n(); - } - return null; - }, ), TextButton.icon( onPressed: () { @@ -76,8 +66,7 @@ class _LoginFormState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => - const AuthPage(baseurl: "kittycat.homes"), + builder: (context) => const AuthPage(), )); } }, @@ -93,7 +82,7 @@ class _LoginFormState extends State { page that handles authenticating user */ class AuthPage extends StatefulWidget { - const AuthPage({Key? key, required String baseurl}) : super(key: key); + const AuthPage({Key? key}) : super(key: key); @override State createState() => _AuthPageState(); diff --git a/lib/pages/timeline/timeline.dart b/lib/pages/timeline/timeline.dart index 2aa666a..7403167 100644 --- a/lib/pages/timeline/timeline.dart +++ b/lib/pages/timeline/timeline.dart @@ -1,9 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:slothmu/partials/post.dart'; +import 'package:slothmu/partials/thread.dart'; Widget timeline(context) { - return Padding( - padding: const EdgeInsets.all(24), - child: Column( - children: [], - )); + return Container( + child: ListView( + padding: const EdgeInsets.fromLTRB(24, 0, 24, 64), + addAutomaticKeepAlives: false, + children: [Thread(), Thread(), Thread()], + ), + ); } diff --git a/lib/partials/main_scaffold.dart b/lib/partials/main_scaffold.dart index ce92bdf..51bfa11 100644 --- a/lib/partials/main_scaffold.dart +++ b/lib/partials/main_scaffold.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:localization/localization.dart'; import 'package:slothmu/pages/chat/chat.dart'; import 'package:slothmu/pages/notifications/notifications.dart'; import 'package:slothmu/pages/timeline/timeline.dart'; @@ -47,13 +48,16 @@ class _MainScaffoldState extends State { onDestinationSelected: (index) => setState(() => this.index = index), selectedIndex: index, - destinations: const [ - NavigationDestination(icon: Icon(Icons.forum), label: "Timeline"), - NavigationDestination(icon: Icon(Icons.chat), label: "Chat"), + destinations: [ NavigationDestination( - icon: Icon(Icons.notifications), label: "Notifications"), + icon: const Icon(Icons.forum), label: "timeline".i18n()), NavigationDestination( - icon: Icon(Icons.settings), label: "Settings"), + icon: const Icon(Icons.chat), label: "chat".i18n()), + NavigationDestination( + icon: const Icon(Icons.notifications), + label: "notifications".i18n()), + NavigationDestination( + icon: const Icon(Icons.settings), label: "settings".i18n()), ]), ), ); diff --git a/lib/partials/post.dart b/lib/partials/post.dart new file mode 100644 index 0000000..bc6e309 --- /dev/null +++ b/lib/partials/post.dart @@ -0,0 +1,82 @@ +import 'package:flutter/material.dart'; + +class Post extends StatefulWidget { + const Post({Key? key}) : super(key: key); + + @override + State createState() => _PostState(); +} + +class _PostState extends State { + @override + Widget build(BuildContext context) { + return Column( + children: [ + Row( + children: [ + const Icon( + Icons.face, + size: 64, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "first name display last name name", + style: Theme.of(context).textTheme.titleMedium, + ), + Text( + "@alice_exampleuser@example.com", + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ), + ], + ), + postBody(context), + postActionBar(context), + ], + ); + } +} + +Widget postBody(context) { + return Container( + padding: const EdgeInsets.fromLTRB(24, 6, 6, 6), + decoration: BoxDecoration( + border: Border( + left: BorderSide(color: Theme.of(context).colorScheme.onSurface), + ), + ), + child: RichText( + textAlign: TextAlign.start, + text: const TextSpan( + text: + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Risus commodo viverra maecenas accumsan lacus vel facilisis volutpat est. Diam in arcu cursus euismod quis viverra. Elementum sagittis vitae et leo duis."), + ), + ); +} + +Widget postActionBar(context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + onPressed: () {}, + icon: const Icon(Icons.reply), + ), + IconButton( + onPressed: () {}, + icon: const Icon(Icons.repeat), + ), + IconButton( + onPressed: () {}, + icon: const Icon(Icons.favorite_outline), + ), + IconButton( + onPressed: () {}, + icon: const Icon(Icons.more_horiz), + ) + ], + ); +} diff --git a/lib/partials/thread.dart b/lib/partials/thread.dart new file mode 100644 index 0000000..e6d4570 --- /dev/null +++ b/lib/partials/thread.dart @@ -0,0 +1,35 @@ +import 'package:flutter/material.dart'; +import 'package:slothmu/partials/post.dart'; + +class Thread extends StatefulWidget { + const Thread({Key? key}) : super(key: key); + + @override + State createState() => _ThreadState(); +} + +class _ThreadState extends State { + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + padding: const EdgeInsets.all(24), + width: MediaQuery.of(context).size.width / 1.2, + constraints: const BoxConstraints(maxWidth: 1000, minWidth: 375), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + border: Border.symmetric( + horizontal: BorderSide( + color: Theme.of(context).colorScheme.background, + width: 12)), + ), + child: Column( + children: [Post(), Post(), Post()], + ), + ), + ], + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index f49952c..e5dc731 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -68,8 +68,6 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - lib/i18n/ - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware