Skip to content

Commit

Permalink
Add pagination in home media list
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Mar 26, 2024
1 parent 84d20f0 commit 5ac8ff8
Show file tree
Hide file tree
Showing 18 changed files with 460 additions and 260 deletions.
4 changes: 2 additions & 2 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 63 additions & 2 deletions app/lib/components/app_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ class AppPage extends StatelessWidget {
final Widget? leading;
final Widget? floatingActionButton;
final Widget? body;
final Widget Function(BuildContext context)? bodyBuilder;
final bool automaticallyImplyLeading;
final bool? resizeToAvoidBottomInset;
final Color? backgroundColor;
final Color? barBackgroundColor;

const AppPage({
super.key,
Expand All @@ -21,7 +24,10 @@ class AppPage extends StatelessWidget {
this.body,
this.floatingActionButton,
this.resizeToAvoidBottomInset,
this.bodyBuilder,
this.automaticallyImplyLeading = true,
this.barBackgroundColor,
this.backgroundColor,
});

@override
Expand All @@ -39,6 +45,7 @@ class AppPage extends StatelessWidget {
leading == null
? null
: CupertinoNavigationBar(
backgroundColor: barBackgroundColor,
leading: leading,
middle: titleWidget ?? _title(context),
border: null,
Expand All @@ -56,10 +63,15 @@ class AppPage extends StatelessWidget {
: null,
),
resizeToAvoidBottomInset: resizeToAvoidBottomInset ?? true,
backgroundColor: backgroundColor,
child: Stack(
alignment: Alignment.bottomRight,
children: [
body ?? const SizedBox(),
body ??
Builder(
builder: (context) =>
bodyBuilder?.call(context) ?? const SizedBox(),
),
SafeArea(
child: Padding(
padding: const EdgeInsets.only(right: 16, bottom: 16),
Expand All @@ -76,12 +88,18 @@ class AppPage extends StatelessWidget {
leading == null
? null
: AppBar(
backgroundColor: barBackgroundColor,
title: titleWidget ?? _title(context),
actions: actions,
leading: leading,
automaticallyImplyLeading: automaticallyImplyLeading,
),
body: body,
body: body ??
Builder(
builder: (context) =>
bodyBuilder?.call(context) ?? const SizedBox(),
),
backgroundColor: backgroundColor,
floatingActionButton: floatingActionButton,
resizeToAvoidBottomInset: resizeToAvoidBottomInset,
);
Expand All @@ -92,3 +110,46 @@ class AppPage extends StatelessWidget {
overflow: TextOverflow.ellipsis,
);
}

class AdaptiveAppBar extends StatelessWidget {
final String text;
final Widget? leading;
final List<Widget>? actions;
final bool iosTransitionBetweenRoutes;
final bool automaticallyImplyLeading;

const AdaptiveAppBar(
{super.key,
required this.text,
this.leading,
this.actions,
this.iosTransitionBetweenRoutes = true,
this.automaticallyImplyLeading = true});

@override
Widget build(BuildContext context) {
return Platform.isIOS || Platform.isMacOS
? CupertinoNavigationBar(
transitionBetweenRoutes: iosTransitionBetweenRoutes,
middle: Text(text),
previousPageTitle:
MaterialLocalizations.of(context).backButtonTooltip,
automaticallyImplyLeading: automaticallyImplyLeading,
leading: leading,
trailing: actions == null
? null
: actions!.length == 1
? actions!.first
: Row(
mainAxisSize: MainAxisSize.min,
children: actions!,
),
)
: AppBar(
leading: leading,
actions: actions,
automaticallyImplyLeading: automaticallyImplyLeading,
title: Text(text),
);
}
}
96 changes: 49 additions & 47 deletions app/lib/ui/flow/accounts/accounts_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,56 +39,58 @@ class _AccountsScreenState extends ConsumerState<AccountsScreen> {

return AppPage(
title: context.l10n.common_accounts,
body: ListView(
padding: const EdgeInsets.all(16),
children: [
if (googleAccount != null)
AccountsTab(
name: googleAccount.displayName ?? googleAccount.email,
serviceDescription: context.l10n.common_google_drive,
profileImage: googleAccount.photoUrl,
actionList: ActionList(buttons: [
ActionListButton(
title: context.l10n.common_auto_back_up,
trailing: Consumer(
builder: (context, ref, child) {
final googleDriveAutoBackUp = ref
.watch(AppPreferences.canTakeAutoBackUpInGoogleDrive);
return AppSwitch(
value: googleDriveAutoBackUp,
onChanged: (bool value) {
ref
.read(AppPreferences
.canTakeAutoBackUpInGoogleDrive.notifier)
.state = value;
},
);
},
bodyBuilder: (context) {
return ListView(
padding: context.systemPadding + const EdgeInsets.all(16),
children: [
if (googleAccount != null)
AccountsTab(
name: googleAccount.displayName ?? googleAccount.email,
serviceDescription: context.l10n.common_google_drive,
profileImage: googleAccount.photoUrl,
actionList: ActionList(buttons: [
ActionListButton(
title: context.l10n.common_auto_back_up,
trailing: Consumer(
builder: (context, ref, child) {
final googleDriveAutoBackUp = ref.watch(
AppPreferences.canTakeAutoBackUpInGoogleDrive);
return AppSwitch(
value: googleDriveAutoBackUp,
onChanged: (bool value) {
ref
.read(AppPreferences
.canTakeAutoBackUpInGoogleDrive.notifier)
.state = value;
},
);
},
),
),
ActionListButton(
title: context.l10n.common_sign_out,
onPressed: notifier.signOutWithGoogle,
),
]),
backgroundColor: AppColors.googleDriveColor.withAlpha(50),
),
if (googleAccount == null)
OnTapScale(
onTap: () {
notifier.signInWithGoogle();
},
child: AccountsTab(
name: context.l10n.add_account_title,
backgroundColor: context.colorScheme.containerNormal,
),
ActionListButton(
title: context.l10n.common_sign_out,
onPressed: notifier.signOutWithGoogle,
),
]),
backgroundColor: AppColors.googleDriveColor.withAlpha(50),
),
if (googleAccount == null)
OnTapScale(
onTap: () {
notifier.signInWithGoogle();
},
child: AccountsTab(
name: context.l10n.add_account_title,
backgroundColor: context.colorScheme.containerNormal,
),
),
const SizedBox(height: 16),
const SettingsActionList(),
const SizedBox(height: 16),
_buildVersion(context: context),
],
),
const SizedBox(height: 16),
const SettingsActionList(),
const SizedBox(height: 16),
_buildVersion(context: context),
],
);
},
);
}

Expand Down
67 changes: 35 additions & 32 deletions app/lib/ui/flow/home/components/app_media_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_svg/svg.dart';
import 'package:style/extensions/context_extensions.dart';
import 'package:style/indicators/circular_progress_indicator.dart';
import 'package:video_player/video_player.dart';
import '../../../../domain/assets/assets_paths.dart';
import 'package:style/animations/item_selector.dart';

Expand All @@ -30,47 +31,47 @@ class AppMediaItem extends StatefulWidget {

class _AppMediaItemState extends State<AppMediaItem>
with AutomaticKeepAliveClientMixin {
//VideoPlayerController? _videoPlayerController;
VideoPlayerController? _videoPlayerController;

@override
void initState() {
///TODO: Video view
// if (widget.media.type.isVideo &&
// widget.media.sources.contains(AppMediaSource.local)) {
//
// _videoPlayerController =
// VideoPlayerController.file(File(widget.media.path))
// ..initialize().then((_) {
// setState(() {});
// });
//
// }
if (widget.media.type.isVideo &&
widget.media.sources.contains(AppMediaSource.local)) {
_videoPlayerController =
VideoPlayerController.file(File(widget.media.path))
..initialize().then((_) {
setState(() {});
});
}
super.initState();
}

@override
void dispose() {
// _videoPlayerController?.dispose();
_videoPlayerController?.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
super.build(context);
return ItemSelector(
onTap: widget.onTap,
onLongTap: widget.onLongTap,
isSelected: widget.isSelected,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Stack(
alignment: Alignment.bottomLeft,
children: [
widget.media.type.isVideo && widget.media.thumbnailLink == null
? _buildVideoView(context: context)
: _buildImageView(context: context),
_sourceIndicators(context: context),
],
return LayoutBuilder(
builder: (context, constraints) => ItemSelector(
onTap: widget.onTap,
onLongTap: widget.onLongTap,
isSelected: widget.isSelected,
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Stack(
alignment: Alignment.bottomLeft,
children: [
widget.media.type.isVideo && widget.media.thumbnailLink == null
? _buildVideoView(context: context)
: _buildImageView(context: context, constraints: constraints),
_sourceIndicators(context: context),
],
),
),
),
);
Expand Down Expand Up @@ -114,9 +115,11 @@ class _AppMediaItemState extends State<AppMediaItem>
);
}

Widget _buildImageView({required BuildContext context}) {
return LayoutBuilder(builder: (context, constraints) {
return Image(
Widget _buildImageView(
{required BuildContext context, required BoxConstraints constraints}) {
return Hero(
tag: widget.media,
child: Image(
image: widget.media.sources.contains(AppMediaSource.local)
? ResizeImage(
FileImage(File(widget.media.path)),
Expand Down Expand Up @@ -162,8 +165,8 @@ class _AppMediaItemState extends State<AppMediaItem>
},
width: double.maxFinite,
height: double.maxFinite,
);
});
),
);
}

Widget _buildVideoView({required BuildContext context}) {
Expand All @@ -174,7 +177,7 @@ class _AppMediaItemState extends State<AppMediaItem>
decoration: BoxDecoration(
color: context.colorScheme.containerNormalOnSurface,
),
// child: VideoPlayer(_videoPlayerController!),
child: VideoPlayer(_videoPlayerController!),
),
Icon(CupertinoIcons.play_arrow_solid,
color: context.colorScheme.onPrimary),
Expand Down
Loading

0 comments on commit 5ac8ff8

Please sign in to comment.