2022-01-26 01:58:47 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2024-04-26 01:14:49 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-01-26 01:58:47 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2024-04-26 01:14:49 +02:00
|
|
|
import 'package:yokutango_mobile_reader/models/data_entry.dart';
|
2022-01-26 01:58:47 +01:00
|
|
|
|
|
|
|
// TODO: merge
|
|
|
|
|
|
|
|
Future<Map<File, List<YokutangoEntry>>> get tangocardFilePaths => rootBundle
|
|
|
|
.loadString('AssetManifest.json')
|
|
|
|
.then(
|
|
|
|
(json) => jsonDecode(json)
|
|
|
|
.keys
|
|
|
|
.where((String key) =>
|
|
|
|
key.contains('yokutango/json/') && key.contains('.json'))
|
|
|
|
.toList(),
|
|
|
|
)
|
|
|
|
.then(
|
|
|
|
(l) async => Map.fromIterables(
|
|
|
|
l.map<File>((f) => File(f)),
|
|
|
|
await Future.wait<List<YokutangoEntry>>(
|
|
|
|
l.map<Future<List<YokutangoEntry>>>(
|
|
|
|
(String t) => rootBundle.loadString(t).then<List<YokutangoEntry>>(
|
|
|
|
(s) => jsonDecode(s)
|
|
|
|
.map<YokutangoEntry>((e) => YokutangoEntry.fromJson(e))
|
|
|
|
.toList()),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2024-04-26 01:14:49 +02:00
|
|
|
Future<Map<File, List<KanjiEntry>>> get kanjicardFilePaths =>
|
|
|
|
rootBundle.loadString('AssetManifest.json').then(
|
|
|
|
(json) {
|
|
|
|
final jsonKeys = jsonDecode(json).keys;
|
|
|
|
|
|
|
|
final kanjiPaths = jsonKeys
|
|
|
|
.where((String key) =>
|
|
|
|
RegExp(r'assets/yokutango/kanji/kanji_\d+.json')
|
|
|
|
.matchAsPrefix(key) !=
|
|
|
|
null)
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
final kanaPaths = jsonKeys
|
|
|
|
.where((String key) =>
|
|
|
|
RegExp(r'assets/yokutango/kanji/(?:hiragana|katakana).json')
|
|
|
|
.matchAsPrefix(key) !=
|
|
|
|
null)
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
return kanaPaths + kanjiPaths;
|
|
|
|
},
|
|
|
|
).then(
|
2022-01-26 01:58:47 +01:00
|
|
|
(l) async => Map.fromIterables(
|
|
|
|
l.map<File>((f) => File(f)),
|
|
|
|
await Future.wait<List<KanjiEntry>>(l.map<Future<List<KanjiEntry>>>(
|
|
|
|
(String t) => rootBundle.loadString(t).then<List<KanjiEntry>>((s) =>
|
|
|
|
jsonDecode(s)
|
|
|
|
.map<KanjiEntry>((e) => KanjiEntry.fromJson(e))
|
|
|
|
.toList()),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
);
|