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