diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index ec76b58b5d..aac24354b2 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -34,9 +34,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -44,6 +42,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.Group; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; import com.sun.mail.imap.IMAPFolder; @@ -69,7 +69,6 @@ public class ActivityEML extends ActivityBase { private Uri uri; private Result result; private MessageHelper.AttachmentPart apart; - private static final int REQUEST_ATTACHMENT = 1; @Override @@ -82,27 +81,14 @@ public class ActivityEML extends ActivityBase { final TextView tvTo = findViewById(R.id.tvTo); final TextView tvFrom = findViewById(R.id.tvFrom); final TextView tvSubject = findViewById(R.id.tvSubject); - final ListView lvAttachment = findViewById(R.id.lvAttachment); + final RecyclerView rvAttachment = findViewById(R.id.rvAttachment); final TextView tvBody = findViewById(R.id.tvBody); final ContentLoadingProgressBar pbWait = findViewById(R.id.pbWait); final Group grpReady = findViewById(R.id.grpReady); - lvAttachment.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - apart = result.parts.getAttachmentParts().get(position); - - Intent create = new Intent(Intent.ACTION_CREATE_DOCUMENT); - create.addCategory(Intent.CATEGORY_OPENABLE); - create.setType(apart.attachment.getMimeType()); - if (!TextUtils.isEmpty(apart.attachment.name)) - create.putExtra(Intent.EXTRA_TITLE, apart.attachment.name); - if (create.resolveActivity(getPackageManager()) == null) - ToastEx.makeText(ActivityEML.this, R.string.title_no_saf, Toast.LENGTH_LONG).show(); - else - startActivityForResult(Helper.getChooser(ActivityEML.this, create), REQUEST_ATTACHMENT); - } - }); + rvAttachment.setHasFixedSize(false); + LinearLayoutManager llm = new LinearLayoutManager(this); + rvAttachment.setLayoutManager(llm); grpReady.setVisibility(View.GONE); @@ -183,9 +169,27 @@ public class ActivityEML extends ActivityBase { attachments.add(sb.toString()); } - ArrayAdapter adapter = new ArrayAdapter<>( - ActivityEML.this, R.layout.list_item1, android.R.id.text1, attachments); - lvAttachment.setAdapter(adapter); + AdapterAttachmentEML adapter = new AdapterAttachmentEML( + ActivityEML.this, + result.parts.getAttachmentParts(), + new AdapterAttachmentEML.IEML() { + @Override + public void onSelected(MessageHelper.AttachmentPart apart) { + ActivityEML.this.apart = apart; + + Intent create = new Intent(Intent.ACTION_CREATE_DOCUMENT); + create.addCategory(Intent.CATEGORY_OPENABLE); + create.setType(apart.attachment.getMimeType()); + if (!TextUtils.isEmpty(apart.attachment.name)) + create.putExtra(Intent.EXTRA_TITLE, apart.attachment.name); + if (create.resolveActivity(getPackageManager()) == null) + ToastEx.makeText(ActivityEML.this, R.string.title_no_saf, Toast.LENGTH_LONG).show(); + else + startActivityForResult(Helper.getChooser(ActivityEML.this, create), REQUEST_ATTACHMENT); + + } + }); + rvAttachment.setAdapter(adapter); tvBody.setText(result.body); grpReady.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/eu/faircode/email/AdapterAttachment.java b/app/src/main/java/eu/faircode/email/AdapterAttachment.java index 9ef3c4519c..5835d7b840 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAttachment.java +++ b/app/src/main/java/eu/faircode/email/AdapterAttachment.java @@ -154,7 +154,9 @@ public class AdapterAttachment extends RecyclerView.Adapter. + + Copyright 2018-2019 by Marcel Bokhorst (M66B) +*/ + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.List; + +public class AdapterAttachmentEML extends RecyclerView.Adapter { + private LayoutInflater inflater; + + private IEML intf; + private List aparts; + + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + private View view; + private TextView tvName; + private TextView tvSize; + private TextView tvType; + + ViewHolder(View itemView) { + super(itemView); + + view = itemView.findViewById(R.id.clItem); + tvName = itemView.findViewById(R.id.tvName); + tvSize = itemView.findViewById(R.id.tvSize); + tvType = itemView.findViewById(R.id.tvType); + } + + private void wire() { + view.setOnClickListener(this); + } + + private void unwire() { + view.setOnClickListener(null); + } + + private void bindTo(MessageHelper.AttachmentPart apart) { + tvName.setText(apart.attachment.name); + + if (apart.attachment.size != null) + tvSize.setText(Helper.humanReadableByteCount(apart.attachment.size, true)); + tvSize.setVisibility(apart.attachment.size == null ? View.GONE : View.VISIBLE); + + StringBuilder sb = new StringBuilder(); + sb.append(apart.attachment.type); + if (apart.attachment.disposition != null) + sb.append(' ').append(apart.attachment.disposition); + tvType.setText(sb.toString()); + } + + @Override + public void onClick(View view) { + int pos = getAdapterPosition(); + if (pos == RecyclerView.NO_POSITION) + return; + + MessageHelper.AttachmentPart apart = aparts.get(pos); + if (apart != null) + intf.onSelected(apart); + } + } + + AdapterAttachmentEML(Context context, List aparts, IEML intf) { + this.inflater = LayoutInflater.from(context); + this.aparts = aparts; + this.intf = intf; + + setHasStableIds(false); + } + + @Override + public int getItemCount() { + return aparts.size(); + } + + @Override + @NonNull + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ViewHolder(inflater.inflate(R.layout.item_attachment_eml, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + holder.unwire(); + + MessageHelper.AttachmentPart apart = aparts.get(position); + holder.bindTo(apart); + + holder.wire(); + } + + interface IEML { + void onSelected(MessageHelper.AttachmentPart apart); + } +} diff --git a/app/src/main/java/eu/faircode/email/ListViewEx.java b/app/src/main/java/eu/faircode/email/ListViewEx.java deleted file mode 100644 index f282fc1866..0000000000 --- a/app/src/main/java/eu/faircode/email/ListViewEx.java +++ /dev/null @@ -1,46 +0,0 @@ -package eu.faircode.email; - -/* - This file is part of FairEmail. - - FairEmail 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. - - FairEmail 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 the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FairEmail. If not, see . - - Copyright 2018-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.ListView; - -public class ListViewEx extends ListView { - public ListViewEx(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ListViewEx(Context context) { - super(context); - } - - public ListViewEx(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure( - widthMeasureSpec, - MeasureSpec.makeMeasureSpec( - Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST)); - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_eml.xml b/app/src/main/res/layout/activity_eml.xml index e5d63e4c4a..121ec91b6d 100644 --- a/app/src/main/res/layout/activity_eml.xml +++ b/app/src/main/res/layout/activity_eml.xml @@ -103,8 +103,8 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvSubject" /> - + app:layout_constraintTop_toBottomOf="@id/rvAttachment" /> diff --git a/app/src/main/res/layout/item_attachment_eml.xml b/app/src/main/res/layout/item_attachment_eml.xml new file mode 100644 index 0000000000..4f7d117028 --- /dev/null +++ b/app/src/main/res/layout/item_attachment_eml.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/list_item1.xml b/app/src/main/res/layout/list_item1.xml deleted file mode 100644 index f50c5740db..0000000000 --- a/app/src/main/res/layout/list_item1.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - \ No newline at end of file