Browse Source

fix(ui): improve message items view to compact and unread

Related: https://framagit.org/dystopia-project/simple-email/issues/30
main
Distopico Vegan 5 years ago
parent
commit
7389734992
No known key found for this signature in database GPG Key ID: 98093A8072546BF3
8 changed files with 81 additions and 12 deletions
  1. +20
    -9
      app/src/main/java/org/dystopia/email/AdapterMessage.java
  2. +23
    -0
      app/src/main/java/org/dystopia/email/Helper.java
  3. +18
    -3
      app/src/main/java/org/dystopia/email/MessageHelper.java
  4. +5
    -0
      app/src/main/res/drawable/item_background_unread_dark.xml
  5. +5
    -0
      app/src/main/res/drawable/item_background_unread_light.xml
  6. +2
    -0
      app/src/main/res/layout/item_message_compact.xml
  7. +2
    -0
      app/src/main/res/values/colors.xml
  8. +6
    -0
      app/src/main/res/values/styles.xml

+ 20
- 9
app/src/main/java/org/dystopia/email/AdapterMessage.java View File

@ -319,18 +319,25 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivFlagged.setVisibility(message.count - message.unflagged > 0 ? View.VISIBLE : View.GONE);
}
Address[] addresses = null;
if (EntityFolder.DRAFTS.equals(message.folderType)
|| EntityFolder.OUTBOX.equals(message.folderType)
|| EntityFolder.SENT.equals(message.folderType)) {
tvFrom.setText(MessageHelper.getFormattedAddresses(message.to, show_expanded));
addresses = message.to;
tvTime.setText(
DateUtils.getRelativeTimeSpanString(
context, message.sent == null ? message.received : message.sent));
} else {
tvFrom.setText(MessageHelper.getFormattedAddresses(message.from, show_expanded));
addresses = message.from;
tvTime.setText(DateUtils.getRelativeTimeSpanString(context, message.received));
}
if (compact && show_expanded) {
tvFrom.setText(MessageHelper.getFormattedAddresses(addresses, false, false));
} else {
tvFrom.setText(MessageHelper.getFormattedAddresses(addresses, show_expanded, true));
}
tvSize.setText(
message.size == null ? null : Helper.humanReadableByteCount(message.size, true));
tvSize.setAlpha(message.content ? 1.0f : 0.5f);
@ -360,13 +367,13 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivThread.setVisibility(View.VISIBLE);
}
if (!compact) {
tvFrom.setMaxLines(show_expanded ? Integer.MAX_VALUE : 1);
tvSubject.setMaxLines(show_expanded ? Integer.MAX_VALUE : 1);
}
tvFrom.setMaxLines(show_expanded ? Integer.MAX_VALUE : 1);
tvSubject.setMaxLines(show_expanded ? Integer.MAX_VALUE : 1);
tvSummary.setVisibility(View.GONE);
if (message.content && !show_expanded) {
if (message.content
&& !show_expanded
&& (!compact || viewType == ViewType.THREAD)) {
try {
String body = message.read(context);
Document doc = Jsoup.parse(body);
@ -431,10 +438,14 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
tvCount.setTypeface(null, typeface);
int colorUnseen = Helper.resolveColor(context, R.attr.colorUnread);
int colorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
Drawable backgroundSeen = Helper.resolveDrawable(context, R.attr.drawableItemBackground);
Drawable backgroundUnseen = Helper.resolveDrawable(context, R.attr.drawableItemUnreadBackground);
tvSubject.setTextColor(colorUnseen);
tvFrom.setTextColor(colorUnseen);
tvTime.setTextColor(colorUnseen);
tvSummary.setTextColor(Helper.resolveColor(context, android.R.attr.textColorSecondary));
tvSummary.setTextColor(colorSecondary);
itemView.setBackground(!message.ui_seen && !show_expanded ? backgroundUnseen : backgroundSeen);
grpExpanded.setVisibility(
viewType == ViewType.THREAD && show_expanded ? View.VISIBLE : View.GONE);


+ 23
- 0
app/src/main/java/org/dystopia/email/Helper.java View File

@ -30,6 +30,7 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
@ -109,6 +110,13 @@ public class Helper {
return intent;
}
/**
* Get color by attr from theme
*
* @param context android context intance
* @param attr R attribute to get styled
* @return integer color value
*/
static int resolveColor(Context context, int attr) {
int[] attrs = new int[] {attr};
TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
@ -117,6 +125,21 @@ public class Helper {
return color;
}
/**
* Get drawable resource from theme
*
* @param context android context intance
* @param attr R attribute to get drawable
* @return drawable resource
*/
static Drawable resolveDrawable(Context context, int attr) {
int[] attrs = new int[] {attr};
TypedArray a = context.getTheme().obtainStyledAttributes(attrs);
Drawable drawable = a.getDrawable(0);
a.recycle();
return drawable;
}
static void setViewsEnabled(ViewGroup view, boolean enabled) {
for (int i = 0; i < view.getChildCount(); i++) {
View child = view.getChildAt(i);


+ 18
- 3
app/src/main/java/org/dystopia/email/MessageHelper.java View File

@ -419,7 +419,15 @@ public class MessageHelper {
return (size < 0 ? null : size);
}
static String getFormattedAddresses(Address[] addresses, boolean full) {
/**
* Get parsed email addresses.
*
* @param addresses list of email <code>Address</code>
* @param full true render the full format
* @param displayName true display name instead of email when is not 'full'
* @return email addresses as string
*/
static String getFormattedAddresses(Address[] addresses, boolean full, boolean displayName) {
if (addresses == null || addresses.length == 0) {
return "";
}
@ -432,11 +440,14 @@ public class MessageHelper {
if (TextUtils.isEmpty(personal)) {
formatted.add(address.toString());
} else {
String email = a.getAddress();
personal = personal.replaceAll("[\\,\\<\\>]", "");
if (full) {
formatted.add(personal + " <" + a.getAddress() + ">");
} else {
formatted.add(personal + " <" + email + ">");
} else if (displayName) {
formatted.add(personal);
} else {
formatted.add(email);
}
}
} else {
@ -446,6 +457,10 @@ public class MessageHelper {
return TextUtils.join(", ", formatted);
}
static String getFormattedAddresses(Address[] addresses, boolean full) {
return getFormattedAddresses(addresses, full, true);
}
String getHtml() throws MessagingException, IOException {
return getHtml(imessage);
}


+ 5
- 0
app/src/main/res/drawable/item_background_unread_dark.xml View File

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

+ 5
- 0
app/src/main/res/drawable/item_background_unread_light.xml View File

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

+ 2
- 0
app/src/main/res/layout/item_message_compact.xml View File

@ -67,6 +67,7 @@
android:layout_marginEnd="20dp"
android:fontFamily="sans-serif-light"
android:text="@string/default_from"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@id/tvTime"
app:layout_constraintStart_toEndOf="@id/ivAvatar"
@ -112,6 +113,7 @@
android:layout_marginEnd="@dimen/margin_sm"
android:fontFamily="sans-serif-light"
android:minLines="1"
android:ellipsize="end"
android:text="@string/default_subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@id/paddingEnd"


+ 2
- 0
app/src/main/res/values/colors.xml View File

@ -17,6 +17,7 @@
<color name="lightColorDrawerScrim">#99000000</color>
<color name="lightColorDrawerText">#111</color>
<color name="lightColorDrawerBackground">#eee</color>
<color name="lightColorUnreadDrawerBackground">#efefef</color>
<color name="darkColorUnread">#fff</color>
<color name="darkColorItemSelected">#555</color>
@ -25,6 +26,7 @@
<color name="darkColorDrawerScrim">#997f7f7f</color>
<color name="darkColorDrawerText">#fff</color>
<color name="darkColorDrawerBackground">#222</color>
<color name="darkColorUnreadDrawerBackground">#191919</color>
<!-- default: #323232 -->
<color name="design_snackbar_background_color" tools:override="true">#ff000000</color>


+ 6
- 0
app/src/main/res/values/styles.xml View File

@ -5,7 +5,9 @@
<attr name="colorDrawerScrim" format="reference" />
<attr name="colorDrawerText" format="reference" />
<attr name="colorDrawerBackground" format="reference" />
<attr name="colorDrawerUnreadBackground" format="reference" />
<attr name="drawableItemBackground" format="reference" />
<attr name="drawableItemUnreadBackground" format="reference" />
<style name="AppThemeLight" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowDisablePreview">true</item>
@ -20,8 +22,10 @@
<item name="colorDrawerScrim">@color/lightColorDrawerScrim</item>
<item name="colorDrawerText">@color/lightColorDrawerText</item>
<item name="colorDrawerBackground">@color/lightColorDrawerBackground</item>
<item name="colorDrawerUnreadBackground">@color/lightColorUnreadDrawerBackground</item>
<item name="drawableItemBackground">@drawable/item_background_light</item>
<item name="drawableItemUnreadBackground">@drawable/item_background_unread_light</item>
<item name="android:checkboxStyle">@style/checkboxStyle</item>
<item name="android:buttonStyle">@style/buttonStyle</item>
@ -42,8 +46,10 @@
<item name="colorDrawerScrim">@color/darkColorDrawerScrim</item>
<item name="colorDrawerText">@color/darkColorDrawerText</item>
<item name="colorDrawerBackground">@color/darkColorDrawerBackground</item>
<item name="colorDrawerUnreadBackground">@color/darkColorUnreadDrawerBackground</item>
<item name="drawableItemBackground">@drawable/item_background_dark</item>
<item name="drawableItemUnreadBackground">@drawable/item_background_unread_dark</item>
<item name="android:checkboxStyle">@style/checkboxStyle</item>
<item name="android:buttonStyle">@style/buttonStyle</item>


Loading…
Cancel
Save