新增阅读器功能,待优化

This commit is contained in:
DelLevin-Home
2026-06-20 00:54:40 +08:00
parent 0af9d4368a
commit 670502b4f5
250 changed files with 97847 additions and 826 deletions

View File

@@ -9,6 +9,8 @@ import '../utils/movie/movie_poster_dao.dart';
import '../utils/book/book_review_dao.dart';
import '../utils/book/book_excerpt_dao.dart';
import '../utils/tag/tag_dao.dart';
import '../utils/reader_book_dao.dart';
import '../models/reader_book.dart';
import '../utils/database_helper.dart';
import '../utils/image_path_helper.dart';
import '../utils/user_prefs.dart';
@@ -25,11 +27,13 @@ class AppProvider extends ChangeNotifier {
final BookReviewDao _bookReviewDao = BookReviewDao();
final BookExcerptDao _bookExcerptDao = BookExcerptDao();
final TagDao _tagDao = TagDao();
final ReaderBookDao _readerBookDao = ReaderBookDao();
// 数据列表
List<Movie> _movies = [];
List<Book> _books = [];
List<Note> _notes = [];
List<ReaderBook> _readerBooks = [];
// 当前主界面选中的标签 (0: 观影1: 阅读2: 笔记)
int _mainTabIndex = 0;
@@ -60,6 +64,10 @@ class AppProvider extends ChangeNotifier {
// 侧边菜单是否打开
bool _drawerOpen = false;
// 回到顶部信号(点击首页图标时递增)
int _scrollToTopSignal = 0;
int get scrollToTopSignal => _scrollToTopSignal;
// 初始化数据库
Future<void> initDatabase() async {
@@ -73,10 +81,12 @@ class AppProvider extends ChangeNotifier {
_movieDao.getAllMovies(),
_bookDao.getAllBooks(),
_noteDao.getAllNotes(),
_readerBookDao.getAllReaderBooks(),
]);
_movies = results[0] as List<Movie>;
_books = results[1] as List<Book>;
_notes = results[2] as List<Note>;
_readerBooks = results[3] as List<ReaderBook>;
debugPrint('[AppProvider] 本地数据: movies=${_movies.length}, books=${_books.length}, notes=${_notes.length}');
notifyListeners();
}
@@ -144,6 +154,26 @@ class AppProvider extends ChangeNotifier {
notifyListeners();
}
Future<void> loadReaderBooks() async {
_readerBooks = await _readerBookDao.getAllReaderBooks();
notifyListeners();
}
Future<void> addReaderBook(ReaderBook book) async {
await _readerBookDao.insertReaderBook(book);
await loadReaderBooks();
}
Future<void> updateReaderBook(ReaderBook book) async {
await _readerBookDao.updateReaderBook(book);
await loadReaderBooks();
}
Future<void> removeReaderBook(String id) async {
await _readerBookDao.deleteReaderBook(id);
await loadReaderBooks();
}
// ─── 分页加载(供列表页触底加载使用)────────────────────────
static const int _pageSize = 20;
@@ -179,6 +209,7 @@ class AppProvider extends ChangeNotifier {
List<Movie> get movies => _movies;
List<Book> get books => _books;
List<Note> get notes => _notes;
List<ReaderBook> get readerBooks => _readerBooks;
// 根据状态获取影视列表
List<Movie> getMoviesByStatus(String status) {
@@ -197,8 +228,14 @@ class AppProvider extends ChangeNotifier {
}
void setBottomNavIndex(int index) {
if (index == 0 && _bottomNavIndex == 0) {
// 已在首页,再次点击 → 回到顶部
_scrollToTopSignal++;
notifyListeners();
return;
}
_bottomNavIndex = index;
_bottomNavVisible = true; // 切换页面时自动显示导航栏
_bottomNavVisible = true;
notifyListeners();
}