initBookmarks method
Initializes the bookmarks of the user.
If userBookmarks
is provided, it is used to initialize the bookmarks.
If overwrite
is true, the bookmarks are cleared and the userBookmarks
are added to the map. Otherwise, the bookmarks are loaded from the
storage and if there are no bookmarks, the default bookmarks are added.
The bookmarks are saved to the storage after initialization.
This method should be called once when the app starts, and before using any other methods of BookmarksCtrl.
Implementation
void initBookmarks(
{Map<int, List<BookmarkModel>>? userBookmarks, bool overwrite = false}) {
if (overwrite) {
bookmarks.clear();
if (userBookmarks != null) {
bookmarks.addAll(userBookmarks);
}
} else {
final savedBookmarks = _quranRepository.getBookmarks();
if (savedBookmarks.isEmpty) {
// إذا لم توجد إشارات محفوظة، يمكن تحميل افتراضية
bookmarks[0xAAFFD354] = []; // اللون الأصفر
bookmarks[0xAAF36077] = []; // اللون الأحمر
bookmarks[0xAA00CD00] = []; // اللون الأخضر
} else {
// قم بتجميع الإشارات المرجعية حسب colorCode
for (var bookmark in savedBookmarks) {
bookmarks.update(
bookmark.colorCode,
(existingList) => [...existingList, bookmark],
ifAbsent: () => [bookmark],
);
}
}
}
_quranRepository.saveBookmarks(_flattenBookmarks());
update(['bookmarks']);
}