forked from codinguser/gnucash-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request codinguser#720 from rivaldi8/bug-544-confirm-irrev…
…ersible-actions Bugfix 544: Add dialog with extra checkbox for irreversible actions Fixes codinguser#544
- Loading branch information
Showing
8 changed files
with
205 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/org/gnucash/android/ui/settings/dialog/DeleteBookConfirmationDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2017 Àlex Magaz Graça <alexandre.magaz@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gnucash.android.ui.settings.dialog; | ||
|
||
import android.app.Dialog; | ||
import android.content.DialogInterface; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
|
||
import org.gnucash.android.R; | ||
import org.gnucash.android.db.adapter.BooksDbAdapter; | ||
import org.gnucash.android.ui.common.Refreshable; | ||
|
||
/** | ||
* Confirmation dialog for deleting a book. | ||
* | ||
* @author Àlex Magaz <alexandre.magaz@gmail.com> | ||
*/ | ||
public class DeleteBookConfirmationDialog extends DoubleConfirmationDialog { | ||
@NonNull | ||
public static DeleteBookConfirmationDialog newInstance(String bookUID) { | ||
DeleteBookConfirmationDialog frag = new DeleteBookConfirmationDialog(); | ||
Bundle args = new Bundle(); | ||
args.putString("bookUID", bookUID); | ||
frag.setArguments(args); | ||
return frag; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
return getDialogBuilder() | ||
.setTitle(R.string.title_confirm_delete_book) | ||
.setIcon(R.drawable.ic_close_black_24dp) | ||
.setMessage(R.string.msg_all_book_data_will_be_deleted) | ||
.setPositiveButton(R.string.btn_delete_book, new DialogInterface.OnClickListener() { | ||
@SuppressWarnings("ConstantConditions") | ||
@Override | ||
public void onClick(DialogInterface dialogInterface, int which) { | ||
final String bookUID = getArguments().getString("bookUID"); | ||
BooksDbAdapter.getInstance().deleteBook(bookUID); | ||
((Refreshable) getTargetFragment()).refresh(); | ||
} | ||
}) | ||
.create(); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
app/src/main/java/org/gnucash/android/ui/settings/dialog/DoubleConfirmationDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2017 Àlex Magaz Graça <alexandre.magaz@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gnucash.android.ui.settings.dialog; | ||
|
||
import android.content.DialogInterface; | ||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.DialogFragment; | ||
import android.support.v7.app.AlertDialog; | ||
import android.widget.CheckBox; | ||
import android.widget.CompoundButton; | ||
|
||
import org.gnucash.android.R; | ||
|
||
/** | ||
* Confirmation dialog with additional checkbox to confirm the action. | ||
* | ||
* <p>It's meant to avoid the user confirming irreversible actions by | ||
* mistake. The positive button to confirm the action is only enabled | ||
* when the checkbox is checked.</p> | ||
* | ||
* <p>Extend this class and override onCreateDialog to finish setting | ||
* up the dialog. See getDialogBuilder().</p> | ||
* | ||
* @author Àlex Magaz <alexandre.magaz@gmail.com> | ||
*/ | ||
public abstract class DoubleConfirmationDialog extends DialogFragment { | ||
/** | ||
* Returns the dialog builder with the defaults for a double confirmation | ||
* dialog already set up. | ||
* | ||
* <p>Call it from onCreateDialog to finish setting up the dialog. | ||
* At least the following should be set:</p> | ||
* | ||
* <ul> | ||
* <li>The title.</li> | ||
* <li>The positive button.</li> | ||
* </ul> | ||
* | ||
* @return AlertDialog.Builder with the defaults for a double confirmation | ||
* dialog already set up. | ||
*/ | ||
@NonNull | ||
protected AlertDialog.Builder getDialogBuilder() { | ||
return new AlertDialog.Builder(getActivity()) | ||
.setView(R.layout.dialog_double_confirm) | ||
.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
onNegativeButton(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
if (getDialog() != null) { | ||
((AlertDialog) getDialog()).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); | ||
setUpConfirmCheckBox(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") | ||
private void setUpConfirmCheckBox() { | ||
final AlertDialog dialog = (AlertDialog) getDialog(); | ||
CheckBox confirmCheckBox = dialog.findViewById(R.id.checkbox_confirm); | ||
confirmCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
@Override | ||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | ||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(b); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Called when the negative button is pressed. | ||
* | ||
* <p>By default it just dismisses the dialog.</p> | ||
*/ | ||
protected void onNegativeButton() { | ||
getDialog().dismiss(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (c) 2017 Ngewi Fet <ngewif@gmail.com> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="@dimen/dialog_padding" > | ||
|
||
<CheckBox | ||
android:id="@+id/checkbox_confirm" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/yes_sure"/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters