2022-02-03 09:06:44 -07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-02-03 21:08:22 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
2022-02-05 23:07:56 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/image_grid.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/ui/profile_drawer.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
class HomePage extends HookConsumerWidget {
|
|
|
|
const HomePage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final ValueNotifier<bool> _showBackToTopBtn = useState(false);
|
|
|
|
ScrollController _scrollController = useScrollController();
|
2022-02-05 23:07:56 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
List<ImmichAssetGroupByDate> assetGroup = ref.watch(assetProvider);
|
|
|
|
List<Widget> imageGridGroup = [];
|
2022-02-03 21:08:22 -07:00
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
_scrollControllerCallback() {
|
|
|
|
var endOfPage = _scrollController.position.maxScrollExtent;
|
|
|
|
|
|
|
|
if (_scrollController.offset >= endOfPage - (endOfPage * 0.1) && !_scrollController.position.outOfRange) {
|
|
|
|
ref.read(assetProvider.notifier).getMoreAsset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_scrollController.offset >= 400) {
|
|
|
|
_showBackToTopBtn.value = true;
|
|
|
|
} else {
|
|
|
|
_showBackToTopBtn.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
ref.read(assetProvider.notifier).getImmichAssets();
|
|
|
|
|
|
|
|
_scrollController.addListener(_scrollControllerCallback);
|
|
|
|
|
2022-02-03 20:01:14 -07:00
|
|
|
return () {
|
|
|
|
_scrollController.removeListener(_scrollControllerCallback);
|
|
|
|
};
|
|
|
|
}, []);
|
|
|
|
|
2022-02-03 09:06:44 -07:00
|
|
|
Widget _buildBody() {
|
|
|
|
if (assetGroup.isNotEmpty) {
|
|
|
|
String lastGroupDate = assetGroup[0].date;
|
|
|
|
|
|
|
|
for (var group in assetGroup) {
|
|
|
|
var dateTitle = group.date;
|
|
|
|
var assetGroup = group.assets;
|
|
|
|
|
|
|
|
int? currentMonth = DateTime.tryParse(dateTitle)?.month;
|
|
|
|
int? previousMonth = DateTime.tryParse(lastGroupDate)?.month;
|
|
|
|
|
2022-02-04 09:41:51 -07:00
|
|
|
// Add Monthly Title Group if started at the beginning of the month
|
2022-02-03 09:06:44 -07:00
|
|
|
if ((currentMonth! - previousMonth!) != 0) {
|
2022-02-03 21:08:22 -07:00
|
|
|
imageGridGroup.add(
|
2022-02-05 23:07:56 -07:00
|
|
|
MonthlyTitleText(isoDate: dateTitle),
|
2022-02-03 21:08:22 -07:00
|
|
|
);
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
2022-02-04 09:41:51 -07:00
|
|
|
// Add Daily Title Group
|
2022-02-03 09:06:44 -07:00
|
|
|
imageGridGroup.add(
|
2022-02-05 23:07:56 -07:00
|
|
|
DailyTitleText(isoDate: dateTitle),
|
2022-02-03 09:06:44 -07:00
|
|
|
);
|
|
|
|
|
2022-02-04 09:41:51 -07:00
|
|
|
// Add Image Group
|
2022-02-03 21:08:22 -07:00
|
|
|
imageGridGroup.add(
|
|
|
|
ImageGrid(assetGroup: assetGroup),
|
|
|
|
);
|
2022-02-05 23:07:56 -07:00
|
|
|
//
|
2022-02-03 09:06:44 -07:00
|
|
|
lastGroupDate = dateTitle;
|
|
|
|
}
|
2022-02-03 20:01:14 -07:00
|
|
|
}
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-02-03 21:18:21 -07:00
|
|
|
return SafeArea(
|
|
|
|
child: DraggableScrollbar.semicircle(
|
2022-02-04 09:41:51 -07:00
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
2022-02-03 21:08:22 -07:00
|
|
|
controller: _scrollController,
|
2022-02-04 09:41:51 -07:00
|
|
|
heightScrollThumb: 48.0,
|
2022-02-03 21:18:21 -07:00
|
|
|
child: CustomScrollView(
|
|
|
|
controller: _scrollController,
|
|
|
|
slivers: [
|
|
|
|
ImmichSliverAppBar(imageGridGroup: imageGridGroup),
|
|
|
|
...imageGridGroup,
|
|
|
|
],
|
|
|
|
),
|
2022-02-03 21:08:22 -07:00
|
|
|
),
|
2022-02-03 20:01:14 -07:00
|
|
|
);
|
2022-02-03 09:06:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
drawer: const ProfileDrawer(),
|
|
|
|
body: _buildBody(),
|
2022-02-03 21:08:22 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MonthlyTitleText extends StatelessWidget {
|
|
|
|
const MonthlyTitleText({
|
|
|
|
Key? key,
|
2022-02-05 23:07:56 -07:00
|
|
|
required this.isoDate,
|
2022-02-03 21:08:22 -07:00
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-02-05 23:07:56 -07:00
|
|
|
final String isoDate;
|
2022-02-03 21:08:22 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-02-05 23:07:56 -07:00
|
|
|
var monthTitleText = DateFormat('MMMM, y').format(DateTime.parse(isoDate));
|
|
|
|
|
2022-02-03 21:08:22 -07:00
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 10.0, top: 32),
|
|
|
|
child: Text(
|
|
|
|
monthTitleText,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-02-03 09:06:44 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-02-04 09:41:51 -07:00
|
|
|
|
|
|
|
class DailyTitleText extends StatelessWidget {
|
|
|
|
const DailyTitleText({
|
|
|
|
Key? key,
|
2022-02-05 23:07:56 -07:00
|
|
|
required this.isoDate,
|
2022-02-04 09:41:51 -07:00
|
|
|
}) : super(key: key);
|
|
|
|
|
2022-02-05 23:07:56 -07:00
|
|
|
final String isoDate;
|
2022-02-04 09:41:51 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var currentYear = DateTime.now().year;
|
2022-02-05 23:07:56 -07:00
|
|
|
var groupYear = DateTime.parse(isoDate).year;
|
2022-02-04 09:41:51 -07:00
|
|
|
var formatDateTemplate = currentYear == groupYear ? 'E, MMM dd' : 'E, MMM dd, yyyy';
|
2022-02-05 23:07:56 -07:00
|
|
|
var dateText = DateFormat(formatDateTemplate).format(DateTime.parse(isoDate));
|
2022-02-04 09:41:51 -07:00
|
|
|
|
|
|
|
return SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24.0, bottom: 24.0, left: 3.0),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 8.0, bottom: 5.0, top: 5.0),
|
|
|
|
child: Text(
|
|
|
|
dateText,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: Colors.black87,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|