mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-24 16:53:37 +00:00
parent
c4f8841a5c
commit
e17c4a350c
4 changed files with 38 additions and 59 deletions
|
@ -49,7 +49,6 @@ import android.webkit.MimeTypeMap;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.MultiAutoCompleteTextView;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -104,15 +103,12 @@ public class FragmentCompose extends FragmentEx {
|
|||
private EditText etSubject;
|
||||
private RecyclerView rvAttachment;
|
||||
private EditText etBody;
|
||||
private ImageButton ibBold;
|
||||
private ImageButton ibItalic;
|
||||
private BottomNavigationView bottom_navigation;
|
||||
private ProgressBar pbWait;
|
||||
private Group grpHeader;
|
||||
private Group grpAddresses;
|
||||
private Group grpAttachments;
|
||||
private Group grpMessage;
|
||||
private Group grpAction;
|
||||
|
||||
private AdapterAttachment adapter;
|
||||
|
||||
|
@ -140,15 +136,12 @@ public class FragmentCompose extends FragmentEx {
|
|||
etSubject = view.findViewById(R.id.etSubject);
|
||||
rvAttachment = view.findViewById(R.id.rvAttachment);
|
||||
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);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpHeader = view.findViewById(R.id.grpHeader);
|
||||
grpAddresses = view.findViewById(R.id.grpAddresses);
|
||||
grpAttachments = view.findViewById(R.id.grpAttachments);
|
||||
grpMessage = view.findViewById(R.id.grpMessage);
|
||||
grpAction = view.findViewById(R.id.grpAction);
|
||||
|
||||
// Wire controls
|
||||
|
||||
|
@ -201,7 +194,6 @@ public class FragmentCompose extends FragmentEx {
|
|||
addresses = (grpAddresses.getVisibility() != View.GONE);
|
||||
grpAddresses.setVisibility(View.GONE);
|
||||
grpAttachments.setVisibility(View.GONE);
|
||||
grpAction.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -220,7 +212,6 @@ public class FragmentCompose extends FragmentEx {
|
|||
grpAddresses.setVisibility(View.VISIBLE);
|
||||
if (rvAttachment.getAdapter().getItemCount() > 0)
|
||||
grpAttachments.setVisibility(View.VISIBLE);
|
||||
grpAction.setVisibility(View.GONE);
|
||||
|
||||
new Handler().post(new Runnable() {
|
||||
@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() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
@ -289,7 +257,6 @@ public class FragmentCompose extends FragmentEx {
|
|||
grpAddresses.setVisibility(View.GONE);
|
||||
grpAttachments.setVisibility(View.GONE);
|
||||
grpMessage.setVisibility(View.GONE);
|
||||
grpAction.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
getActivity().invalidateOptionsMenu();
|
||||
|
@ -427,6 +394,8 @@ public class FragmentCompose extends FragmentEx {
|
|||
@Override
|
||||
public void onPrepareOptionsMenu(Menu 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).setEnabled(etBody.isEnabled());
|
||||
menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0);
|
||||
|
@ -435,6 +404,10 @@ public class FragmentCompose extends FragmentEx {
|
|||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_bold:
|
||||
case R.id.menu_italic:
|
||||
onMenuStyle(item.getItemId());
|
||||
return true;
|
||||
case R.id.menu_attachment:
|
||||
onMenuAttachment();
|
||||
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() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
android:layout_marginStart="6dp"
|
||||
android:fillViewport="true"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toTopOf="@+id/ibBold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/vSeparator">
|
||||
|
||||
|
@ -170,25 +170,6 @@
|
|||
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
|
||||
</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
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -236,10 +217,4 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
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>
|
|
@ -2,6 +2,18 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
android:id="@+id/menu_attachment"
|
||||
android:icon="@drawable/baseline_attachment_24"
|
||||
|
|
|
@ -178,6 +178,8 @@
|
|||
<string name="title_save">Save</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_add_attachment">Add attachment</string>
|
||||
|
||||
|
|
Loading…
Reference in a new issue