refactor: MVC archive
This commit is contained in:
parent
ca70ec0240
commit
bff8a2629a
8 changed files with 88 additions and 27 deletions
|
|
@ -1,21 +1,13 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/controllers/archive_controller.dart';
|
||||
import 'package:fluffychat/views/widgets/list_items/chat_list_item.dart';
|
||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class Archive extends StatefulWidget {
|
||||
@override
|
||||
_ArchiveState createState() => _ArchiveState();
|
||||
}
|
||||
class ArchiveView extends StatelessWidget {
|
||||
final ArchiveController controller;
|
||||
|
||||
class _ArchiveState extends State<Archive> {
|
||||
List<Room> archive;
|
||||
|
||||
Future<List<Room>> getArchive(BuildContext context) async {
|
||||
if (archive != null) return archive;
|
||||
return await Matrix.of(context).client.archive;
|
||||
}
|
||||
const ArchiveView(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -25,17 +17,25 @@ class _ArchiveState extends State<Archive> {
|
|||
title: Text(L10n.of(context).archive),
|
||||
),
|
||||
body: FutureBuilder<List<Room>>(
|
||||
future: getArchive(context),
|
||||
future: controller.getArchive(context),
|
||||
builder: (BuildContext context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child: Text(
|
||||
L10n.of(context).oopsSomethingWentWrong,
|
||||
textAlign: TextAlign.center,
|
||||
));
|
||||
}
|
||||
if (!snapshot.hasData) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
archive = snapshot.data;
|
||||
controller.archive = snapshot.data;
|
||||
return ListView.builder(
|
||||
itemCount: archive.length,
|
||||
itemCount: controller.archive.length,
|
||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||
archive[i],
|
||||
onForget: () => setState(() => archive.removeAt(i))),
|
||||
controller.archive[i],
|
||||
onForget: controller.forgetAction,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
@ -86,7 +86,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
|
||||
void _initWithStore() async {
|
||||
try {
|
||||
await client.init();
|
||||
if (!testMode) await client.init();
|
||||
if (client.isLogged()) {
|
||||
final statusMsg = await store.getItem(SettingKeys.ownStatusMessage);
|
||||
if (statusMsg?.isNotEmpty ?? false) {
|
||||
|
|
@ -261,7 +261,7 @@ class MatrixState extends State<Matrix> with WidgetsBindingObserver {
|
|||
});
|
||||
});
|
||||
}
|
||||
client = widget.testClient ?? FluffyClient();
|
||||
client = FluffyClient();
|
||||
LoadingDialog.defaultTitle = L10n.of(context).loadingPleaseWait;
|
||||
LoadingDialog.defaultBackLabel = L10n.of(context).close;
|
||||
LoadingDialog.defaultOnError = (Object e) => e.toLocalizedString(context);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue