Added LanguageTool to answers

pull/210/head
M66B 2 years ago
parent 7091e9baf5
commit 87956d420f

@ -45,6 +45,7 @@ import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.HorizontalScrollView; import android.widget.HorizontalScrollView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -183,6 +184,17 @@ public class FragmentAnswer extends FragmentBase {
} }
}); });
bottom_navigation.findViewById(R.id.action_save).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (LanguageTool.isEnabled(context)) {
onLanguageTool();
return true;
} else
return false;
}
});
// Initialize // Initialize
FragmentDialogTheme.setBackground(context, view, true); FragmentDialogTheme.setBackground(context, view, true);
@ -597,4 +609,55 @@ public class FragmentAnswer extends FragmentBase {
} }
}.execute(this, args, "answer:delete"); }.execute(this, args, "answer:delete");
} }
private void onLanguageTool() {
etText.clearComposingText();
Bundle args = new Bundle();
args.putCharSequence("text", etText.getText());
new SimpleTask<List<LanguageTool.Suggestion>>() {
private Toast toast = null;
@Override
protected void onPreExecute(Bundle args) {
toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG);
toast.show();
}
@Override
protected void onPostExecute(Bundle args) {
if (toast != null)
toast.cancel();
}
@Override
protected List<LanguageTool.Suggestion> onExecute(Context context, Bundle args) throws Throwable {
CharSequence text = args.getCharSequence("text").toString();
return LanguageTool.getSuggestions(context, text);
}
@Override
protected void onExecuted(Bundle args, List<LanguageTool.Suggestion> suggestions) {
LanguageTool.applySuggestions(etText, 0, etText.length(), suggestions);
if (suggestions == null || suggestions.size() == 0)
ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show();
}
@Override
protected void onDestroyed(Bundle args) {
if (toast != null) {
toast.cancel();
toast = null;
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Throwable exex = new Throwable("LanguageTool", ex);
Log.unexpectedError(getParentFragmentManager(), exex, false);
}
}.execute(this, args, "answer:lt");
}
} }

Loading…
Cancel
Save