FairEmail/app/src/main/java/eu/faircode/email/FragmentAnswer.java

581 lines
22 KiB
Java
Raw Normal View History

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.
2018-10-29 10:46:49 +00:00
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
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2022-01-01 08:46:36 +00:00
Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
2018-08-27 09:39:27 +00:00
import android.content.Context;
2019-07-01 13:01:37 +00:00
import android.content.Intent;
2021-01-31 10:56:28 +00:00
import android.content.SharedPreferences;
2022-01-22 09:16:00 +00:00
import android.graphics.Color;
2020-04-27 07:40:43 +00:00
import android.graphics.drawable.Drawable;
2019-09-27 18:04:33 +00:00
import android.net.Uri;
2022-03-14 10:08:53 +00:00
import android.os.Build;
import android.os.Bundle;
2021-06-26 08:36:25 +00:00
import android.text.Editable;
2020-04-27 07:40:43 +00:00
import android.text.SpannableStringBuilder;
2019-05-03 12:26:01 +00:00
import android.text.Spanned;
2020-02-02 09:13:42 +00:00
import android.text.TextUtils;
2020-04-27 07:40:43 +00:00
import android.text.style.ImageSpan;
2021-06-26 08:36:25 +00:00
import android.text.style.SuggestionSpan;
2021-11-07 08:33:17 +00:00
import android.util.TypedValue;
import android.view.LayoutInflater;
2020-02-02 09:13:42 +00:00
import android.view.Menu;
import android.view.MenuInflater;
2018-08-27 09:39:27 +00:00
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
2019-04-20 08:35:30 +00:00
import android.widget.CheckBox;
2018-09-08 06:09:47 +00:00
import android.widget.EditText;
2018-08-27 09:39:27 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
2021-01-31 10:56:28 +00:00
import androidx.preference.PreferenceManager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
2020-02-02 09:13:42 +00:00
import com.google.android.material.snackbar.Snackbar;
2020-08-04 13:20:41 +00:00
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
2020-08-04 13:20:41 +00:00
2019-01-15 17:41:55 +00:00
public class FragmentAnswer extends FragmentBase {
private ViewGroup view;
2018-09-08 06:09:47 +00:00
private EditText etName;
2020-09-05 15:06:58 +00:00
private EditText etGroup;
2020-09-13 16:50:47 +00:00
private CheckBox cbStandard;
private CheckBox cbReceipt;
2021-05-06 19:11:51 +00:00
private CheckBox cbFavorite;
2022-03-14 08:48:49 +00:00
private CheckBox cbSnippet;
2019-04-20 08:35:30 +00:00
private CheckBox cbHide;
private CheckBox cbExternal;
2022-01-22 09:16:00 +00:00
private ViewButtonColor btnColor;
2019-09-27 18:04:33 +00:00
private EditTextCompose etText;
private BottomNavigationView style_bar;
private BottomNavigationView bottom_navigation;
2018-12-27 12:31:02 +00:00
private ContentLoadingProgressBar pbWait;
private Group grpReady;
2018-08-27 09:39:27 +00:00
private long id = -1;
2019-08-20 20:18:42 +00:00
private long copy = -1;
2018-08-27 09:39:27 +00:00
2022-01-22 09:16:00 +00:00
private static final int REQUEST_COLOR = 1;
private static final int REQUEST_IMAGE = 2;
private static final int REQUEST_LINK = 3;
2022-01-22 11:16:08 +00:00
private final static int REQUEST_DELETE = 4;
2019-07-01 13:01:37 +00:00
2018-08-27 09:39:27 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get arguments
Bundle args = getArguments();
2019-08-21 18:34:26 +00:00
if (args != null)
if (args.getBoolean("copy"))
copy = args.getLong("id", -1);
else
id = args.getLong("id", -1);
2018-08-27 09:39:27 +00:00
}
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
2021-11-07 08:33:17 +00:00
final Context context = getContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
2022-02-11 08:36:32 +00:00
String compose_font = prefs.getString("compose_font", "");
2021-11-07 08:33:17 +00:00
boolean compact = prefs.getBoolean("compose_compact", false);
int zoom = prefs.getInt("compose_zoom", compact ? 0 : 1);
int message_zoom = prefs.getInt("message_zoom", 100);
2021-01-31 10:56:28 +00:00
2019-05-03 05:28:36 +00:00
setSubtitle(R.string.title_answer_caption);
2020-02-02 09:13:42 +00:00
setHasOptionsMenu(true);
2019-02-21 20:17:09 +00:00
view = (ViewGroup) inflater.inflate(R.layout.fragment_answer, container, false);
// Get controls
etName = view.findViewById(R.id.etName);
2020-09-05 15:06:58 +00:00
etGroup = view.findViewById(R.id.etGroup);
2020-09-13 16:50:47 +00:00
cbStandard = view.findViewById(R.id.cbStandard);
cbReceipt = view.findViewById(R.id.cbReceipt);
2021-05-06 19:11:51 +00:00
cbFavorite = view.findViewById(R.id.cbFavorite);
2022-03-14 08:48:49 +00:00
cbSnippet = view.findViewById(R.id.cbSnippet);
2019-04-20 08:35:30 +00:00
cbHide = view.findViewById(R.id.cbHide);
cbExternal = view.findViewById(R.id.cbExternal);
2022-01-22 09:16:00 +00:00
btnColor = view.findViewById(R.id.btnColor);
2018-08-27 09:39:27 +00:00
etText = view.findViewById(R.id.etText);
2019-06-20 08:33:29 +00:00
2019-09-27 18:04:33 +00:00
style_bar = view.findViewById(R.id.style_bar);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
2019-06-20 08:33:29 +00:00
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
2022-01-22 09:16:00 +00:00
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putInt("color", btnColor.getColor());
args.putString("title", getString(R.string.title_color));
args.putBoolean("reset", true);
FragmentDialogColor fragment = new FragmentDialogColor();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentAnswer.this, REQUEST_COLOR);
fragment.show(getParentFragmentManager(), "account:color");
}
});
2021-11-07 08:33:17 +00:00
etText.setTypeface(StyleHelper.getTypeface(compose_font, context));
float textSize = Helper.getTextSize(context, zoom);
if (textSize != 0)
etText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * message_zoom / 100f);
2021-01-31 10:56:28 +00:00
2019-09-27 18:04:33 +00:00
etText.setSelectionListener(new EditTextCompose.ISelection() {
@Override
public void onSelected(boolean selection) {
style_bar.setVisibility(selection ? View.VISIBLE : View.GONE);
}
});
style_bar.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return onActionStyle(item.getItemId());
}
});
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
2018-08-27 09:39:27 +00:00
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
2021-02-05 10:15:02 +00:00
int itemId = menuItem.getItemId();
if (itemId == R.id.action_insert_image) {
onInsertImage();
return true;
} else if (itemId == R.id.action_delete) {
onActionDelete();
return true;
} else if (itemId == R.id.action_save) {
onActionSave();
return true;
}
2021-02-05 10:15:02 +00:00
return false;
2018-08-27 09:39:27 +00:00
}
});
// Initialize
2021-11-07 08:33:17 +00:00
FragmentDialogTheme.setBackground(context, view, true);
2021-09-12 09:05:15 +00:00
cbExternal.setVisibility(View.GONE);
2022-03-14 10:08:53 +00:00
cbSnippet.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
2019-09-27 18:04:33 +00:00
style_bar.setVisibility(View.GONE);
2020-11-03 08:39:27 +00:00
bottom_navigation.setVisibility(View.GONE);
2020-08-03 06:31:48 +00:00
pbWait.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
2018-11-14 16:21:53 +00:00
Bundle args = new Bundle();
2019-08-20 20:18:42 +00:00
args.putLong("id", copy < 0 ? id : copy);
2018-11-14 16:21:53 +00:00
new SimpleTask<EntityAnswer>() {
2020-08-03 06:31:48 +00:00
@Override
protected void onPreExecute(Bundle args) {
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
pbWait.setVisibility(View.GONE);
}
@Override
2019-01-17 12:14:16 +00:00
protected EntityAnswer onExecute(Context context, Bundle args) {
2018-11-14 16:21:53 +00:00
long id = args.getLong("id");
return DB.getInstance(context).answer().getAnswer(id);
}
@Override
2018-12-31 07:03:48 +00:00
protected void onExecuted(Bundle args, EntityAnswer answer) {
2021-08-01 16:45:47 +00:00
final Context context = getContext();
2021-05-13 15:25:34 +00:00
if (copy > 0 && answer != null) {
answer.applied = 0;
answer.last_applied = null;
}
2020-05-31 09:48:18 +00:00
if (savedInstanceState == null) {
2021-03-05 11:12:03 +00:00
Bundle a = getArguments();
if (a == null)
a = new Bundle();
etName.setText(answer == null ? a.getString("subject") : answer.name);
2020-09-05 15:06:58 +00:00
etGroup.setText(answer == null ? null : answer.group);
2020-09-13 16:50:47 +00:00
cbStandard.setChecked(answer == null ? false : answer.standard);
cbReceipt.setChecked(answer == null ? false : answer.receipt);
2021-05-06 19:11:51 +00:00
cbFavorite.setChecked(answer == null ? false : answer.favorite);
2022-03-14 08:48:49 +00:00
cbSnippet.setChecked(answer == null ? false : answer.snippet);
2020-05-31 09:48:18 +00:00
cbHide.setChecked(answer == null ? false : answer.hide);
cbExternal.setChecked(answer == null ? false : answer.external);
2022-01-22 09:16:00 +00:00
btnColor.setColor(answer == null ? null : answer.color);
2021-03-05 11:12:03 +00:00
String html = (answer == null ? a.getString("html") : answer.text);
2021-03-05 07:52:33 +00:00
if (html == null)
2020-05-31 09:48:18 +00:00
etText.setText(null);
else
etText.setText(HtmlHelper.fromHtml(html, new HtmlHelper.ImageGetterEx() {
2020-05-31 09:48:18 +00:00
@Override
public Drawable getDrawable(Element element) {
String source = element.attr("src");
if (source.startsWith("cid:"))
element.attr("src", "cid:");
return ImageHelper.decodeImage(context,
-1, element, true, 0, 1.0f, etText);
2020-05-31 09:48:18 +00:00
}
2021-08-01 16:45:47 +00:00
}, null, context));
2020-05-31 09:48:18 +00:00
}
2021-12-17 17:47:36 +00:00
if (answer == null)
bottom_navigation.getMenu().removeItem(R.id.action_delete);
2021-08-01 16:45:47 +00:00
if (ActivityAnswer.canAnswer(context))
cbExternal.setVisibility(View.VISIBLE);
2022-03-14 10:08:53 +00:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
cbSnippet.setVisibility(View.VISIBLE);
grpReady.setVisibility(View.VISIBLE);
2020-11-03 08:39:27 +00:00
bottom_navigation.setVisibility(View.VISIBLE);
}
2018-12-01 09:47:08 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2018-12-01 09:47:08 +00:00
}
2019-01-12 13:15:15 +00:00
}.execute(this, args, "answer:get");
}
2018-08-27 09:39:27 +00:00
2020-02-02 09:13:42 +00:00
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_answer, menu);
2020-02-02 09:13:42 +00:00
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
menu.findItem(R.id.menu_placeholder_firstname).setVisible(BuildConfig.DEBUG);
menu.findItem(R.id.menu_placeholder_lastname).setVisible(BuildConfig.DEBUG);
super.onPrepareOptionsMenu(menu);
}
2020-02-02 09:13:42 +00:00
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
2022-03-14 10:20:29 +00:00
if (itemId == R.id.menu_help) {
onMenuHelp();
return true;
} else if (itemId == R.id.menu_placeholder_name) {
onMenuPlaceholder("$name$");
return true;
} else if (itemId == R.id.menu_placeholder_email) {
onMenuPlaceholder("$email$");
return true;
} else if (itemId == R.id.menu_placeholder_firstname) {
onMenuPlaceholder("$firstname$");
return true;
} else if (itemId == R.id.menu_placeholder_lastname) {
onMenuPlaceholder("$lastname$");
2021-02-05 10:15:02 +00:00
return true;
2020-02-02 09:13:42 +00:00
}
2021-02-05 10:15:02 +00:00
return super.onOptionsItemSelected(item);
2020-02-02 09:13:42 +00:00
}
2022-03-14 10:20:29 +00:00
private void onMenuHelp() {
Helper.viewFAQ(getContext(), 179);
}
private void onMenuPlaceholder(String name) {
int start = etText.getSelectionStart();
int end = etText.getSelectionEnd();
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
if (start >= 0 && start < end)
etText.getText().replace(start, end, name);
else {
if (start < 0) {
start = etText.length() - 1;
if (start < 0)
start = 0;
}
etText.getText().insert(start, name);
}
2020-02-02 09:13:42 +00:00
}
2020-04-27 07:40:43 +00:00
private void onInsertImage() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/*");
Helper.openAdvanced(intent);
startActivityForResult(intent, REQUEST_IMAGE);
}
private void onActionDelete() {
2019-07-01 13:01:37 +00:00
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_ask_delete_answer));
2020-10-25 13:55:58 +00:00
args.putBoolean("warning", true);
2019-07-01 13:01:37 +00:00
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentAnswer.this, REQUEST_DELETE);
2019-10-12 15:16:53 +00:00
fragment.show(getParentFragmentManager(), "answer:delete");
2018-08-27 09:39:27 +00:00
}
private void onActionSave() {
2019-09-23 09:56:54 +00:00
etText.clearComposingText();
2021-06-26 08:36:25 +00:00
// Prevent splitting placeholders
Editable edit = etText.getText();
SuggestionSpan[] suggestions = edit.getSpans(0, etText.length(), SuggestionSpan.class);
for (SuggestionSpan suggestion : suggestions)
edit.removeSpan(suggestion);
2018-08-27 09:39:27 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
2020-02-02 09:13:42 +00:00
args.putString("name", etName.getText().toString().trim());
2020-09-05 15:06:58 +00:00
args.putString("group", etGroup.getText().toString().trim());
2020-09-13 16:50:47 +00:00
args.putBoolean("standard", cbStandard.isChecked());
args.putBoolean("receipt", cbReceipt.isChecked());
2021-05-06 19:11:51 +00:00
args.putBoolean("favorite", cbFavorite.isChecked());
2022-03-14 08:48:49 +00:00
args.putBoolean("snippet", cbSnippet.isChecked());
2019-04-20 08:35:30 +00:00
args.putBoolean("hide", cbHide.isChecked());
args.putBoolean("external", cbExternal.isChecked());
2022-01-22 09:16:00 +00:00
args.putInt("color", btnColor.getColor());
2020-08-04 13:20:41 +00:00
args.putString("html", HtmlHelper.toHtml(etText.getText(), getContext()));
2018-08-27 09:39:27 +00:00
new SimpleTask<Void>() {
2019-01-17 19:22:16 +00:00
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
}
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
}
2018-08-27 09:39:27 +00:00
@Override
2018-12-31 07:03:48 +00:00
protected Void onExecute(Context context, Bundle args) {
2018-08-27 09:39:27 +00:00
long id = args.getLong("id");
String name = args.getString("name");
2020-09-05 15:06:58 +00:00
String group = args.getString("group");
2020-09-13 16:50:47 +00:00
boolean standard = args.getBoolean("standard");
boolean receipt = args.getBoolean("receipt");
2021-05-06 19:11:51 +00:00
boolean favorite = args.getBoolean("favorite");
2022-03-14 08:48:49 +00:00
boolean snippet = args.getBoolean("snippet");
2019-04-20 08:35:30 +00:00
boolean hide = args.getBoolean("hide");
boolean external = args.getBoolean("external");
2022-01-22 09:16:00 +00:00
Integer color = args.getInt("color");
2020-08-04 13:20:41 +00:00
String html = args.getString("html");
2018-08-27 09:39:27 +00:00
2020-02-02 09:13:42 +00:00
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
2020-09-05 15:06:58 +00:00
if (TextUtils.isEmpty(group))
group = null;
2022-01-22 09:16:00 +00:00
if (color == Color.TRANSPARENT)
color = null;
2020-02-02 09:13:42 +00:00
2020-08-11 11:21:28 +00:00
Document document = JsoupEx.parse(html);
2020-08-04 13:20:41 +00:00
2018-08-27 09:39:27 +00:00
DB db = DB.getInstance(context);
2020-09-13 16:50:47 +00:00
try {
db.beginTransaction();
if (standard)
db.answer().resetStandard();
if (receipt)
db.answer().resetReceipt();
2020-09-13 16:50:47 +00:00
2021-08-01 17:05:17 +00:00
EntityAnswer answer;
if (id < 0)
answer = new EntityAnswer();
else
answer = db.answer().getAnswer(id);
answer.name = name;
answer.group = group;
answer.standard = standard;
answer.receipt = receipt;
answer.favorite = favorite;
2022-03-14 08:48:49 +00:00
answer.snippet = snippet;
2021-08-01 17:05:17 +00:00
answer.hide = hide;
answer.external = external;
2022-01-22 09:16:00 +00:00
answer.color = color;
2021-08-01 17:05:17 +00:00
answer.text = document.body().html();
if (id < 0)
2020-09-13 16:50:47 +00:00
answer.id = db.answer().insertAnswer(answer);
2021-08-01 17:05:17 +00:00
else
2020-09-13 16:50:47 +00:00
db.answer().updateAnswer(answer);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
2018-08-27 09:39:27 +00:00
}
return null;
}
@Override
2018-12-31 07:03:48 +00:00
protected void onExecuted(Bundle args, Void data) {
2018-08-27 09:39:27 +00:00
finish();
}
@Override
protected void onException(Bundle args, Throwable ex) {
2020-02-02 09:13:42 +00:00
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
2020-02-02 09:13:42 +00:00
else
Log.unexpectedError(getParentFragmentManager(), ex);
2018-08-27 09:39:27 +00:00
}
2019-01-12 13:15:15 +00:00
}.execute(this, args, "answer:save");
2018-08-27 09:39:27 +00:00
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
2022-01-22 09:16:00 +00:00
case REQUEST_COLOR:
if (resultCode == RESULT_OK && data != null) {
Bundle args = data.getBundleExtra("args");
btnColor.setColor(args.getInt("color"));
}
break;
2020-04-27 07:40:43 +00:00
case REQUEST_IMAGE:
if (resultCode == RESULT_OK && data != null)
onImageSelected(data.getData());
break;
case REQUEST_LINK:
if (resultCode == RESULT_OK && data != null)
onLinkSelected(data.getBundleExtra("args"));
break;
case REQUEST_DELETE:
if (resultCode == RESULT_OK)
onDelete();
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
2020-04-27 07:40:43 +00:00
private void onImageSelected(Uri uri) {
try {
2022-03-18 16:22:25 +00:00
NoStreamException.check(uri, getContext());
2020-04-27 07:40:43 +00:00
getContext().getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
int start = etText.getSelectionStart();
2021-09-09 10:52:10 +00:00
SpannableStringBuilder ssb = new SpannableStringBuilderEx(etText.getText());
2020-04-27 08:27:52 +00:00
ssb.insert(start, " \uFFFC"); // Object replacement character
2020-04-27 07:40:43 +00:00
String source = uri.toString();
2020-09-06 16:12:17 +00:00
Drawable d = ImageHelper.decodeImage(getContext(), -1, source, true, 0, 1.0f, etText);
2020-04-27 07:40:43 +00:00
ImageSpan is = new ImageSpan(d, source);
2020-04-27 08:27:52 +00:00
ssb.setSpan(is, start + 1, start + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
2020-04-27 07:40:43 +00:00
etText.setText(ssb);
2020-04-27 08:27:52 +00:00
etText.setSelection(start + 2);
2022-03-18 16:22:25 +00:00
} catch (NoStreamException ex) {
2022-03-19 07:12:46 +00:00
ex.report(getActivity());
2020-04-27 07:40:43 +00:00
} catch (Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}
private void onLinkSelected(Bundle args) {
String link = args.getString("link");
int start = args.getInt("start");
int end = args.getInt("end");
2022-05-31 14:55:59 +00:00
String title = args.getString("title");
etText.setSelection(start, end);
2022-05-31 14:55:59 +00:00
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etText, link, title);
}
2019-07-01 13:01:37 +00:00
private void onDelete() {
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
}
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, true);
}
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB.getInstance(context).answer().deleteAnswer(id);
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
finish();
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2019-07-01 13:01:37 +00:00
}
2019-09-11 12:03:59 +00:00
}.execute(this, args, "answer:delete");
2019-07-01 13:01:37 +00:00
}
2019-09-27 18:04:33 +00:00
private boolean onActionStyle(int action) {
Log.i("Style action=" + action);
if (action == R.id.menu_link) {
2021-04-04 11:45:32 +00:00
FragmentDialogInsertLink fragment = new FragmentDialogInsertLink();
2022-05-31 14:55:59 +00:00
fragment.setArguments(FragmentDialogInsertLink.getArguments(etText));
2019-09-27 18:04:33 +00:00
fragment.setTargetFragment(this, REQUEST_LINK);
2020-02-23 10:16:40 +00:00
fragment.show(getParentFragmentManager(), "answer:link");
2019-09-27 18:04:33 +00:00
return true;
} else
2020-11-12 14:08:34 +00:00
return StyleHelper.apply(action, getViewLifecycleOwner(), view.findViewById(action), etText);
2019-09-27 18:04:33 +00:00
}
}