Gestita cancellazione righe collo
This commit is contained in:
parent
ab183893b0
commit
3c638c2640
@ -2,6 +2,7 @@ package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.CommonModelConsts;
|
||||
import it.integry.integrywmsnative.core.model.MtbColr;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
|
||||
public class ColliMagazzinoRESTConsumer {
|
||||
@ -31,4 +32,30 @@ public class ColliMagazzinoRESTConsumer {
|
||||
|
||||
}
|
||||
|
||||
public static void deleteRiga(MtbColr mtbColrToDelete, Runnable onComplete, RunnableArgs<Exception> onFailed){
|
||||
MtbColr newMtbColr = new MtbColr();
|
||||
|
||||
newMtbColr.setNumCollo(mtbColrToDelete.getNumCollo());
|
||||
newMtbColr.setDataCollo(mtbColrToDelete.getDataCollo());
|
||||
newMtbColr.setSerCollo(mtbColrToDelete.getSerCollo());
|
||||
newMtbColr.setGestione(mtbColrToDelete.getGestione());
|
||||
newMtbColr.setRiga(mtbColrToDelete.getRiga());
|
||||
|
||||
|
||||
newMtbColr.setOperation(CommonModelConsts.OPERATION.DELETE);
|
||||
|
||||
EntityRESTConsumer.processEntity(newMtbColr, new ISimpleOperationCallback<MtbColr>() {
|
||||
@Override
|
||||
public void onSuccess(MtbColr value) {
|
||||
if(onComplete != null) onComplete.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Exception ex) {
|
||||
if(onFailed != null) onFailed.run(ex);
|
||||
}
|
||||
}, MtbColr.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package it.integry.integrywmsnative.core.REST.consumers;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@ -23,18 +24,18 @@ public class EntityRESTConsumer {
|
||||
public static <T extends EntityBase> void processEntity(T entityToSave, final ISimpleOperationCallback<T> callback, Class<T> type){
|
||||
|
||||
EntityRESTConsumerService service = RESTBuilder.getService(EntityRESTConsumerService.class);
|
||||
Call<ServiceRESTResponse<Object>> request = service.processEntity(entityToSave);
|
||||
request.enqueue(new Callback<ServiceRESTResponse<Object>>() {
|
||||
Call<ServiceRESTResponse<JsonObject>> request = service.processEntity(entityToSave);
|
||||
request.enqueue(new Callback<ServiceRESTResponse<JsonObject>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<Object>> call, Response<ServiceRESTResponse<Object>> response) {
|
||||
public void onResponse(Call<ServiceRESTResponse<JsonObject>> call, Response<ServiceRESTResponse<JsonObject>> response) {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.body() != null) {
|
||||
if(response.body().getEsito() == EsitoType.OK) {
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(response.body().getEntity());
|
||||
T object = gson.fromJson(response.body().getEntity(), type);
|
||||
|
||||
callback.onSuccess(gson.fromJson(json, type));
|
||||
callback.onSuccess(object);
|
||||
} else {
|
||||
Log.e("EntityRESTConsumer", response.body().getErrorMessage());
|
||||
callback.onFailed(new Exception(response.body().getErrorMessage()));
|
||||
@ -50,7 +51,7 @@ public class EntityRESTConsumer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<Object>> call, Throwable t) {
|
||||
public void onFailure(Call<ServiceRESTResponse<JsonObject>> call, Throwable t) {
|
||||
Log.e("EntityRESTConsumer", t.toString());
|
||||
callback.onFailed(new Exception(t));
|
||||
}
|
||||
@ -64,27 +65,22 @@ public class EntityRESTConsumer {
|
||||
public static <T extends EntityBase> void selectEntity(T entityToSave, final ISimpleOperationCallback<List<T>> callback, Class type){
|
||||
|
||||
EntityRESTConsumerService service = RESTBuilder.getService(EntityRESTConsumerService.class);
|
||||
Call<ServiceRESTResponse<Object>> request = service.processEntity(entityToSave);
|
||||
request.enqueue(new Callback<ServiceRESTResponse<Object>>() {
|
||||
Call<ServiceRESTResponse<JsonObject>> request = service.processEntity(entityToSave);
|
||||
request.enqueue(new Callback<ServiceRESTResponse<JsonObject>>() {
|
||||
@Override
|
||||
public void onResponse(Call<ServiceRESTResponse<Object>> call, Response<ServiceRESTResponse<Object>> response) {
|
||||
public void onResponse(Call<ServiceRESTResponse<JsonObject>> call, Response<ServiceRESTResponse<JsonObject>> response) {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.body() != null) {
|
||||
if(response.body().getEsito() == EsitoType.OK) {
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(response.body().getEntityList());
|
||||
List<JsonObject> jsons = response.body().getEntityList();
|
||||
|
||||
List<T> newList = new ArrayList<T>();
|
||||
|
||||
Type fooType = new TypeToken<ArrayList<T>>() {}.getType();
|
||||
List<T> oldList = gson.fromJson(json, fooType);
|
||||
|
||||
|
||||
|
||||
if(oldList != null) {
|
||||
for (int i = 0; i < oldList.size(); i ++){
|
||||
String jsonTmp = gson.toJson(oldList.get(i));
|
||||
if(jsons != null) {
|
||||
for (int i = 0; i < jsons.size(); i ++){
|
||||
JsonObject jsonTmp = jsons.get(i);
|
||||
|
||||
newList.add((T) gson.fromJson(jsonTmp, type));
|
||||
}
|
||||
@ -107,7 +103,7 @@ public class EntityRESTConsumer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<ServiceRESTResponse<Object>> call, Throwable t) {
|
||||
public void onFailure(Call<ServiceRESTResponse<JsonObject>> call, Throwable t) {
|
||||
Log.e("EntityRESTConsumer", t.toString());
|
||||
callback.onFailed(new Exception(t));
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package it.integry.integrywmsnative.core.REST.consumers;
|
||||
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import it.integry.integrywmsnative.core.REST.model.ServiceRESTResponse;
|
||||
import it.integry.integrywmsnative.core.model.EntityBase;
|
||||
import retrofit2.Call;
|
||||
@ -10,6 +12,6 @@ import retrofit2.http.POST;
|
||||
public interface EntityRESTConsumerService {
|
||||
|
||||
@POST("processEntity")
|
||||
Call<ServiceRESTResponse<Object>> processEntity(@Body Object entity);
|
||||
Call<ServiceRESTResponse<JsonObject>> processEntity(@Body Object entity);
|
||||
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ public class MtbColr extends EntityBase implements Parcelable {
|
||||
private String gestione;
|
||||
private String serCollo;
|
||||
private Integer numCollo;
|
||||
private String dataCollo;
|
||||
private Integer riga;
|
||||
private Integer rigaOrd;
|
||||
private String codMart;
|
||||
@ -56,6 +57,7 @@ public class MtbColr extends EntityBase implements Parcelable {
|
||||
} else {
|
||||
numCollo = in.readInt();
|
||||
}
|
||||
dataCollo = in.readString();
|
||||
if (in.readByte() == 0) {
|
||||
riga = null;
|
||||
} else {
|
||||
@ -128,6 +130,7 @@ public class MtbColr extends EntityBase implements Parcelable {
|
||||
dest.writeByte((byte) 1);
|
||||
dest.writeInt(numCollo);
|
||||
}
|
||||
dest.writeString(dataCollo);
|
||||
if (riga == null) {
|
||||
dest.writeByte((byte) 0);
|
||||
} else {
|
||||
@ -242,6 +245,16 @@ public class MtbColr extends EntityBase implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDataCollo() {
|
||||
return dataCollo;
|
||||
}
|
||||
|
||||
public MtbColr setDataCollo(String dataCollo) {
|
||||
this.dataCollo = dataCollo;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Integer getRiga() {
|
||||
return riga;
|
||||
}
|
||||
|
||||
@ -83,9 +83,10 @@ public class AccettazioneOnOrdineInevasoViewModel implements IOnColloClosedCallb
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
||||
private void init(){
|
||||
mArticoliInColloBottomSheetViewModel.setOnCloseColloCallbackListener(this);
|
||||
mArticoliInColloBottomSheetViewModel.setOnItemDeletedCallback(this::refreshOrderBy);
|
||||
mArticoliInColloBottomSheetViewModel.setOnItemEditedCallback(this::refreshOrderBy);
|
||||
|
||||
groupedOrdini = new ArrayList<>();
|
||||
for (OrdineAccettazioneDTO ordine : mOrders){
|
||||
@ -118,7 +119,7 @@ public class AccettazioneOnOrdineInevasoViewModel implements IOnColloClosedCallb
|
||||
mActivity.bindings.accettazioneOrdineMainList.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private void refreshOrderBy(){
|
||||
public void refreshOrderBy(){
|
||||
switch (currentOrderBy){
|
||||
case COD_ART_FOR:
|
||||
groupedRighe = helper.getOrdiniRaggruppatiPerCodArtForn(groupedOrdini);
|
||||
@ -385,15 +386,8 @@ public class AccettazioneOnOrdineInevasoViewModel implements IOnColloClosedCallb
|
||||
isFabVisible.set(true);
|
||||
|
||||
progress.dismiss();
|
||||
}, ex -> {
|
||||
progress.dismiss();
|
||||
String errorMessage = CommonRESTException.tryRecognizeThenGetMessage(ex);
|
||||
|
||||
if(errorMessage == null) errorMessage = ex.getMessage();
|
||||
DialogSimpleMessageHelper.makeErrorDialog(mActivity, new SpannableString(errorMessage), null, null).show();
|
||||
|
||||
UtilityLogger.errorMe(ex);
|
||||
});
|
||||
}, ex -> UtilityExceptions.defaultException(mActivity, ex, progress)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -495,7 +489,13 @@ public class AccettazioneOnOrdineInevasoViewModel implements IOnColloClosedCallb
|
||||
@Override
|
||||
public void onSuccess(MtbColt value) {
|
||||
|
||||
mtbColr.setUntMis(item.getMtbAart().untMis);
|
||||
mtbColr
|
||||
.setDataCollo(value.getDataColloS())
|
||||
.setNumCollo(value.getNumCollo())
|
||||
.setGestione(value.getGestione())
|
||||
.setSerCollo(value.getSerCollo())
|
||||
.setRiga(value.getMtbColr().get(0).getRiga())
|
||||
.setUntMis(item.getMtbAart().untMis);
|
||||
|
||||
mArticoliInColloBottomSheetViewModel.mtbColt.get().getMtbColr().add(mtbColr);
|
||||
refreshOrderBy();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package it.integry.integrywmsnative.view.bottomsheet.viewmodel;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.databinding.Observable;
|
||||
@ -9,10 +10,12 @@ import android.databinding.ViewDataBinding;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomSheetBehavior;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.SpannableString;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.linearlistview.LinearListView;
|
||||
|
||||
@ -20,14 +23,17 @@ import java.lang.ref.WeakReference;
|
||||
|
||||
import it.integry.integrywmsnative.BR;
|
||||
import it.integry.integrywmsnative.R;
|
||||
import it.integry.integrywmsnative.core.REST.consumers.ColliMagazzinoRESTConsumer;
|
||||
import it.integry.integrywmsnative.core.expansion.RunnableArgs;
|
||||
import it.integry.integrywmsnative.core.model.MtbColr;
|
||||
import it.integry.integrywmsnative.core.model.MtbColt;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityNumber;
|
||||
import it.integry.integrywmsnative.databinding.FragmentArticoliInColloBottomSheetBinding;
|
||||
import it.integry.integrywmsnative.view.bottomsheet.ArticoliInColloBottomSheetHelper;
|
||||
import it.integry.integrywmsnative.view.bottomsheet.interfaces.IOnColloClosedCallback;
|
||||
import it.integry.integrywmsnative.view.bottomsheet.interfaces.IOnSimpleListChangedCallback;
|
||||
import it.integry.integrywmsnative.view.dialogs.DialogSimpleMessageHelper;
|
||||
|
||||
public class ArticoliInColloBottomSheetViewModel {
|
||||
|
||||
@ -43,6 +49,9 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
|
||||
private BottomSheetBehavior mBottomSheetBehavior;
|
||||
|
||||
private Runnable mOnItemDeletedCallback;
|
||||
private Runnable mOnItemEditedCallback;
|
||||
|
||||
|
||||
public ArticoliInColloBottomSheetViewModel(AppCompatActivity context, final FragmentArticoliInColloBottomSheetBinding bindings){
|
||||
mContext = context;
|
||||
@ -54,15 +63,17 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
mtbColt.addOnPropertyChangedCallback(new Observable.OnPropertyChangedCallback() {
|
||||
@Override
|
||||
public void onPropertyChanged(Observable sender, int propertyId) {
|
||||
mBindings.linearListview.setAdapter(new ArticoliInColloBottomSheetMtbColrAdapter());
|
||||
|
||||
mBindings.linearListview.setOnItemClickListener((parent, view, position, id) -> {
|
||||
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
|
||||
onItemClicked.run(position);
|
||||
});
|
||||
|
||||
if(mtbColt.get() != null) {
|
||||
|
||||
mBindings.linearListview.setAdapter(new ArticoliInColloBottomSheetMtbColrAdapter());
|
||||
|
||||
mBindings.linearListview.setOnItemClickListener((parent, view, position, id) -> {
|
||||
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
|
||||
onItemClicked.run(position);
|
||||
});
|
||||
|
||||
mArticoliInColloBottomSheetHelper.updateRigheNumber(mtbColt.get().getMtbColr().size());
|
||||
mArticoliInColloBottomSheetHelper.initCollo(mtbColt.get());
|
||||
|
||||
@ -76,6 +87,14 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
initBottomSheetActions();
|
||||
}
|
||||
|
||||
public void setOnItemEditedCallback(Runnable onItemEditedCallback) {
|
||||
this.mOnItemEditedCallback = onItemEditedCallback;
|
||||
}
|
||||
|
||||
public void setOnItemDeletedCallback(Runnable onItemDeletedCallback) {
|
||||
this.mOnItemDeletedCallback = onItemDeletedCallback;
|
||||
}
|
||||
|
||||
private void initBottomSheetActions() {
|
||||
mBindings.bg.setOnClickListener(v -> mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED));
|
||||
|
||||
@ -125,11 +144,50 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
mBindings.bottomSheetActionsTitle.setText(clickedItem.getDescrizione());
|
||||
mBindings.bottomSheetActionsSubtitle.setText(clickedItem.getCodMart());
|
||||
|
||||
mBindings.bottomSheetActionsEditBtn.setOnClickListener(v -> onItemEdit(position));
|
||||
|
||||
mBindings.bottomSheetActionsDeleteBtn.setOnClickListener(v -> onItemDelete(position));
|
||||
|
||||
mBindings.bottomSheetActionsQuantity.setText(UtilityNumber.decimalToString(clickedItem.getQtaCol()) + " " + clickedItem.getUntMis());
|
||||
|
||||
|
||||
};
|
||||
|
||||
private void onItemEdit(int position) {
|
||||
|
||||
MtbColr itemToEdit = mtbColt.get().getMtbColr().get(position);
|
||||
|
||||
|
||||
|
||||
if(this.mOnItemEditedCallback != null) this.mOnItemEditedCallback.run();
|
||||
}
|
||||
|
||||
private void onItemDelete(int position) {
|
||||
|
||||
|
||||
String text = mContext.getResources().getString(R.string.alert_delete_mtb_colr);
|
||||
DialogSimpleMessageHelper.makeWarningDialog(mContext, new SpannableString(text), null, () -> {
|
||||
MtbColr itemToDelete = mtbColt.get().getMtbColr().get(position);
|
||||
|
||||
final ProgressDialog progress = ProgressDialog.show(mContext, mContext.getText(R.string.waiting),
|
||||
mContext.getText(R.string.loading) + " ...", true);
|
||||
|
||||
progress.show();
|
||||
|
||||
ColliMagazzinoRESTConsumer.deleteRiga(itemToDelete, () -> {
|
||||
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
|
||||
progress.dismiss();
|
||||
mtbColt.get().getMtbColr().remove(position);
|
||||
|
||||
if(this.mOnItemDeletedCallback != null) this.mOnItemDeletedCallback.run();
|
||||
}, ex -> UtilityExceptions.defaultException(mContext, ex, progress));
|
||||
}, null).show();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class ArticoliInColloBottomSheetMtbColrAdapter extends BaseAdapter {
|
||||
|
||||
@ -139,6 +197,8 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
public ArticoliInColloBottomSheetMtbColrAdapter() {
|
||||
super();
|
||||
this.onListChangedCallback = new WeakReferenceOnListChangedCallback(this);
|
||||
|
||||
mtbColt.get().getMtbColr().addOnListChangedCallback(onListChangedCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -170,7 +230,7 @@ public class ArticoliInColloBottomSheetViewModel {
|
||||
@Override
|
||||
public int getCount() {
|
||||
if(mtbColt.get() != null && mtbColt.get().getMtbColr() != null) {
|
||||
mtbColt.get().getMtbColr().addOnListChangedCallback(onListChangedCallback);
|
||||
|
||||
return mtbColt.get().getMtbColr().size();
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
@ -149,6 +149,17 @@ public class DialogSimpleMessageHelper {
|
||||
}
|
||||
|
||||
|
||||
public static AlertDialog makeWarningDialog(Context mContext, Spanned messageText, HashMap<String, String> hashmapContent, Runnable onPositiveClick, Runnable onNegativeClick){
|
||||
return makeBase(TYPE.WARNING,
|
||||
mContext,
|
||||
mContext.getText(R.string.warning).toString(),
|
||||
messageText,
|
||||
hashmapContent,
|
||||
onPositiveClick,
|
||||
() -> { if(onNegativeClick != null) onNegativeClick.run(); }, -1, null);
|
||||
}
|
||||
|
||||
|
||||
public static AlertDialog makeWarningDialog(Context mContext, Spanned messageText, HashMap<String, String> hashmapContent, Runnable onPositiveClick){
|
||||
return makeBase(TYPE.WARNING,
|
||||
mContext,
|
||||
|
||||
@ -456,6 +456,7 @@
|
||||
android:gravity="center">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageButton
|
||||
android:id="@+id/bottom_sheet_actions_edit_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
@ -481,6 +482,7 @@
|
||||
android:gravity="center">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageButton
|
||||
android:id="@+id/bottom_sheet_actions_delete_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
|
||||
@ -101,6 +101,8 @@
|
||||
<string name="check_box_preference_title">Check box</string>
|
||||
<string name="check_box_preference_summary">This is a regular preference</string>
|
||||
|
||||
<string name="alert_delete_mtb_colr">Stai per eliminare una riga. Confermi?</string>
|
||||
|
||||
<string name="activity_lista_bancali_title">Lista UL</string>
|
||||
<string name="activity_contenuto_bancale_title">Contenuto UL</string>
|
||||
|
||||
|
||||
@ -107,6 +107,7 @@
|
||||
<string name="check_box_preference_title">Check box</string>
|
||||
<string name="check_box_preference_summary">This is a regular preference</string>
|
||||
|
||||
<string name="alert_delete_mtb_colr">Are you sure to delete? Please confirm</string>
|
||||
|
||||
<string name="warehouse">Warehouse</string>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user