3838import android .view .MenuItem ;
3939import android .view .View ;
4040import android .view .ViewGroup ;
41+ import android .widget .CheckBox ;
42+ import android .widget .CompoundButton ;
4143import android .widget .EditText ;
4244import android .widget .ImageView ;
4345import android .widget .ListView ;
@@ -199,30 +201,8 @@ public boolean onMenuItemClick(MenuItem item) {
199201 case R .id .ctx_menu_sync_book :
200202 //TODO implement sync
201203 return false ;
202- case R .id .ctx_menu_delete_book : {
203- AlertDialog .Builder dialogBuilder = new AlertDialog .Builder (getActivity ());
204- dialogBuilder .setTitle (getString (R .string .title_confirm_delete_book ))
205- .setIcon (R .drawable .ic_close_black_24dp )
206- .setMessage (getString (R .string .msg_all_book_data_will_be_deleted ));
207- dialogBuilder .setPositiveButton (getString (R .string .btn_delete_book ), new DialogInterface .OnClickListener () {
208- @ Override
209- public void onClick (DialogInterface dialog , int which ) {
210- BooksDbAdapter .getInstance ().deleteBook (bookUID );
211- refresh ();
212- }
213- });
214- dialogBuilder .setNegativeButton (R .string .btn_cancel , new DialogInterface .OnClickListener () {
215- @ Override
216- public void onClick (DialogInterface dialog , int which ) {
217- dialog .dismiss ();
218- }
219- });
220- AlertDialog dialog = dialogBuilder .create ();
221- dialog .show (); //must be called before you can access buttons
222- dialog .getButton (AlertDialog .BUTTON_POSITIVE )
223- .setTextColor (ContextCompat .getColor (context , R .color .account_red ));
224- }
225- return true ;
204+ case R .id .ctx_menu_delete_book :
205+ return handleMenuDeleteBook (bookUID );
226206 default :
227207 return true ;
228208 }
@@ -238,6 +218,38 @@ public void onClick(DialogInterface dialog, int which) {
238218 });
239219 }
240220
221+ private boolean handleMenuDeleteBook (final String bookUID ) {
222+ AlertDialog .Builder dialogBuilder = new AlertDialog .Builder (getActivity ());
223+ dialogBuilder .setTitle (getString (R .string .title_confirm_delete_book ))
224+ .setIcon (R .drawable .ic_close_black_24dp )
225+ .setView (R .layout .dialog_double_confirm )
226+ .setMessage (getString (R .string .msg_all_book_data_will_be_deleted ));
227+ dialogBuilder .setPositiveButton (getString (R .string .btn_delete_book ), new DialogInterface .OnClickListener () {
228+ @ Override
229+ public void onClick (DialogInterface dialog , int which ) {
230+ BooksDbAdapter .getInstance ().deleteBook (bookUID );
231+ refresh ();
232+ }
233+ });
234+ dialogBuilder .setNegativeButton (R .string .btn_cancel , new DialogInterface .OnClickListener () {
235+ @ Override
236+ public void onClick (DialogInterface dialog , int which ) {
237+ dialog .dismiss ();
238+ }
239+ });
240+ final AlertDialog dialog = dialogBuilder .create ();
241+ dialog .show (); //must be called before you can access buttons
242+ dialog .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (false );
243+ CheckBox confirmCheckBox = dialog .findViewById (R .id .checkbox_confirm );
244+ confirmCheckBox .setOnCheckedChangeListener (new CompoundButton .OnCheckedChangeListener () {
245+ @ Override
246+ public void onCheckedChanged (CompoundButton compoundButton , boolean b ) {
247+ dialog .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (b );
248+ }
249+ });
250+ return true ;
251+ }
252+
241253 /**
242254 * Opens a dialog for renaming a book
243255 * @param bookName Current name of the book
0 commit comments