Browse Source

Move bold/italic to action menu

Refs #49
main
M66B 6 years ago
parent
commit
e17c4a350c
4 changed files with 38 additions and 59 deletions
  1. +23
    -33
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +1
    -26
      app/src/main/res/layout/fragment_compose.xml
  3. +12
    -0
      app/src/main/res/menu/menu_compose.xml
  4. +2
    -0
      app/src/main/res/values/strings.xml

+ 23
- 33
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -49,7 +49,6 @@ import android.webkit.MimeTypeMap;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.FilterQueryProvider; import android.widget.FilterQueryProvider;
import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.MultiAutoCompleteTextView; import android.widget.MultiAutoCompleteTextView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -104,15 +103,12 @@ public class FragmentCompose extends FragmentEx {
private EditText etSubject; private EditText etSubject;
private RecyclerView rvAttachment; private RecyclerView rvAttachment;
private EditText etBody; private EditText etBody;
private ImageButton ibBold;
private ImageButton ibItalic;
private BottomNavigationView bottom_navigation; private BottomNavigationView bottom_navigation;
private ProgressBar pbWait; private ProgressBar pbWait;
private Group grpHeader; private Group grpHeader;
private Group grpAddresses; private Group grpAddresses;
private Group grpAttachments; private Group grpAttachments;
private Group grpMessage; private Group grpMessage;
private Group grpAction;
private AdapterAttachment adapter; private AdapterAttachment adapter;
@ -140,15 +136,12 @@ public class FragmentCompose extends FragmentEx {
etSubject = view.findViewById(R.id.etSubject); etSubject = view.findViewById(R.id.etSubject);
rvAttachment = view.findViewById(R.id.rvAttachment); rvAttachment = view.findViewById(R.id.rvAttachment);
etBody = view.findViewById(R.id.etBody); etBody = view.findViewById(R.id.etBody);
ibBold = view.findViewById(R.id.ibBold);
ibItalic = view.findViewById(R.id.ibItalic);
bottom_navigation = view.findViewById(R.id.bottom_navigation); bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpHeader = view.findViewById(R.id.grpHeader); grpHeader = view.findViewById(R.id.grpHeader);
grpAddresses = view.findViewById(R.id.grpAddresses); grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments); grpAttachments = view.findViewById(R.id.grpAttachments);
grpMessage = view.findViewById(R.id.grpMessage); grpMessage = view.findViewById(R.id.grpMessage);
grpAction = view.findViewById(R.id.grpAction);
// Wire controls // Wire controls
@ -201,7 +194,6 @@ public class FragmentCompose extends FragmentEx {
addresses = (grpAddresses.getVisibility() != View.GONE); addresses = (grpAddresses.getVisibility() != View.GONE);
grpAddresses.setVisibility(View.GONE); grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE); grpAttachments.setVisibility(View.GONE);
grpAction.setVisibility(View.VISIBLE);
} }
} }
}); });
@ -220,7 +212,6 @@ public class FragmentCompose extends FragmentEx {
grpAddresses.setVisibility(View.VISIBLE); grpAddresses.setVisibility(View.VISIBLE);
if (rvAttachment.getAdapter().getItemCount() > 0) if (rvAttachment.getAdapter().getItemCount() > 0)
grpAttachments.setVisibility(View.VISIBLE); grpAttachments.setVisibility(View.VISIBLE);
grpAction.setVisibility(View.GONE);
new Handler().post(new Runnable() { new Handler().post(new Runnable() {
@Override @Override
@ -237,29 +228,6 @@ public class FragmentCompose extends FragmentEx {
} }
}); });
View.OnClickListener styleListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
if (start != end) {
SpannableString s = new SpannableString(etBody.getText());
s.setSpan(new StyleSpan(v.getId() == ibBold.getId() ? Typeface.BOLD : Typeface.ITALIC),
start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(s);
etBody.setSelection(end);
}
}
};
ibBold.setOnClickListener(styleListener);
ibItalic.setOnClickListener(styleListener);
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@ -289,7 +257,6 @@ public class FragmentCompose extends FragmentEx {
grpAddresses.setVisibility(View.GONE); grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE); grpAttachments.setVisibility(View.GONE);
grpMessage.setVisibility(View.GONE); grpMessage.setVisibility(View.GONE);
grpAction.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
@ -427,6 +394,8 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_bold).setVisible(free && working >= 0);
menu.findItem(R.id.menu_italic).setVisible(free && working >= 0);
menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0); menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0);
menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled()); menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled());
menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0); menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0);
@ -435,6 +404,10 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.menu_bold:
case R.id.menu_italic:
onMenuStyle(item.getItemId());
return true;
case R.id.menu_attachment: case R.id.menu_attachment:
onMenuAttachment(); onMenuAttachment();
return true; return true;
@ -446,6 +419,23 @@ public class FragmentCompose extends FragmentEx {
} }
} }
private void onMenuStyle(int id) {
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
if (start > end) {
int tmp = start;
start = end;
end = tmp;
}
if (start != end) {
SpannableString s = new SpannableString(etBody.getText());
s.setSpan(new StyleSpan(id == R.id.menu_bold ? Typeface.BOLD : Typeface.ITALIC),
start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(s);
etBody.setSelection(end);
}
}
private void onMenuAttachment() { private void onMenuAttachment() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE); intent.addCategory(Intent.CATEGORY_OPENABLE);


+ 1
- 26
app/src/main/res/layout/fragment_compose.xml View File

@ -154,7 +154,7 @@
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:fillViewport="true" android:fillViewport="true"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/ibBold"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparator"> app:layout_constraintTop_toBottomOf="@id/vSeparator">
@ -170,25 +170,6 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" /> android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</ScrollView> </ScrollView>
<ImageButton
android:id="@+id/ibBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:src="@drawable/baseline_format_bold_24"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/scroll" />
<ImageButton
android:id="@+id/ibItalic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_format_italic_24"
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
app:layout_constraintStart_toEndOf="@id/ibBold"
app:layout_constraintTop_toBottomOf="@id/scroll" />
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation" android:id="@+id/bottom_navigation"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -236,10 +217,4 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="scroll,bottom_navigation" /> app:constraint_referenced_ids="scroll,bottom_navigation" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAction"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="ibBold,ibItalic" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

+ 12
- 0
app/src/main/res/menu/menu_compose.xml View File

@ -2,6 +2,18 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_bold"
android:icon="@drawable/baseline_format_bold_24"
android:title="@string/title_style_bold"
app:showAsAction="always" />
<item
android:id="@+id/menu_italic"
android:icon="@drawable/baseline_format_italic_24"
android:title="@string/title_style_italic"
app:showAsAction="always" />
<item <item
android:id="@+id/menu_attachment" android:id="@+id/menu_attachment"
android:icon="@drawable/baseline_attachment_24" android:icon="@drawable/baseline_attachment_24"


+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -178,6 +178,8 @@
<string name="title_save">Save</string> <string name="title_save">Save</string>
<string name="title_send">Send</string> <string name="title_send">Send</string>
<string name="title_style_bold">Bold</string>
<string name="title_style_italic">Italic</string>
<string name="title_show_addresses">Show CC/BCC</string> <string name="title_show_addresses">Show CC/BCC</string>
<string name="title_add_attachment">Add attachment</string> <string name="title_add_attachment">Add attachment</string>


Loading…
Cancel
Save