Disable all on action

pull/50/head
M66B 6 years ago
parent 0a4621abad
commit 3314826120

@ -191,7 +191,7 @@ public class FragmentCompose extends FragmentEx {
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
bottom_navigation.getMenu().setGroupEnabled(0, false); getActivity().invalidateOptionsMenu();
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS) if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {
@ -295,6 +295,7 @@ public class FragmentCompose extends FragmentEx {
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
menu.findItem(R.id.menu_attachment).setVisible(working >= 0); 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(working >= 0);
} }
@ -496,7 +497,7 @@ public class FragmentCompose extends FragmentEx {
private void onAction(int action) { private void onAction(int action) {
Helper.setViewsEnabled(view, false); Helper.setViewsEnabled(view, false);
bottom_navigation.getMenu().setGroupEnabled(0, false); getActivity().invalidateOptionsMenu();
EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem();
@ -640,7 +641,7 @@ public class FragmentCompose extends FragmentEx {
etTo.requestFocus(); etTo.requestFocus();
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
bottom_navigation.getMenu().setGroupEnabled(0, true); getActivity().invalidateOptionsMenu();
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
@ -845,7 +846,7 @@ public class FragmentCompose extends FragmentEx {
Log.i(Helper.TAG, "Loaded action id=" + draft.id + " action=" + action); Log.i(Helper.TAG, "Loaded action id=" + draft.id + " action=" + action);
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
bottom_navigation.getMenu().setGroupEnabled(0, true); getActivity().invalidateOptionsMenu();
if (action == R.id.action_trash) { if (action == R.id.action_trash) {
autosave = false; autosave = false;
@ -865,7 +866,7 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true); Helper.setViewsEnabled(view, true);
bottom_navigation.getMenu().setGroupEnabled(0, true); getActivity().invalidateOptionsMenu();
if (ex instanceof IllegalArgumentException) if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show(); Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();

@ -23,7 +23,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -67,6 +66,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
public class FragmentMessage extends FragmentEx { public class FragmentMessage extends FragmentEx {
private ViewGroup view;
private TextView tvFrom; private TextView tvFrom;
private TextView tvTime; private TextView tvTime;
private TextView tvSubject; private TextView tvSubject;
@ -92,7 +92,7 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
@Nullable @Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_message, container, false); view = (ViewGroup) inflater.inflate(R.layout.fragment_message, container, false);
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
@ -390,11 +390,7 @@ public class FragmentMessage extends FragmentEx {
} }
private void onActionSeen(long id) { private void onActionSeen(long id) {
final MenuItem item = top_navigation.getMenu().findItem(R.id.action_seen); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -427,25 +423,19 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void data) { protected void onLoaded(Bundle args, Void data) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
public void onException(Bundle args, Throwable ex) { public void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(this, args); }.load(this, args);
} }
private void onActionEdit(final long id) { private void onActionEdit(final long id) {
final MenuItem item = top_navigation.getMenu().findItem(R.id.action_edit); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -480,8 +470,7 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void data) { protected void onLoaded(Bundle args, Void data) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
getContext().startActivity( getContext().startActivity(
new Intent(getContext(), ActivityCompose.class) new Intent(getContext(), ActivityCompose.class)
.putExtra("action", "edit") .putExtra("action", "edit")
@ -490,8 +479,7 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
public void onException(Bundle args, Throwable ex) { public void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(this, args); }.load(this, args);
@ -516,11 +504,7 @@ public class FragmentMessage extends FragmentEx {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final MenuItem item = bottom_navigation.getMenu().findItem(R.id.action_spam); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -553,14 +537,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void result) { protected void onLoaded(Bundle args, Void result) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(FragmentMessage.this, args); }.load(FragmentMessage.this, args);
@ -579,11 +561,7 @@ public class FragmentMessage extends FragmentEx {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final MenuItem item = bottom_navigation.getMenu().findItem(R.id.action_trash); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -614,14 +592,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void result) { protected void onLoaded(Bundle args, Void result) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(FragmentMessage.this, args); }.load(FragmentMessage.this, args);
@ -629,11 +605,7 @@ public class FragmentMessage extends FragmentEx {
}) })
.setNegativeButton(android.R.string.cancel, null).show(); .setNegativeButton(android.R.string.cancel, null).show();
} else { } else {
final MenuItem item = bottom_navigation.getMenu().findItem(R.id.action_trash); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -669,14 +641,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void result) { protected void onLoaded(Bundle args, Void result) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(FragmentMessage.this, args); }.load(FragmentMessage.this, args);
@ -741,11 +711,7 @@ public class FragmentMessage extends FragmentEx {
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(final MenuItem target) { public boolean onMenuItemClick(final MenuItem target) {
final MenuItem item = bottom_navigation.getMenu().findItem(R.id.action_move); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
args.putLong("target", target.getItemId()); args.putLong("target", target.getItemId());
@ -780,14 +746,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void result) { protected void onLoaded(Bundle args, Void result) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(FragmentMessage.this, args); }.load(FragmentMessage.this, args);
@ -802,11 +766,7 @@ public class FragmentMessage extends FragmentEx {
} }
private void onActionArchive(long id) { private void onActionArchive(long id) {
final MenuItem item = bottom_navigation.getMenu().findItem(R.id.action_archive); Helper.setViewsEnabled(view, false);
item.setEnabled(false);
final Drawable icon = item.getIcon();
item.setIcon(Helper.toDimmed(icon));
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
@ -839,14 +799,12 @@ public class FragmentMessage extends FragmentEx {
@Override @Override
protected void onLoaded(Bundle args, Void result) { protected void onLoaded(Bundle args, Void result) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
} }
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
item.setEnabled(true); Helper.setViewsEnabled(view, true);
item.setIcon(icon);
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}.load(FragmentMessage.this, args); }.load(FragmentMessage.this, args);

@ -21,25 +21,24 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner; import android.widget.Spinner;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import androidx.annotation.NonNull;
public class Helper { public class Helper {
static final String TAG = BuildConfig.APPLICATION_ID; static final String TAG = BuildConfig.APPLICATION_ID;
@ -51,25 +50,19 @@ public class Helper {
return color; return color;
} }
static Drawable toDimmed(@NonNull Drawable drawable) {
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
Drawable mutated = drawable.mutate();
mutated.setColorFilter(filter);
mutated.setAlpha(128);
return mutated;
}
static void setViewsEnabled(ViewGroup view, boolean enabled) { static void setViewsEnabled(ViewGroup view, boolean enabled) {
for (int i = 0; i < view.getChildCount(); i++) { for (int i = 0; i < view.getChildCount(); i++) {
View child = view.getChildAt(i); View child = view.getChildAt(i);
if (child instanceof Spinner || if (child instanceof Spinner ||
child instanceof EditText || child instanceof EditText ||
child instanceof CheckBox || child instanceof CheckBox ||
child instanceof ImageView ||
child instanceof ImageButton) child instanceof ImageButton)
child.setEnabled(enabled); child.setEnabled(enabled);
else if (child instanceof ViewGroup) if (child instanceof BottomNavigationView) {
Menu menu = ((BottomNavigationView) child).getMenu();
menu.setGroupEnabled(0, enabled);
} else if (child instanceof ViewGroup)
setViewsEnabled((ViewGroup) child, enabled); setViewsEnabled((ViewGroup) child, enabled);
} }
} }

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorActionForegroundDisabled" android:state_enabled="false" />
<item android:color="@color/colorActionForeground" android:state_enabled="true" />
</selector>

@ -175,9 +175,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
app:itemIconTint="@color/colorActionForeground" app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/colorActionForeground" app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="unlabeled" app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

@ -180,8 +180,8 @@
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:background="@color/darkColorSeparator" android:background="@color/darkColorSeparator"
app:itemIconTint="@color/colorActionForeground" app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/colorActionForeground" app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="unlabeled" app:labelVisibilityMode="unlabeled"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -216,8 +216,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:background="@color/colorPrimary" android:background="@color/colorPrimary"
app:itemIconTint="@color/colorActionForeground" app:itemIconTint="@color/bottomnav_background"
app:itemTextColor="@color/colorActionForeground" app:itemTextColor="@color/bottomnav_background"
app:labelVisibilityMode="labeled" app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

@ -5,6 +5,7 @@
<color name="colorAccent">#ffb300</color> <color name="colorAccent">#ffb300</color>
<color name="colorActionForeground">#fff</color> <color name="colorActionForeground">#fff</color>
<color name="colorActionForegroundDisabled">#ccc</color>
<color name="lightColorUnread">#000</color> <color name="lightColorUnread">#000</color>
<color name="lightColorSeparator">#ffaaaaaa</color> <color name="lightColorSeparator">#ffaaaaaa</color>

Loading…
Cancel
Save