mirror of https://github.com/M66B/FairEmail.git
parent
a2bb26e086
commit
2b3e119445
@ -0,0 +1,186 @@
|
|||||||
|
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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.recyclerview.widget.DiffUtil;
|
||||||
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.ViewHolder> {
|
||||||
|
private ICertificate intf;
|
||||||
|
private Context context;
|
||||||
|
private LifecycleOwner owner;
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
|
||||||
|
private List<EntityCertificate> items = new ArrayList<>();
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
private View view;
|
||||||
|
private TextView tvEmail;
|
||||||
|
private TextView tvSubject;
|
||||||
|
|
||||||
|
ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
view = itemView.findViewById(R.id.clItem);
|
||||||
|
tvEmail = itemView.findViewById(R.id.tvEmail);
|
||||||
|
tvSubject = itemView.findViewById(R.id.tvSubject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int pos = getAdapterPosition();
|
||||||
|
if (pos == RecyclerView.NO_POSITION)
|
||||||
|
return;
|
||||||
|
|
||||||
|
EntityCertificate certificate = items.get(pos);
|
||||||
|
intf.onSelected(certificate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wire() {
|
||||||
|
view.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unwire() {
|
||||||
|
view.setOnClickListener(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bindTo(EntityCertificate certificate) {
|
||||||
|
tvEmail.setText(certificate.email);
|
||||||
|
tvSubject.setText(certificate.subject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AdapterCertificate(Fragment parentFragment, ICertificate intf) {
|
||||||
|
this.intf = intf;
|
||||||
|
this.context = parentFragment.getContext();
|
||||||
|
this.owner = parentFragment.getViewLifecycleOwner();
|
||||||
|
this.inflater = LayoutInflater.from(parentFragment.getContext());
|
||||||
|
|
||||||
|
setHasStableIds(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(@NonNull List<EntityCertificate> certificates) {
|
||||||
|
Log.i("Set certificates=" + certificates.size());
|
||||||
|
|
||||||
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, certificates), false);
|
||||||
|
|
||||||
|
items = certificates;
|
||||||
|
|
||||||
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
||||||
|
@Override
|
||||||
|
public void onInserted(int position, int count) {
|
||||||
|
Log.i("Inserted @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoved(int position, int count) {
|
||||||
|
Log.i("Removed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMoved(int fromPosition, int toPosition) {
|
||||||
|
Log.i("Moved " + fromPosition + ">" + toPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onChanged(int position, int count, Object payload) {
|
||||||
|
Log.i("Changed @" + position + " #" + count);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
diff.dispatchUpdatesTo(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DiffCallback extends DiffUtil.Callback {
|
||||||
|
private List<EntityCertificate> prev = new ArrayList<>();
|
||||||
|
private List<EntityCertificate> next = new ArrayList<>();
|
||||||
|
|
||||||
|
DiffCallback(List<EntityCertificate> prev, List<EntityCertificate> next) {
|
||||||
|
this.prev.addAll(prev);
|
||||||
|
this.next.addAll(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOldListSize() {
|
||||||
|
return prev.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNewListSize() {
|
||||||
|
return next.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
|
EntityCertificate c1 = prev.get(oldItemPosition);
|
||||||
|
EntityCertificate c2 = next.get(newItemPosition);
|
||||||
|
return c1.id.equals(c2.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||||
|
EntityCertificate c1 = prev.get(oldItemPosition);
|
||||||
|
EntityCertificate c2 = next.get(newItemPosition);
|
||||||
|
return c1.equals(c2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return items.get(position).id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return new ViewHolder(inflater.inflate(R.layout.item_certificate, parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
holder.unwire();
|
||||||
|
|
||||||
|
EntityCertificate certificate = items.get(position);
|
||||||
|
holder.bindTo(certificate);
|
||||||
|
|
||||||
|
holder.wire();
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ICertificate {
|
||||||
|
void onSelected(EntityCertificate certificate);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/rvCertificate"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:scrollbarStyle="outsideOverlay"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<eu.faircode.email.ContentLoadingProgressBar
|
||||||
|
android:id="@+id/pbWait"
|
||||||
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:padding="24dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/clItem"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/activatableItemBackground"
|
||||||
|
android:foreground="?attr/selectableItemBackground"
|
||||||
|
android:padding="6dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvEmail"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="test@example.com"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvSubject"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="CN=marcel@faircode.eu"
|
||||||
|
android:textAppearance="@android:style/TextAppearance.Small"
|
||||||
|
android:textIsSelectable="true"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tvEmail" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</FrameLayout>
|
Loading…
Reference in new issue