Skip to content

Commit

Permalink
Confirm dialog for Multistage service.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Aug 25, 2020
1 parent 844fc10 commit a024d83
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -9,6 +9,9 @@
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.widget.Toast;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.HashSet;
import de.tudarmstadt.informatik.hostage.Hostage;
import de.tudarmstadt.informatik.hostage.R;
Expand Down Expand Up @@ -119,7 +122,7 @@ private void checkMultistage(CheckBoxPreference checkboxPrefMultiStage){
boolean myValue = (Boolean) newValue;

if (myValue) {
startMultiStage();
confirmMultistage(checkboxPrefMultiStage).create().show();
}
else {
stopMultiStage();
Expand All @@ -129,6 +132,20 @@ private void checkMultistage(CheckBoxPreference checkboxPrefMultiStage){

}

private MaterialAlertDialogBuilder confirmMultistage(CheckBoxPreference checkboxPrefMultiStage){
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
builder.setTitle("Attention");
builder.setMessage("if you enable this service,it may use a lot of memory and drain your battery faster.");
builder.setPositiveButton("Enable", (dialog, which) -> {
startMultiStage();
});
builder.setNegativeButton(R.string.close, (dialog, which) -> {
checkboxPrefMultiStage.setChecked(false);
});

return builder;
}

public void stopMultiStage() {
Context context =Hostage.getContext();
alarm.CancelAlarm(context);
Expand Down

0 comments on commit a024d83

Please sign in to comment.