Added adapter for tags to show a visually appealing card
This commit is contained in:
parent
00c211aa75
commit
02469295b4
|
|
@ -15,7 +15,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.example.acloc.adapter.ReportTypeAdapter;
|
import com.example.acloc.adapter.ReportTypeAdapter;
|
||||||
|
|
@ -31,6 +30,11 @@ import com.example.acloc.utility.DialogUtils;
|
||||||
import com.example.acloc.utility.Helper;
|
import com.example.acloc.utility.Helper;
|
||||||
import com.example.acloc.utility.SharedPref;
|
import com.example.acloc.utility.SharedPref;
|
||||||
import com.example.acloc.utility.UploadManager;
|
import com.example.acloc.utility.UploadManager;
|
||||||
|
import com.google.android.flexbox.AlignItems;
|
||||||
|
import com.google.android.flexbox.FlexDirection;
|
||||||
|
import com.google.android.flexbox.FlexWrap;
|
||||||
|
import com.google.android.flexbox.FlexboxLayoutManager;
|
||||||
|
import com.google.android.flexbox.JustifyContent;
|
||||||
import com.google.android.material.button.MaterialButton;
|
import com.google.android.material.button.MaterialButton;
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
|
@ -115,8 +119,15 @@ public class AddReportActivity extends AppCompatActivity implements View.OnClick
|
||||||
rvReportTypes = findViewById(R.id.rvReportTypes);
|
rvReportTypes = findViewById(R.id.rvReportTypes);
|
||||||
|
|
||||||
// Setup RecyclerView for report types
|
// Setup RecyclerView for report types
|
||||||
rvReportTypes.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
|
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
|
||||||
|
layoutManager.setFlexDirection(FlexDirection.ROW);
|
||||||
|
layoutManager.setFlexWrap(FlexWrap.WRAP);
|
||||||
|
layoutManager.setJustifyContent(JustifyContent.FLEX_START);
|
||||||
|
layoutManager.setAlignItems(AlignItems.FLEX_START);
|
||||||
|
rvReportTypes.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
reportTypeAdapter = new ReportTypeAdapter(this, reportTypesList);
|
reportTypeAdapter = new ReportTypeAdapter(this, reportTypesList);
|
||||||
|
rvReportTypes.setAdapter(reportTypeAdapter);
|
||||||
reportTypeAdapter.setOnReportTypeClickListener(new ReportTypeAdapter.OnReportTypeClickListener() {
|
reportTypeAdapter.setOnReportTypeClickListener(new ReportTypeAdapter.OnReportTypeClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onReportTypeClick(ReportType reportType, int position, boolean isSelected) {
|
public void onReportTypeClick(ReportType reportType, int position, boolean isSelected) {
|
||||||
|
|
@ -255,7 +266,16 @@ public class AddReportActivity extends AppCompatActivity implements View.OnClick
|
||||||
|
|
||||||
// Set selected report types (multiple)
|
// Set selected report types (multiple)
|
||||||
selectedReportTypeUuids.clear();
|
selectedReportTypeUuids.clear();
|
||||||
selectedReportTypeUuids.addAll(reportEntity.getReportTypeUuids());
|
if (reportEntity.getReportTypeUuids() != null) {
|
||||||
|
selectedReportTypeUuids.addAll(reportEntity.getReportTypeUuids());
|
||||||
|
}
|
||||||
|
|
||||||
|
// establish selection
|
||||||
|
if (!reportTypesList.isEmpty()) {
|
||||||
|
rvReportTypes.post(() -> {
|
||||||
|
reportTypeAdapter.setSelectedReportTypes(selectedReportTypeUuids);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,14 +362,15 @@ public class AddReportActivity extends AppCompatActivity implements View.OnClick
|
||||||
reportTypesList.add(reportType);
|
reportTypesList.add(reportType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If editing existing report, mark selected types
|
Log.d(TAG, "Loaded " + reportTypesList.size() + " report types");
|
||||||
if (isEditMode && reportEntity != null && !reportEntity.getReportTypeUuids().isEmpty()) {
|
|
||||||
reportTypeAdapter.setSelectedReportTypes(reportEntity.getReportTypeUuids());
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d("tag", "reportTypesList: " + reportTypesList.toString());
|
|
||||||
|
|
||||||
reportTypeAdapter.notifyDataSetChanged();
|
reportTypeAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
|
if (isEditMode && reportEntity != null && !reportEntity.getReportTypeUuids().isEmpty()) {
|
||||||
|
rvReportTypes.post(() -> {
|
||||||
|
reportTypeAdapter.setSelectedReportTypes(reportEntity.getReportTypeUuids());
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package com.example.acloc.adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.example.acloc.utility.AccessibilityHelper;
|
||||||
|
import com.google.android.material.card.MaterialCardView;
|
||||||
|
import com.ieslamar.acloc.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AccessibilityTagsAdapter extends RecyclerView.Adapter<AccessibilityTagsAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
public static class TagData {
|
||||||
|
public final String reportTypeName;
|
||||||
|
public final int rating;
|
||||||
|
|
||||||
|
public TagData(String reportTypeName, int rating) {
|
||||||
|
this.reportTypeName = reportTypeName;
|
||||||
|
this.rating = rating;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final List<TagData> tagDataList;
|
||||||
|
|
||||||
|
public AccessibilityTagsAdapter(Context context, List<TagData> tagDataList) {
|
||||||
|
this.context = context;
|
||||||
|
this.tagDataList = tagDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(context).inflate(R.layout.item_accessibility_tag, parent, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
TagData tagData = tagDataList.get(position);
|
||||||
|
AccessibilityHelper.AccessibilityInfo info = AccessibilityHelper.getAccessibilityInfo(
|
||||||
|
context,
|
||||||
|
tagData.reportTypeName,
|
||||||
|
tagData.rating
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set text and icon
|
||||||
|
holder.tvTypeName.setText(info.displayName);
|
||||||
|
holder.ivIcon.setImageResource(info.iconResource);
|
||||||
|
|
||||||
|
// Set colors
|
||||||
|
holder.card.setCardBackgroundColor(
|
||||||
|
ContextCompat.getColor(context, info.backgroundColorRes));
|
||||||
|
holder.card.setStrokeColor(
|
||||||
|
ContextCompat.getColor(context, info.borderColorRes));
|
||||||
|
holder.tvTypeName.setTextColor(
|
||||||
|
ContextCompat.getColor(context, info.textColorRes));
|
||||||
|
holder.ivIcon.setColorFilter(
|
||||||
|
ContextCompat.getColor(context, info.textColorRes));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return tagDataList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
final MaterialCardView card;
|
||||||
|
final ImageView ivIcon;
|
||||||
|
final TextView tvTypeName;
|
||||||
|
final ImageView ivSelected;
|
||||||
|
|
||||||
|
public ViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
card = itemView.findViewById(R.id.reportTypeCard);
|
||||||
|
ivIcon = itemView.findViewById(R.id.reportTypeIcon);
|
||||||
|
tvTypeName = itemView.findViewById(R.id.tvReportTypeName);
|
||||||
|
ivSelected = itemView.findViewById(R.id.ivSelected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue