代码优化

This commit is contained in:
DelLevin-Home
2026-06-30 15:12:11 +08:00
parent 0c7c39e641
commit 9fd80f83c8
30 changed files with 313 additions and 424 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:collection';
import 'package:flutter/material.dart';
import '../models/data_models.dart';
import '../models/note_plus_models.dart';
import '../utils/movie/movie_dao.dart';
import '../utils/book/book_dao.dart';
import '../utils/note/note_dao.dart';
@@ -8,6 +9,7 @@ import '../utils/movie/movie_review_dao.dart';
import '../utils/movie/movie_poster_dao.dart';
import '../utils/book/book_review_dao.dart';
import '../utils/book/book_excerpt_dao.dart';
import '../utils/note_plus/note_plus_dao.dart';
import '../utils/tag/tag_dao.dart';
import '../utils/database_helper.dart';
import '../utils/image_path_helper.dart';
@@ -24,6 +26,7 @@ class AppProvider extends ChangeNotifier {
final MoviePosterDao _posterDao = MoviePosterDao();
final BookReviewDao _bookReviewDao = BookReviewDao();
final BookExcerptDao _bookExcerptDao = BookExcerptDao();
final NotePlusDao _notePlusDao = NotePlusDao();
final TagDao _tagDao = TagDao();
// 数据列表
List<Movie> _movies = [];
@@ -325,6 +328,7 @@ class AppProvider extends ChangeNotifier {
Future<void> toggleNotePin(String id, bool isPinned) async {
await _noteDao.togglePin(id, isPinned);
await loadNotes();
notifyListeners();
}
// ========== 影评相关方法 ==========
@@ -494,6 +498,8 @@ class AppProvider extends ChangeNotifier {
final deletedNotes = await getDeletedNotes();
final deletedMovieReviews = await getDeletedMovieReviews();
final deletedBookReviews = await getDeletedBookReviews();
final deletedBookExcerpts = await getDeletedBookExcerpts();
final deletedNotePlusDocs = await _notePlusDao.getDeleted();
for (final movie in deletedMovies) {
await permanentDeleteMovie(movie.id);
@@ -510,6 +516,12 @@ class AppProvider extends ChangeNotifier {
for (final review in deletedBookReviews) {
await _bookReviewDao.permanentDeleteReview(review.id);
}
for (final excerpt in deletedBookExcerpts) {
await _bookExcerptDao.permanentDeleteExcerpt(excerpt.id);
}
for (final doc in deletedNotePlusDocs) {
await _notePlusDao.permanentDelete(doc.id);
}
await loadMovies();
await loadBooks();
@@ -542,6 +554,34 @@ class AppProvider extends ChangeNotifier {
await _bookReviewDao.permanentDeleteReview(id);
}
// ========== 摘抄回收站方法 ==========
Future<List<BookExcerpt>> getDeletedBookExcerpts() async {
return await _bookExcerptDao.getDeletedExcerpts();
}
Future<void> restoreBookExcerpt(String id) async {
await _bookExcerptDao.restoreExcerpt(id);
}
Future<void> permanentDeleteBookExcerpt(String id) async {
await _bookExcerptDao.permanentDeleteExcerpt(id);
}
// ========== Note Plus 回收站 ==========
Future<List<NotePlusDocument>> getDeletedNotePlusDocs() async {
return await _notePlusDao.getDeleted();
}
Future<void> restoreNotePlusDoc(String id) async {
await _notePlusDao.restore(id);
}
Future<void> permanentDeleteNotePlusDoc(String id) async {
await _notePlusDao.permanentDelete(id);
}
// ========== 标签管理方法 ==========
Future<List<Map<String, dynamic>>> getTags(String type, {bool excludeHidden = false}) async {

View File

@@ -201,16 +201,6 @@ class NotePlusProvider extends ChangeNotifier {
notifyListeners();
}
/// 更新文档所属文件夹
Future<void> updateDocumentFolder(String id, String folder) async {
final idx = _documents.indexWhere((d) => d.id == id);
if (idx < 0) return;
final doc = _documents[idx].copyWith(parentId: folder, updatedAt: DateTime.now());
await _dao.update(doc);
_documents[idx] = doc;
notifyListeners();
}
// ========== Block 操作 ==========
void setFocusedBlock(int index) {