Allow set don't ask again

This commit is contained in:
M66B
2019-09-19 09:00:50 +02:00
parent 450a82c72b
commit 84028c17fb
3 changed files with 42 additions and 33 deletions

View File

@@ -27,6 +27,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -38,25 +39,30 @@ public class FragmentDialogAsk extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final String question = getArguments().getString("question");
final String notagain = getArguments().getString("notagain");
String question = getArguments().getString("question");
String notagain = getArguments().getString("notagain");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
tvMessage.setText(question);
cbNotAgain.setVisibility(notagain == null ? View.GONE : View.VISIBLE);
if (notagain != null)
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean(notagain, isChecked).apply();
}
});
return new AlertDialog.Builder(getContext())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (notagain != null && cbNotAgain.isChecked()) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
prefs.edit().putBoolean(notagain, true).apply();
}
sendResult(Activity.RESULT_OK);
}
})