Commit 53429332 authored by Hussein's avatar Hussein

Merge branch 'bug/P4A-950' into develop

parents de9eea3e b4856ccd
......@@ -2,30 +2,32 @@ package com.fsck.k9.ui.messageview;
import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.helper.SizeFormatter;
import com.fsck.k9.mailstore.AttachmentViewInfo;
import timber.log.Timber;
public class AttachmentView extends FrameLayout implements OnClickListener, OnLongClickListener {
public class AttachmentView extends ConstraintLayout {
private AttachmentViewInfo attachment;
private AttachmentViewCallback callback;
private Button viewButton;
private ImageView downloadButton;
private View attachmentContainer;
public AttachmentView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
......@@ -39,46 +41,42 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
super(context);
}
private void init() {
downloadButton = findViewById(R.id.download);
}
public AttachmentViewInfo getAttachment() {
return attachment;
}
public void setAttachment(AttachmentViewInfo attachment) {
this.attachment = attachment;
displayAttachmentInformation();
}
public void enableButtons() {
viewButton.setEnabled(true);
downloadButton.setEnabled(true);
}
public void disableButtons() {
viewButton.setEnabled(false);
downloadButton.setEnabled(false);
}
public void setAttachment(AttachmentViewInfo attachment) {
this.attachment = attachment;
displayAttachmentInformation();
}
private void displayAttachmentInformation() {
attachmentContainer = findViewById(R.id.attachment_container);
viewButton = (Button) findViewById(R.id.view);
downloadButton = (ImageView) findViewById(R.id.download);
init();
if (attachment.size > K9.MAX_ATTACHMENT_DOWNLOAD_SIZE) {
viewButton.setVisibility(View.GONE);
downloadButton.setVisibility(View.GONE);
}
attachmentContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
onViewClick();
}
setOnClickListener(v -> onViewClick());
downloadButton.setOnClickListener(v -> onSaveButtonClick());
downloadButton.setOnLongClickListener(v -> {
onSaveButtonLongClick();
return true;
});
downloadButton.setOnClickListener(this);
downloadButton.setOnLongClickListener(this);
TextView attachmentName = (TextView) findViewById(R.id.attachment_name);
TextView attachmentName = findViewById(R.id.attachment_name);
attachmentName.setText(attachment.displayName);
setAttachmentSize(attachment.size);
......@@ -87,7 +85,7 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
}
private void setAttachmentSize(long size) {
TextView attachmentSize = (TextView) findViewById(R.id.attachment_info);
TextView attachmentSize = findViewById(R.id.attachment_info);
if (size == AttachmentViewInfo.UNKNOWN_SIZE) {
attachmentSize.setText("");
} else {
......@@ -96,26 +94,6 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.download: {
onSaveButtonClick();
break;
}
}
}
@Override
public boolean onLongClick(View view) {
if (view.getId() == R.id.download) {
onSaveButtonLongClick();
return true;
}
return false;
}
private void onViewClick() {
callback.onViewAttachment(attachment);
}
......@@ -133,11 +111,25 @@ public class AttachmentView extends FrameLayout implements OnClickListener, OnLo
}
public void refreshThumbnail() {
ImageView thumbnailView = (ImageView) findViewById(R.id.attachment_icon);
ImageView thumbnailView = findViewById(R.id.attachment_icon);
Glide.with(getContext())
.load(attachment.internalUri)
.placeholder(R.drawable.attached_image_placeholder)
.placeholder(ContextCompat.getDrawable(getContext(), R.drawable.ic_file_light))
.centerCrop()
.into(thumbnailView);
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override
public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
Timber.e(e);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
thumbnailView.setPadding(0, 0, 0, 0);
return false;
}
})
.into(thumbnailView)
;
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/white"
android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/white"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:alpha="0.54"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:alpha="0.54"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.ui.messageview.AttachmentView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/attachment">
android:id="@+id/attachment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@drawable/selectable_item_background"
android:clickable="true"
android:paddingTop="16dp">
<LinearLayout android:id="@+id/attachment_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/download"
android:layout_width="56dp"
android:layout_height="56dp"
android:background="@drawable/selectable_item_background"
android:orientation="vertical">
android:clickable="true"
android:padding="16dp"
android:src="?attr/iconActionDownload"
app:layout_constraintBottom_toBottomOf="@+id/attachment_info"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:gravity="center_vertical">
<ImageView
android:id="@+id/attachment_icon"
android:layout_width="62dp"
android:layout_height="62dp"
android:src="@drawable/attached_image_placeholder" />
<TextView
android:id="@+id/attachment_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
android:ellipsize="middle"
android:layout_alignParentTop="true"
android:maxLines="2"
android:layout_toStartOf="@+id/download"
android:layout_toRightOf="@id/attachment_icon"
tools:text="here be attachment name and it can be so long but no more than 2 lines"
android:layout_alignWithParentIfMissing="true"/>
<TextView
android:id="@+id/attachment_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorTertiary"
android:singleLine="true"
android:ellipsize="middle"
android:paddingLeft="16dp"
tools:text="here be attachment name and this is not so long"
android:layout_alignLeft="@id/attachment_name"
android:layout_toStartOf="@+id/download"
android:layout_below="@id/attachment_name"
android:layout_alignWithParentIfMissing="true" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/attachment_icon"
android:layout_width="56dp"
android:layout_height="56dp"
android:padding="8dp"
android:src="?attr/iconFile"
app:layout_constraintBottom_toBottomOf="@+id/attachment_info"
app:layout_constraintStart_toEndOf="@+id/download"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/buttonStyleSmall"
android:paddingLeft="20dip"
android:paddingRight="20dip"
android:text="@string/message_view_attachment_view_action"
android:singleLine="true"
android:layout_alignWithParentIfMissing="true"
android:layout_below="@id/attachment_name"
android:visibility="gone"
android:layout_marginTop="6dip" />
<TextView
android:id="@+id/attachment_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:maxLines="2"
android:paddingStart="8dp"
android:paddingEnd="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/attachment_icon"
app:layout_constraintTop_toTopOf="parent"
tools:text="here be attachment name and it can be so long but no more than 2 lines" />
<ImageView
android:id="@+id/download"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/message_view_attachment_download_action"
android:clickable="true"
android:background="@drawable/selectable_item_background"
android:src="@drawable/ic_file_file_download"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="@+id/attachment_icon" />
</RelativeLayout>
<TextView
android:id="@+id/attachment_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:paddingStart="8dp"
android:paddingEnd="16dp"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorTertiary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/attachment_name"
app:layout_constraintTop_toBottomOf="@+id/attachment_name"
tools:text="here be attachment name and this is not so long" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#E1E1E1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:background="?attr/messageListDividerColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/attachment_info" />
</com.fsck.k9.ui.messageview.AttachmentView>
......@@ -33,6 +33,8 @@
<attr name="iconActionAdd" format="reference" />
<attr name="iconActionImportExport" format="reference" />
<attr name="iconActionUpload" format="reference" />
<attr name="iconActionDownload" format="reference" />
<attr name="iconFile" format="reference" />
<attr name="iconActionSelectAll" format="reference" />
<attr name="iconActionSave" format="reference" />
<attr name="iconActionCancel" format="reference" />
......
......@@ -43,6 +43,8 @@
<item name="iconActionAdd">@drawable/ic_plus_light</item>
<item name="iconActionImportExport">@drawable/ic_arrow_up_down_light</item>
<item name="iconActionUpload">@drawable/ic_file_upload_light</item>
<item name="iconActionDownload">@drawable/ic_file_download_light</item>
<item name="iconFile">@drawable/ic_file_light</item>
<item name="iconActionSelectAll">@drawable/ic_select_all_light</item>
<item name="iconActionSave">@drawable/ic_floppy_light</item>
<item name="iconActionCancel">@drawable/ic_clear_light</item>
......@@ -139,6 +141,8 @@
<item name="iconActionAdd">@drawable/ic_plus_dark</item>
<item name="iconActionImportExport">@drawable/ic_arrow_up_down_dark</item>
<item name="iconActionUpload">@drawable/ic_file_upload_dark</item>
<item name="iconActionDownload">@drawable/ic_file_download_dark</item>
<item name="iconFile">@drawable/ic_file_dark</item>
<item name="iconActionSelectAll">@drawable/ic_select_all_dark</item>
<item name="iconActionSave">@drawable/ic_floppy_dark</item>
<item name="iconActionCancel">@drawable/ic_clear_dark</item>
......@@ -271,6 +275,8 @@
<item name="iconActionAdd">@drawable/ic_plus_light</item>
<item name="iconActionImportExport">@drawable/ic_arrow_up_down_light</item>
<item name="iconActionUpload">@drawable/ic_file_upload_light</item>
<item name="iconActionDownload">@drawable/ic_file_download_light</item>
<item name="iconFile">@drawable/ic_file_light</item>
<item name="iconActionSelectAll">@drawable/ic_select_all_light</item>
<item name="iconActionSave">@drawable/ic_floppy_light</item>
<item name="iconActionCancel">@drawable/ic_clear_light</item>
......@@ -358,6 +364,8 @@
<item name="iconActionAdd">@drawable/ic_file_upload_dark</item>
<item name="iconActionImportExport">@drawable/ic_arrow_up_down_dark</item>
<item name="iconActionUpload">@drawable/ic_file_upload_dark</item>
<item name="iconActionDownload">@drawable/ic_file_download_dark</item>
<item name="iconFile">@drawable/ic_file_dark</item>
<item name="iconActionSelectAll">@drawable/ic_select_all_dark</item>
<item name="iconActionSave">@drawable/ic_floppy_dark</item>
<item name="iconActionCancel">@drawable/ic_clear_dark</item>
......
......@@ -42,7 +42,7 @@ public class PEpStatusPresenterTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
PEpIdentityMapper pEpIdentityMapper = new PEpIdentityMapper();
PEpIdentityMapper pEpIdentityMapper = new PEpIdentityMapper(provider);
presenter = new PEpStatusPresenter(simpleMessageLoaderHelper,
pEpIdentityMapper);
presenterSpy = spy(presenter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment