mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-06-25 09:04:07 +00:00
pre cache the chat list view
This commit is contained in:
parent
e4bc21ea10
commit
f278a1dd38
4 changed files with 27 additions and 55 deletions
|
|
@ -1,9 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cryptography_plus/cryptography_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
|
@ -13,7 +10,6 @@ import 'package:twonly/src/database/twonly.db.dart';
|
|||
import 'package:twonly/src/providers/purchases.provider.dart';
|
||||
import 'package:twonly/src/services/mediafiles/mediafile.service.dart';
|
||||
import 'package:twonly/src/services/subscription.service.dart';
|
||||
import 'package:twonly/src/services/user.service.dart';
|
||||
import 'package:twonly/src/utils/log.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
import 'package:twonly/src/visual/components/avatar_icon.comp.dart';
|
||||
|
|
@ -32,7 +28,7 @@ class ChatListView extends StatefulWidget {
|
|||
State<ChatListView> createState() => _ChatListViewState();
|
||||
}
|
||||
|
||||
class _ChatListViewState extends State<ChatListView> {
|
||||
class _ChatListViewState extends State<ChatListView> with AutomaticKeepAliveClientMixin<ChatListView> {
|
||||
StreamSubscription<void>? _userSub;
|
||||
StreamSubscription<List<Group>>? _contactsSub;
|
||||
StreamSubscription<List<Contact>>? _contactsCountSub;
|
||||
|
|
@ -126,32 +122,11 @@ class _ChatListViewState extends State<ChatListView> {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
final changeLog = await rootBundle.loadString('CHANGELOG.md');
|
||||
final changeLogHash = (await compute(
|
||||
Sha256().hash,
|
||||
changeLog.codeUnits,
|
||||
)).bytes;
|
||||
if (!userService.currentUser.hideChangeLog &&
|
||||
userService.currentUser.lastChangeLogHash.toString() !=
|
||||
changeLogHash.toString()) {
|
||||
await UserService.update((u) {
|
||||
u.lastChangeLogHash = changeLogHash;
|
||||
});
|
||||
if (!mounted) return;
|
||||
// only show changelog to people who already have contacts
|
||||
// this prevents that this is shown directly after the user registered
|
||||
if (_groupsNotPinned.isNotEmpty) {
|
||||
await context.push(
|
||||
Routes.settingsHelpChangelog,
|
||||
extra: changeLog,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_contactsSub?.cancel();
|
||||
|
|
@ -165,6 +140,7 @@ class _ChatListViewState extends State<ChatListView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final plan = context.watch<PurchasesProvider>().plan;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:app_links/app_links.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:flutter_sharing_intent/model/sharing_file.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
|
|
@ -268,6 +269,10 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
|||
setState(() {
|
||||
_offsetFromOne = 1.0 - (_homeViewPageController.page ?? 0);
|
||||
_offsetRatio = _offsetFromOne.abs();
|
||||
final pageIndex = _homeViewPageController.page?.round();
|
||||
if (pageIndex != null && pageIndex != _activePageIdx) {
|
||||
_activePageIdx = pageIndex;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -310,17 +315,19 @@ class HomeViewState extends State<HomeView> with WidgetsBindingObserver {
|
|||
NotificationListener<ScrollNotification>(
|
||||
onNotification: _onPageView,
|
||||
child: Positioned.fill(
|
||||
child: PageView(
|
||||
child: CustomScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: const PageScrollPhysics(),
|
||||
controller: _homeViewPageController,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_activePageIdx = index;
|
||||
});
|
||||
},
|
||||
children: [
|
||||
const ChatListView(),
|
||||
Container(),
|
||||
const MemoriesView(),
|
||||
scrollCacheExtent: const ScrollCacheExtent.viewport(1),
|
||||
slivers: [
|
||||
SliverFillViewport(
|
||||
delegate: SliverChildListDelegate([
|
||||
const ChatListView(),
|
||||
Container(),
|
||||
const MemoriesView(),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class MemoriesView extends StatefulWidget {
|
|||
State<MemoriesView> createState() => MemoriesViewState();
|
||||
}
|
||||
|
||||
class MemoriesViewState extends State<MemoriesView> {
|
||||
class MemoriesViewState extends State<MemoriesView> with AutomaticKeepAliveClientMixin<MemoriesView> {
|
||||
late final MemoriesService _service;
|
||||
final ValueNotifier<String?> _activeMediaIdNotifier = ValueNotifier(null);
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
|
@ -38,6 +38,9 @@ class MemoriesViewState extends State<MemoriesView> {
|
|||
_activeMediaIdNotifier.addListener(_onActiveMediaChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_activeMediaIdNotifier.removeListener(_onActiveMediaChanged);
|
||||
|
|
@ -369,6 +372,7 @@ class MemoriesViewState extends State<MemoriesView> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import 'dart:async';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:twonly/locator.dart';
|
||||
import 'package:twonly/src/services/user.service.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
|
||||
List<Widget> parseMarkdown(BuildContext context, String markdown) {
|
||||
|
|
@ -107,20 +106,6 @@ class _ChangeLogViewState extends State<ChangeLogView> {
|
|||
),
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: BottomAppBar(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(context.lang.openChangeLog),
|
||||
Switch.adaptive(
|
||||
value: !userService.currentUser.hideChangeLog,
|
||||
onChanged: (_) => UserService.update(
|
||||
(u) => u.hideChangeLog = !u.hideChangeLog,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue