1
0
mirror of https://codeberg.org/gitnex/GitNex synced 2025-01-24 16:31:16 +01:00

Applying changes of LabelWidthCalculator to LabelsAdapter. (#398)

Trying to find a compromise.

make them great again ;)

Applying changes of LabelWidthCalculator to LabelsAdapter.

Co-authored-by: opyale <example@example.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/398
Reviewed-by: 6543 <6543@noreply.gitea.io>
Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
opyale 2020-04-13 07:25:39 +00:00 committed by M M Arif
parent 3a524c9f5d
commit 4123e03f7d

View File

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -109,7 +110,6 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) { public void onBindViewHolder(@NonNull LabelsAdapter.LabelsViewHolder holder, int position) {
Labels currentItem = labelsList.get(position); Labels currentItem = labelsList.get(position);
int width = 33;
holder.labelTitle.setText(currentItem.getName()); holder.labelTitle.setText(currentItem.getName());
holder.labelId.setText(String.valueOf(currentItem.getId())); holder.labelId.setText(String.valueOf(currentItem.getId()));
@ -117,35 +117,24 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
String labelColor = currentItem.getColor(); String labelColor = currentItem.getColor();
String labelName = currentItem.getName(); String labelName = currentItem.getName();
int color = Color.parseColor("#" + labelColor); int color = Color.parseColor("#" + labelColor);
TextDrawable drawable = TextDrawable.builder() TextDrawable drawable = TextDrawable.builder()
.beginConfig() .beginConfig()
//.useFont(Typeface.DEFAULT) .useFont(Typeface.DEFAULT)
.bold() .bold()
.textColor(new ColorInverter().getContrastColor(color)) .textColor(new ColorInverter().getContrastColor(color))
.fontSize(40) .fontSize(35)
.width(LabelWidthCalculator.customWidth(getMaxLabelLength())) .width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, 40, 20))
.height(65) .height(55)
.endConfig() .endConfig()
.buildRoundRect(labelName, color, 10); .buildRoundRect(labelName, color, 10);
holder.labelsView.setImageDrawable(drawable); holder.labelsView.setImageDrawable(drawable);
} }
private int getMaxLabelLength() {
for(int i = 0; i < labelsList.size(); i++) {
Labels labelItem = labelsList.get(i);
labelsArray.add(labelItem.getName().length());
}
return Collections.max(labelsArray);
}
@Override @Override
public int getItemCount() { public int getItemCount() {
return labelsList.size(); return labelsList.size();