Improve recent calls presentation
This commit is contained in:
parent
1df3f333d9
commit
0e41e5969a
|
@ -1,5 +1,6 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -14,6 +15,7 @@ import androidx.appcompat.widget.AppCompatImageView;
|
|||
import java.util.List;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.CallLogItem;
|
||||
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||
|
||||
public class CallLogItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
||||
<CallLogItem, CallLogItemRecyclerViewAdapter.ViewHolder> {
|
||||
|
@ -41,6 +43,8 @@ public class CallLogItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
final AppCompatImageView callTypeIcon;
|
||||
final TextView label;
|
||||
final AppCompatImageView numberInfoIcon;
|
||||
final TextView duration;
|
||||
final TextView description;
|
||||
final TextView time;
|
||||
|
||||
ViewHolder(View view) {
|
||||
|
@ -49,11 +53,15 @@ public class CallLogItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
callTypeIcon = view.findViewById(R.id.callTypeIcon);
|
||||
label = view.findViewById(R.id.item_label);
|
||||
numberInfoIcon = view.findViewById(R.id.numberInfoIcon);
|
||||
duration = view.findViewById(R.id.duration);
|
||||
description = view.findViewById(R.id.description);
|
||||
time = view.findViewById(R.id.time);
|
||||
}
|
||||
|
||||
@Override
|
||||
void bind(CallLogItem item) {
|
||||
Context context = itemView.getContext();
|
||||
|
||||
Integer icon;
|
||||
switch (item.type) {
|
||||
case INCOMING:
|
||||
|
@ -82,27 +90,54 @@ public class CallLogItemRecyclerViewAdapter extends GenericRecyclerViewAdapter
|
|||
callTypeIcon.setImageDrawable(null);
|
||||
}
|
||||
|
||||
label.setText(ellipsize(
|
||||
item.numberInfo.noNumber ? label.getContext().getString(R.string.no_number) :
|
||||
item.numberInfo.name != null ? item.numberInfo.name : item.number,
|
||||
15));
|
||||
NumberInfo numberInfo = item.numberInfo;
|
||||
|
||||
label.setText(numberInfo.noNumber
|
||||
? context.getString(R.string.no_number)
|
||||
: numberInfo.name != null ? numberInfo.name : item.number);
|
||||
|
||||
IconAndColor iconAndColor = IconAndColor.forNumberRating(
|
||||
item.numberInfo.rating, item.numberInfo.contactItem != null);
|
||||
numberInfo.rating, numberInfo.contactItem != null);
|
||||
|
||||
if (!iconAndColor.noInfo) {
|
||||
iconAndColor.setOnImageView(numberInfoIcon);
|
||||
iconAndColor.applyToImageView(numberInfoIcon);
|
||||
} else {
|
||||
numberInfoIcon.setImageDrawable(null);
|
||||
}
|
||||
|
||||
time.setText(DateUtils.getRelativeTimeSpanString(item.timestamp));
|
||||
if (item.duration == 0 && item.type == CallLogItem.Type.MISSED
|
||||
|| item.type == CallLogItem.Type.REJECTED) {
|
||||
duration.setVisibility(View.GONE);
|
||||
} else {
|
||||
duration.setText(getDuration(context, item.duration));
|
||||
duration.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
String descriptionString = NumberInfoUtils.getShortDescription(context, numberInfo);
|
||||
if (!TextUtils.isEmpty(descriptionString)) {
|
||||
description.setText(descriptionString);
|
||||
description.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
description.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
time.setText(DateUtils.getRelativeTimeSpanString(
|
||||
item.timestamp, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_ALL));
|
||||
}
|
||||
|
||||
String ellipsize(String s, int maxLength) {
|
||||
return s == null || s.length() <= maxLength
|
||||
? s
|
||||
: (s.substring(0, maxLength - 1) + '…');
|
||||
private String getDuration(Context context, long duration) {
|
||||
long seconds = duration % 60;
|
||||
long minutes = duration / 60;
|
||||
long hours = minutes / 60;
|
||||
minutes -= hours * 60;
|
||||
|
||||
if (hours != 0) {
|
||||
return context.getString(R.string.duration_h_m_s, hours, minutes, seconds);
|
||||
} else if (minutes != 0) {
|
||||
return context.getString(R.string.duration_m_s, minutes, seconds);
|
||||
}
|
||||
return context.getString(R.string.duration_s, seconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,7 @@ class CustomListViewAdapter extends RecyclerView.Adapter<CustomListViewAdapter.C
|
|||
tvDescription.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
IconAndColor.forReviewRating(item.getRating()).setOnImageView(ivRating);
|
||||
IconAndColor.forReviewRating(item.getRating()).applyToImageView(ivRating);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class IconAndColor {
|
|||
return UiUtils.getColorInt(context, colorResId);
|
||||
}
|
||||
|
||||
void setOnImageView(AppCompatImageView imageView) {
|
||||
void applyToImageView(AppCompatImageView imageView) {
|
||||
imageView.setImageResource(iconResId);
|
||||
ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(
|
||||
getColorInt(imageView.getContext())));
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
|
||||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||
|
||||
import static dummydomain.yetanothercallblocker.IntentHelper.clearTop;
|
||||
|
@ -204,20 +202,7 @@ public class NotificationHelper {
|
|||
}
|
||||
|
||||
private static String getTitleExtra(Context context, NumberInfo numberInfo) {
|
||||
if (numberInfo.communityDatabaseItem != null) {
|
||||
CommunityDatabaseItem communityItem = numberInfo.communityDatabaseItem;
|
||||
|
||||
NumberCategory category = NumberCategory.getById(communityItem.getCategory());
|
||||
if (category != null && category != NumberCategory.NONE) {
|
||||
return SiaNumberCategoryUtils.getName(context, category);
|
||||
}
|
||||
}
|
||||
|
||||
if (numberInfo.blacklistItem != null && numberInfo.contactItem == null) {
|
||||
return context.getString(R.string.info_in_blacklist);
|
||||
}
|
||||
|
||||
return null;
|
||||
return NumberInfoUtils.getShortDescription(context, numberInfo);
|
||||
}
|
||||
|
||||
private static String getInfoDescription(Context context, NumberInfo numberInfo) {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package dummydomain.yetanothercallblocker;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||
import dummydomain.yetanothercallblocker.data.SiaNumberCategoryUtils;
|
||||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||
|
||||
public class NumberInfoUtils {
|
||||
|
||||
public static String getShortDescription(Context context, NumberInfo numberInfo) {
|
||||
if (numberInfo.communityDatabaseItem != null) {
|
||||
NumberCategory category = NumberCategory.getById(
|
||||
numberInfo.communityDatabaseItem.getCategory());
|
||||
|
||||
if (category != null && category != NumberCategory.NONE) {
|
||||
return SiaNumberCategoryUtils.getName(context, category);
|
||||
}
|
||||
}
|
||||
|
||||
if (numberInfo.blacklistItem != null && numberInfo.contactItem == null) {
|
||||
return context.getString(R.string.info_in_blacklist);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,42 +6,85 @@
|
|||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical|start"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/item_padding">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/callTypeIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_call_missed_24dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLength="15"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?attr/textAppearanceListItem"
|
||||
tools:text="+12345678901" />
|
||||
android:paddingLeft="@dimen/item_padding"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingRight="@dimen/item_padding"
|
||||
android:paddingBottom="8dp">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/numberInfoIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_thumb_down_24dp" />
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="28dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_thumb_down_24dp"
|
||||
tools:tint="@color/rateNegative" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?attr/textAppearanceListItemSecondary"
|
||||
android:textSize="12sp"
|
||||
tools:text="1 minute ago" />
|
||||
android:layout_marginLeft="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="bottom"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_label"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textAppearance="?attr/textAppearanceListItem"
|
||||
tools:text="+12345678901 | very looooong line that is still going" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
tools:text="1m 25s" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:gravity="bottom"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/callTypeIcon"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/ic_call_missed_24dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:textSize="12sp"
|
||||
tools:text="1 min ago" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:gravity="right"
|
||||
android:maxLines="1"
|
||||
tools:text="Debt collector | very looooong line that is still going" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -173,4 +173,7 @@
|
|||
<string name="monitoring_service_label">Служба мониторинга вызовов</string>
|
||||
<string name="monitoring_service_description">Служба для мониторинга состояния телефона в фоне</string>
|
||||
<string name="monitoring_service_notification_title">Мониторинг вызовов</string>
|
||||
<string name="duration_h_m_s">%1$dч %2$dм %3$dс</string>
|
||||
<string name="duration_m_s">%1$dм %2$dс</string>
|
||||
<string name="duration_s">%dс</string>
|
||||
</resources>
|
|
@ -192,4 +192,8 @@
|
|||
<string name="monitoring_service_label">Call monitoring service</string>
|
||||
<string name="monitoring_service_description">A service for monitoring phone state in background</string>
|
||||
<string name="monitoring_service_notification_title">Monitoring calls</string>
|
||||
|
||||
<string name="duration_h_m_s">%1$dh %2$dm %3$ds</string>
|
||||
<string name="duration_m_s">%1$dm %2$ds</string>
|
||||
<string name="duration_s">%ds</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue