Distraction free reading and composing

This commit is contained in:
M66B
2018-08-16 12:45:03 +00:00
parent b41060ffde
commit 887d80925a
86 changed files with 138 additions and 23 deletions

View File

@@ -26,11 +26,13 @@ import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
import android.provider.OpenableColumns;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -94,14 +96,15 @@ public class FragmentCompose extends FragmentEx {
private EditText etBody;
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait;
//private Group grpFrom;
private Group grpReady;
private Group grpHeader;
private Group grpAddresses;
private Group grpAttachments;
private Group grpReady;
private AdapterAttachment adapter;
private long working = -1;
private boolean free = false;
private boolean autosave = true;
private static final int ATTACHMENT_BUFFER_SIZE = 8192; // bytes
@@ -127,10 +130,10 @@ public class FragmentCompose extends FragmentEx {
etBody = view.findViewById(R.id.etBody);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
//grpFrom = view.findViewById(R.id.grpFrom);
grpReady = view.findViewById(R.id.grpReady);
grpHeader = view.findViewById(R.id.grpHeader);
grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments);
grpReady = view.findViewById(R.id.grpReady);
// Wire controls
@@ -173,6 +176,48 @@ public class FragmentCompose extends FragmentEx {
}
});
etBody.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
free = hasFocus;
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
if (hasFocus) {
grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
}
}
});
etBody.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (grpHeader.getVisibility() == View.GONE) {
free = false;
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(View.VISIBLE);
if (rvAttachment.getAdapter().getItemCount() > 0)
grpAttachments.setVisibility(View.VISIBLE);
new Handler().post(new Runnable() {
@Override
public void run() {
etSubject.requestFocus();
}
});
return true;
}
}
}
return false;
}
});
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@@ -304,7 +349,7 @@ public class FragmentCompose extends FragmentEx {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_attachment).setVisible(working >= 0);
menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled());
menu.findItem(R.id.menu_addresses).setVisible(working >= 0);
menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0);
}
@Override
@@ -723,7 +768,8 @@ public class FragmentCompose extends FragmentEx {
attachments = new ArrayList<>();
adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
if (!free)
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});

View File

@@ -43,6 +43,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.text.Collator;
import java.text.DateFormat;
@@ -80,12 +81,15 @@ public class FragmentMessage extends FragmentEx {
private TextView tvError;
private BottomNavigationView top_navigation;
private TextView tvBody;
private FloatingActionButton fab;
private BottomNavigationView bottom_navigation;
private ProgressBar pbWait;
private Group grpReady;
private Group grpHeader;
private Group grpAddresses;
private Group grpAttachments;
private Group grpReady;
private boolean free = false;
private AdapterAttachment adapter;
private boolean debug;
@@ -114,11 +118,13 @@ public class FragmentMessage extends FragmentEx {
tvError = view.findViewById(R.id.tvError);
top_navigation = view.findViewById(R.id.top_navigation);
tvBody = view.findViewById(R.id.tvBody);
fab = view.findViewById(R.id.fab);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
grpHeader = view.findViewById(R.id.grpHeader);
grpAddresses = view.findViewById(R.id.grpAddresses);
grpAttachments = view.findViewById(R.id.grpAttachments);
grpReady = view.findViewById(R.id.grpReady);
setHasOptionsMenu(true);
@@ -193,6 +199,24 @@ public class FragmentMessage extends FragmentEx {
}
});
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
free = (top_navigation.getVisibility() != View.GONE);
getActivity().invalidateOptionsMenu();
grpHeader.setVisibility(free ? View.GONE : View.VISIBLE);
if (free) {
fab.setImageResource(R.drawable.baseline_fullscreen_exit_24);
grpAddresses.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
} else {
fab.setImageResource(R.drawable.baseline_fullscreen_24);
if (rvAttachment.getAdapter().getItemCount() > 0)
grpAttachments.setVisibility(View.VISIBLE);
}
}
});
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@@ -357,7 +381,8 @@ public class FragmentMessage extends FragmentEx {
attachments = new ArrayList<>();
adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
if (!free)
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
}
});
@@ -369,6 +394,12 @@ public class FragmentMessage extends FragmentEx {
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_addresses).setVisible(!free);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {