mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-02-17 14:30:40 +01:00
feat: Archive with clean up
This commit is contained in:
parent
2b9bd9cdc0
commit
f366ab6a22
@ -21,6 +21,11 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
|
"clearArchive": "Clear archive",
|
||||||
|
"@people": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
"publicGroups": "Public Groups",
|
"publicGroups": "Public Groups",
|
||||||
"@publicGroups": {
|
"@publicGroups": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:fluffychat/views/ui/archive_ui.dart';
|
import 'package:fluffychat/views/ui/archive_ui.dart';
|
||||||
import 'package:fluffychat/views/widgets/matrix.dart';
|
import 'package:fluffychat/views/widgets/matrix.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
|
|
||||||
class Archive extends StatefulWidget {
|
class Archive extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -18,6 +21,31 @@ class ArchiveController extends State<Archive> {
|
|||||||
|
|
||||||
void forgetAction(int i) => setState(() => archive.removeAt(i));
|
void forgetAction(int i) => setState(() => archive.removeAt(i));
|
||||||
|
|
||||||
|
void forgetAllAction() async {
|
||||||
|
if (await showOkCancelAlertDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).areYouSure,
|
||||||
|
okLabel: L10n.of(context).yes,
|
||||||
|
cancelLabel: L10n.of(context).cancel,
|
||||||
|
message: L10n.of(context).clearArchive,
|
||||||
|
useRootNavigator: false,
|
||||||
|
) !=
|
||||||
|
OkCancelResult.ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await showFutureLoadingDialog(
|
||||||
|
context: context,
|
||||||
|
future: () async {
|
||||||
|
while (archive.isNotEmpty) {
|
||||||
|
Logs().v('Forget room ${archive.last.displayname}');
|
||||||
|
await archive.last.forget();
|
||||||
|
archive.removeLast();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
setState(() => null);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => ArchiveUI(this);
|
Widget build(BuildContext context) => ArchiveUI(this);
|
||||||
}
|
}
|
||||||
|
@ -11,34 +11,48 @@ class ArchiveUI extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return FutureBuilder<List<Room>>(
|
||||||
appBar: AppBar(
|
future: controller.getArchive(context),
|
||||||
leading: BackButton(),
|
builder: (BuildContext context, snapshot) => Scaffold(
|
||||||
title: Text(L10n.of(context).archive),
|
appBar: AppBar(
|
||||||
),
|
leading: BackButton(),
|
||||||
body: FutureBuilder<List<Room>>(
|
title: Text(L10n.of(context).archive),
|
||||||
future: controller.getArchive(context),
|
actions: [
|
||||||
builder: (BuildContext context, snapshot) {
|
if (snapshot.hasData &&
|
||||||
if (snapshot.hasError) {
|
controller.archive != null &&
|
||||||
return Center(
|
controller.archive.isNotEmpty)
|
||||||
child: Text(
|
TextButton(
|
||||||
L10n.of(context).oopsSomethingWentWrong,
|
onPressed: controller.forgetAllAction,
|
||||||
textAlign: TextAlign.center,
|
child: Text(L10n.of(context).clearArchive),
|
||||||
));
|
)
|
||||||
}
|
],
|
||||||
if (!snapshot.hasData) {
|
),
|
||||||
return Center(child: CircularProgressIndicator());
|
body: Builder(
|
||||||
} else {
|
builder: (BuildContext context) {
|
||||||
controller.archive = snapshot.data;
|
if (snapshot.hasError) {
|
||||||
return ListView.builder(
|
return Center(
|
||||||
itemCount: controller.archive.length,
|
child: Text(
|
||||||
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
L10n.of(context).oopsSomethingWentWrong,
|
||||||
controller.archive[i],
|
textAlign: TextAlign.center,
|
||||||
onForget: controller.forgetAction,
|
));
|
||||||
),
|
}
|
||||||
);
|
if (!snapshot.hasData) {
|
||||||
}
|
return Center(child: CircularProgressIndicator());
|
||||||
},
|
} else {
|
||||||
|
controller.archive = snapshot.data;
|
||||||
|
if (controller.archive.isEmpty) {
|
||||||
|
return Center(child: Icon(Icons.archive_outlined, size: 80));
|
||||||
|
}
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: controller.archive.length,
|
||||||
|
itemBuilder: (BuildContext context, int i) => ChatListItem(
|
||||||
|
controller.archive[i],
|
||||||
|
onForget: controller.forgetAction,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user