mirror of
https://github.com/leanote/leanote-android.git
synced 2026-01-13 07:03:54 +08:00
code refactoring: replace database query code to xxDataStore
This commit is contained in:
@@ -18,6 +18,7 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
@@ -106,7 +107,7 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder> {
|
||||
}
|
||||
|
||||
private void updateNotebookMap() {
|
||||
List<Notebook> notebooks = Notebook.getAllNotebooks(Account.getCurrent().getUserId());
|
||||
List<Notebook> notebooks = NotebookDataStore.getAllNotebooks(Account.getCurrent().getUserId());
|
||||
mNotebookId2TitleMaps = new HashMap<>();
|
||||
for (Notebook notebook : notebooks) {
|
||||
mNotebookId2TitleMaps.put(notebook.getNotebookId(), notebook.getTitle());
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
@@ -55,14 +56,14 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
|
||||
private void getSafeNotebook(Stack<String> stack) {
|
||||
if (stack.isEmpty()) {
|
||||
mData = Notebook.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
mData = NotebookDataStore.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
} else {
|
||||
Notebook parent = Notebook.getByServerId(stack.peek());
|
||||
Notebook parent = NotebookDataStore.getByServerId(stack.peek());
|
||||
if (parent.isDeleted()) {
|
||||
stack.pop();
|
||||
getSafeNotebook(stack);
|
||||
} else {
|
||||
mData = Notebook.getChildNotebook(mStack.peek(), Account.getCurrent().getUserId());
|
||||
mData = NotebookDataStore.getChildNotebook(mStack.peek(), Account.getCurrent().getUserId());
|
||||
mData.add(0, parent);
|
||||
}
|
||||
}
|
||||
@@ -147,7 +148,7 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
}
|
||||
|
||||
private boolean hasChild(String notebookId) {
|
||||
return CollectionUtils.isNotEmpty(Notebook.getChildNotebook(notebookId, Account.getCurrent().getUserId()));
|
||||
return CollectionUtils.isNotEmpty(NotebookDataStore.getChildNotebook(notebookId, Account.getCurrent().getUserId()));
|
||||
}
|
||||
|
||||
private void listUpper() {
|
||||
@@ -157,11 +158,11 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
|
||||
mStack.pop();
|
||||
if (mStack.isEmpty()) {
|
||||
mData = Notebook.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
mData = NotebookDataStore.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
} else {
|
||||
String parentId = mStack.peek();
|
||||
mData.add(Notebook.getByServerId(parentId));
|
||||
mData.addAll(Notebook.getChildNotebook(parentId, Account.getCurrent().getUserId()));
|
||||
mData.add(NotebookDataStore.getByServerId(parentId));
|
||||
mData.addAll(NotebookDataStore.getChildNotebook(parentId, Account.getCurrent().getUserId()));
|
||||
}
|
||||
notifyItemRangeInserted(0, mData.size());
|
||||
}
|
||||
@@ -180,7 +181,7 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
notifyItemChanged(0);
|
||||
|
||||
mStack.push(notebook.getNotebookId());
|
||||
List<Notebook> children = Notebook.getChildNotebook(notebook.getNotebookId(), Account.getCurrent().getUserId());
|
||||
List<Notebook> children = NotebookDataStore.getChildNotebook(notebook.getNotebookId(), Account.getCurrent().getUserId());
|
||||
int childrenSize = children.size();
|
||||
mData.addAll(children);
|
||||
notifyItemRangeInserted(1, childrenSize);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.houxg.leamonax.database;
|
||||
|
||||
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Account_Table;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AccountDataStore {
|
||||
public static Account getAccount(String email, String host) {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.email.eq(email))
|
||||
.and(Account_Table.host.eq(host))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Account getCurrent() {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.token.notEq(""))
|
||||
.orderBy(Account_Table.lastUseTime, false)
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Account> getAccountListWithToken() {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.token.notEq(""))
|
||||
.orderBy(Account_Table.lastUseTime, false)
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Account getAccountById(long id) {
|
||||
return new Select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.id.eq(id))
|
||||
.querySingle();
|
||||
}
|
||||
}
|
||||
113
app/src/main/java/org/houxg/leamonax/database/NoteDataStore.java
Normal file
113
app/src/main/java/org/houxg/leamonax/database/NoteDataStore.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package org.houxg.leamonax.database;
|
||||
|
||||
|
||||
import com.raizlabs.android.dbflow.sql.language.Join;
|
||||
import com.raizlabs.android.dbflow.sql.language.NameAlias;
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
import com.raizlabs.android.dbflow.sql.language.property.IProperty;
|
||||
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Note_Table;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag_Table;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.model.Tag_Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NoteDataStore {
|
||||
public static List<Note> searchByTitle(String keyword) {
|
||||
keyword = String.format(Locale.US, "%%%s%%", keyword);
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(Account.getCurrent().getUserId()))
|
||||
.and(Note_Table.title.like(keyword))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Note getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.noteId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Note getByLocalId(long localId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.id.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Note> getAllNotes(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Note> getAllDirtyNotes(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDirty.eq(true))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Note> getNotesFromNotebook(String userId, long localNotebookId) {
|
||||
Notebook notebook = NotebookDataStore.getByLocalId(localNotebookId);
|
||||
if (notebook == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.notebookId.eq(notebook.getNotebookId()))
|
||||
.and(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Note> getByTagText(String tagText, String userId) {
|
||||
Tag tag = Tag.getByText(tagText, userId);
|
||||
if (tag == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getNotesByTagId(tag.getId());
|
||||
}
|
||||
|
||||
private static List<Note> getNotesByTagId(long tagId) {
|
||||
IProperty[] properties = Note_Table.ALL_COLUMN_PROPERTIES;
|
||||
NameAlias nameAlias = NameAlias.builder("N").build();
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
properties[i] = properties[i].withTable(nameAlias);
|
||||
}
|
||||
return SQLite.select(properties)
|
||||
.from(Note.class).as("N")
|
||||
.join(RelationshipOfNoteTag.class, Join.JoinType.INNER).as("R")
|
||||
.on(Tag_Table.id.withTable(NameAlias.builder("N").build())
|
||||
.eq(RelationshipOfNoteTag_Table.noteLocalId.withTable(NameAlias.builder("R").build())))
|
||||
.where(RelationshipOfNoteTag_Table.tagLocalId.withTable(NameAlias.builder("R").build()).eq(tagId))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.houxg.leamonax.database;
|
||||
|
||||
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
import org.houxg.leamonax.model.NoteFile_Table;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class NoteFileDataStore {
|
||||
|
||||
public static List<NoteFile> getAllRelated(long noteLocalId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.noteLocalId.eq(noteLocalId))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static NoteFile getByLocalId(String localId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.localId.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static NoteFile getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.serverId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static void deleteExcept(long noteLocalId, Collection<String> excepts) {
|
||||
SQLite.delete()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.noteLocalId.eq(noteLocalId))
|
||||
.and(NoteFile_Table.localId.notIn(excepts))
|
||||
.async()
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.houxg.leamonax.database;
|
||||
|
||||
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag_Table;
|
||||
|
||||
public class NoteTagDataStore {
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(RelationshipOfNoteTag.class)
|
||||
.where(RelationshipOfNoteTag_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.houxg.leamonax.database;
|
||||
|
||||
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Note_Table;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.Notebook_Table;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class NotebookDataStore {
|
||||
public static List<Notebook> getAllNotebooks(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Notebook getByLocalId(long localId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.id.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Notebook getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.notebookId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Notebook getRecentNoteBook(String userId) {
|
||||
Note recentNotes = SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.notebookId.notEq(""))
|
||||
.orderBy(Note_Table.updatedTime, false)
|
||||
.querySingle();
|
||||
if (recentNotes != null) {
|
||||
Notebook notebook = getByServerId(recentNotes.getNoteBookId());
|
||||
if (notebook != null && !notebook.isDeleted()) {
|
||||
return notebook;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Notebook> getRootNotebooks(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.parentNotebookId.eq(""))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Notebook> getChildNotebook(String notebookId, String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.parentNotebookId.eq(notebookId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import org.houxg.leamonax.database.AccountDataStore;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
|
||||
import java.util.List;
|
||||
@@ -174,35 +175,8 @@ public class Account extends BaseModel {
|
||||
return lastUseTime;
|
||||
}
|
||||
|
||||
public static Account getAccount(String email, String host) {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.email.eq(email))
|
||||
.and(Account_Table.host.eq(host))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Account getCurrent() {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.token.notEq(""))
|
||||
.orderBy(Account_Table.lastUseTime, false)
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Account> getAccountListWithToken() {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.token.notEq(""))
|
||||
.orderBy(Account_Table.lastUseTime, false)
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Account getAccountById(long id) {
|
||||
return new Select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.id.eq(id))
|
||||
.querySingle();
|
||||
return AccountDataStore.getCurrent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,6 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by binnchx on 10/18/15.
|
||||
*/
|
||||
@Table(name = "Note", database = AppDataBase.class)
|
||||
public class Note extends BaseModel implements Serializable {
|
||||
|
||||
@@ -236,113 +233,6 @@ public class Note extends BaseModel implements Serializable {
|
||||
return noteFiles;
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public String getUpdatedTime() {
|
||||
return updatedTimeData;
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public String getCreatedTime() {
|
||||
return updatedTimeData;
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public String getPublicTime() {
|
||||
return publicTimeData;
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public void setUpdatedTime(String v) {
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public void setCreatedTime(String v) {
|
||||
}
|
||||
|
||||
//TODO:delete this
|
||||
public void setPublicTime(String publicTime) {
|
||||
}
|
||||
|
||||
public static List<Note> searchByTitle(String keyword) {
|
||||
keyword = String.format(Locale.US, "%%%s%%", keyword);
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(Account.getCurrent().getUserId()))
|
||||
.and(Note_Table.title.like(keyword))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Note getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.noteId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Note getByLocalId(long localId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.id.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Note> getAllNotes(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Note> getNotesFromNotebook(String userId, long localNotebookId) {
|
||||
Notebook notebook = Notebook.getByLocalId(localNotebookId);
|
||||
if (notebook == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.notebookId.eq(notebook.getNotebookId()))
|
||||
.and(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.and(Note_Table.isDeleted.eq(false))
|
||||
.and(Note_Table.isTrash.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Note> getByTagText(String tagText, String userId) {
|
||||
Tag tag = Tag.getByText(tagText, userId);
|
||||
if (tag == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getNotesByTagId(tag.getId());
|
||||
}
|
||||
|
||||
private static List<Note> getNotesByTagId(long tagId) {
|
||||
IProperty[] properties = Note_Table.ALL_COLUMN_PROPERTIES;
|
||||
NameAlias nameAlias = NameAlias.builder("N").build();
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
properties[i] = properties[i].withTable(nameAlias);
|
||||
}
|
||||
return SQLite.select(properties)
|
||||
.from(Note.class).as("N")
|
||||
.join(RelationshipOfNoteTag.class, Join.JoinType.INNER).as("R")
|
||||
.on(Tag_Table.id.withTable(NameAlias.builder("N").build())
|
||||
.eq(RelationshipOfNoteTag_Table.noteLocalId.withTable(NameAlias.builder("R").build())))
|
||||
.where(RelationshipOfNoteTag_Table.tagLocalId.withTable(NameAlias.builder("R").build()).eq(tagId))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Note{" +
|
||||
|
||||
@@ -107,34 +107,4 @@ public class NoteFile extends BaseModel {
|
||||
public void setIsAttach(boolean mIsAttach) {
|
||||
this.mIsAttach = mIsAttach;
|
||||
}
|
||||
|
||||
public static List<NoteFile> getAllRelated(long noteLocalId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.noteLocalId.eq(noteLocalId))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static NoteFile getByLocalId(String localId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.localId.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static NoteFile getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.serverId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static void deleteExcept(long noteLocalId, Collection<String> excepts) {
|
||||
SQLite.delete()
|
||||
.from(NoteFile.class)
|
||||
.where(NoteFile_Table.noteLocalId.eq(noteLocalId))
|
||||
.and(NoteFile_Table.localId.notIn(excepts))
|
||||
.async()
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,72 +180,4 @@ public class Notebook extends BaseModel {
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static List<Notebook> getAllNotebooks(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static Notebook getByLocalId(long localId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.id.eq(localId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Notebook getByServerId(String serverId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.notebookId.eq(serverId))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Notebook getRecentNoteBook(String userId) {
|
||||
Note recentNotes = SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(userId))
|
||||
.and(Note_Table.notebookId.notEq(""))
|
||||
.orderBy(Note_Table.updatedTime, false)
|
||||
.querySingle();
|
||||
if (recentNotes != null) {
|
||||
Notebook notebook = getByServerId(recentNotes.getNoteBookId());
|
||||
if (notebook != null && !notebook.isDeleted()) {
|
||||
return notebook;
|
||||
}
|
||||
}
|
||||
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static List<Notebook> getRootNotebooks(String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.parentNotebookId.eq(""))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static List<Notebook> getChildNotebook(String notebookId, String userId) {
|
||||
return SQLite.select()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.and(Notebook_Table.parentNotebookId.eq(notebookId))
|
||||
.and(Notebook_Table.isDeletedOnServer.eq(false))
|
||||
.queryList();
|
||||
}
|
||||
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(Notebook.class)
|
||||
.where(Notebook_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,4 @@ public class RelationshipOfNoteTag extends BaseModel {
|
||||
public long getTagLocalId() {
|
||||
return tagLocalId;
|
||||
}
|
||||
|
||||
public static void deleteAll(String userId) {
|
||||
SQLite.delete()
|
||||
.from(RelationshipOfNoteTag.class)
|
||||
.where(RelationshipOfNoteTag_Table.userId.eq(userId))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.houxg.leamonax.service;
|
||||
|
||||
import org.houxg.leamonax.database.AccountDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Authentication;
|
||||
import org.houxg.leamonax.model.BaseResponse;
|
||||
@@ -26,7 +27,7 @@ public class AccountService {
|
||||
}
|
||||
|
||||
public static long saveToAccount(Authentication authentication, String host) {
|
||||
Account localAccount = Account.getAccount(authentication.getEmail(), host);
|
||||
Account localAccount = AccountDataStore.getAccount(authentication.getEmail(), host);
|
||||
if (localAccount == null) {
|
||||
localAccount = new Account();
|
||||
}
|
||||
@@ -40,7 +41,7 @@ public class AccountService {
|
||||
}
|
||||
|
||||
public static void saveToAccount(User user, String host) {
|
||||
Account localAccount = Account.getAccount(user.getEmail(), host);
|
||||
Account localAccount = AccountDataStore.getAccount(user.getEmail(), host);
|
||||
if (localAccount == null) {
|
||||
localAccount = new Account();
|
||||
}
|
||||
@@ -68,7 +69,7 @@ public class AccountService {
|
||||
}
|
||||
|
||||
public static List<Account> getAccountList() {
|
||||
return Account.getAccountListWithToken();
|
||||
return AccountDataStore.getAccountListWithToken();
|
||||
}
|
||||
|
||||
public static boolean isSignedIn() {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.houxg.leamonax.Leamonax;
|
||||
import org.houxg.leamonax.database.NoteFileDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
|
||||
@@ -32,7 +33,7 @@ public class NoteFileService {
|
||||
private static final String IMAGE_PATH_WITH_SLASH = "/getImage";
|
||||
|
||||
public static String convertFromLocalIdToServerId(String localId) {
|
||||
NoteFile noteFile = NoteFile.getByLocalId(localId);
|
||||
NoteFile noteFile = NoteFileDataStore.getByLocalId(localId);
|
||||
return noteFile == null ? null : noteFile.getServerId();
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ public class NoteFileService {
|
||||
|
||||
public static String getImagePath(Uri uri) {
|
||||
String localId = uri.getQueryParameter("id");
|
||||
NoteFile noteFile = NoteFile.getByLocalId(localId);
|
||||
NoteFile noteFile = NoteFileDataStore.getByLocalId(localId);
|
||||
if (noteFile == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -74,11 +75,11 @@ public class NoteFileService {
|
||||
}
|
||||
|
||||
public static List<NoteFile> getRelatedNoteFiles(long noteLocalId) {
|
||||
return NoteFile.getAllRelated(noteLocalId);
|
||||
return NoteFileDataStore.getAllRelated(noteLocalId);
|
||||
}
|
||||
|
||||
public static InputStream getImage(String localId) {
|
||||
NoteFile noteFile = NoteFile.getByLocalId(localId);
|
||||
NoteFile noteFile = NoteFileDataStore.getByLocalId(localId);
|
||||
if (noteFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import com.elvishew.xlog.XLog;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.ReadableException;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.database.NoteFileDataStore;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
@@ -52,7 +55,7 @@ public class NoteService {
|
||||
do {
|
||||
notebooks = RetrofitUtils.excuteWithException(ApiProvider.getInstance().getNotebookApi().getSyncNotebooks(notebookUsn, MAX_ENTRY));
|
||||
for (Notebook remoteNotebook : notebooks) {
|
||||
Notebook localNotebook = Notebook.getByServerId(remoteNotebook.getNotebookId());
|
||||
Notebook localNotebook = NotebookDataStore.getByServerId(remoteNotebook.getNotebookId());
|
||||
if (localNotebook == null) {
|
||||
XLog.i(TAG + "notebook insert, usn=" + remoteNotebook.getUsn() + ", id=" + remoteNotebook.getNotebookId());
|
||||
remoteNotebook.insert();
|
||||
@@ -77,7 +80,7 @@ public class NoteService {
|
||||
notes = RetrofitUtils.excuteWithException(ApiProvider.getInstance().getNoteApi().getSyncNotes(noteUsn, MAX_ENTRY));
|
||||
for (Note noteMeta : notes) {
|
||||
Note remoteNote = RetrofitUtils.excuteWithException(ApiProvider.getInstance().getNoteApi().getNoteAndContent(noteMeta.getNoteId()));
|
||||
Note localNote = Note.getByServerId(noteMeta.getNoteId());
|
||||
Note localNote = NoteDataStore.getByServerId(noteMeta.getNoteId());
|
||||
noteUsn = remoteNote.getUsn();
|
||||
long localId;
|
||||
if (localNote == null) {
|
||||
@@ -124,9 +127,9 @@ public class NoteService {
|
||||
for (NoteFile remote : remoteFiles) {
|
||||
NoteFile local;
|
||||
if (TextUtils.isEmpty(remote.getLocalId())) {
|
||||
local = NoteFile.getByServerId(remote.getServerId());
|
||||
local = NoteFileDataStore.getByServerId(remote.getServerId());
|
||||
} else {
|
||||
local = NoteFile.getByLocalId(remote.getLocalId());
|
||||
local = NoteFileDataStore.getByLocalId(remote.getLocalId());
|
||||
}
|
||||
if (local != null) {
|
||||
XLog.i(TAG + "has local file, id=" + remote.getServerId());
|
||||
@@ -141,7 +144,7 @@ public class NoteService {
|
||||
local.save();
|
||||
excepts.add(local.getLocalId());
|
||||
}
|
||||
NoteFile.deleteExcept(noteLocalId, excepts);
|
||||
NoteFileDataStore.deleteExcept(noteLocalId, excepts);
|
||||
}
|
||||
|
||||
private static String convertToLocalImageLinkForRichText(long noteLocalId, String noteContent) {
|
||||
@@ -154,7 +157,7 @@ public class NoteService {
|
||||
XLog.i(TAG + "in=" + original);
|
||||
Uri linkUri = Uri.parse(original.substring(6, original.length() - 1));
|
||||
String serverId = linkUri.getQueryParameter("fileId");
|
||||
NoteFile noteFile = NoteFile.getByServerId(serverId);
|
||||
NoteFile noteFile = NoteFileDataStore.getByServerId(serverId);
|
||||
if (noteFile == null) {
|
||||
noteFile = new NoteFile();
|
||||
noteFile.setNoteId((Long) extraData[0]);
|
||||
@@ -179,7 +182,7 @@ public class NoteService {
|
||||
public String replaceWith(String original, Object... extraData) {
|
||||
Uri linkUri = Uri.parse(original.substring(1, original.length() - 1));
|
||||
String serverId = linkUri.getQueryParameter("fileId");
|
||||
NoteFile noteFile = NoteFile.getByServerId(serverId);
|
||||
NoteFile noteFile = NoteFileDataStore.getByServerId(serverId);
|
||||
if (noteFile == null) {
|
||||
noteFile = new NoteFile();
|
||||
noteFile.setNoteId((Long) extraData[0]);
|
||||
@@ -194,7 +197,7 @@ public class NoteService {
|
||||
}
|
||||
|
||||
public static void saveNote(final long noteLocalId) {
|
||||
Note modifiedNote = Note.getByLocalId(noteLocalId);
|
||||
Note modifiedNote = NoteDataStore.getByLocalId(noteLocalId);
|
||||
|
||||
Map<String, RequestBody> requestBodyMap = generateCommonBodyMap(modifiedNote);
|
||||
List<MultipartBody.Part> fileBodies = handleFileBodies(modifiedNote, requestBodyMap);
|
||||
@@ -274,7 +277,7 @@ public class NoteService {
|
||||
if (serverNote == null) {
|
||||
return false;
|
||||
}
|
||||
Note localNote = Note.getByServerId(serverId);
|
||||
Note localNote = NoteDataStore.getByServerId(serverId);
|
||||
long localId;
|
||||
if (localNote == null) {
|
||||
localId = serverNote.insert();
|
||||
@@ -332,8 +335,8 @@ public class NoteService {
|
||||
} else {
|
||||
imageLocalIds = getImagesFromContentForRichText(note.getContent());
|
||||
}
|
||||
NoteFile.deleteExcept(note.getId(), imageLocalIds);
|
||||
List<NoteFile> files = NoteFile.getAllRelated(note.getId());
|
||||
NoteFileDataStore.deleteExcept(note.getId(), imageLocalIds);
|
||||
List<NoteFile> files = NoteFileDataStore.getAllRelated(note.getId());
|
||||
if (CollectionUtils.isNotEmpty(files)) {
|
||||
int size = files.size();
|
||||
for (int index = 0; index < size; index++) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.houxg.leamonax.service;
|
||||
|
||||
import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.network.ApiProvider;
|
||||
@@ -32,7 +33,7 @@ public class NotebookService {
|
||||
}
|
||||
|
||||
public static String getTitle(long notebookLocalId) {
|
||||
Notebook notebook = Notebook.getByLocalId(notebookLocalId);
|
||||
Notebook notebook = NotebookDataStore.getByLocalId(notebookLocalId);
|
||||
return notebook != null ? notebook.getTitle() : "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.background.NoteSyncService;
|
||||
import org.houxg.leamonax.component.PullToRefresh;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
@@ -149,9 +151,9 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
Notebook notebook;
|
||||
Navigation.Mode currentMode = mNavigation.getCurrentMode();
|
||||
if (currentMode == Navigation.Mode.NOTEBOOK) {
|
||||
notebook = Notebook.getByLocalId(currentMode.notebookId);
|
||||
notebook = NotebookDataStore.getByLocalId(currentMode.notebookId);
|
||||
} else {
|
||||
notebook = Notebook.getRecentNoteBook(Account.getCurrent().getUserId());
|
||||
notebook = NotebookDataStore.getRecentNoteBook(Account.getCurrent().getUserId());
|
||||
}
|
||||
if (notebook != null) {
|
||||
newNote.setNoteBookId(notebook.getNotebookId());
|
||||
@@ -181,13 +183,13 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
List<Note> notes;
|
||||
switch (mode) {
|
||||
case RECENT_NOTES:
|
||||
notes = Note.getAllNotes(Account.getCurrent().getUserId());
|
||||
notes = NoteDataStore.getAllNotes(Account.getCurrent().getUserId());
|
||||
break;
|
||||
case NOTEBOOK:
|
||||
notes = Note.getNotesFromNotebook(Account.getCurrent().getUserId(), mode.notebookId);
|
||||
notes = NoteDataStore.getNotesFromNotebook(Account.getCurrent().getUserId(), mode.notebookId);
|
||||
break;
|
||||
case TAG:
|
||||
notes = Note.getByTagText(mode.tagText, Account.getCurrent().getUserId());
|
||||
notes = NoteDataStore.getByTagText(mode.tagText, Account.getCurrent().getUserId());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.adapter.AccountAdapter;
|
||||
import org.houxg.leamonax.adapter.NotebookAdapter;
|
||||
import org.houxg.leamonax.adapter.TagAdapter;
|
||||
import org.houxg.leamonax.database.AccountDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
@@ -410,7 +411,7 @@ public class Navigation {
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == REQ_ADD_ACCOUNT) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
Account account = Account.getAccountById(SignInActivity.getAccountIdFromData(data));
|
||||
Account account = AccountDataStore.getAccountById(SignInActivity.getAccountIdFromData(data));
|
||||
if (account != null) {
|
||||
changeAccount(account);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.tencent.bugly.crashreport.CrashReport;
|
||||
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.ui.edit.EditorFragment;
|
||||
@@ -55,7 +56,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
ButterKnife.bind(this);
|
||||
initToolBar((Toolbar) findViewById(R.id.toolbar), true);
|
||||
long noteLocalId = getIntent().getLongExtra(EXT_NOTE_LOCAL_ID, -1);
|
||||
mNote = Note.getByLocalId(noteLocalId);
|
||||
mNote = NoteDataStore.getByLocalId(noteLocalId);
|
||||
if (mNote == null) {
|
||||
ToastUtils.show(this, R.string.note_not_found);
|
||||
CrashReport.postCatchedException(new IllegalStateException("Note not found while preview, localId=" + noteLocalId));
|
||||
@@ -112,7 +113,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
if (requestCode == REQ_EDIT) {
|
||||
switch (resultCode) {
|
||||
case RESULT_OK:
|
||||
mNote = Note.getByLocalId(mNote.getId());
|
||||
mNote = NoteDataStore.getByLocalId(mNote.getId());
|
||||
if (mNote == null) {
|
||||
finish();
|
||||
} else {
|
||||
@@ -162,7 +163,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
|
||||
@Override
|
||||
public void onNext(Long aLong) {
|
||||
mNote = Note.getByLocalId(mNote.getId());
|
||||
mNote = NoteDataStore.getByLocalId(mNote.getId());
|
||||
mNote.setIsDirty(false);
|
||||
mNote.save();
|
||||
refresh();
|
||||
@@ -204,7 +205,7 @@ public class NotePreviewActivity extends BaseActivity implements EditorFragment.
|
||||
@Override
|
||||
public void call(Boolean isSucceed) {
|
||||
if (isSucceed) {
|
||||
mNote = Note.getByServerId(mNote.getNoteId());
|
||||
mNote = NoteDataStore.getByServerId(mNote.getNoteId());
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.widget.ImageView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.adapter.NoteAdapter;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.utils.ActionModeHandler;
|
||||
@@ -129,7 +130,7 @@ public class SearchActivity extends BaseActivity implements NoteAdapter.NoteAdap
|
||||
if (TextUtils.isEmpty(keyword)) {
|
||||
mNotes = new ArrayList<>();
|
||||
} else {
|
||||
mNotes = Note.searchByTitle(keyword);
|
||||
mNotes = NoteDataStore.searchByTitle(keyword);
|
||||
Collections.sort(mNotes, new Note.UpdateTimeComparetor());
|
||||
}
|
||||
mAdapter.setHighlight(keyword);
|
||||
|
||||
@@ -17,6 +17,9 @@ import com.bumptech.glide.Glide;
|
||||
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.database.NoteTagDataStore;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.BaseResponse;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
@@ -188,10 +191,10 @@ public class SettingsActivity extends BaseActivity {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
Account currentUser = Account.getCurrent();
|
||||
String userId = currentUser.getUserId();
|
||||
Note.deleteAll(userId);
|
||||
Notebook.deleteAll(userId);
|
||||
NoteDataStore.deleteAll(userId);
|
||||
NotebookDataStore.deleteAll(userId);
|
||||
Tag.deleteAll(userId);
|
||||
RelationshipOfNoteTag.deleteAll(userId);
|
||||
NoteTagDataStore.deleteAll(userId);
|
||||
currentUser.setNoteUsn(0);
|
||||
currentUser.setNotebookUsn(0);
|
||||
currentUser.update();
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.elvishew.xlog.XLog;
|
||||
import org.houxg.leamonax.Leamonax;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.ReadableException;
|
||||
import org.houxg.leamonax.database.NoteDataStore;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.service.NoteFileService;
|
||||
@@ -81,8 +82,8 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
return;
|
||||
}
|
||||
mIsNewNote = getIntent().getBooleanExtra(EXT_IS_NEW_NOTE, false);
|
||||
mOriginal = new Wrapper(Note.getByLocalId(noteLocalId));
|
||||
mModified = new Wrapper(Note.getByLocalId(noteLocalId));
|
||||
mOriginal = new Wrapper(NoteDataStore.getByLocalId(noteLocalId));
|
||||
mModified = new Wrapper(NoteDataStore.getByLocalId(noteLocalId));
|
||||
setResult(RESULT_CANCELED);
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
|
||||
@Override
|
||||
public void onNext(Long noteLocalId) {
|
||||
Note localNote = Note.getByLocalId(noteLocalId);
|
||||
Note localNote = NoteDataStore.getByLocalId(noteLocalId);
|
||||
localNote.setIsDirty(false);
|
||||
localNote.save();
|
||||
}
|
||||
@@ -286,7 +287,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
||||
private void saveAsDraft(Wrapper wrapper) {
|
||||
Note modifiedNote = wrapper.note;
|
||||
XLog.i(TAG + "saveAsDraft(), local id=" + modifiedNote.getId());
|
||||
Note noteFromDb = Note.getByLocalId(modifiedNote.getId());
|
||||
Note noteFromDb = NoteDataStore.getByLocalId(modifiedNote.getId());
|
||||
noteFromDb.setContent(modifiedNote.getContent());
|
||||
noteFromDb.setTitle(modifiedNote.getTitle());
|
||||
noteFromDb.setNoteBookId(modifiedNote.getNoteBookId());
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.NotebookDataStore;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
@@ -135,7 +136,7 @@ public class SettingFragment extends Fragment {
|
||||
public void setNotebookId(String notebookId) {
|
||||
mNoteBookId = notebookId;
|
||||
if (!TextUtils.isEmpty(mNoteBookId)) {
|
||||
Notebook notebook = Notebook.getByServerId(mNoteBookId);
|
||||
Notebook notebook = NotebookDataStore.getByServerId(mNoteBookId);
|
||||
if (notebook != null) {
|
||||
mNotebookTv.setText(notebook.getTitle());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user