mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-18 16:41:13 +00:00
update notebook title
This commit is contained in:
@@ -14,6 +14,7 @@ import org.houxg.leamonax.database.AppDataBase;
|
|||||||
import org.houxg.leamonax.model.Notebook;
|
import org.houxg.leamonax.model.Notebook;
|
||||||
import org.houxg.leamonax.service.AccountService;
|
import org.houxg.leamonax.service.AccountService;
|
||||||
import org.houxg.leamonax.utils.CollectionUtils;
|
import org.houxg.leamonax.utils.CollectionUtils;
|
||||||
|
import org.houxg.leamonax.utils.ToastUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -113,14 +114,16 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
|||||||
String notebookId = notebook.getNotebookId();
|
String notebookId = notebook.getNotebookId();
|
||||||
boolean isSuper = isSuper(notebookId);
|
boolean isSuper = isSuper(notebookId);
|
||||||
boolean isSuperOrRoot = isSuper | mStack.isEmpty();
|
boolean isSuperOrRoot = isSuper | mStack.isEmpty();
|
||||||
boolean hasChild = hasChild(notebookId);
|
final boolean hasChild = hasChild(notebookId);
|
||||||
holder.placeholder.setVisibility(isSuperOrRoot ? View.GONE : View.VISIBLE);
|
holder.placeholder.setVisibility(isSuperOrRoot ? View.GONE : View.VISIBLE);
|
||||||
holder.navigator.setVisibility(mCanOpenEmpty | hasChild ? View.VISIBLE : View.INVISIBLE);
|
|
||||||
holder.navigator.setImageResource(isSuper ? R.drawable.ic_expanding : R.drawable.ic_expandable);
|
holder.navigator.setImageResource(isSuper ? R.drawable.ic_expanding : R.drawable.ic_expandable);
|
||||||
holder.navigator.setOnClickListener(new View.OnClickListener() {
|
holder.navigator.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
//TODO: arrow animation
|
//TODO: arrow animation
|
||||||
|
if (!hasChild) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isSuper(notebook.getNotebookId())) {
|
if (isSuper(notebook.getNotebookId())) {
|
||||||
listUpper();
|
listUpper();
|
||||||
} else {
|
} else {
|
||||||
@@ -132,11 +135,19 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
listChild(notebook);
|
|
||||||
mListener.onClickedNotebook(notebook);
|
mListener.onClickedNotebook(notebook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
holder.titleTv.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onEditNotebook(notebook);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSuper(String notebookId) {
|
private boolean isSuper(String notebookId) {
|
||||||
@@ -197,6 +208,8 @@ public class NotebookAdapter extends RecyclerView.Adapter<NotebookAdapter.Notebo
|
|||||||
void onClickedNotebook(Notebook notebook);
|
void onClickedNotebook(Notebook notebook);
|
||||||
|
|
||||||
void onClickedAddNotebook(String parentNotebookId);
|
void onClickedAddNotebook(String parentNotebookId);
|
||||||
|
|
||||||
|
void onEditNotebook(Notebook notebook);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NotebookHolder extends RecyclerView.ViewHolder {
|
static class NotebookHolder extends RecyclerView.ViewHolder {
|
||||||
|
@@ -19,4 +19,9 @@ public interface NotebookApi {
|
|||||||
|
|
||||||
@POST("notebook/addNotebook")
|
@POST("notebook/addNotebook")
|
||||||
Call<Notebook> addNotebook(@Query("title") String title, @Query("parentNotebookId") String parentId);
|
Call<Notebook> addNotebook(@Query("title") String title, @Query("parentNotebookId") String parentId);
|
||||||
|
|
||||||
|
@POST("notebook/updateNotebook")
|
||||||
|
Call<Notebook> updateNotebook(@Query("notebookId") String notebookId, @Query("title") String title,
|
||||||
|
@Query("parentNotebookId") String parentId, @Query("seq") int seq, @Query("usn") int usn);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -36,4 +36,24 @@ public class NotebookService {
|
|||||||
Notebook notebook = AppDataBase.getNotebookByLocalId(notebookLocalId);
|
Notebook notebook = AppDataBase.getNotebookByLocalId(notebookLocalId);
|
||||||
return notebook != null ? notebook.getTitle() : "";
|
return notebook != null ? notebook.getTitle() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Notebook updateNotebook(String title, Notebook notebook) {
|
||||||
|
Notebook newNotebook = RetrofitUtils.excute(ApiProvider.getInstance().getNotebookApi().
|
||||||
|
updateNotebook(notebook.getNotebookId(), title, notebook.getParentNotebookId(), notebook.getSeq(), notebook.getUsn()));
|
||||||
|
if (newNotebook == null) {
|
||||||
|
throw new IllegalStateException("Network error");
|
||||||
|
}
|
||||||
|
if (newNotebook.isOk()) {
|
||||||
|
Account account = AccountService.getCurrent();
|
||||||
|
if (notebook.getUsn() - account.getNotebookUsn() == 1) {
|
||||||
|
account.setNotebookUsn(notebook.getUsn());
|
||||||
|
account.save();
|
||||||
|
}
|
||||||
|
newNotebook.setId(notebook.getId());
|
||||||
|
newNotebook.update();
|
||||||
|
return notebook;
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(notebook.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ import org.houxg.leamonax.service.AccountService;
|
|||||||
import org.houxg.leamonax.service.NotebookService;
|
import org.houxg.leamonax.service.NotebookService;
|
||||||
import org.houxg.leamonax.utils.DisplayUtils;
|
import org.houxg.leamonax.utils.DisplayUtils;
|
||||||
import org.houxg.leamonax.utils.OpenUtils;
|
import org.houxg.leamonax.utils.OpenUtils;
|
||||||
|
import org.houxg.leamonax.utils.ToastUtils;
|
||||||
import org.houxg.leamonax.widget.AlphabetDrawable;
|
import org.houxg.leamonax.widget.AlphabetDrawable;
|
||||||
import org.houxg.leamonax.widget.TriangleView;
|
import org.houxg.leamonax.widget.TriangleView;
|
||||||
|
|
||||||
@@ -312,6 +313,25 @@ public class Navigation {
|
|||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEditNotebook(final Notebook notebook) {
|
||||||
|
View view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_sigle_edittext, null);
|
||||||
|
final EditText mEdit = (EditText) view.findViewById(R.id.edit);
|
||||||
|
mEdit.setText(notebook.getTitle());
|
||||||
|
mEdit.setSelection(notebook.getTitle().length());
|
||||||
|
new AlertDialog.Builder(mActivity)
|
||||||
|
.setTitle(R.string.update_notebook_title)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
updateNotebook(mEdit.getText().toString(), notebook);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mNotebookRv.setAdapter(mNotebookAdapter);
|
mNotebookRv.setAdapter(mNotebookAdapter);
|
||||||
mNotebookAdapter.refresh();
|
mNotebookAdapter.refresh();
|
||||||
@@ -323,7 +343,47 @@ public class Navigation {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateNotebook(final String title, final Notebook notebook) {
|
||||||
|
if (TextUtils.isEmpty(title)) {
|
||||||
|
ToastUtils.show(mActivity, R.string.toast_notebook_title_not_empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Observable.create(
|
||||||
|
new Observable.OnSubscribe<Notebook>() {
|
||||||
|
@Override
|
||||||
|
public void call(Subscriber<? super Notebook> subscriber) {
|
||||||
|
if (!subscriber.isUnsubscribed()) {
|
||||||
|
subscriber.onNext(NotebookService.updateNotebook(title, notebook));
|
||||||
|
subscriber.onCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(new Observer<Notebook>() {
|
||||||
|
@Override
|
||||||
|
public void onCompleted() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Notebook isSucceed) {
|
||||||
|
mNotebookAdapter.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void addNotebook(final String title, final String parentNotebookId) {
|
private void addNotebook(final String title, final String parentNotebookId) {
|
||||||
|
if (TextUtils.isEmpty(title)) {
|
||||||
|
ToastUtils.show(mActivity, R.string.toast_notebook_title_not_empty);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Observable.create(
|
Observable.create(
|
||||||
new Observable.OnSubscribe<Notebook>() {
|
new Observable.OnSubscribe<Notebook>() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -75,6 +75,11 @@ public class DialogUtils {
|
|||||||
public void onClickedAddNotebook(String parentNotebookId) {
|
public void onClickedAddNotebook(String parentNotebookId) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEditNotebook(Notebook notebook) {
|
||||||
|
|
||||||
|
}
|
||||||
});
|
});
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
|
@@ -108,4 +108,6 @@
|
|||||||
<string name="host_example">登录接口地址将会是:\n%s/api/login</string>
|
<string name="host_example">登录接口地址将会是:\n%s/api/login</string>
|
||||||
<string name="my_blog">我的博客</string>
|
<string name="my_blog">我的博客</string>
|
||||||
<string name="explore">蚂蚁笔记探索</string>
|
<string name="explore">蚂蚁笔记探索</string>
|
||||||
|
<string name="toast_notebook_title_not_empty">笔记本的名称不能为空</string>
|
||||||
|
<string name="update_notebook_title">修改笔记本的名称</string>
|
||||||
</resources>
|
</resources>
|
@@ -110,4 +110,6 @@
|
|||||||
<string name="host_example">For example, login api will be:\n%s/api/login</string>
|
<string name="host_example">For example, login api will be:\n%s/api/login</string>
|
||||||
<string name="my_blog">My Blog</string>
|
<string name="my_blog">My Blog</string>
|
||||||
<string name="explore">Leanote Explore</string>
|
<string name="explore">Leanote Explore</string>
|
||||||
|
<string name="toast_notebook_title_not_empty">the notebook title can\'t empty</string>
|
||||||
|
<string name="update_notebook_title">Update notebook title</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Reference in New Issue
Block a user