2019-06-30 11:06:12 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2021-01-01 07:56:36 +00:00
|
|
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
2019-06-30 11:06:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.Dialog;
|
2020-10-25 13:55:58 +00:00
|
|
|
import android.content.Context;
|
2019-06-30 11:06:12 +00:00
|
|
|
import android.content.DialogInterface;
|
2019-06-30 12:29:31 +00:00
|
|
|
import android.content.SharedPreferences;
|
2020-10-25 13:55:58 +00:00
|
|
|
import android.graphics.drawable.Drawable;
|
2019-06-30 11:06:12 +00:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2019-06-30 12:29:31 +00:00
|
|
|
import android.widget.CheckBox;
|
2019-09-19 07:00:50 +00:00
|
|
|
import android.widget.CompoundButton;
|
2021-05-15 08:21:08 +00:00
|
|
|
import android.widget.ImageButton;
|
2019-06-30 11:06:12 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-06-30 12:29:31 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
2019-06-30 11:06:12 +00:00
|
|
|
|
2019-09-11 19:43:27 +00:00
|
|
|
public class FragmentDialogAsk extends FragmentDialogBase {
|
2019-06-30 11:06:12 +00:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
2020-10-25 13:55:58 +00:00
|
|
|
Bundle args = getArguments();
|
|
|
|
String question = args.getString("question");
|
|
|
|
String remark = args.getString("remark");
|
2021-05-14 05:28:03 +00:00
|
|
|
String confirm = args.getString("confirm");
|
2020-10-25 13:55:58 +00:00
|
|
|
String notagain = args.getString("notagain");
|
2021-05-30 08:27:42 +00:00
|
|
|
String accept = args.getString("accept");
|
2020-10-25 13:55:58 +00:00
|
|
|
boolean warning = args.getBoolean("warning");
|
2021-05-15 08:21:08 +00:00
|
|
|
int faq = args.getInt("faq");
|
2019-06-30 11:06:12 +00:00
|
|
|
|
2020-10-25 13:55:58 +00:00
|
|
|
final Context context = getContext();
|
|
|
|
final int colorError = Helper.resolveColor(context, R.attr.colorError);
|
|
|
|
|
|
|
|
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_ask_again, null);
|
2019-06-30 11:06:12 +00:00
|
|
|
TextView tvMessage = dview.findViewById(R.id.tvMessage);
|
2020-07-26 10:16:48 +00:00
|
|
|
TextView tvRemark = dview.findViewById(R.id.tvRemark);
|
2021-05-14 05:28:03 +00:00
|
|
|
CheckBox cbConfirm = dview.findViewById(R.id.cbConfirm);
|
2019-09-19 07:00:50 +00:00
|
|
|
CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain);
|
2021-05-30 08:27:42 +00:00
|
|
|
TextView tvAccept = dview.findViewById(R.id.tvAccept);
|
2021-05-15 08:21:08 +00:00
|
|
|
ImageButton ibInfo = dview.findViewById(R.id.ibInfo);
|
2019-06-30 11:06:12 +00:00
|
|
|
|
|
|
|
tvMessage.setText(question);
|
2020-07-26 10:16:48 +00:00
|
|
|
tvRemark.setText(remark);
|
|
|
|
tvRemark.setVisibility(remark == null ? View.GONE : View.VISIBLE);
|
2021-05-14 05:28:03 +00:00
|
|
|
cbConfirm.setText(confirm);
|
|
|
|
cbConfirm.setVisibility(confirm == null ? View.GONE : View.VISIBLE);
|
2019-06-30 12:29:31 +00:00
|
|
|
cbNotAgain.setVisibility(notagain == null ? View.GONE : View.VISIBLE);
|
2021-05-30 08:27:42 +00:00
|
|
|
tvAccept.setText(accept);
|
|
|
|
tvAccept.setVisibility(View.GONE);
|
2021-05-15 08:21:08 +00:00
|
|
|
ibInfo.setVisibility(faq == 0 ? View.GONE : View.VISIBLE);
|
2019-06-30 11:06:12 +00:00
|
|
|
|
2020-10-25 13:55:58 +00:00
|
|
|
if (warning) {
|
2021-01-23 08:28:51 +00:00
|
|
|
Drawable w = context.getDrawable(R.drawable.twotone_warning_24);
|
2020-10-25 13:55:58 +00:00
|
|
|
w.setBounds(0, 0, w.getIntrinsicWidth(), w.getIntrinsicHeight());
|
|
|
|
w.setTint(colorError);
|
|
|
|
tvMessage.setCompoundDrawablesRelative(w, null, null, null);
|
|
|
|
tvMessage.setCompoundDrawablePadding(Helper.dp2pixels(context, 12));
|
|
|
|
}
|
|
|
|
|
2019-09-19 07:00:50 +00:00
|
|
|
if (notagain != null)
|
|
|
|
cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
2021-05-30 08:27:42 +00:00
|
|
|
if (accept == null) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs.edit().putBoolean(notagain, isChecked).apply();
|
|
|
|
}
|
|
|
|
tvAccept.setVisibility(isChecked && accept != null ? View.VISIBLE : View.GONE);
|
2019-09-19 07:00:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-15 08:21:08 +00:00
|
|
|
if (faq != 0)
|
|
|
|
ibInfo.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Helper.viewFAQ(v.getContext(), faq);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-09 15:40:37 +00:00
|
|
|
return new AlertDialog.Builder(context)
|
2019-06-30 11:06:12 +00:00
|
|
|
.setView(dview)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2021-05-30 08:27:42 +00:00
|
|
|
if (confirm == null || cbConfirm.isChecked()) {
|
|
|
|
if (notagain != null && accept != null) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
prefs.edit().putBoolean(notagain, cbNotAgain.isChecked()).apply();
|
|
|
|
}
|
2021-05-14 05:28:03 +00:00
|
|
|
sendResult(Activity.RESULT_OK);
|
2021-05-30 08:27:42 +00:00
|
|
|
} else
|
2021-05-14 05:28:03 +00:00
|
|
|
sendResult(Activity.RESULT_CANCELED);
|
2019-06-30 11:06:12 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
sendResult(Activity.RESULT_CANCELED);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.create();
|
|
|
|
}
|
|
|
|
}
|