From e5a63d74ac5ceb4762a8fb85695f63ef0eaad292 Mon Sep 17 00:00:00 2001 From: Lukas Nagel Date: Fri, 1 Nov 2024 11:41:10 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Login=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 +- lib/apis/auth_info_api.dart | 4 +- lib/apis/inventory_api.dart | 12 +-- lib/apis/metadata_api.dart | 4 +- lib/globals/auth_globals.dart | 4 +- lib/globals/preference_globals.dart | 5 - lib/views/detail_views/episode_detail.dart | 4 +- lib/views/detail_views/movie_detail.dart | 4 +- lib/views/login.dart | 114 ++++++++++++++++----- 9 files changed, 108 insertions(+), 46 deletions(-) delete mode 100644 lib/globals/preference_globals.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index c84c776..8e5abf5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,7 +2,8 @@ "cSpell.words": [ "autofocus", "Focusable", - "fullscreen" + "fullscreen", + "grey" ], "cmake.sourceDirectory": "/home/lna-dev/Documents/Repos/OpenMediaStation.FE.MovieTV/windows/runner" } \ No newline at end of file diff --git a/lib/apis/auth_info_api.dart b/lib/apis/auth_info_api.dart index 263c9f2..9d0e60f 100644 --- a/lib/apis/auth_info_api.dart +++ b/lib/apis/auth_info_api.dart @@ -1,12 +1,12 @@ import 'dart:convert'; import 'package:open_media_server_app/apis/base_api.dart'; import 'package:http/http.dart' as http; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/auth/auth_info.dart'; class AuthInfoApi { Future getAuthInfo() async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/auth/info"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/auth/info"; var headers = BaseApi.getHeaders(); diff --git a/lib/apis/inventory_api.dart b/lib/apis/inventory_api.dart index 8e649e4..92644d8 100644 --- a/lib/apis/inventory_api.dart +++ b/lib/apis/inventory_api.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'package:open_media_server_app/apis/base_api.dart'; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/inventory/episode.dart'; import 'package:open_media_server_app/models/inventory/inventory_item.dart'; import 'package:http/http.dart' as http; @@ -10,7 +10,7 @@ import 'package:open_media_server_app/models/inventory/show.dart'; class InventoryApi { Future> listItems(String category) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/items?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/items?"; var headers = BaseApi.getHeaders(); @@ -26,7 +26,7 @@ class InventoryApi { } Future getMovie(String id) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/movie?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/movie?"; var headers = BaseApi.getHeaders(); @@ -42,7 +42,7 @@ class InventoryApi { } Future getShow(String id) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/show?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/show?"; var headers = BaseApi.getHeaders(); @@ -58,7 +58,7 @@ class InventoryApi { } Future getSeason(String id) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/season?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/season?"; var headers = BaseApi.getHeaders(); @@ -74,7 +74,7 @@ class InventoryApi { } Future getEpisode(String id) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/episode?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/episode?"; var headers = BaseApi.getHeaders(); diff --git a/lib/apis/metadata_api.dart b/lib/apis/metadata_api.dart index 9cf3e2b..a1f3946 100644 --- a/lib/apis/metadata_api.dart +++ b/lib/apis/metadata_api.dart @@ -1,12 +1,12 @@ import 'dart:convert'; import 'package:open_media_server_app/apis/base_api.dart'; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/metadata/metadata_model.dart'; import 'package:http/http.dart' as http; class MetadataApi { Future getMetadata(String id, String category) async { - String apiUrl = "${PreferenceGlobals.BaseUrl}/api/metadata?"; + String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/metadata?"; var headers = BaseApi.getHeaders(); diff --git a/lib/globals/auth_globals.dart b/lib/globals/auth_globals.dart index 8ca32f2..01108de 100644 --- a/lib/globals/auth_globals.dart +++ b/lib/globals/auth_globals.dart @@ -1,12 +1,12 @@ import 'package:flutter/foundation.dart'; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; class AuthGlobals { static String get redirectUriWeb { if (kDebugMode) { return "http://localhost:8000/redirect.html"; } else { - return "https://${PreferenceGlobals.BaseUrl}/redirect.html"; + return "https://${Preferences.prefs?.getString("BaseUrl")}/redirect.html"; } } diff --git a/lib/globals/preference_globals.dart b/lib/globals/preference_globals.dart deleted file mode 100644 index 71b51cb..0000000 --- a/lib/globals/preference_globals.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:open_media_server_app/helpers/preferences.dart'; - -class PreferenceGlobals { - static String BaseUrl = Preferences.prefs!.getString("BaseUrl")!; -} \ No newline at end of file diff --git a/lib/views/detail_views/episode_detail.dart b/lib/views/detail_views/episode_detail.dart index 2302e39..682a32b 100644 --- a/lib/views/detail_views/episode_detail.dart +++ b/lib/views/detail_views/episode_detail.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:open_media_server_app/globals/globals.dart'; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/internal/grid_item_model.dart'; import 'package:open_media_server_app/views/player.dart'; import 'package:open_media_server_app/widgets/custom_image.dart'; @@ -72,7 +72,7 @@ class EpisodeDetailView extends StatelessWidget { MaterialPageRoute( builder: (context) => PlayerView( url: - "${PreferenceGlobals.BaseUrl}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), + "${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), ), ); }, diff --git a/lib/views/detail_views/movie_detail.dart b/lib/views/detail_views/movie_detail.dart index 6101047..012a14c 100644 --- a/lib/views/detail_views/movie_detail.dart +++ b/lib/views/detail_views/movie_detail.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:open_media_server_app/globals/globals.dart'; -import 'package:open_media_server_app/globals/preference_globals.dart'; +import 'package:open_media_server_app/helpers/preferences.dart'; import 'package:open_media_server_app/models/internal/grid_item_model.dart'; import 'package:open_media_server_app/views/player.dart'; import 'package:open_media_server_app/widgets/custom_image.dart'; @@ -71,7 +71,7 @@ class MovieDetailView extends StatelessWidget { MaterialPageRoute( builder: (context) => PlayerView( url: - "${PreferenceGlobals.BaseUrl}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), + "${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"), ), ); }, diff --git a/lib/views/login.dart b/lib/views/login.dart index 2e8c11e..89abb46 100644 --- a/lib/views/login.dart +++ b/lib/views/login.dart @@ -14,6 +14,21 @@ class LoginView extends StatelessWidget { @override Widget build(BuildContext context) { + if (Preferences.prefs?.getString("BaseUrl") != null) { + return FutureBuilder( + future: authenticate(context), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } + + return widget; + }, + ); + } + return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).scaffoldBackgroundColor, @@ -22,32 +37,83 @@ class LoginView extends StatelessWidget { ), body: Form( key: _formKey, - child: Column( - children: [ - TextFormField( - controller: domainController, - decoration: const InputDecoration( - hintText: 'Domain', + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + children: [ + TextFormField( + controller: domainController, + decoration: InputDecoration( + hintText: 'Host', + contentPadding: const EdgeInsets.symmetric( + vertical: 16.0, + horizontal: 16.0, + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(12.0), + borderSide: BorderSide( + color: Colors.grey[400]!, + width: 1.5, + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(12.0), + borderSide: const BorderSide( + color: Colors.blue, + width: 2.0, + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(12.0), + borderSide: BorderSide( + color: Colors.grey[400]!, + width: 1.5, + ), + ), + ), + validator: (String? value) { + if (value == null || value.isEmpty) { + return 'Please enter some text'; + } + + if (!value.contains("http://") && !value.contains("https://")) { + return 'You need to specify the host in this format\nExample: https://example.com'; + } + + return null; + }, ), - validator: (String? value) { - if (value == null || value.isEmpty) { - return 'Please enter some text'; - } - return null; - }, - ), - ElevatedButton( - onPressed: () async { - if (_formKey.currentState!.validate()) { - Preferences.prefs! - .setString("BaseUrl", domainController.text); + const SizedBox( + height: 16, + ), + SizedBox( + width: double.infinity, + height: 40, + child: ElevatedButton( + onPressed: () async { + if (_formKey.currentState!.validate()) { + await Preferences.prefs! + .setString("BaseUrl", domainController.text); - authenticate(context); - } - }, - child: const Text("Submit"), - ), - ], + await authenticate(context); + } + }, + style: ElevatedButton.styleFrom( + padding: const EdgeInsets.symmetric( + vertical: 8, + ), + textStyle: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.w400, + ), + backgroundColor: Colors.white, + foregroundColor: Colors.black, + ), + child: const Text("Connect"), + ), + ), + ], + ), ), ), );