Migliorie in elenco inventari
This commit is contained in:
@@ -60,4 +60,8 @@ public class InventarioRepository extends _BaseRepository<MtbInvent, InventarioR
|
||||
}, onError);
|
||||
}
|
||||
|
||||
public void delete(InventarioRoomDTO inventarioDTO, Runnable onComplete, RunnableArgs<Exception> onError){
|
||||
localDataSource.makeDeleteRequest(inventarioDTO, onComplete, onError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -358,6 +358,33 @@ public class Converters {
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("binding")
|
||||
public static void bindTextInputEditTextLong(TextInputEditText view, final ObservableField<Long> observableLong) {
|
||||
Pair<ObservableField<Long>, TextWatcherAdapter> pair = (Pair) view.getTag(R.id.bound_observable);
|
||||
if (pair == null || pair.first != observableLong) {
|
||||
if (pair != null) {
|
||||
view.removeTextChangedListener(pair.second);
|
||||
}
|
||||
TextWatcherAdapter watcher = new TextWatcherAdapter() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
Long value = null;
|
||||
if (!UtilityString.isNullOrEmpty(s.toString()))
|
||||
value = Long.valueOf(s.toString());
|
||||
observableLong.set(value);
|
||||
}
|
||||
};
|
||||
view.setTag(R.id.bound_observable, new Pair<>(observableLong, watcher));
|
||||
view.addTextChangedListener(watcher);
|
||||
}
|
||||
Long newValue = observableLong.get();
|
||||
Long viewValue = view.getText().toString().trim().length() > 0 ? Long.valueOf(view.getText().toString()) : Long.valueOf(0);
|
||||
|
||||
if (!viewValue.equals(newValue) && newValue != null) {
|
||||
view.setText(newValue.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter(value = {"binding", "parentView", "warningOnOldDates"}, requireAll = false)
|
||||
public static void bindTextInputEditTextDate(TextInputEditText view, final ObservableField<Date> observableDate, BaseDialogFragment parentFragment, boolean warningOnOldDates) {
|
||||
Pair<ObservableField<Date>, TextWatcherAdapter> pair = (Pair) view.getTag(R.id.bound_observable);
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -26,6 +27,9 @@ public abstract class BaseFragment extends Fragment {
|
||||
@Inject
|
||||
public DialogProgressView mCurrentProgress;
|
||||
|
||||
@Inject
|
||||
public ExecutorService executorService;
|
||||
|
||||
protected ElevatedToolbar mToolbar;
|
||||
|
||||
protected final List<Runnable> mOnPreDestroyList = new ArrayList<>();
|
||||
@@ -65,7 +69,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
BarcodeManager.disable();
|
||||
if (!progressOpened && !this.mCurrentProgress.isAdded()) {
|
||||
this.progressOpened = true;
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
executorService.execute(() -> {
|
||||
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
}
|
||||
@@ -75,7 +79,7 @@ public abstract class BaseFragment extends Fragment {
|
||||
BarcodeManager.enable();
|
||||
if (progressOpened) {
|
||||
this.progressOpened = false;
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
executorService.execute(() -> {
|
||||
mCurrentProgress.dismissAllowingStateLoss();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,27 +78,33 @@ public class ElencoInventariFragment extends BaseFragment implements ITitledFrag
|
||||
|
||||
private void initRecyclerView() {
|
||||
mViewModel.getInventarioList().observe(getViewLifecycleOwner(), data -> {
|
||||
// binding.reportEmptyView.setVisibility(data == null || data.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
mBinding.emptyView.setVisibility(data == null || data.isEmpty() ? View.VISIBLE : View.GONE);
|
||||
});
|
||||
|
||||
var itemType = new Type<InventarioRoomDTO, FragmentElencoInventarioListSingleItemBinding>(R.layout.fragment_elenco_inventario_list_single_item, BR.item);
|
||||
itemType.onClick(x -> {
|
||||
|
||||
new BottomSheetInventarioActionsView(x.getBinding().getItem())
|
||||
.setListener(new BottomSheetInventarioActionsView.Listener() {
|
||||
@Override
|
||||
public void onItemEdit() {
|
||||
mViewModel.loadInventarioData(x.getBinding().getItem().getIdInventario(), listArts -> {
|
||||
startPicking(x.getBinding().getItem(), listArts);
|
||||
});
|
||||
}
|
||||
var item = x.getBinding().getItem();
|
||||
|
||||
@Override
|
||||
public void onItemDelete() {
|
||||
if (!item.isSyncronized()) {
|
||||
var bottomSheetActions = new BottomSheetInventarioActionsView(item)
|
||||
.setListener(new BottomSheetInventarioActionsView.Listener() {
|
||||
@Override
|
||||
public void onItemEdit() {
|
||||
mViewModel.loadInventarioData(item.getIdInventario(), listArts -> {
|
||||
startPicking(item, listArts);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
@Override
|
||||
public void onItemDelete() {
|
||||
deleteInventarioRequest(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
bottomSheetActions.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
@@ -115,11 +121,6 @@ public class ElencoInventariFragment extends BaseFragment implements ITitledFrag
|
||||
}
|
||||
|
||||
|
||||
private void startPicking(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> listArts) {
|
||||
PickingInventarioActivity.startActivity(requireContext(), inventarioRoomDTO, listArts);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPreDestroy(Runnable onComplete) {
|
||||
mViewModel.destroyData();
|
||||
@@ -132,13 +133,23 @@ public class ElencoInventariFragment extends BaseFragment implements ITitledFrag
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventarioInfoRequest(RunnableArgss<Integer, String> onComplete) {
|
||||
public void onInventarioInfoRequest(RunnableArgss<Long, String> onComplete) {
|
||||
DialogAskInfoInventarioView.newInstance(onComplete, null)
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateInventarioRequest(int inventoryId, String zone) {
|
||||
public void onInventarioLoaded(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> listaArts) {
|
||||
startPicking(inventarioRoomDTO, listaArts);
|
||||
}
|
||||
|
||||
|
||||
private void startPicking(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> listArts) {
|
||||
PickingInventarioActivity.startActivity(requireContext(), inventarioRoomDTO, listArts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateInventarioRequest(long inventoryId, String zone) {
|
||||
DialogYesNoView
|
||||
.newInstance(null, "Vuoi procedere con la creazione di un nuovo inventario con codice " + inventoryId + "?",
|
||||
dialogResponse -> {
|
||||
@@ -155,4 +166,21 @@ public class ElencoInventariFragment extends BaseFragment implements ITitledFrag
|
||||
})
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
|
||||
public void deleteInventarioRequest(InventarioRoomDTO inventarioRoomDTO) {
|
||||
DialogYesNoView
|
||||
.newInstance(null, "Vuoi cancellare l'inventario?",
|
||||
dialogResponse -> {
|
||||
switch (dialogResponse) {
|
||||
case YES:
|
||||
this.mViewModel.deleteInventario(inventarioRoomDTO);
|
||||
break;
|
||||
|
||||
case NO:
|
||||
case ABORT:
|
||||
break;
|
||||
}
|
||||
})
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package it.integry.integrywmsnative.gest.inventario;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import it.integry.integrywmsnative.core.data_store.db.entity.InventarioRoomDTO;
|
||||
import it.integry.integrywmsnative.core.data_store.db.respository_new.InventarioRepository;
|
||||
@@ -13,6 +14,7 @@ import it.integry.integrywmsnative.core.rest.consumers.InventarioRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.rest.model.inventario.InventarioArtDTO;
|
||||
import it.integry.integrywmsnative.core.settings.SettingsManager;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityDate;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
|
||||
public class ElencoInventariViewModel {
|
||||
|
||||
@@ -54,13 +56,31 @@ public class ElencoInventariViewModel {
|
||||
this.sendOnLoadingStarted();
|
||||
|
||||
inventarioRESTConsumer.loadInventario(inventoryId, loadedInventario -> {
|
||||
this.sendOnLoadingEnded();
|
||||
|
||||
if (loadedInventario == null || loadedInventario.getMtbInvent() == null)
|
||||
if (loadedInventario == null || loadedInventario.getMtbInvent() == null) {
|
||||
this.sendOnLoadingEnded();
|
||||
this.sendCreateInventarioRequest(inventoryId, zone);
|
||||
else this.createNewInventario(inventoryId, zone, (inventarioRoom, listaArts) -> {
|
||||
} else {
|
||||
|
||||
});
|
||||
var matchedInventory = getInventarioList().getValue()
|
||||
.stream()
|
||||
.filter(x -> Objects.equals(x.getIdInventario(), inventoryId) && UtilityString.equalsIgnoreCase(x.getZona(), zone))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (matchedInventory == null)
|
||||
this.createNewInventario(inventoryId, zone, (inventarioRoom, listaArts) -> {
|
||||
this.sendOnLoadingEnded();
|
||||
this.sendOnInventarioLoaded(inventarioRoom, listaArts);
|
||||
});
|
||||
|
||||
else
|
||||
loadInventarioData(inventoryId, listaArts -> {
|
||||
this.sendOnLoadingEnded();
|
||||
this.sendOnInventarioLoaded(matchedInventory, listaArts);
|
||||
});
|
||||
|
||||
}
|
||||
}, this::sendOnError);
|
||||
});
|
||||
}
|
||||
@@ -83,16 +103,21 @@ public class ElencoInventariViewModel {
|
||||
|
||||
var createdInventario = new InventarioRoomDTO();
|
||||
createdInventario.setIdInventario(inventoryId);
|
||||
createdInventario.setZona(zone);
|
||||
createdInventario.setCodMdep(codMdep);
|
||||
createdInventario.setInseritoDa(settingsManager.getSettings().getUser().getFullname());
|
||||
createdInventario.setDataInventario(UtilityDate.getNow());
|
||||
|
||||
inventarioRepository.insert(createdInventario, () -> {
|
||||
loadInventarioData(inventoryId, inventarioArts -> {
|
||||
loadInventarioData(inventoryId, inventarioArts -> {
|
||||
inventarioRepository.insert(createdInventario, () -> {
|
||||
this.sendOnLoadingEnded();
|
||||
onComplete.run(createdInventario, inventarioArts);
|
||||
});
|
||||
}, this::sendOnError);
|
||||
}, this::sendOnError);
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteInventario(InventarioRoomDTO inventarioRoomDTO) {
|
||||
inventarioRepository.delete(inventarioRoomDTO, null, this::sendOnError);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,11 +125,15 @@ public class ElencoInventariViewModel {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void sendOnInventarioInfoRequest(RunnableArgss<Integer, String> onComplete) {
|
||||
private void sendOnInventarioInfoRequest(RunnableArgss<Long, String> onComplete) {
|
||||
if (listener != null) listener.onInventarioInfoRequest(onComplete);
|
||||
}
|
||||
|
||||
private void sendCreateInventarioRequest(int inventoryId, String zone) {
|
||||
private void sendOnInventarioLoaded(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> listaArts) {
|
||||
if (listener != null) listener.onInventarioLoaded(inventarioRoomDTO, listaArts);
|
||||
}
|
||||
|
||||
private void sendCreateInventarioRequest(long inventoryId, String zone) {
|
||||
if (this.listener != null) this.listener.onCreateInventarioRequest(inventoryId, zone);
|
||||
}
|
||||
|
||||
@@ -122,9 +151,11 @@ public class ElencoInventariViewModel {
|
||||
|
||||
public interface Listener extends ILoadingListener {
|
||||
|
||||
void onInventarioInfoRequest(RunnableArgss<Integer, String> onComplete);
|
||||
void onInventarioInfoRequest(RunnableArgss<Long, String> onComplete);
|
||||
|
||||
void onCreateInventarioRequest(int inventoryId, String zone);
|
||||
void onInventarioLoaded(InventarioRoomDTO inventarioRoomDTO, List<InventarioArtDTO> listaArts);
|
||||
|
||||
void onCreateInventarioRequest(long inventoryId, String zone);
|
||||
|
||||
void onError(Exception ex);
|
||||
|
||||
|
||||
@@ -11,12 +11,15 @@ import androidx.databinding.ObservableField;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import it.integry.integrywmsnative.MainApplication;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.expansion.BaseDialogFragment;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgss;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityString;
|
||||
import it.integry.integrywmsnative.databinding.DialogAskInfoInventarioBinding;
|
||||
|
||||
public class DialogAskInfoInventarioView extends BaseDialogFragment {
|
||||
@@ -24,21 +27,21 @@ public class DialogAskInfoInventarioView extends BaseDialogFragment {
|
||||
@Inject
|
||||
DialogAskInfoInventarioViewModel mViewModel;
|
||||
|
||||
private final RunnableArgss<Integer, String> onConfirmed;
|
||||
private final RunnableArgss<Long, String> onConfirmed;
|
||||
private final Runnable onAbort;
|
||||
|
||||
public ObservableField<Integer> inventoryId = new ObservableField<>();
|
||||
public ObservableField<Long> inventoryId = new ObservableField<>();
|
||||
public ObservableField<String> zone = new ObservableField<>();
|
||||
|
||||
private DialogAskInfoInventarioBinding mBindings;
|
||||
private Context mContext;
|
||||
|
||||
//Pass here all external parameters
|
||||
public static DialogAskInfoInventarioView newInstance(RunnableArgss<Integer, String> onConfirmed, Runnable onAbort) {
|
||||
public static DialogAskInfoInventarioView newInstance(RunnableArgss<Long, String> onConfirmed, Runnable onAbort) {
|
||||
return new DialogAskInfoInventarioView(onConfirmed, onAbort);
|
||||
}
|
||||
|
||||
private DialogAskInfoInventarioView(RunnableArgss<Integer, String> onConfirmed, Runnable onAbort) {
|
||||
private DialogAskInfoInventarioView(RunnableArgss<Long, String> onConfirmed, Runnable onAbort) {
|
||||
super();
|
||||
|
||||
this.onConfirmed = onConfirmed;
|
||||
@@ -66,8 +69,12 @@ public class DialogAskInfoInventarioView extends BaseDialogFragment {
|
||||
.setView(mBindings.getRoot())
|
||||
.setCancelable(cancelable)
|
||||
.setPositiveButton(R.string.ok, (dialog, which) -> {
|
||||
var zone = UtilityString.empty2null(this.zone.get());
|
||||
if(zone != null) zone = StringUtils.capitalize(zone);
|
||||
|
||||
|
||||
if (this.onConfirmed != null)
|
||||
this.onConfirmed.run(this.inventoryId.get(), this.zone.get());
|
||||
this.onConfirmed.run(this.inventoryId.get(), zone);
|
||||
})
|
||||
.setNegativeButton(R.string.abort, (dialog, which) -> {
|
||||
if (this.onAbort != null) this.onAbort.run();
|
||||
|
||||
Reference in New Issue
Block a user