Refactoring

This commit is contained in:
M66B 2020-11-12 15:08:34 +01:00
parent 42f7cd6444
commit f748c3717c
4 changed files with 13 additions and 12 deletions

View File

@ -278,7 +278,7 @@ public class ActivitySignature extends ActivityBase {
public void onClick(DialogInterface dialog, int which) {
String link = etLink.getText().toString();
etText.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, null, etText, link);
StyleHelper.apply(R.id.menu_link, ActivitySignature.this, null, etText, link);
}
})
.setNegativeButton(android.R.string.cancel, null)
@ -286,7 +286,7 @@ public class ActivitySignature extends ActivityBase {
return true;
} else
return StyleHelper.apply(action, findViewById(action), etText);
return StyleHelper.apply(action, ActivitySignature.this, findViewById(action), etText);
}
private void onImageSelected(Uri uri) {

View File

@ -397,7 +397,7 @@ public class FragmentAnswer extends FragmentBase {
int start = args.getInt("start");
int end = args.getInt("end");
etText.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, null, etText, link);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etText, link);
}
private void onDelete() {
@ -460,7 +460,7 @@ public class FragmentAnswer extends FragmentBase {
return true;
} else
return StyleHelper.apply(action, view.findViewById(action), etText);
return StyleHelper.apply(action, getViewLifecycleOwner(), view.findViewById(action), etText);
}
public static class FragmentInfo extends FragmentDialogBase {

View File

@ -1441,7 +1441,7 @@ public class FragmentCompose extends FragmentBase {
onMenuAnswer();
return true;
case R.id.menu_clear:
StyleHelper.apply(R.id.menu_clear, null, etBody);
StyleHelper.apply(R.id.menu_clear, getViewLifecycleOwner(), null, etBody);
return true;
case R.id.menu_legend:
onMenuLegend();
@ -1718,7 +1718,7 @@ public class FragmentCompose extends FragmentBase {
private boolean onActionStyle(int action, View anchor) {
Log.i("Style action=" + action);
return StyleHelper.apply(action, anchor, etBody);
return StyleHelper.apply(action, getViewLifecycleOwner(), anchor, etBody);
}
private void onActionRecordAudio() {
@ -3063,7 +3063,7 @@ public class FragmentCompose extends FragmentBase {
int start = args.getInt("start");
int end = args.getInt("end");
etBody.setSelection(start, end);
StyleHelper.apply(R.id.menu_link, null, etBody, link);
StyleHelper.apply(R.id.menu_link, getViewLifecycleOwner(), null, etBody, link);
}
private void onActionDiscardConfirmed() {
@ -5253,17 +5253,17 @@ public class FragmentCompose extends FragmentBase {
return true;
case KeyEvent.KEYCODE_B:
if (etBody.hasSelection())
return StyleHelper.apply(R.id.menu_bold, null, etBody);
return StyleHelper.apply(R.id.menu_bold, getViewLifecycleOwner(), null, etBody);
else
return false;
case KeyEvent.KEYCODE_I:
if (etBody.hasSelection())
return StyleHelper.apply(R.id.menu_italic, null, etBody);
return StyleHelper.apply(R.id.menu_italic, getViewLifecycleOwner(), null, etBody);
else
return false;
case KeyEvent.KEYCODE_U:
if (etBody.hasSelection())
return StyleHelper.apply(R.id.menu_underline, null, etBody);
return StyleHelper.apply(R.id.menu_underline, getViewLifecycleOwner(), null, etBody);
else
return false;
}

View File

@ -30,6 +30,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.LifecycleOwner;
import androidx.preference.PreferenceManager;
import com.flask.colorpicker.ColorPickerView;
@ -41,7 +42,7 @@ import java.util.List;
import java.util.Locale;
public class StyleHelper {
static boolean apply(int action, View anchor, EditText etBody, Object... args) {
static boolean apply(int action, LifecycleOwner owner, View anchor, EditText etBody, Object... args) {
Log.i("Style action=" + action);
try {
@ -102,7 +103,7 @@ public class StyleHelper {
final int e = end;
final SpannableStringBuilder t = new SpannableStringBuilder(ss);
PopupMenu popupMenu = new PopupMenu(anchor.getContext(), anchor);
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(anchor.getContext(), owner, anchor);
popupMenu.inflate(R.menu.popup_style);
String[] fontNames = anchor.getResources().getStringArray(R.array.fontNameNames);