mirror of https://github.com/M66B/FairEmail.git
Display answers by group
This commit is contained in:
parent
c7ad6e057a
commit
c8e292f2bf
|
@ -7,6 +7,7 @@
|
||||||
### Next version
|
### Next version
|
||||||
|
|
||||||
* Added colors to reply templates
|
* Added colors to reply templates
|
||||||
|
* Added displaying reply templates by group
|
||||||
* Added option to group messages by account category (default disabled)
|
* Added option to group messages by account category (default disabled)
|
||||||
* Small improvements and minor bug fixes
|
* Small improvements and minor bug fixes
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
### Next version
|
### Next version
|
||||||
|
|
||||||
* Added colors to reply templates
|
* Added colors to reply templates
|
||||||
|
* Added displaying reply templates by group
|
||||||
* Added option to group messages by account category (default disabled)
|
* Added option to group messages by account category (default disabled)
|
||||||
* Small improvements and minor bug fixes
|
* Small improvements and minor bug fixes
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
||||||
private View view;
|
private View view;
|
||||||
private View vwColor;
|
private View vwColor;
|
||||||
private TextView tvName;
|
private TextView tvName;
|
||||||
private TextView tvGroup;
|
|
||||||
private ImageView ivExternal;
|
private ImageView ivExternal;
|
||||||
private ImageView ivStandard;
|
private ImageView ivStandard;
|
||||||
private ImageView ivFavorite;
|
private ImageView ivFavorite;
|
||||||
|
@ -89,7 +88,6 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
||||||
view = itemView.findViewById(R.id.clItem);
|
view = itemView.findViewById(R.id.clItem);
|
||||||
vwColor = itemView.findViewById(R.id.vwColor);
|
vwColor = itemView.findViewById(R.id.vwColor);
|
||||||
tvName = itemView.findViewById(R.id.tvName);
|
tvName = itemView.findViewById(R.id.tvName);
|
||||||
tvGroup = itemView.findViewById(R.id.tvGroup);
|
|
||||||
ivExternal = itemView.findViewById(R.id.ivExternal);
|
ivExternal = itemView.findViewById(R.id.ivExternal);
|
||||||
ivStandard = itemView.findViewById(R.id.ivStandard);
|
ivStandard = itemView.findViewById(R.id.ivStandard);
|
||||||
ivFavorite = itemView.findViewById(R.id.ivFavorite);
|
ivFavorite = itemView.findViewById(R.id.ivFavorite);
|
||||||
|
@ -112,8 +110,6 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
||||||
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
|
view.setAlpha(answer.hide ? Helper.LOW_LIGHT : 1.0f);
|
||||||
vwColor.setBackgroundColor(answer.color == null ? Color.TRANSPARENT : answer.color);
|
vwColor.setBackgroundColor(answer.color == null ? Color.TRANSPARENT : answer.color);
|
||||||
tvName.setText(answer.name);
|
tvName.setText(answer.name);
|
||||||
tvGroup.setText(answer.group);
|
|
||||||
tvGroup.setVisibility(TextUtils.isEmpty(answer.group) ? View.GONE : View.VISIBLE);
|
|
||||||
ivExternal.setVisibility(answer.external ? View.VISIBLE : View.GONE);
|
ivExternal.setVisibility(answer.external ? View.VISIBLE : View.GONE);
|
||||||
ivStandard.setVisibility(answer.standard ? View.VISIBLE : View.GONE);
|
ivStandard.setVisibility(answer.standard ? View.VISIBLE : View.GONE);
|
||||||
ivFavorite.setVisibility(answer.favorite ? View.VISIBLE : View.GONE);
|
ivFavorite.setVisibility(answer.favorite ? View.VISIBLE : View.GONE);
|
||||||
|
@ -406,6 +402,13 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
|
||||||
return selected.get(position).id;
|
return selected.get(position).id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityAnswer getItemAtPosition(int pos) {
|
||||||
|
if (pos >= 0 && pos < selected.size())
|
||||||
|
return selected.get(pos);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return selected.size();
|
return selected.size();
|
||||||
|
|
|
@ -58,7 +58,7 @@ public interface DaoAnswer {
|
||||||
EntityAnswer getReceiptAnswer();
|
EntityAnswer getReceiptAnswer();
|
||||||
|
|
||||||
@Query("SELECT * FROM answer" +
|
@Query("SELECT * FROM answer" +
|
||||||
" ORDER BY -favorite, name COLLATE NOCASE")
|
" ORDER BY `group`, -favorite, name COLLATE NOCASE")
|
||||||
LiveData<List<EntityAnswer>> liveAnswers();
|
LiveData<List<EntityAnswer>> liveAnswers();
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM answer" +
|
@Query("SELECT COUNT(*) FROM answer" +
|
||||||
|
|
|
@ -19,7 +19,11 @@ package eu.faircode.email;
|
||||||
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -28,12 +32,14 @@ import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.constraintlayout.widget.Group;
|
import androidx.constraintlayout.widget.Group;
|
||||||
import androidx.fragment.app.FragmentTransaction;
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||||
|
@ -44,6 +50,7 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class FragmentAnswers extends FragmentBase {
|
public class FragmentAnswers extends FragmentBase {
|
||||||
private boolean cards;
|
private boolean cards;
|
||||||
|
@ -90,6 +97,78 @@ public class FragmentAnswers extends FragmentBase {
|
||||||
rvAnswer.addItemDecoration(itemDecorator);
|
rvAnswer.addItemDecoration(itemDecorator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DividerItemDecoration categoryDecorator = new DividerItemDecoration(getContext(), llm.getOrientation()) {
|
||||||
|
@Override
|
||||||
|
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||||
|
int count = parent.getChildCount();
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
View view = parent.getChildAt(i);
|
||||||
|
int pos = parent.getChildAdapterPosition(view);
|
||||||
|
|
||||||
|
View header = getView(view, parent, pos);
|
||||||
|
if (header != null) {
|
||||||
|
canvas.save();
|
||||||
|
canvas.translate(0, parent.getChildAt(i).getTop() - header.getMeasuredHeight());
|
||||||
|
header.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||||
|
int pos = parent.getChildAdapterPosition(view);
|
||||||
|
View header = getView(view, parent, pos);
|
||||||
|
if (header == null)
|
||||||
|
outRect.setEmpty();
|
||||||
|
else
|
||||||
|
outRect.top = header.getMeasuredHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
private View getView(View view, RecyclerView parent, int pos) {
|
||||||
|
if (pos == NO_POSITION)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
EntityAnswer prev = adapter.getItemAtPosition(pos - 1);
|
||||||
|
EntityAnswer account = adapter.getItemAtPosition(pos);
|
||||||
|
if (pos > 0 && prev == null)
|
||||||
|
return null;
|
||||||
|
if (account == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (pos > 0) {
|
||||||
|
if (Objects.equals(prev.group, account.group))
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
if (account.group == null)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
View header = inflater.inflate(R.layout.item_group, parent, false);
|
||||||
|
TextView tvCategory = header.findViewById(R.id.tvCategory);
|
||||||
|
TextView tvDate = header.findViewById(R.id.tvDate);
|
||||||
|
|
||||||
|
if (cards) {
|
||||||
|
View vSeparator = header.findViewById(R.id.vSeparator);
|
||||||
|
vSeparator.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
tvCategory.setText(account.group);
|
||||||
|
tvDate.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
|
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
|
||||||
|
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
|
||||||
|
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
rvAnswer.addItemDecoration(categoryDecorator);
|
||||||
|
|
||||||
adapter = new AdapterAnswer(this);
|
adapter = new AdapterAnswer(this);
|
||||||
rvAnswer.setAdapter(adapter);
|
rvAnswer.setAdapter(adapter);
|
||||||
|
|
||||||
|
|
|
@ -39,19 +39,6 @@
|
||||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
app:layout_constraintStart_toEndOf="@id/vwColor"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
|
||||||
android:id="@+id/tvGroup"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="6dp"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="Group"
|
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/ivExternal"
|
|
||||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tvName" />
|
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
<eu.faircode.email.FixedTextView
|
||||||
android:id="@+id/tvLastApplied"
|
android:id="@+id/tvLastApplied"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -62,7 +49,7 @@
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintEnd_toStartOf="@id/tvApplied"
|
app:layout_constraintEnd_toStartOf="@id/tvApplied"
|
||||||
app:layout_constraintStart_toEndOf="@id/vwColor"
|
app:layout_constraintStart_toEndOf="@id/vwColor"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvGroup" />
|
app:layout_constraintTop_toBottomOf="@id/tvName" />
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
<eu.faircode.email.FixedTextView
|
||||||
android:id="@+id/tvApplied"
|
android:id="@+id/tvApplied"
|
||||||
|
@ -71,7 +58,7 @@
|
||||||
android:text="123"
|
android:text="123"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvGroup" />
|
app:layout_constraintTop_toBottomOf="@id/tvName" />
|
||||||
|
|
||||||
<eu.faircode.email.FixedImageView
|
<eu.faircode.email.FixedImageView
|
||||||
android:id="@+id/ivExternal"
|
android:id="@+id/ivExternal"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
### Next version
|
### Next version
|
||||||
|
|
||||||
* Added colors to reply templates
|
* Added colors to reply templates
|
||||||
|
* Added displaying reply templates by group
|
||||||
* Added option to group messages by account category (default disabled)
|
* Added option to group messages by account category (default disabled)
|
||||||
* Small improvements and minor bug fixes
|
* Small improvements and minor bug fixes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue