Distraction free reading and composing

pull/50/head
M66B 6 years ago
parent b41060ffde
commit 887d80925a

@ -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);
}
});

@ -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()) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M5,16h3v3h2v-5L5,14v2zM8,8L5,8v2h5L10,5L8,5v3zM14,19h2v-3h3v-2h-5v5zM16,8L16,5h-2v5h5L19,8h-3z"/>
</vector>

@ -195,26 +195,26 @@
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFrom"
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="spFrom,ivIdentityAdd" />
app:constraint_referenced_ids="etTo,ivToAdd,etSubject,vSeparator,scroll,bottom_navigation" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAddresses"
android:id="@+id/grpHeader"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="etCc,ivCcAdd,etBcc,ivBccAdd" />
app:constraint_referenced_ids="spFrom,ivIdentityAdd,etTo,ivToAdd,etSubject,vSeparator" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAttachments"
android:id="@+id/grpAddresses"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
app:constraint_referenced_ids="etCc,ivCcAdd,etBcc,ivBccAdd" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:id="@+id/grpAttachments"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="etTo,ivToAdd,etSubject,vSeparator,scroll,bottom_navigation" />
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -233,6 +233,18 @@
android:textIsSelectable="true" />
</ScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/baseline_fullscreen_24"
android:tint="@color/colorActionForeground"
app:backgroundTint="?attr/colorAccent"
app:layout_constraintBottom_toBottomOf="@+id/scroll"
app:layout_constraintEnd_toEndOf="parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
@ -259,20 +271,26 @@
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAddresses"
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAddress,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc" />
app:constraint_referenced_ids="tvFrom,tvToTitle,tvTo,tvTime,tvSubject,tvCount,scroll,fab" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAttachments"
android:id="@+id/grpHeader"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
app:constraint_referenced_ids="tvFrom,tvToTitle,tvTo,tvTime,tvSubject,tvCount,top_navigation" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:id="@+id/grpAddresses"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAddress,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAttachments"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvFrom,tvToTitle,tvTo,tvTime,tvSubject,tvCount,scroll" />
app:constraint_referenced_ids="vSeparatorAttachments,rvAttachment" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save