Implemented option to see more or less reports. Fixed tags' visibility
This commit is contained in:
parent
02469295b4
commit
4aee95207a
|
|
@ -69,6 +69,8 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
private PlaceReportsAdapter adapter;
|
private PlaceReportsAdapter adapter;
|
||||||
private final List<Report> reportList = new ArrayList<>();
|
private final List<Report> reportList = new ArrayList<>();
|
||||||
private BottomSheetBehavior<View> behavior;
|
private BottomSheetBehavior<View> behavior;
|
||||||
|
private TextView tvViewAllReports;
|
||||||
|
private List<Report> allReportsList = new ArrayList<>();
|
||||||
|
|
||||||
public PlaceBottomSheetDialog(Place place) {
|
public PlaceBottomSheetDialog(Place place) {
|
||||||
this.place = place;
|
this.place = place;
|
||||||
|
|
@ -100,7 +102,7 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
|
||||||
// Do nothing for now
|
// Do nothing
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -136,6 +138,7 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
btnAddReport = view.findViewById(R.id.btnAddReport);
|
btnAddReport = view.findViewById(R.id.btnAddReport);
|
||||||
rvReports = view.findViewById(R.id.rvReports);
|
rvReports = view.findViewById(R.id.rvReports);
|
||||||
rvAccessibilityOverview = view.findViewById(R.id.rvAccessibilityOverview);
|
rvAccessibilityOverview = view.findViewById(R.id.rvAccessibilityOverview);
|
||||||
|
tvViewAllReports = view.findViewById(R.id.tvViewAllReports);
|
||||||
|
|
||||||
rvReports.setLayoutManager(new LinearLayoutManager(context));
|
rvReports.setLayoutManager(new LinearLayoutManager(context));
|
||||||
rvAccessibilityOverview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
|
rvAccessibilityOverview.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
|
||||||
|
|
@ -219,15 +222,24 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
View.OnClickListener fullScreenListener = v -> {
|
/*View.OnClickListener fullScreenListener = v -> {
|
||||||
Helper.goTo(context, PlaceDetailActivity.class, Constants.PLACE, place);
|
Helper.goTo(context, PlaceDetailActivity.class, Constants.PLACE, place);
|
||||||
dismiss();
|
dismiss();
|
||||||
};
|
};*/
|
||||||
|
|
||||||
tvPlaceName.setOnClickListener(fullScreenListener);
|
tvViewAllReports.setOnClickListener(v -> {
|
||||||
|
//expand
|
||||||
|
showAllReports();
|
||||||
|
|
||||||
|
// fullscreen
|
||||||
|
// Helper.goTo(context, PlaceDetailActivity.class, Constants.PLACE, place);
|
||||||
|
// dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
/*tvPlaceName.setOnClickListener(fullScreenListener);
|
||||||
tvAddress.setOnClickListener(fullScreenListener);
|
tvAddress.setOnClickListener(fullScreenListener);
|
||||||
tvDescription.setOnClickListener(fullScreenListener);
|
tvDescription.setOnClickListener(fullScreenListener);
|
||||||
ivPlaceImage.setOnClickListener(fullScreenListener);
|
ivPlaceImage.setOnClickListener(fullScreenListener);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadReports() {
|
private void loadReports() {
|
||||||
|
|
@ -243,19 +255,28 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
JsonObject data = responseBody.getAsJsonObject("_data");
|
JsonObject data = responseBody.getAsJsonObject("_data");
|
||||||
|
|
||||||
if (data != null && data.has("reports")) {
|
if (data != null && data.has("reports")) {
|
||||||
reportList.clear();
|
allReportsList.clear();
|
||||||
|
|
||||||
for (JsonElement element : data.getAsJsonArray("reports")) {
|
for (JsonElement element : data.getAsJsonArray("reports")) {
|
||||||
Report report = getReport(element);
|
Report report = getReport(element);
|
||||||
reportList.add(report);
|
allReportsList.add(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse(reportList);
|
Collections.reverse(allReportsList);
|
||||||
List<Report> latestReports = reportList.size() > 3 ?
|
|
||||||
reportList.subList(0, 3) : reportList;
|
List<Report> latestReports = allReportsList.size() > 3 ?
|
||||||
|
allReportsList.subList(0, 3) : allReportsList;
|
||||||
|
|
||||||
updateReportsUI(latestReports);
|
updateReportsUI(latestReports);
|
||||||
calculateAndShowAccessibilityStats(reportList);
|
|
||||||
|
if (allReportsList.size() > 3) {
|
||||||
|
tvViewAllReports.setVisibility(View.VISIBLE);
|
||||||
|
tvViewAllReports.setText(getString(R.string.view_all) + " (" + allReportsList.size() + ")");
|
||||||
|
} else {
|
||||||
|
tvViewAllReports.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateAndShowAccessibilityStats(allReportsList);
|
||||||
} else {
|
} else {
|
||||||
showNoReports();
|
showNoReports();
|
||||||
}
|
}
|
||||||
|
|
@ -275,37 +296,68 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
JsonObject reportObject = element.getAsJsonObject();
|
JsonObject reportObject = element.getAsJsonObject();
|
||||||
Report report = new Report();
|
Report report = new Report();
|
||||||
|
|
||||||
report.setUuid(reportObject.get("uuid").getAsString());
|
try {
|
||||||
report.setReportRating(reportObject.get("rating").getAsInt());
|
// Campos básicos con verificación de null
|
||||||
report.setDescription(reportObject.get("description").getAsString());
|
if (reportObject.has("uuid") && !reportObject.get("uuid").isJsonNull()) {
|
||||||
report.setPlaceName(reportObject.get("place_name").getAsString());
|
report.setUuid(reportObject.get("uuid").getAsString());
|
||||||
report.setPlaceUuid(reportObject.get("place_uuid").getAsString());
|
}
|
||||||
|
|
||||||
List<String> reportTypeUuids = new ArrayList<>();
|
if (reportObject.has("rating") && !reportObject.get("rating").isJsonNull()) {
|
||||||
List<String> reportTypeNames = new ArrayList<>();
|
report.setReportRating(reportObject.get("rating").getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
processReportTypeField(reportObject, "report_type_uuids", reportTypeUuids);
|
if (reportObject.has("description") && !reportObject.get("description").isJsonNull()) {
|
||||||
processReportTypeField(reportObject, "report_type_names", reportTypeNames);
|
report.setDescription(reportObject.get("description").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback for legacy fields (singular)
|
if (reportObject.has("place_name") && !reportObject.get("place_name").isJsonNull()) {
|
||||||
if (reportTypeUuids.isEmpty() && reportObject.has("report_type_uuid") && !reportObject.get("report_type_uuid").isJsonNull()) {
|
report.setPlaceName(reportObject.get("place_name").getAsString());
|
||||||
reportTypeUuids.add(reportObject.get("report_type_uuid").getAsString());
|
}
|
||||||
|
|
||||||
|
if (reportObject.has("place_uuid") && !reportObject.get("place_uuid").isJsonNull()) {
|
||||||
|
report.setPlaceUuid(reportObject.get("place_uuid").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Images
|
||||||
|
if (reportObject.has("images") && !reportObject.get("images").isJsonNull()) {
|
||||||
|
JsonElement imagesElement = reportObject.get("images");
|
||||||
|
if (imagesElement.isJsonArray()) {
|
||||||
|
report.setImage(imagesElement.toString());
|
||||||
|
} else {
|
||||||
|
report.setImage(imagesElement.getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//report type
|
||||||
|
List<String> reportTypeUuids = new ArrayList<>();
|
||||||
|
List<String> reportTypeNames = new ArrayList<>();
|
||||||
|
|
||||||
|
processReportTypeField(reportObject, "report_type_uuids", reportTypeUuids);
|
||||||
|
processReportTypeField(reportObject, "report_type_names", reportTypeNames);
|
||||||
|
|
||||||
|
// Fallback para campos legacy (singular)
|
||||||
|
if (reportTypeUuids.isEmpty() && reportObject.has("report_type_uuid") && !reportObject.get("report_type_uuid").isJsonNull()) {
|
||||||
|
reportTypeUuids.add(reportObject.get("report_type_uuid").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reportTypeNames.isEmpty() && reportObject.has("report_type_name") && !reportObject.get("report_type_name").isJsonNull()) {
|
||||||
|
reportTypeNames.add(reportObject.get("report_type_name").getAsString());
|
||||||
|
}
|
||||||
|
|
||||||
|
report.setReportTypeUuids(reportTypeUuids);
|
||||||
|
report.setReportTypeNames(reportTypeNames);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error parsing report: " + (report.getUuid() != null ? report.getUuid() : "unknown"), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reportTypeNames.isEmpty() && reportObject.has("report_type_name") && !reportObject.get("report_type_name").isJsonNull()) {
|
|
||||||
reportTypeNames.add(reportObject.get("report_type_name").getAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
report.setReportTypeUuids(reportTypeUuids);
|
|
||||||
report.setReportTypeNames(reportTypeNames);
|
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void processReportTypeField(JsonObject reportObject, String fieldName, List<String> resultList) {
|
private static void processReportTypeField(JsonObject reportObject, String fieldName, List<String> resultList) {
|
||||||
try {
|
try {
|
||||||
if (!reportObject.has(fieldName) || reportObject.get(fieldName).isJsonNull()) {
|
if (!reportObject.has(fieldName) || reportObject.get(fieldName).isJsonNull()) {
|
||||||
return; // null
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement element = reportObject.get(fieldName);
|
JsonElement element = reportObject.get(fieldName);
|
||||||
|
|
@ -314,9 +366,11 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
// array JSON
|
// array JSON
|
||||||
JsonArray array = element.getAsJsonArray();
|
JsonArray array = element.getAsJsonArray();
|
||||||
for (JsonElement item : array) {
|
for (JsonElement item : array) {
|
||||||
String value = item.getAsString().trim();
|
if (!item.isJsonNull()) {
|
||||||
if (!value.isEmpty()) {
|
String value = item.getAsString().trim();
|
||||||
resultList.add(value);
|
if (!value.isEmpty()) {
|
||||||
|
resultList.add(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, fieldName + " processed as array: " + resultList.size() + " items");
|
Log.d(TAG, fieldName + " processed as array: " + resultList.size() + " items");
|
||||||
|
|
@ -333,10 +387,7 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
resultList.add(cleanValue);
|
resultList.add(cleanValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(TAG, fieldName + " processed as string: " + resultList.size() + " items from '" + stringValue + "'");
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.w(TAG, fieldName + " is neither array nor primitive: " + element.getClass().getSimpleName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -344,6 +395,31 @@ public class PlaceBottomSheetDialog extends BottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showAllReports() {
|
||||||
|
updateReportsUI(allReportsList);
|
||||||
|
|
||||||
|
tvViewAllReports.setText(getString(R.string.show_less));
|
||||||
|
|
||||||
|
tvViewAllReports.setOnClickListener(v -> showLessReports());
|
||||||
|
|
||||||
|
// Expand bottom sheet if it is not expanded
|
||||||
|
if (behavior != null && behavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {
|
||||||
|
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLessReports() {
|
||||||
|
// Mostrar solo los primeros 3 reportes
|
||||||
|
List<Report> latestReports = allReportsList.size() > 3 ?
|
||||||
|
allReportsList.subList(0, 3) : allReportsList;
|
||||||
|
|
||||||
|
updateReportsUI(latestReports);
|
||||||
|
|
||||||
|
// Restaurar texto y listener original
|
||||||
|
tvViewAllReports.setText(getString(R.string.view_all) + " (" + allReportsList.size() + ")");
|
||||||
|
tvViewAllReports.setOnClickListener(v -> showAllReports());
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateAndShowAccessibilityStats(List<Report> allReports) {
|
private void calculateAndShowAccessibilityStats(List<Report> allReports) {
|
||||||
if (allReports.isEmpty()) {
|
if (allReports.isEmpty()) {
|
||||||
rvAccessibilityOverview.setVisibility(View.GONE);
|
rvAccessibilityOverview.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,6 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_toStartOf="@+id/ivExpand"
|
|
||||||
android:textColor="?attr/colorOnSurface"
|
android:textColor="?attr/colorOnSurface"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
|
@ -223,14 +222,37 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="24dp">
|
android:padding="24dp">
|
||||||
|
|
||||||
<TextView
|
<!-- Reports Header with View All button -->
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="18sp"
|
android:orientation="horizontal"
|
||||||
android:textStyle="bold"
|
android:gravity="center_vertical"
|
||||||
android:textColor="?attr/colorPrimary"
|
android:layout_marginBottom="16dp">
|
||||||
android:text="@string/recent_reports"
|
|
||||||
android:layout_marginBottom="16dp" />
|
<TextView
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="?attr/colorPrimary"
|
||||||
|
android:text="@string/recent_reports" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvViewAllReports"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/view_all"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="?attr/colorPrimary"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Empty State -->
|
<!-- Empty State -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue