Use dialog fragments for answers and contacts

pull/157/head
M66B 5 years ago
parent be56a865cb
commit 19c8fbce7a

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@ -34,7 +35,9 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.DialogFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;
@ -80,20 +83,7 @@ public class FragmentAnswer extends FragmentBase {
ibInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Spanned spanned = HtmlHelper.fromHtml("<p>" +
getString(R.string.title_answer_template_name) +
"<br>" +
getString(R.string.title_answer_template_email) +
"</p>");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(spanned);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setView(dview)
.show();
new FragmentInfo().show(getFragmentManager(), "rule:info");
}
});
@ -249,4 +239,25 @@ public class FragmentAnswer extends FragmentBase {
}
}.execute(this, args, "answer:save");
}
public static class FragmentInfo extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Spanned spanned = HtmlHelper.fromHtml("<p>" +
getString(R.string.title_answer_template_name) +
"<br>" +
getString(R.string.title_answer_template_email) +
"</p>");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(spanned);
return new AlertDialog.Builder(getContext())
.setView(dview)
.create();
}
}
}

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -36,8 +37,10 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -160,7 +163,7 @@ public class FragmentContacts extends FragmentBase {
onMenuHelp();
return true;
case R.id.menu_delete:
onMenuDelete();
new FragmentDelete().show(getFragmentManager(), "contacts:delete");
return true;
default:
return super.onOptionsItemSelected(item);
@ -171,13 +174,24 @@ public class FragmentContacts extends FragmentBase {
startActivity(getIntentHelp());
}
private void onMenuDelete() {
private static Intent getIntentHelp() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq84"));
return intent;
}
public static class FragmentDelete extends DialogFragment {
private TwoStateOwner owner = new TwoStateOwner("contacts:delete");
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_message, null);
final TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(getText(R.string.title_delete_contacts));
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
return new AlertDialog.Builder(getContext())
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
@ -185,25 +199,33 @@ public class FragmentContacts extends FragmentBase {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
int count = DB.getInstance(context).contact().clearContacts();
DB db = DB.getInstance(context);
int count = db.contact().clearContacts();
Log.i("Cleared contacts=" + count);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
Helper.unexpectedError(getContext(), owner, ex);
}
}.execute(getContext(), getViewLifecycleOwner(), new Bundle(), "setup:privacy");
}.execute(getContext(), owner, new Bundle(), "contacts:delete");
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
.create();
}
private static Intent getIntentHelp() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://github.com/M66B/open-source-email/blob/master/FAQ.md#user-content-faq84"));
return intent;
@Override
public void onStart() {
super.onStart();
owner.resume();
}
@Override
public void onDestroyView() {
owner.destroy();
super.onDestroyView();
}
}
}

Loading…
Cancel
Save