From 1e9c5e861c20171d0104896670043c03e1b2303f Mon Sep 17 00:00:00 2001 From: Distopico Vegan Date: Tue, 20 Nov 2018 10:12:47 -0500 Subject: [PATCH] feat: improve messages UI - show bg color on swipe action --- .../org/dystopia/email/FragmentMessages.java | 50 ++++++++++++------- app/src/main/res/values/strings.xml | 2 +- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/dystopia/email/FragmentMessages.java b/app/src/main/java/org/dystopia/email/FragmentMessages.java index 52f9206a..390dd247 100644 --- a/app/src/main/java/org/dystopia/email/FragmentMessages.java +++ b/app/src/main/java/org/dystopia/email/FragmentMessages.java @@ -22,6 +22,8 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; @@ -42,6 +44,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SearchView; import androidx.constraintlayout.widget.Group; +import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LiveData; @@ -341,8 +344,12 @@ public class FragmentMessages extends FragmentEx { View itemView = viewHolder.itemView; int margin = Math.round(12 * (getResources().getDisplayMetrics().density)); + Paint color = new Paint(); + color.setColor(ContextCompat.getColor(getContext(), R.color.colorPrimaryDark)); if (dX > margin) { + canvas.drawRect((float) itemView.getLeft(), (float) itemView.getTop(), dX, + (float) itemView.getBottom(), color); // Right swipe Drawable d = getResources().getDrawable( inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_archive_24, @@ -351,8 +358,12 @@ public class FragmentMessages extends FragmentEx { d.setBounds(itemView.getLeft() + margin, itemView.getTop() + padding / 2, itemView.getLeft() + margin + d.getIntrinsicWidth(), itemView.getTop() + padding / 2 + d.getIntrinsicHeight()); + d.setTint(Color.WHITE); d.draw(canvas); } else if (dX < -margin) { + canvas.drawRect((float) itemView.getRight() + dX, (float) itemView.getTop(), + (float) itemView.getRight(), (float) itemView.getBottom(), color); + // Left swipe Drawable d = getResources().getDrawable( inbox ? R.drawable.baseline_move_to_inbox_24 : R.drawable.baseline_delete_24, @@ -361,6 +372,7 @@ public class FragmentMessages extends FragmentEx { d.setBounds(itemView.getLeft() + itemView.getWidth() - d.getIntrinsicWidth() - margin, itemView.getTop() + padding / 2, itemView.getLeft() + itemView.getWidth() - margin, itemView.getTop() + padding / 2 + d.getIntrinsicHeight()); + d.setTint(Color.WHITE); d.draw(canvas); } @@ -1220,36 +1232,36 @@ public class FragmentMessages extends FragmentEx { // - no more non archived/sent messages if (count == 0) { - finish(); + finish(); } } } else { - ViewModelMessages model = - ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); - model.setMessages(messages); + ViewModelMessages model = + ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); + model.setMessages(messages); } - Log.i(Helper.TAG, "Submit messages=" + messages.size()); - adapter.submitList(messages); + Log.i(Helper.TAG, "Submit messages=" + messages.size()); + adapter.submitList(messages); - boolean searching = (searchCallback != null && searchCallback.isSearching()); + boolean searching = (searchCallback != null && searchCallback.isSearching()); - if (!searching) { - pbWait.setVisibility(View.GONE); - } - grpReady.setVisibility(View.VISIBLE); + if (!searching) { + pbWait.setVisibility(View.GONE); + } + grpReady.setVisibility(View.VISIBLE); - if (messages.size() == 0) { - if (searchCallback == null) { - tvNoEmail.setVisibility(View.VISIBLE); - } + if (messages.size() == 0) { + if (searchCallback == null) { + tvNoEmail.setVisibility(View.VISIBLE); + } rvMessage.setVisibility(View.GONE); } else { - tvNoEmail.setVisibility(View.GONE); - rvMessage.setVisibility(View.VISIBLE); + tvNoEmail.setVisibility(View.GONE); + rvMessage.setVisibility(View.VISIBLE); } - } - }); + } + }); } private void handleExpand(long id) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9667d0fa..a83764ec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ SimpleEmail Email - Copyright Ⓒ 2018 by M. Bokhorst\nCopyright Ⓒ 2018 by Distopico (dystopia project) and contributors + Copyright Ⓒ 2018 by M. Bokhorst\nCopyright Ⓒ 2018 by Distopico (dystopia project) and contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses. Service