Skip to content

Commit

Permalink
Allow to rename books
Browse files Browse the repository at this point in the history
  • Loading branch information
rivaldi8 committed Apr 4, 2017
1 parent c581408 commit 5c2841f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
Expand Down Expand Up @@ -165,6 +166,7 @@ public void bindView(View view, final Context context, Cursor cursor) {
setLastExportedText(view, bookUID);
setStatisticsText(view, bookUID);

final String bookName = cursor.getString(cursor.getColumnIndexOrThrow(BookEntry.COLUMN_DISPLAY_NAME));
ImageView optionsMenu = (ImageView) view.findViewById(R.id.options_menu);
optionsMenu.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -176,6 +178,32 @@ public void onClick(View v) {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.ctx_menu_rename_book:
final EditText nameEditText = new EditText(context);
nameEditText.setText(bookName);

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setTitle(R.string.title_rename_book)
.setView(nameEditText)
.setPositiveButton(R.string.btn_rename, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
BooksDbAdapter.getInstance()
.updateRecord(bookUID,
BookEntry.COLUMN_DISPLAY_NAME,
nameEditText.getText().toString());
refresh();
}
})
.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = dialogBuilder.create();
dialog.show();
return true;
case R.id.ctx_menu_sync_book:
//TODO implement sync
return false;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/cardview_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
android:layout_marginLeft="@dimen/dialog_padding"
android:layout_marginRight="52dp"/>

<ImageView android:visibility="gone"
<ImageView
android:id="@+id/options_menu"
android:layout_width="48dp"
android:layout_height="48dp"
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/res/menu/book_context_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:id="@+id/ctx_menu_rename_book"
android:title="@string/menu_rename"
app:showAsAction="ifRoom"
android:orderInCategory="1" />

<item android:id="@+id/ctx_menu_sync_book"
android:visible="false"
android:checkable="true"
android:title="@string/menu_title_enable_sync"
app:showAsAction="always"
android:orderInCategory="1" />
app:showAsAction="ifRoom"
android:orderInCategory="2" />
</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,7 @@
<string name="menu_show_compact_view">Compact View</string>
<string name="book_default_name">Book %1$d</string>
<string name="last_export_time_never">never</string>
<string name="title_rename_book">Rename Book</string>
<string name="btn_rename">Rename</string>
<string name="menu_rename">Rename</string>
</resources>

0 comments on commit 5c2841f

Please sign in to comment.