mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-14 14:10:56 +00:00
code refactoring: move getCurrent() method to Account class
This commit is contained in:
@@ -18,10 +18,10 @@ import android.widget.TextView;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.service.NoteFileService;
|
||||
import org.houxg.leamonax.utils.FileUtils;
|
||||
import org.houxg.leamonax.utils.TimeUtils;
|
||||
@@ -106,7 +106,7 @@ public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.NoteHolder> {
|
||||
}
|
||||
|
||||
private void updateNotebookMap() {
|
||||
List<Notebook> notebooks = Notebook.getAllNotebooks(AccountService.getCurrent().getUserId());
|
||||
List<Notebook> notebooks = Notebook.getAllNotebooks(Account.getCurrent().getUserId());
|
||||
mNotebookId2TitleMaps = new HashMap<>();
|
||||
for (Notebook notebook : notebooks) {
|
||||
mNotebookId2TitleMaps.put(notebook.getNotebookId(), notebook.getTitle());
|
||||
|
@@ -10,9 +10,8 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -56,14 +55,14 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
|
||||
private void getSafeNotebook(Stack<String> stack) {
|
||||
if (stack.isEmpty()) {
|
||||
mData = Notebook.getRootNotebooks(AccountService.getCurrent().getUserId());
|
||||
mData = Notebook.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
} else {
|
||||
Notebook parent = Notebook.getByServerId(stack.peek());
|
||||
if (parent.isDeleted()) {
|
||||
stack.pop();
|
||||
getSafeNotebook(stack);
|
||||
} else {
|
||||
mData = Notebook.getChildNotebook(mStack.peek(), AccountService.getCurrent().getUserId());
|
||||
mData = Notebook.getChildNotebook(mStack.peek(), Account.getCurrent().getUserId());
|
||||
mData.add(0, parent);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +147,7 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
}
|
||||
|
||||
private boolean hasChild(String notebookId) {
|
||||
return CollectionUtils.isNotEmpty(Notebook.getChildNotebook(notebookId, AccountService.getCurrent().getUserId()));
|
||||
return CollectionUtils.isNotEmpty(Notebook.getChildNotebook(notebookId, Account.getCurrent().getUserId()));
|
||||
}
|
||||
|
||||
private void listUpper() {
|
||||
@@ -158,11 +157,11 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
|
||||
mStack.pop();
|
||||
if (mStack.isEmpty()) {
|
||||
mData = Notebook.getRootNotebooks(AccountService.getCurrent().getUserId());
|
||||
mData = Notebook.getRootNotebooks(Account.getCurrent().getUserId());
|
||||
} else {
|
||||
String parentId = mStack.peek();
|
||||
mData.add(Notebook.getByServerId(parentId));
|
||||
mData.addAll(Notebook.getChildNotebook(parentId, AccountService.getCurrent().getUserId()));
|
||||
mData.addAll(Notebook.getChildNotebook(parentId, Account.getCurrent().getUserId()));
|
||||
}
|
||||
notifyItemRangeInserted(0, mData.size());
|
||||
}
|
||||
@@ -181,7 +180,7 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
||||
notifyItemChanged(0);
|
||||
|
||||
mStack.push(notebook.getNotebookId());
|
||||
List<Notebook> children = Notebook.getChildNotebook(notebook.getNotebookId(), AccountService.getCurrent().getUserId());
|
||||
List<Notebook> children = Notebook.getChildNotebook(notebook.getNotebookId(), Account.getCurrent().getUserId());
|
||||
int childrenSize = children.size();
|
||||
mData.addAll(children);
|
||||
notifyItemRangeInserted(1, childrenSize);
|
||||
|
@@ -8,11 +8,9 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
@@ -28,7 +26,7 @@ public class TagAdapter extends RecyclerView.Adapter<TagAdapter.TagHolder> {
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
mData = Tag.getAllTags(AccountService.getCurrent().getUserId());
|
||||
mData = Tag.getAllTags(Account.getCurrent().getUserId());
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@@ -182,7 +182,7 @@ public class Account extends BaseModel {
|
||||
.querySingle();
|
||||
}
|
||||
|
||||
public static Account getAccountWithToken() {
|
||||
public static Account getCurrent() {
|
||||
return SQLite.select()
|
||||
.from(Account.class)
|
||||
.where(Account_Table.token.notEq(""))
|
||||
|
@@ -14,7 +14,6 @@ import com.raizlabs.android.dbflow.sql.language.property.IProperty;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
import org.houxg.leamonax.utils.TimeUtils;
|
||||
|
||||
@@ -268,7 +267,7 @@ public class Note extends BaseModel implements Serializable {
|
||||
keyword = String.format(Locale.US, "%%%s%%", keyword);
|
||||
return SQLite.select()
|
||||
.from(Note.class)
|
||||
.where(Note_Table.userId.eq(AccountService.getCurrent().getUserId()))
|
||||
.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))
|
||||
|
@@ -4,8 +4,6 @@ package org.houxg.leamonax.model;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
|
||||
public class User extends BaseResponse {
|
||||
|
||||
@SerializedName("UserId")
|
||||
@@ -37,7 +35,7 @@ public class User extends BaseResponse {
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
Account current = AccountService.getCurrent();
|
||||
Account current = Account.getCurrent();
|
||||
String host = current.getHost();
|
||||
if(host.equals("https://leanote.com")){
|
||||
return avatar;}
|
||||
|
@@ -8,7 +8,6 @@ import org.houxg.leamonax.network.api.AuthApi;
|
||||
import org.houxg.leamonax.network.api.NoteApi;
|
||||
import org.houxg.leamonax.network.api.NotebookApi;
|
||||
import org.houxg.leamonax.network.api.UserApi;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -29,7 +28,7 @@ public class ApiProvider {
|
||||
}
|
||||
|
||||
public static ApiProvider getInstance() {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
if (account != null && SingletonHolder.INSTANCE.mApiRetrofit == null) {
|
||||
SingletonHolder.INSTANCE.init(account.getHost());
|
||||
}
|
||||
@@ -50,7 +49,7 @@ public class ApiProvider {
|
||||
HttpUrl newUrl = url;
|
||||
if (shouldAddTokenToQuery(path)) {
|
||||
newUrl = url.newBuilder()
|
||||
.addQueryParameter("token", AccountService.getCurrent().getAccessToken())
|
||||
.addQueryParameter("token", Account.getCurrent().getAccessToken())
|
||||
.build();
|
||||
}
|
||||
Request newRequest = request.newBuilder()
|
||||
|
@@ -54,7 +54,7 @@ public class AccountService {
|
||||
}
|
||||
|
||||
public static void logout() {
|
||||
Account account = getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
account.setAccessToken("");
|
||||
account.update();
|
||||
}
|
||||
@@ -67,15 +67,11 @@ public class AccountService {
|
||||
return RetrofitUtils.create(ApiProvider.getInstance().getUserApi().updateUsername(userName));
|
||||
}
|
||||
|
||||
public static Account getCurrent() {
|
||||
return Account.getAccountWithToken();
|
||||
}
|
||||
|
||||
public static List<Account> getAccountList() {
|
||||
return Account.getAccountListWithToken();
|
||||
}
|
||||
|
||||
public static boolean isSignedIn() {
|
||||
return getCurrent() != null;
|
||||
return Account.getCurrent() != null;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.houxg.leamonax.Leamonax;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
|
||||
import java.io.File;
|
||||
@@ -50,7 +51,7 @@ public class NoteFileService {
|
||||
}
|
||||
|
||||
public static Uri getServerImageUri(String serverId) {
|
||||
Uri uri = Uri.parse(AccountService.getCurrent().getHost());
|
||||
Uri uri = Uri.parse(Account.getCurrent().getHost());
|
||||
return uri.buildUpon().appendEncodedPath("api/file/getImage").appendQueryParameter("fileId", serverId).build();
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ public class NoteFileService {
|
||||
filePath = noteFile.getLocalPath();
|
||||
XLog.i(TAG + "use local image, path=" + filePath);
|
||||
} else {
|
||||
String url = NoteFileService.getUrl(AccountService.getCurrent().getHost(), noteFile.getServerId(), AccountService.getCurrent().getAccessToken());
|
||||
String url = NoteFileService.getUrl(Account.getCurrent().getHost(), noteFile.getServerId(), Account.getCurrent().getAccessToken());
|
||||
XLog.i(TAG + "use server image, url=" + url);
|
||||
try {
|
||||
filePath = NoteFileService.getImageFromServer(Uri.parse(url), Leamonax.getContext().getCacheDir());
|
||||
|
@@ -7,7 +7,6 @@ import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.elvishew.xlog.XLog;
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.houxg.leamonax.R;
|
||||
@@ -15,7 +14,6 @@ import org.houxg.leamonax.ReadableException;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.NoteFile;
|
||||
import org.houxg.leamonax.model.Note_Table;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
@@ -49,7 +47,7 @@ public class NoteService {
|
||||
|
||||
public static void fetchFromServer() {
|
||||
//sync notebook
|
||||
int notebookUsn = AccountService.getCurrent().getNotebookUsn();
|
||||
int notebookUsn = Account.getCurrent().getNotebookUsn();
|
||||
List<Notebook> notebooks;
|
||||
do {
|
||||
notebooks = RetrofitUtils.excuteWithException(ApiProvider.getInstance().getNotebookApi().getSyncNotebooks(notebookUsn, MAX_ENTRY));
|
||||
@@ -65,7 +63,7 @@ public class NoteService {
|
||||
remoteNotebook.update();
|
||||
}
|
||||
notebookUsn = remoteNotebook.getUsn();
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
account.setNotebookUsn(notebookUsn);
|
||||
account.save();
|
||||
}
|
||||
@@ -73,7 +71,7 @@ public class NoteService {
|
||||
|
||||
|
||||
//sync note
|
||||
int noteUsn = AccountService.getCurrent().getNoteUsn();
|
||||
int noteUsn = Account.getCurrent().getNoteUsn();
|
||||
List<Note> notes;
|
||||
do {
|
||||
notes = RetrofitUtils.excuteWithException(ApiProvider.getInstance().getNoteApi().getSyncNotes(noteUsn, MAX_ENTRY));
|
||||
@@ -110,7 +108,7 @@ public class NoteService {
|
||||
remoteNote.update();
|
||||
handleFile(localId, remoteNote.getNoteFiles());
|
||||
updateTagsToLocal(localId, remoteNote.getTagData());
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
account.setNoteUsn(noteUsn);
|
||||
account.save();
|
||||
}
|
||||
@@ -149,7 +147,7 @@ public class NoteService {
|
||||
private static String convertToLocalImageLinkForRichText(long noteLocalId, String noteContent) {
|
||||
return StringUtils.replace(noteContent,
|
||||
"<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>",
|
||||
String.format(Locale.US, "\\ssrc\\s*=\\s*\"%s/api/file/getImage\\?fileId=.*?\"", AccountService.getCurrent().getHost()),
|
||||
String.format(Locale.US, "\\ssrc\\s*=\\s*\"%s/api/file/getImage\\?fileId=.*?\"", Account.getCurrent().getHost()),
|
||||
new StringUtils.Replacer() {
|
||||
@Override
|
||||
public String replaceWith(String original, Object... extraData) {
|
||||
@@ -174,8 +172,8 @@ public class NoteService {
|
||||
|
||||
private static String convertToLocalImageLinkForMD(long noteLocalId, String noteContent) {
|
||||
return StringUtils.replace(noteContent,
|
||||
String.format(Locale.US, "!\\[.*?\\]\\(%s/api/file/getImage\\?fileId=.*?\\)", AccountService.getCurrent().getHost()),
|
||||
String.format(Locale.US, "\\(%s/api/file/getImage\\?fileId=.*?\\)", AccountService.getCurrent().getHost()),
|
||||
String.format(Locale.US, "!\\[.*?\\]\\(%s/api/file/getImage\\?fileId=.*?\\)", Account.getCurrent().getHost()),
|
||||
String.format(Locale.US, "\\(%s/api/file/getImage\\?fileId=.*?\\)", Account.getCurrent().getHost()),
|
||||
new StringUtils.Replacer() {
|
||||
@Override
|
||||
public String replaceWith(String original, Object... extraData) {
|
||||
@@ -404,7 +402,7 @@ public class NoteService {
|
||||
* if new usn equals to (current usn + 1), then just simply update usn without syncing.
|
||||
*/
|
||||
private static void updateNoteUsnIfNeed(int newUsn) {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
if (newUsn - account.getNoteUsn() == 1) {
|
||||
account.setNoteUsn(newUsn);
|
||||
account.update();
|
||||
@@ -412,7 +410,7 @@ public class NoteService {
|
||||
}
|
||||
|
||||
public static void updateTagsToLocal(long noteLocalId, List<String> tags) {
|
||||
String currentUid = AccountService.getCurrent().getUserId();
|
||||
String currentUid = Account.getCurrent().getUserId();
|
||||
if (tags == null) {
|
||||
tags = new ArrayList<>();
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ package org.houxg.leamonax.service;
|
||||
|
||||
import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.network.ApiProvider;
|
||||
@@ -19,7 +18,7 @@ public class NotebookService {
|
||||
throw new IllegalStateException("Network error");
|
||||
}
|
||||
if (notebook.isOk()) {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
if (notebook.getUsn() - account.getNotebookUsn() == 1) {
|
||||
XLog.d(TAG + "update usn=" + notebook.getUsn());
|
||||
account.setNotebookUsn(notebook.getUsn());
|
||||
|
@@ -13,8 +13,8 @@ import org.bson.types.ObjectId;
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.OpenUtils;
|
||||
import org.houxg.leamonax.utils.TestUtils;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class AboutActivity extends BaseActivity {
|
||||
new Observable.OnSubscribe<Void>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super Void> subscriber) {
|
||||
String userId = AccountService.getCurrent().getUserId();
|
||||
String userId = Account.getCurrent().getUserId();
|
||||
SecureRandom random = new SecureRandom();
|
||||
String notebookId = new ObjectId().toString();
|
||||
List<Note> notes = new ArrayList<>(8000);
|
||||
|
@@ -15,7 +15,7 @@ public class LaunchActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
Intent intent;
|
||||
if (AccountService.isSignedIn()) {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
ApiProvider.getInstance().init(account.getHost());
|
||||
intent = MainActivity.getOpenIntent(this, false);
|
||||
} else {
|
||||
|
@@ -8,7 +8,6 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -20,20 +19,15 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.adapter.NotebookAdapter;
|
||||
import org.houxg.leamonax.background.NoteSyncService;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.SyncEvent;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.ui.edit.NoteEditActivity;
|
||||
import org.houxg.leamonax.utils.NetworkUtils;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -69,7 +63,7 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
initToolBar((Toolbar) findViewById(R.id.toolbar));
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white);
|
||||
CrashReport.setUserId(AccountService.getCurrent().getUserId());
|
||||
CrashReport.setUserId(Account.getCurrent().getUserId());
|
||||
|
||||
mNavigation = new Navigation(this);
|
||||
mNavigation.init(this, mNavigationView);
|
||||
@@ -154,7 +148,7 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
|
||||
@OnClick(R.id.fab)
|
||||
void clickedFab() {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
Note newNote = new Note();
|
||||
newNote.setUserId(account.getUserId());
|
||||
Notebook notebook;
|
||||
@@ -162,7 +156,7 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
if (currentMode == Navigation.Mode.NOTEBOOK) {
|
||||
notebook = Notebook.getByLocalId(currentMode.notebookId);
|
||||
} else {
|
||||
notebook = Notebook.getRecentNoteBook(AccountService.getCurrent().getUserId());
|
||||
notebook = Notebook.getRecentNoteBook(Account.getCurrent().getUserId());
|
||||
}
|
||||
if (notebook != null) {
|
||||
newNote.setNoteBookId(notebook.getNotebookId());
|
||||
@@ -192,13 +186,13 @@ public class MainActivity extends BaseActivity implements Navigation.Callback {
|
||||
List<Note> notes;
|
||||
switch (mode) {
|
||||
case RECENT_NOTES:
|
||||
notes = Note.getAllNotes(AccountService.getCurrent().getUserId());
|
||||
notes = Note.getAllNotes(Account.getCurrent().getUserId());
|
||||
break;
|
||||
case NOTEBOOK:
|
||||
notes = Note.getNotesFromNotebook(AccountService.getCurrent().getUserId(), mode.notebookId);
|
||||
notes = Note.getNotesFromNotebook(Account.getCurrent().getUserId(), mode.notebookId);
|
||||
break;
|
||||
case TAG:
|
||||
notes = Note.getByTagText(mode.tagText, AccountService.getCurrent().getUserId());
|
||||
notes = Note.getByTagText(mode.tagText, Account.getCurrent().getUserId());
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
@@ -6,16 +6,12 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.ViewGroupCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -25,8 +21,6 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.elvishew.xlog.XLog;
|
||||
import com.tencent.bugly.Bugly;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
@@ -108,7 +102,7 @@ public class Navigation {
|
||||
}
|
||||
|
||||
private void fetchInfo() {
|
||||
AccountService.getInfo(AccountService.getCurrent().getUserId())
|
||||
AccountService.getInfo(Account.getCurrent().getUserId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<User>() {
|
||||
@@ -124,8 +118,8 @@ public class Navigation {
|
||||
|
||||
@Override
|
||||
public void onNext(User user) {
|
||||
AccountService.saveToAccount(user, AccountService.getCurrent().getHost());
|
||||
refreshUserInfo(AccountService.getCurrent());
|
||||
AccountService.saveToAccount(user, Account.getCurrent().getHost());
|
||||
refreshUserInfo(Account.getCurrent());
|
||||
mAccountAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
@@ -371,7 +365,7 @@ public class Navigation {
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
refreshUserInfo(AccountService.getCurrent());
|
||||
refreshUserInfo(Account.getCurrent());
|
||||
mAccountAdapter.load(AccountService.getAccountList());
|
||||
mTagAdapter.refresh();
|
||||
mNotebookAdapter.refresh();
|
||||
|
@@ -6,10 +6,7 @@ import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.ActionMode;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -17,22 +14,13 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.elvishew.xlog.XLog;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.adapter.NoteAdapter;
|
||||
import org.houxg.leamonax.background.NoteSyncService;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.SyncEvent;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.utils.ActionModeHandler;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
import org.houxg.leamonax.utils.NetworkUtils;
|
||||
import org.houxg.leamonax.utils.SharedPreferenceUtils;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
import org.houxg.leamonax.widget.NoteList;
|
||||
@@ -40,7 +28,6 @@ import org.houxg.leamonax.widget.NoteList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@@ -15,7 +15,6 @@ import com.tencent.bugly.crashreport.CrashReport;
|
||||
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.ui.edit.EditorFragment;
|
||||
|
@@ -3,7 +3,6 @@ package org.houxg.leamonax.ui;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@@ -11,10 +10,7 @@ import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.transition.Slide;
|
||||
import android.transition.Transition;
|
||||
import android.transition.TransitionInflater;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@@ -24,14 +20,11 @@ import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.service.NoteService;
|
||||
import org.houxg.leamonax.utils.ActionModeHandler;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
import org.houxg.leamonax.utils.DisplayUtils;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
import org.houxg.leamonax.widget.DividerDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@@ -14,20 +14,15 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.raizlabs.android.dbflow.sql.language.SQLite;
|
||||
|
||||
import org.houxg.leamonax.BuildConfig;
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.BaseResponse;
|
||||
import org.houxg.leamonax.model.Note;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag;
|
||||
import org.houxg.leamonax.model.Note_Table;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.Notebook_Table;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag_Table;
|
||||
import org.houxg.leamonax.model.RelationshipOfNoteTag;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.model.Tag_Table;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.ToastUtils;
|
||||
|
||||
@@ -76,11 +71,11 @@ public class SettingsActivity extends BaseActivity {
|
||||
void selectEditor() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.choose_editor)
|
||||
.setSingleChoiceItems(mEditors, AccountService.getCurrent().getDefaultEditor(), new DialogInterface.OnClickListener() {
|
||||
.setSingleChoiceItems(mEditors, Account.getCurrent().getDefaultEditor(), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
account.setDefaultEditor(which);
|
||||
account.update();
|
||||
mEditorTv.setText(mEditors[which]);
|
||||
@@ -128,7 +123,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
void clickedUserName() {
|
||||
View view = LayoutInflater.from(this).inflate(R.layout.dialog_sigle_edittext, null);
|
||||
final EditText mUserNameEt = (EditText) view.findViewById(R.id.edit);
|
||||
mUserNameEt.setText(AccountService.getCurrent().getUserName());
|
||||
mUserNameEt.setText(Account.getCurrent().getUserName());
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.change_user_name)
|
||||
.setView(view)
|
||||
@@ -191,7 +186,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
@Override
|
||||
public void call(Subscriber<? super Void> subscriber) {
|
||||
if (!subscriber.isUnsubscribed()) {
|
||||
Account currentUser = AccountService.getCurrent();
|
||||
Account currentUser = Account.getCurrent();
|
||||
String userId = currentUser.getUserId();
|
||||
Note.deleteAll(userId);
|
||||
Notebook.deleteAll(userId);
|
||||
@@ -228,18 +223,18 @@ public class SettingsActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
ToastUtils.showNetworkError(SettingsActivity.this);
|
||||
mUserNameTv.setText(AccountService.getCurrent().getUserName());
|
||||
mUserNameTv.setText(Account.getCurrent().getUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
if (baseResponse.isOk()) {
|
||||
Account account = AccountService.getCurrent();
|
||||
Account account = Account.getCurrent();
|
||||
account.setUserName(username);
|
||||
account.update();
|
||||
ToastUtils.show(SettingsActivity.this, R.string.change_user_name_successful);
|
||||
} else {
|
||||
mUserNameTv.setText(AccountService.getCurrent().getUserName());
|
||||
mUserNameTv.setText(Account.getCurrent().getUserName());
|
||||
ToastUtils.show(SettingsActivity.this, R.string.change_user_name_failed);
|
||||
}
|
||||
}
|
||||
@@ -273,7 +268,7 @@ public class SettingsActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
Account current = AccountService.getCurrent();
|
||||
Account current = Account.getCurrent();
|
||||
mEditorTv.setText(mEditors[current.getDefaultEditor()]);
|
||||
mUserNameTv.setText(current.getUserName());
|
||||
mEmailTv.setText(current.getEmail());
|
||||
|
@@ -41,7 +41,6 @@ import org.houxg.leamonax.utils.DialogUtils;
|
||||
import org.houxg.leamonax.utils.OpenUtils;
|
||||
import org.houxg.leamonax.widget.ToggleImageButton;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@@ -18,10 +18,9 @@ import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.houxg.leamonax.R;
|
||||
import org.houxg.leamonax.database.AppDataBase;
|
||||
import org.houxg.leamonax.model.Account;
|
||||
import org.houxg.leamonax.model.Notebook;
|
||||
import org.houxg.leamonax.model.Tag;
|
||||
import org.houxg.leamonax.service.AccountService;
|
||||
import org.houxg.leamonax.utils.CollectionUtils;
|
||||
import org.houxg.leamonax.utils.DialogUtils;
|
||||
import org.houxg.leamonax.utils.DisplayUtils;
|
||||
@@ -63,7 +62,7 @@ public class SettingFragment extends Fragment {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
List<Tag> tags = Tag.getAllTags(AccountService.getCurrent().getUserId());
|
||||
List<Tag> tags = Tag.getAllTags(Account.getCurrent().getUserId());
|
||||
String[] tagTexts = new String[tags.size()];
|
||||
int i = 0;
|
||||
for (Tag tag : tags) {
|
||||
|
Reference in New Issue
Block a user