From 8a72f62d149e24ba8009466e11da41c792d13e86 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Wed, 12 Oct 2022 19:54:04 +0600 Subject: [PATCH] fix(android): dynamic status bar and safearea, playerview artist link, login success redirect --- lib/components/Home/Shell.dart | 32 ++++++++++--------- lib/components/Library/UserLocalTracks.dart | 14 ++++++++ lib/components/Login/TokenLogin.dart | 2 +- lib/components/Login/WebViewLogin.dart | 3 +- lib/components/Player/PlayerView.dart | 4 +++ lib/components/Settings/Settings.dart | 1 - .../Shared/TrackCollectionView.dart | 2 +- lib/utils/type_conversion_utils.dart | 30 ++++++++++++----- 8 files changed, 61 insertions(+), 27 deletions(-) diff --git a/lib/components/Home/Shell.dart b/lib/components/Home/Shell.dart index 557df6eb1..06115aaef 100644 --- a/lib/components/Home/Shell.dart +++ b/lib/components/Home/Shell.dart @@ -10,6 +10,7 @@ import 'package:spotube/components/Shared/PageWindowTitleBar.dart'; import 'package:spotube/components/Shared/ReplaceDownloadedFileDialog.dart'; import 'package:spotube/hooks/useUpdateChecker.dart'; import 'package:spotube/provider/Downloader.dart'; +import 'package:spotube/utils/platform.dart'; const _path = { 0: "/", @@ -66,21 +67,22 @@ class Shell extends HookConsumerWidget { final preferredSize = allowedPath ? PageWindowTitleBar.staticPreferredSize : Size.zero; return Scaffold( - primary: true, - appBar: PreferredSize( - preferredSize: preferredSize, - child: AnimatedContainer( - duration: const Duration(milliseconds: 250), - height: - allowedPath ? PageWindowTitleBar.staticPreferredSize.height : 0, - child: AnimatedOpacity( - duration: const Duration(milliseconds: 250), - opacity: allowedPath ? 1 : 0, - child: PageWindowTitleBar(preferredSize: preferredSize), - ), - ), - ), - extendBodyBehindAppBar: true, + appBar: kIsDesktop + ? PreferredSize( + preferredSize: preferredSize, + child: AnimatedContainer( + duration: const Duration(milliseconds: 250), + height: allowedPath + ? PageWindowTitleBar.staticPreferredSize.height + : 0, + child: AnimatedOpacity( + duration: const Duration(milliseconds: 250), + opacity: allowedPath ? 1 : 0, + child: PageWindowTitleBar(preferredSize: preferredSize), + ), + ), + ) + : null, body: Row( children: [ Sidebar( diff --git a/lib/components/Library/UserLocalTracks.dart b/lib/components/Library/UserLocalTracks.dart index df523c3a3..445757436 100644 --- a/lib/components/Library/UserLocalTracks.dart +++ b/lib/components/Library/UserLocalTracks.dart @@ -7,9 +7,11 @@ import 'package:metadata_god/metadata_god.dart'; import 'package:mime/mime.dart'; import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/components/LoaderShimmers/ShimmerTrackTile.dart'; import 'package:spotube/components/Shared/TrackTile.dart'; +import 'package:spotube/hooks/useAsyncEffect.dart'; import 'package:spotube/models/CurrentPlaylist.dart'; import 'package:spotube/models/Logger.dart'; import 'package:spotube/provider/Playback.dart'; @@ -132,6 +134,18 @@ class UserLocalTracks extends HookConsumerWidget { final playback = ref.watch(playbackProvider); final isPlaylistPlaying = playback.playlist?.id == "local"; final trackSnapshot = ref.watch(localTracksProvider); + + useAsyncEffect( + () async { + if (!await Permission.storage.isGranted && + !await Permission.storage.isLimited) { + await Permission.storage.request(); + } + }, + null, + [], + ); + return Column( children: [ Padding( diff --git a/lib/components/Login/TokenLogin.dart b/lib/components/Login/TokenLogin.dart index 16c0dea9b..9515d816a 100644 --- a/lib/components/Login/TokenLogin.dart +++ b/lib/components/Login/TokenLogin.dart @@ -38,7 +38,7 @@ class TokenLogin extends HookConsumerWidget { ), const SizedBox(height: 10), TokenLoginForm( - onDone: () => ServiceUtils.navigate(context, "/"), + onDone: () => GoRouter.of(context).go("/"), ), const SizedBox(height: 10), Wrap( diff --git a/lib/components/Login/WebViewLogin.dart b/lib/components/Login/WebViewLogin.dart index 5204772aa..3a58dcd96 100644 --- a/lib/components/Login/WebViewLogin.dart +++ b/lib/components/Login/WebViewLogin.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; +import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotube/provider/Auth.dart'; import 'package:spotube/utils/platform.dart'; @@ -61,7 +62,7 @@ class WebViewLogin extends HookConsumerWidget { ); if (mounted()) { // ignore: use_build_context_synchronously - ServiceUtils.navigate(context, "/"); + GoRouter.of(context).go("/"); } } }, diff --git a/lib/components/Player/PlayerView.dart b/lib/components/Player/PlayerView.dart index 51cc8dc03..391ae4c6c 100644 --- a/lib/components/Player/PlayerView.dart +++ b/lib/components/Player/PlayerView.dart @@ -100,6 +100,10 @@ class PlayerView extends HookConsumerWidget { fontWeight: FontWeight.bold, color: paletteColor.bodyTextColor, ), + onRouteChange: (route) { + GoRouter.of(context).pop(); + GoRouter.of(context).push(route); + }, ), ], ), diff --git a/lib/components/Settings/Settings.dart b/lib/components/Settings/Settings.dart index 948f639d6..67f659375 100644 --- a/lib/components/Settings/Settings.dart +++ b/lib/components/Settings/Settings.dart @@ -49,7 +49,6 @@ class Settings extends HookConsumerWidget { return SafeArea( child: Scaffold( appBar: PageWindowTitleBar( - leading: const BackButton(), center: Text( "Settings", style: Theme.of(context).textTheme.headline5, diff --git a/lib/components/Shared/TrackCollectionView.dart b/lib/components/Shared/TrackCollectionView.dart index c0e41d642..a1e872a50 100644 --- a/lib/components/Shared/TrackCollectionView.dart +++ b/lib/components/Shared/TrackCollectionView.dart @@ -112,7 +112,7 @@ class TrackCollectionView extends HookConsumerWidget { return SafeArea( child: Scaffold( - appBar: (kIsDesktop) + appBar: kIsDesktop ? PageWindowTitleBar( backgroundColor: color?.color, foregroundColor: color?.titleTextColor, diff --git a/lib/utils/type_conversion_utils.dart b/lib/utils/type_conversion_utils.dart index 708cc3782..970a1afe2 100644 --- a/lib/utils/type_conversion_utils.dart +++ b/lib/utils/type_conversion_utils.dart @@ -5,10 +5,12 @@ import 'dart:io'; import 'package:flutter/widgets.dart' hide Image; import 'package:metadata_god/metadata_god.dart' hide Image; import 'package:path/path.dart'; +import 'package:spotube/components/Shared/AnchorButton.dart'; import 'package:spotube/components/Shared/LinkText.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/models/SpotubeTrack.dart'; import 'package:spotube/utils/primitive_utils.dart'; +import 'package:spotube/utils/service_utils.dart'; import 'package:youtube_explode_dart/youtube_explode_dart.dart'; enum ImagePlaceholder { @@ -46,6 +48,7 @@ abstract class TypeConversionUtils { WrapCrossAlignment crossAxisAlignment = WrapCrossAlignment.center, WrapAlignment mainAxisAlignment = WrapAlignment.center, TextStyle textStyle = const TextStyle(), + void Function(String route)? onRouteChange, }) { return Wrap( crossAxisAlignment: crossAxisAlignment, @@ -54,14 +57,25 @@ abstract class TypeConversionUtils { .asMap() .entries .map( - (artist) => LinkText( - (artist.key != artists.length - 1) - ? "${artist.value.name}, " - : artist.value.name!, - "/artist/${artist.value.id}", - overflow: TextOverflow.ellipsis, - style: textStyle, - ), + (artist) => Builder(builder: (context) { + return AnchorButton( + (artist.key != artists.length - 1) + ? "${artist.value.name}, " + : artist.value.name!, + onTap: () { + if (onRouteChange != null) { + onRouteChange("/artist/${artist.value.id}"); + } else { + ServiceUtils.navigate( + context, + "/artist/${artist.value.id}", + ); + } + }, + overflow: TextOverflow.ellipsis, + style: textStyle, + ); + }), ) .toList(), );