Click on contact picture (de)selects a message

This commit is contained in:
cketti 2020-03-18 17:13:43 +01:00
parent 86c3af8892
commit 5bdc8cc5f1
6 changed files with 79 additions and 23 deletions

View file

@ -71,7 +71,14 @@ class MessageListAdapter internal constructor(
private val flagClickListener = OnClickListener { view: View ->
val messageViewHolder = view.tag as MessageViewHolder
val messageListItem = getItem(messageViewHolder.position)
listItemListener.toggleMessageFlag(messageListItem)
listItemListener.onToggleMessageFlag(messageListItem)
}
private val contactPictureClickListener = OnClickListener { view: View ->
val parentView = view.parent.parent as View
val messageViewHolder = parentView.tag as MessageViewHolder
val messageListItem = getItem(messageViewHolder.position)
listItemListener.onToggleMessageSelection(messageListItem)
}
private fun recipientSigil(toMe: Boolean, ccMe: Boolean): String {
@ -105,7 +112,9 @@ class MessageListAdapter internal constructor(
val holder = MessageViewHolder(view)
holder.contactPicture.isVisible = appearance.showContactPicture
view.findViewById<View>(R.id.contact_picture_container).isVisible = appearance.showContactPicture
holder.contactPicture.setOnClickListener(contactPictureClickListener)
holder.chip.isVisible = appearance.showAccountChip
appearance.fontSizes.setViewTextSize(holder.subject, subjectViewFontSize)
@ -132,6 +141,16 @@ class MessageListAdapter internal constructor(
val holder = view.tag as MessageViewHolder
if (appearance.showContactPicture) {
if (isSelected) {
holder.contactPicture.isVisible = false
holder.selected.isVisible = true
} else {
holder.selected.isVisible = false
holder.contactPicture.isVisible = true
}
}
with(message) {
val maybeBoldTypeface = if (isRead) Typeface.NORMAL else Typeface.BOLD
val displayDate = DateUtils.getRelativeTimeSpanString(context, messageDate)
@ -148,7 +167,7 @@ class MessageListAdapter internal constructor(
holder.flagged.isChecked = isStarred
}
holder.position = position
if (holder.contactPicture.isVisible) {
if (appearance.showContactPicture && holder.contactPicture.isVisible) {
setContactPicture(holder.contactPicture, counterPartyAddress)
}
setBackgroundColor(view, isSelected, isRead, isActive)
@ -282,5 +301,6 @@ class MessageListAdapter internal constructor(
}
interface MessageListItemActionListener {
fun toggleMessageFlag(item: MessageListItem)
fun onToggleMessageSelection(item: MessageListItem)
fun onToggleMessageFlag(item: MessageListItem)
}

View file

@ -69,6 +69,8 @@ import com.fsck.k9.ui.messagelist.MessageListViewModel;
import net.jcip.annotations.GuardedBy;
import org.jetbrains.annotations.NotNull;
import timber.log.Timber;
import static com.fsck.k9.Account.Expunge.EXPUNGE_MANUALLY;
@ -1180,17 +1182,22 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
return;
}
toggleMessageSelectWithAdapterPosition(adapterPosition);
MessageListItem messageListItem = adapter.getItem(adapterPosition);
toggleMessageSelect(messageListItem);
}
@Override
public void toggleMessageFlag(MessageListItem messageListItem) {
public void onToggleMessageSelection(@NotNull MessageListItem messageListItem) {
toggleMessageSelect(messageListItem);
}
@Override
public void onToggleMessageFlag(MessageListItem messageListItem) {
boolean flagged = messageListItem.isStarred();
setFlag(messageListItem, Flag.FLAGGED, !flagged);
}
private void toggleMessageSelectWithAdapterPosition(int adapterPosition) {
MessageListItem messageListItem = adapter.getItem(adapterPosition);
private void toggleMessageSelect(MessageListItem messageListItem) {
long uniqueId = messageListItem.getUniqueId();
boolean selected = this.selected.contains(uniqueId);

View file

@ -9,6 +9,7 @@ import com.fsck.k9.ui.R
class MessageViewHolder(view: View) {
var position = -1
val selected: View = view.findViewById(R.id.selected)
val contactPicture: ImageView = view.findViewById(R.id.contact_picture)
val subject: TextView = view.findViewById(R.id.subject)
val preview: TextView = view.findViewById(R.id.preview)

View file

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M20,20m-20,0a20,20 0,1 1,40 0a20,20 0,1 1,-40 0"
android:strokeWidth="1"
android:fillColor="#1976d2"
android:strokeColor="#00000000"/>
<path
android:pathData="m16.795,23.875 l-4.17,-4.17 -1.42,1.41 5.59,5.59 12,-12 -1.41,-1.41z"
android:strokeWidth="1"
android:fillColor="#ffffff"/>
</vector>

View file

@ -7,18 +7,32 @@
android:layout_gravity="center_vertical"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/contact_picture"
android:layout_marginRight="10dp"
android:layout_marginTop="4dip"
android:layout_marginBottom="3dip"
android:layout_height="40dip"
android:layout_width="40dip"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
tools:src="@drawable/ic_contact_picture"
android:background="@android:color/transparent"/>
<FrameLayout
android:id="@+id/contact_picture_container"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginTop="4dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="3dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/contact_picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
tools:src="@drawable/ic_contact_picture" />
<ImageView
android:id="@+id/selected"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_check_circle_large"
android:visibility="gone"
android:contentDescription="@null" />
</FrameLayout>
<RelativeLayout
android:id="@+id/list_item_inner"

View file

@ -7,7 +7,6 @@ import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.view.isGone
@ -105,7 +104,7 @@ class MessageListAdapterTest : RobolectricTest() {
val view = adapter.createAndBindView()
assertTrue(view.contactPictureView.isGone)
assertTrue(view.contactPictureContainerView.isGone)
}
@Test
@ -114,7 +113,7 @@ class MessageListAdapterTest : RobolectricTest() {
val view = adapter.createAndBindView()
assertTrue(view.contactPictureView.isVisible)
assertTrue(view.contactPictureContainerView.isVisible)
}
@Test
@ -525,7 +524,7 @@ class MessageListAdapterTest : RobolectricTest() {
val View.accountChipView: View get() = findViewById(R.id.account_color_chip)
val View.starView: CheckBox get() = findViewById(R.id.star)
val View.contactPictureView: ImageView get() = findViewById(R.id.contact_picture)
val View.contactPictureContainerView: View get() = findViewById(R.id.contact_picture_container)
val View.threadCountView: TextView get() = findViewById(R.id.thread_count)
val View.firstLineView: TextView get() = findViewById(R.id.subject)
val View.secondLineView: TextView get() = findViewById(R.id.preview)