design: New encryption page
parent
ea4f2bffb0
commit
46d77bff5d
Binary file not shown.
After Width: | Height: | Size: 51 KiB |
@ -1,93 +1,45 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:vrouter/vrouter.dart';
|
import 'package:vrouter/vrouter.dart';
|
||||||
|
|
||||||
import '../../widgets/matrix.dart';
|
import '../../widgets/matrix.dart';
|
||||||
|
|
||||||
class EncryptionButton extends StatefulWidget {
|
class EncryptionButton extends StatelessWidget {
|
||||||
final Room room;
|
final Room room;
|
||||||
const EncryptionButton(this.room, {Key? key}) : super(key: key);
|
const EncryptionButton(this.room, {Key? key}) : super(key: key);
|
||||||
@override
|
|
||||||
EncryptionButtonState createState() => EncryptionButtonState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class EncryptionButtonState extends State<EncryptionButton> {
|
|
||||||
StreamSubscription? _onSyncSub;
|
|
||||||
|
|
||||||
void _enableEncryptionAction() async {
|
|
||||||
if (widget.room.encrypted) {
|
|
||||||
VRouter.of(context).toSegments(['rooms', widget.room.id, 'encryption']);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (widget.room.joinRules == JoinRules.public) {
|
|
||||||
await showOkAlertDialog(
|
|
||||||
useRootNavigator: false,
|
|
||||||
context: context,
|
|
||||||
okLabel: L10n.of(context)!.ok,
|
|
||||||
message: L10n.of(context)!.noEncryptionForPublicRooms,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (await showOkCancelAlertDialog(
|
|
||||||
useRootNavigator: false,
|
|
||||||
context: context,
|
|
||||||
title: L10n.of(context)!.enableEncryption,
|
|
||||||
message: widget.room.client.encryptionEnabled
|
|
||||||
? L10n.of(context)!.enableEncryptionWarning
|
|
||||||
: L10n.of(context)!.needPantalaimonWarning,
|
|
||||||
okLabel: L10n.of(context)!.yes,
|
|
||||||
cancelLabel: L10n.of(context)!.cancel,
|
|
||||||
) ==
|
|
||||||
OkCancelResult.ok) {
|
|
||||||
await showFutureLoadingDialog(
|
|
||||||
context: context,
|
|
||||||
future: () => widget.room.enableEncryption(),
|
|
||||||
);
|
|
||||||
// we want to enable the lock icon
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_onSyncSub?.cancel();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.room.encrypted) {
|
return StreamBuilder<SyncUpdate>(
|
||||||
_onSyncSub ??= Matrix.of(context)
|
stream: Matrix.of(context)
|
||||||
.client
|
.client
|
||||||
.onSync
|
.onSync
|
||||||
.stream
|
.stream
|
||||||
.where((s) => s.deviceLists != null)
|
.where((s) => s.deviceLists != null),
|
||||||
.listen((s) => setState(() {}));
|
builder: (context, snapshot) {
|
||||||
}
|
return FutureBuilder<EncryptionHealthState>(
|
||||||
return FutureBuilder<EncryptionHealthState>(
|
future: room.calcEncryptionHealthState(),
|
||||||
future: widget.room.calcEncryptionHealthState(),
|
builder: (BuildContext context, snapshot) => IconButton(
|
||||||
builder: (BuildContext context, snapshot) => IconButton(
|
tooltip: room.encrypted
|
||||||
tooltip: widget.room.encrypted
|
? L10n.of(context)!.encrypted
|
||||||
? L10n.of(context)!.encrypted
|
: L10n.of(context)!.encryptionNotEnabled,
|
||||||
: L10n.of(context)!.encryptionNotEnabled,
|
icon: Icon(
|
||||||
icon: Icon(
|
room.encrypted
|
||||||
widget.room.encrypted
|
? Icons.lock_outlined
|
||||||
? Icons.lock_outlined
|
: Icons.lock_open_outlined,
|
||||||
: Icons.lock_open_outlined,
|
size: 20,
|
||||||
size: 20,
|
color: room.joinRules != JoinRules.public &&
|
||||||
color: widget.room.joinRules != JoinRules.public &&
|
!room.encrypted
|
||||||
!widget.room.encrypted
|
? Colors.red
|
||||||
? Colors.red
|
: snapshot.data ==
|
||||||
: snapshot.data == EncryptionHealthState.unverifiedDevices
|
EncryptionHealthState.unverifiedDevices
|
||||||
? Colors.orange
|
? Colors.orange
|
||||||
: null),
|
: null),
|
||||||
onPressed: _enableEncryptionAction,
|
onPressed: () => VRouter.of(context)
|
||||||
));
|
.toSegments(['rooms', room.id, 'encryption']),
|
||||||
|
));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue