feat: Normalize book code by stripping accents

This commit is contained in:
Ninjdai 2024-12-21 13:19:24 +01:00
parent 2de0662663
commit 12ac1c0931
2 changed files with 10 additions and 5 deletions

View File

@ -3,5 +3,5 @@ package dev.ninjdai.balscanner.books
data class Book(val title: String, val author: String, val EAN: String, val owner: Owner, var price: Int)
data class Owner(var firstName: String, var lastName: String, var contact: String) {
val id: String = if (firstName.isNotEmpty() && lastName.isNotEmpty()) firstName[0].toString().uppercase() + lastName[0].toString().uppercase() else ""
val id: String = if (firstName.isNotEmpty() && lastName.isNotEmpty()) lastName[0].toString().uppercase() + firstName[0].toString().uppercase() else ""
}

View File

@ -3,6 +3,7 @@ package dev.ninjdai.balscanner.ui.home;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputType;
@ -23,6 +24,7 @@ import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
@ -34,6 +36,7 @@ import com.journeyapps.barcodescanner.ScanOptions;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Objects;
@ -81,7 +84,7 @@ public class HomeFragment extends Fragment {
final EditText cInput = Util.getEditText(getActivity(),InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
Util.getEditTextAlertDialogBuilder(activity, "Contact", "Valider", cInput, (cDialog, cWhich) -> {
tmpOwner.setContact(cInput.getText().toString());
Owner o = new Owner(tmpOwner.getFirstName().strip(), tmpOwner.getLastName().strip(), tmpOwner.getContact().strip());
Owner o = new Owner(Normalizer.normalize(tmpOwner.getFirstName().strip(), Normalizer.Form.NFKD), Normalizer.normalize(tmpOwner.getLastName().strip(), Normalizer.Form.NFKD), tmpOwner.getContact().strip());
MainActivity.books.put(o, new ArrayList<>());
MainActivity.current_owner = o;
adapter.setmData(new ArrayList<>(MainActivity.books.keySet()));
@ -124,9 +127,7 @@ public class HomeFragment extends Fragment {
addOwner();
});
Button exportButton = view.findViewById(R.id.export_button);
exportButton.setOnClickListener(v -> {
documentCreator.launch("export.csv");
});
exportButton.setOnClickListener(v -> documentCreator.launch("BAL_export.csv"));
}
@Override
@ -141,6 +142,10 @@ public class HomeFragment extends Fragment {
return;
}
try {
if (getActivity()==null) {
Toast.makeText(getContext(), "Erreur: getActivity is null", Toast.LENGTH_LONG).show();
return;
}
OutputStream stream = getActivity().getContentResolver().openOutputStream(result);
if (stream==null) {
Toast.makeText(getContext(), "Erreur lors de l'ouverture du fichier", Toast.LENGTH_LONG).show();