mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Update create user dialog
This commit is contained in:
@@ -2,12 +2,12 @@ import 'dart:convert';
|
||||
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eh_downloader_flutter/api/file.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
import 'api_result.dart';
|
||||
import 'config.dart';
|
||||
import 'eh.dart';
|
||||
import 'file.dart';
|
||||
import 'gallery.dart';
|
||||
import 'status.dart';
|
||||
import 'tags.dart';
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:enum_flag/enum_flag.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'user.g.dart';
|
||||
@@ -7,16 +9,35 @@ enum UserPermission with EnumFlag {
|
||||
readGallery,
|
||||
editGallery,
|
||||
deleteGallery,
|
||||
manageTasks,
|
||||
manageTasks;
|
||||
|
||||
String localText(BuildContext context) {
|
||||
final i18n = AppLocalizations.of(context)!;
|
||||
switch (this) {
|
||||
case UserPermission.readGallery:
|
||||
return i18n.readGallery;
|
||||
case UserPermission.editGallery:
|
||||
return i18n.editGallery;
|
||||
case UserPermission.deleteGallery:
|
||||
return i18n.deleteGallery;
|
||||
case UserPermission.manageTasks:
|
||||
return i18n.manageTasks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const userPermissionAll = 15;
|
||||
|
||||
class UserPermissions {
|
||||
const UserPermissions(this.code);
|
||||
final int code;
|
||||
UserPermissions(this.code);
|
||||
int code;
|
||||
bool has(UserPermission permission) => code.hasFlag(permission);
|
||||
bool get isAll => code == userPermissionAll;
|
||||
int toJson() => code;
|
||||
void add(UserPermission flag) {
|
||||
code |= flag.value;
|
||||
}
|
||||
|
||||
static int toJson2(UserPermissions code) {
|
||||
return code.code;
|
||||
}
|
||||
@@ -25,6 +46,10 @@ class UserPermissions {
|
||||
return UserPermissions(code);
|
||||
}
|
||||
|
||||
void remove(UserPermission flag) {
|
||||
code &= ~flag.value;
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
if (code & userPermissionAll == userPermissionAll) return "all";
|
||||
|
||||
Reference in New Issue
Block a user