|
|
|
|
@ -601,4 +601,207 @@ public class DataManager extends Observable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据邮箱获取用户
|
|
|
|
|
* @param email 用户邮箱
|
|
|
|
|
* @return 用户对象,如果未找到则返回null
|
|
|
|
|
*/
|
|
|
|
|
public User getUserByEmail(String email) {
|
|
|
|
|
if (email == null) return null;
|
|
|
|
|
for (User user : users) {
|
|
|
|
|
if (email.equalsIgnoreCase(user.getEmail())) {
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== 书签相关 ==========
|
|
|
|
|
private List<ReadingBookmark> bookmarks = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public static class ReadingBookmark {
|
|
|
|
|
private String id;
|
|
|
|
|
private String userId;
|
|
|
|
|
private String bookId;
|
|
|
|
|
private int pageNumber;
|
|
|
|
|
private String chapter;
|
|
|
|
|
private String label;
|
|
|
|
|
private String highlightText;
|
|
|
|
|
private long createdAt;
|
|
|
|
|
|
|
|
|
|
public String getId() { return id; }
|
|
|
|
|
public void setId(String id) { this.id = id; }
|
|
|
|
|
public String getUserId() { return userId; }
|
|
|
|
|
public void setUserId(String userId) { this.userId = userId; }
|
|
|
|
|
public String getBookId() { return bookId; }
|
|
|
|
|
public void setBookId(String bookId) { this.bookId = bookId; }
|
|
|
|
|
public int getPageNumber() { return pageNumber; }
|
|
|
|
|
public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; }
|
|
|
|
|
public String getChapter() { return chapter; }
|
|
|
|
|
public void setChapter(String chapter) { this.chapter = chapter; }
|
|
|
|
|
public String getLabel() { return label; }
|
|
|
|
|
public void setLabel(String label) { this.label = label; }
|
|
|
|
|
public String getHighlightText() { return highlightText; }
|
|
|
|
|
public void setHighlightText(String highlightText) { this.highlightText = highlightText; }
|
|
|
|
|
public long getCreatedAt() { return createdAt; }
|
|
|
|
|
public void setCreatedAt(long createdAt) { this.createdAt = createdAt; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReadingBookmark> getBookmarksForBook(String userId, String bookId) {
|
|
|
|
|
List<ReadingBookmark> result = new ArrayList<>();
|
|
|
|
|
for (ReadingBookmark bm : bookmarks) {
|
|
|
|
|
if (userId.equals(bm.getUserId()) && bookId.equals(bm.getBookId())) {
|
|
|
|
|
result.add(bm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addBookmark(String userId, String bookId, int pageNumber, String chapter, String label, String highlightText) {
|
|
|
|
|
ReadingBookmark bm = new ReadingBookmark();
|
|
|
|
|
bm.setId("BM" + System.currentTimeMillis());
|
|
|
|
|
bm.setUserId(userId);
|
|
|
|
|
bm.setBookId(bookId);
|
|
|
|
|
bm.setPageNumber(pageNumber);
|
|
|
|
|
bm.setChapter(chapter);
|
|
|
|
|
bm.setLabel(label);
|
|
|
|
|
bm.setHighlightText(highlightText);
|
|
|
|
|
bm.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
bookmarks.add(bm);
|
|
|
|
|
Log.d(TAG, "添加书签: " + bm.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteBookmark(String bookmarkId) {
|
|
|
|
|
for (int i = 0; i < bookmarks.size(); i++) {
|
|
|
|
|
if (bookmarks.get(i).getId().equals(bookmarkId)) {
|
|
|
|
|
bookmarks.remove(i);
|
|
|
|
|
Log.d(TAG, "删除书签: " + bookmarkId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== 收藏相关 ==========
|
|
|
|
|
private List<Favorite> favorites = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public static class Favorite {
|
|
|
|
|
private String id;
|
|
|
|
|
private String userId;
|
|
|
|
|
private String bookId;
|
|
|
|
|
private long createdAt;
|
|
|
|
|
|
|
|
|
|
public String getId() { return id; }
|
|
|
|
|
public void setId(String id) { this.id = id; }
|
|
|
|
|
public String getUserId() { return userId; }
|
|
|
|
|
public void setUserId(String userId) { this.userId = userId; }
|
|
|
|
|
public String getBookId() { return bookId; }
|
|
|
|
|
public void setBookId(String bookId) { this.bookId = bookId; }
|
|
|
|
|
public long getCreatedAt() { return createdAt; }
|
|
|
|
|
public void setCreatedAt(long createdAt) { this.createdAt = createdAt; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Favorite> getFavoritesByUserId(String userId) {
|
|
|
|
|
List<Favorite> result = new ArrayList<>();
|
|
|
|
|
for (Favorite fav : favorites) {
|
|
|
|
|
if (userId.equals(fav.getUserId())) {
|
|
|
|
|
result.add(fav);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addFavorite(String userId, String bookId) {
|
|
|
|
|
// 检查是否已收藏
|
|
|
|
|
for (Favorite fav : favorites) {
|
|
|
|
|
if (userId.equals(fav.getUserId()) && bookId.equals(fav.getBookId())) {
|
|
|
|
|
Log.d(TAG, "已收藏过该图书");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Favorite fav = new Favorite();
|
|
|
|
|
fav.setId("FAV" + System.currentTimeMillis());
|
|
|
|
|
fav.setUserId(userId);
|
|
|
|
|
fav.setBookId(bookId);
|
|
|
|
|
fav.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
favorites.add(fav);
|
|
|
|
|
Log.d(TAG, "添加收藏: " + fav.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeFavorite(String userId, String bookId) {
|
|
|
|
|
for (int i = 0; i < favorites.size(); i++) {
|
|
|
|
|
Favorite fav = favorites.get(i);
|
|
|
|
|
if (userId.equals(fav.getUserId()) && bookId.equals(fav.getBookId())) {
|
|
|
|
|
favorites.remove(i);
|
|
|
|
|
Log.d(TAG, "取消收藏: " + fav.getId());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========== 笔记相关 ==========
|
|
|
|
|
private List<ReadingNote> notes = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public static class ReadingNote {
|
|
|
|
|
private String id;
|
|
|
|
|
private String userId;
|
|
|
|
|
private String bookId;
|
|
|
|
|
private String title;
|
|
|
|
|
private String content;
|
|
|
|
|
private int pageNumber;
|
|
|
|
|
private String chapter;
|
|
|
|
|
private long createdAt;
|
|
|
|
|
|
|
|
|
|
public String getId() { return id; }
|
|
|
|
|
public void setId(String id) { this.id = id; }
|
|
|
|
|
public String getUserId() { return userId; }
|
|
|
|
|
public void setUserId(String userId) { this.userId = userId; }
|
|
|
|
|
public String getBookId() { return bookId; }
|
|
|
|
|
public void setBookId(String bookId) { this.bookId = bookId; }
|
|
|
|
|
public String getTitle() { return title; }
|
|
|
|
|
public void setTitle(String title) { this.title = title; }
|
|
|
|
|
public String getContent() { return content; }
|
|
|
|
|
public void setContent(String content) { this.content = content; }
|
|
|
|
|
public int getPageNumber() { return pageNumber; }
|
|
|
|
|
public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber; }
|
|
|
|
|
public String getChapter() { return chapter; }
|
|
|
|
|
public void setChapter(String chapter) { this.chapter = chapter; }
|
|
|
|
|
public long getCreatedAt() { return createdAt; }
|
|
|
|
|
public void setCreatedAt(long createdAt) { this.createdAt = createdAt; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReadingNote> getNotesByUserId(String userId) {
|
|
|
|
|
List<ReadingNote> result = new ArrayList<>();
|
|
|
|
|
for (ReadingNote note : notes) {
|
|
|
|
|
if (userId.equals(note.getUserId())) {
|
|
|
|
|
result.add(note);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addNote(String userId, String bookId, String title, String content, int pageNumber, String chapter) {
|
|
|
|
|
ReadingNote note = new ReadingNote();
|
|
|
|
|
note.setId("NOTE" + System.currentTimeMillis());
|
|
|
|
|
note.setUserId(userId);
|
|
|
|
|
note.setBookId(bookId);
|
|
|
|
|
note.setTitle(title);
|
|
|
|
|
note.setContent(content);
|
|
|
|
|
note.setPageNumber(pageNumber);
|
|
|
|
|
note.setChapter(chapter);
|
|
|
|
|
note.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
notes.add(note);
|
|
|
|
|
Log.d(TAG, "添加笔记: " + note.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteNote(String userId, String noteId) {
|
|
|
|
|
for (int i = 0; i < notes.size(); i++) {
|
|
|
|
|
ReadingNote note = notes.get(i);
|
|
|
|
|
if (noteId.equals(note.getId()) && userId.equals(note.getUserId())) {
|
|
|
|
|
notes.remove(i);
|
|
|
|
|
Log.d(TAG, "删除笔记: " + noteId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|