Skip to content

Commit

Permalink
Introduce enum ArtistType
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Sep 8, 2024
1 parent 0414ada commit 6640900
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 415 deletions.
4 changes: 2 additions & 2 deletions violet/assets/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "Read",
"artists": "Artists",
"groups": "Groups",
"artist": "Artists",
"group": "Groups",
"tags": "Tags",
"series": "Series",
"character": "Character",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "Leer",
"artists": "Artistas",
"groups": "Grupos",
"artist": "Artistas",
"group": "Grupos",
"tags": "Etiquetas",
"series": "Series",
"character": "Personajes",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "Leggi",
"artists": "Artisti",
"groups": "Gruppi",
"artist": "Artisti",
"group": "Gruppi",
"tags": "Tags",
"series": "Serie",
"character": "Personaggi",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "内部ストレージを使う",
"default": "Default",
"read": "読む",
"artists": "アーティスト",
"groups": "グループ",
"artist": "アーティスト",
"group": "グループ",
"tags": "タグ",
"series": "シリーズ",
"character": "キャラクター",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "내부 저장소 사용",
"default": "기본값",
"read": "읽기",
"artists": "작가",
"groups": "그룹",
"artist": "작가",
"group": "그룹",
"tags": "태그",
"series": "시리즈",
"character": "캐릭터",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Usar armazenamento interno",
"default": "Padrão",
"read": "Ler",
"artists": "Artistas",
"groups": "Grupos",
"artist": "Artistas",
"group": "Grupos",
"tags": "Tags",
"series": "Series",
"character": "Personagem",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "Read",
"artists": "Artists",
"groups": "Groups",
"artist": "Artists",
"group": "Groups",
"tags": "Tags",
"series": "Series",
"character": "Character",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/zh_Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "阅读",
"artists": "作者",
"groups": "团体",
"artist": "作者",
"group": "团体",
"tags": "标签",
"series": "系列",
"character": "角色",
Expand Down
4 changes: 2 additions & 2 deletions violet/assets/locale/zh_Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"useinnerstorage": "Use Inner Storage",
"default": "Default",
"read": "Read",
"artists": "Artists",
"groups": "Groups",
"artist": "Artists",
"group": "Groups",
"tags": "Tags",
"series": "Series",
"character": "Character",
Expand Down
70 changes: 52 additions & 18 deletions violet/lib/database/user/bookmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,42 @@ class BookmarkArticle {
}
}

enum ArtistType { artist, group, uploader, series, character }

extension ArtistTypeExtension on ArtistType {
bool get isGroup => this == ArtistType.group;
bool get isUploader => this == ArtistType.uploader;
bool get isCharacter => this == ArtistType.character;
bool get isSeries => this == ArtistType.series;
}

class ArtistTypeHelper {
static ArtistType? fromString(String name) {
switch (name.toLowerCase()) {
case 'artist':
case 'artists':
return ArtistType.artist;

case 'group':
case 'groups':
return ArtistType.group;

case 'uploader':
case 'uploaders':
return ArtistType.uploader;

case 'series':
return ArtistType.series;

case 'character':
case 'characters':
return ArtistType.character;
}

return null;
}
}

class BookmarkArtist {
Map<String, dynamic> result;
BookmarkArtist({required this.result});
Expand All @@ -72,7 +108,8 @@ class BookmarkArtist {
// 2: uploader
// 3: series
// 4: character
int type() => result['IsGroup']; // backward compatibility
ArtistType type() =>
ArtistType.values[result['IsGroup']]; // backward compatibility
String datetime() => result['DateTime'];
int group() => result['GroupId'];

Expand Down Expand Up @@ -233,17 +270,17 @@ class Bookmark {
bookmarkSet!.add(int.parse(article));
}

Future<void> insertArtist(String artist, int isgroup,
Future<void> insertArtist(String artist, ArtistType type,
[DateTime? datetime, int group = 1]) async {
datetime ??= DateTime.now();
var db = await CommonUserDatabase.getInstance();
await db.insert('BookmarkArtist', {
'Artist': artist,
'IsGroup': isgroup,
'IsGroup': type.index,
'DateTime': datetime.toString(),
'GroupId': group,
});
bookmarkArtistSet![isgroup]!.add(artist);
bookmarkArtistSet![type]!.add(artist);
}

Future<void> insertUser(String user,
Expand Down Expand Up @@ -454,17 +491,15 @@ class Bookmark {
bookmarkSet!.remove(id);
}

Map<int, HashSet<String>>? bookmarkArtistSet;
Future<bool> isBookmarkArtist(String name, int type) async {
Map<ArtistType, HashSet<String>>? bookmarkArtistSet;
Future<bool> isBookmarkArtist(String name, ArtistType type) async {
if (bookmarkArtistSet == null) {
var artist = await getArtist();
bookmarkArtistSet = <int, HashSet<String>>{};
bookmarkArtistSet![0] = HashSet<String>();
bookmarkArtistSet![1] = HashSet<String>();
bookmarkArtistSet![2] = HashSet<String>();
bookmarkArtistSet![3] = HashSet<String>();
bookmarkArtistSet![4] = HashSet<String>();
for (var element in artist) {
final artist = await getArtist();
bookmarkArtistSet = <ArtistType, HashSet<String>>{};
for (final type in ArtistType.values) {
bookmarkArtistSet![type] = HashSet<String>();
}
for (final element in artist) {
bookmarkArtistSet![element.type()]!.add(element.artist());
}
}
Expand Down Expand Up @@ -498,19 +533,18 @@ class Bookmark {
return historyUserSet!.contains(user);
}

Future<void> bookmarkArtist(String name, int type, [int group = 1]) async {
Future<void> bookmarkArtist(String name, ArtistType type,
[int group = 1]) async {
if (await isBookmarkArtist(name, type)) return;
bookmarkArtistSet![type]!.add(name);
await insertArtist(name, type, null, group);
}

Future<void> unbookmarkArtist(String name, int type) async {
Future<void> unbookmarkArtist(String name, ArtistType type) async {
if (!await isBookmarkArtist(name, type)) return;
var db = await CommonUserDatabase.getInstance();
await db.delete('BookmarkArtist', 'Artist=? AND IsGroup=?', [name, type]);
bookmarkArtistSet![type]!.remove(name);

print('delete $name, $type');
}

Future<void> bookmarkUser(String user, [int group = 1]) async {
Expand Down
29 changes: 10 additions & 19 deletions violet/lib/pages/article_info/article_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:violet/component/eh/eh_parser.dart';
import 'package:violet/component/hitomi/related.dart';
import 'package:violet/component/hitomi/tag_translate.dart';
import 'package:violet/database/query.dart';
import 'package:violet/database/user/bookmark.dart';
import 'package:violet/database/user/download.dart';
import 'package:violet/database/user/record.dart';
import 'package:violet/locale/locale.dart';
Expand Down Expand Up @@ -372,22 +373,22 @@ class TagInfoAreaWidget extends StatelessWidget {
'language'),
MultiChipWidget(
queryResult.artists(),
Translations.of(context).trans('artists'),
Translations.of(context).trans('artist'),
queryResult.artists() != null
? (queryResult.artists() as String)
.split('|')
.where((element) => element != '')
.map((e) => Tuple2<String, String>('artists', e))
.map((e) => Tuple2<String, String>('artist', e))
.toList()
: []),
MultiChipWidget(
queryResult.groups(),
Translations.of(context).trans('groups'),
Translations.of(context).trans('group'),
queryResult.groups() != null
? (queryResult.groups() as String)
.split('|')
.where((element) => element != '')
.map((e) => Tuple2<String, String>('groups', e))
.map((e) => Tuple2<String, String>('group', e))
.toList()
: []),
MultiChipWidget(
Expand Down Expand Up @@ -924,14 +925,14 @@ class _Chip extends StatelessWidget {
size: 18.0,
color: Colors.white,
);
} else if (group == 'artists') {
} else if (group == 'artist') {
mustHasMorePad = false;
avatar = const Icon(
MdiIcons.account,
size: 18.0,
color: Colors.white,
);
} else if (group == 'groups') {
} else if (group == 'group') {
mustHasMorePad = false;
avatar = const Icon(
MdiIcons.accountGroup,
Expand Down Expand Up @@ -989,21 +990,11 @@ class _Chip extends StatelessWidget {
}
},
onTap: () async {
if ((group == 'groups' ||
group == 'artists' ||
group == 'uploader' ||
group == 'series' ||
group == 'character') &&
name.toLowerCase() != 'n/a') {
final type = ArtistTypeHelper.fromString(group);
if (type != null && name.toLowerCase() != 'n/a') {
PlatformNavigator.navigateSlide(
context,
ArtistInfoPage(
isGroup: group == 'groups',
isUploader: group == 'uploader',
isCharacter: group == 'character',
isSeries: group == 'series',
artist: name,
),
ArtistInfoPage(name: name, type: type),
);
} else if (group == 'id') {
Clipboard.setData(ClipboardData(text: name));
Expand Down
Loading

0 comments on commit 6640900

Please sign in to comment.