Prevent crash

pull/205/head
M66B 3 years ago
parent b3a5d8cf87
commit 718274ecc7

@ -1477,8 +1477,11 @@ public class FragmentCompose extends FragmentBase {
PopupMenuLifecycle.insertIcons(getContext(), menu); PopupMenuLifecycle.insertIcons(getContext(), menu);
menu.findItem(R.id.menu_encrypt).setActionView(R.layout.action_button_text); LayoutInflater infl = LayoutInflater.from(getContext());
ImageButton ib = menu.findItem(R.id.menu_encrypt).getActionView().findViewById(R.id.button);
View v = infl.inflate(R.layout.action_button_text, null);
v.setId(View.generateViewId());
ImageButton ib = v.findViewById(R.id.button);
ib.setOnClickListener(new View.OnClickListener() { ib.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -1498,26 +1501,31 @@ public class FragmentCompose extends FragmentBase {
return true; return true;
} }
}); });
menu.findItem(R.id.menu_encrypt).setActionView(v);
menu.findItem(R.id.menu_translate).setActionView(R.layout.action_button); ImageButton ibTranslate = (ImageButton) infl.inflate(R.layout.action_button, null);
ImageButton ibTranslate = (ImageButton) menu.findItem(R.id.menu_translate).getActionView(); ibTranslate.setId(View.generateViewId());
ibTranslate.setImageResource(R.drawable.twotone_translate_24); ibTranslate.setImageResource(R.drawable.twotone_translate_24);
ib.setContentDescription(getString(R.string.title_translate));
ibTranslate.setOnClickListener(new View.OnClickListener() { ibTranslate.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
onTranslate(vwAnchorMenu); onTranslate(vwAnchorMenu);
} }
}); });
menu.findItem(R.id.menu_translate).setActionView(ibTranslate);
menu.findItem(R.id.menu_zoom).setActionView(R.layout.action_button); ImageButton ibZoom = (ImageButton) infl.inflate(R.layout.action_button, null);
ImageButton ibZoom = (ImageButton) menu.findItem(R.id.menu_zoom).getActionView(); ibZoom.setId(View.generateViewId());
ibZoom.setImageResource(R.drawable.twotone_format_size_24); ibZoom.setImageResource(R.drawable.twotone_format_size_24);
ib.setContentDescription(getString(R.string.title_legend_zoom));
ibZoom.setOnClickListener(new View.OnClickListener() { ibZoom.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
onMenuZoom(); onMenuZoom();
} }
}); });
menu.findItem(R.id.menu_zoom).setActionView(ibZoom);
MenuCompat.setGroupDividerEnabled(menu, true); MenuCompat.setGroupDividerEnabled(menu, true);
@ -1528,9 +1536,11 @@ public class FragmentCompose extends FragmentBase {
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
final Context context = getContext();
menu.findItem(R.id.menu_encrypt).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_encrypt).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_translate).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_translate).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_translate).setVisible(DeepL.isAvailable(getContext())); menu.findItem(R.id.menu_translate).setVisible(DeepL.isAvailable(context));
menu.findItem(R.id.menu_zoom).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_zoom).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_media).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_media).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_compact).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_compact).setEnabled(state == State.LOADED);
@ -1540,7 +1550,8 @@ public class FragmentCompose extends FragmentBase {
menu.findItem(R.id.menu_answer_create).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_answer_create).setEnabled(state == State.LOADED);
menu.findItem(R.id.menu_clear).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_clear).setEnabled(state == State.LOADED);
int colorEncrypt = Helper.resolveColor(getContext(), R.attr.colorEncrypt); int colorEncrypt = Helper.resolveColor(context, R.attr.colorEncrypt);
int colorActionForeground = Helper.resolveColor(context, R.attr.colorActionForeground);
View v = menu.findItem(R.id.menu_encrypt).getActionView(); View v = menu.findItem(R.id.menu_encrypt).getActionView();
ImageButton ib = v.findViewById(R.id.button); ImageButton ib = v.findViewById(R.id.button);
@ -1551,7 +1562,7 @@ public class FragmentCompose extends FragmentBase {
if (EntityMessage.PGP_SIGNONLY.equals(encrypt) || EntityMessage.SMIME_SIGNONLY.equals(encrypt)) { if (EntityMessage.PGP_SIGNONLY.equals(encrypt) || EntityMessage.SMIME_SIGNONLY.equals(encrypt)) {
ib.setImageResource(R.drawable.twotone_gesture_24); ib.setImageResource(R.drawable.twotone_gesture_24);
ib.setImageTintList(null); ib.setImageTintList(ColorStateList.valueOf(colorActionForeground));
tv.setText(EntityMessage.PGP_SIGNONLY.equals(encrypt) ? "P" : "S"); tv.setText(EntityMessage.PGP_SIGNONLY.equals(encrypt) ? "P" : "S");
} else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt) || EntityMessage.SMIME_SIGNENCRYPT.equals(encrypt)) { } else if (EntityMessage.PGP_SIGNENCRYPT.equals(encrypt) || EntityMessage.SMIME_SIGNENCRYPT.equals(encrypt)) {
ib.setImageResource(R.drawable.twotone_lock_24); ib.setImageResource(R.drawable.twotone_lock_24);
@ -1559,11 +1570,11 @@ public class FragmentCompose extends FragmentBase {
tv.setText(EntityMessage.PGP_SIGNENCRYPT.equals(encrypt) ? "P" : "S"); tv.setText(EntityMessage.PGP_SIGNENCRYPT.equals(encrypt) ? "P" : "S");
} else { } else {
ib.setImageResource(R.drawable.twotone_lock_open_24); ib.setImageResource(R.drawable.twotone_lock_open_24);
ib.setImageTintList(null); ib.setImageTintList(ColorStateList.valueOf(colorActionForeground));
tv.setText(null); tv.setText(null);
} }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean save_drafts = prefs.getBoolean("save_drafts", true); boolean save_drafts = prefs.getBoolean("save_drafts", true);
boolean send_dialog = prefs.getBoolean("send_dialog", true); boolean send_dialog = prefs.getBoolean("send_dialog", true);
boolean image_dialog = prefs.getBoolean("image_dialog", true); boolean image_dialog = prefs.getBoolean("image_dialog", true);

@ -498,9 +498,11 @@ public class FragmentFolders extends FragmentBase {
} }
}); });
menu.findItem(R.id.menu_search).setActionView(R.layout.action_button); LayoutInflater infl = LayoutInflater.from(getContext());
ImageButton ibSearch = (ImageButton) menu.findItem(R.id.menu_search).getActionView(); ImageButton ibSearch = (ImageButton) infl.inflate(R.layout.action_button, null);
ibSearch.setId(View.generateViewId());
ibSearch.setImageResource(R.drawable.twotone_search_24); ibSearch.setImageResource(R.drawable.twotone_search_24);
ibSearch.setContentDescription(getString(R.string.title_legend_search));
ibSearch.setOnClickListener(new View.OnClickListener() { ibSearch.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -514,6 +516,7 @@ public class FragmentFolders extends FragmentBase {
return true; return true;
} }
}); });
menu.findItem(R.id.menu_search).setActionView(ibSearch);
MenuCompat.setGroupDividerEnabled(menu, true); MenuCompat.setGroupDividerEnabled(menu, true);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);

@ -4269,8 +4269,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_messages, menu); inflater.inflate(R.menu.menu_messages, menu);
menu.findItem(R.id.menu_folders).setActionView(R.layout.action_button); LayoutInflater infl = LayoutInflater.from(getContext());
ImageButton ib = (ImageButton) menu.findItem(R.id.menu_folders).getActionView(); ImageButton ib = (ImageButton) infl.inflate(R.layout.action_button, null);
ib.setId(View.generateViewId());
ib.setImageResource(R.drawable.twotone_folder_24); ib.setImageResource(R.drawable.twotone_folder_24);
ib.setContentDescription(getString(R.string.title_legend_section_folders)); ib.setContentDescription(getString(R.string.title_legend_section_folders));
ib.setOnClickListener(new View.OnClickListener() { ib.setOnClickListener(new View.OnClickListener() {
@ -4289,6 +4290,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
return true; return true;
} }
}); });
menu.findItem(R.id.menu_folders).setActionView(ib);
MenuCompat.setGroupDividerEnabled(menu, true); MenuCompat.setGroupDividerEnabled(menu, true);

@ -4,4 +4,5 @@
style="@style/Widget.AppCompat.Toolbar.Button.Navigation" style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:srcCompat="@mipmap/ic_launcher" /> app:srcCompat="@mipmap/ic_launcher"
app:tint="?colorActionForeground" />

@ -12,7 +12,8 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_lock_24" /> app:srcCompat="@drawable/twotone_lock_24"
app:tint="?colorActionForeground" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/text" android:id="@+id/text"
@ -22,7 +23,7 @@
android:clickable="false" android:clickable="false"
android:text="P" android:text="P"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorControlNormal" android:textColor="?colorActionForeground"
app:layout_constraintBottom_toBottomOf="@id/button" app:layout_constraintBottom_toBottomOf="@id/button"
app:layout_constraintEnd_toEndOf="@id/button" app:layout_constraintEnd_toEndOf="@id/button"
app:layout_constraintTop_toTopOf="@id/button" /> app:layout_constraintTop_toTopOf="@id/button" />

Loading…
Cancel
Save