Migliorata gestione del loading dialog (evitate concorrenze di apertura)

This commit is contained in:
Giuseppe Scorrano 2024-11-05 11:23:51 +01:00
parent 845a4c8faa
commit 342753aeac
8 changed files with 60 additions and 65 deletions

View File

@ -6,6 +6,8 @@ import android.view.KeyEvent;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import it.integry.integrywmsnative.MainApplication; import it.integry.integrywmsnative.MainApplication;
@ -18,7 +20,8 @@ public class BaseActivity extends AppCompatActivity {
@Inject @Inject
public DialogProgressView mCurrentProgress; public DialogProgressView mCurrentProgress;
private boolean progressOpened; @Inject
public ExecutorService executorService;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -47,29 +50,20 @@ public class BaseActivity extends AppCompatActivity {
} }
private void openProgress() { private void openProgress() {
BarcodeManager.disable(); BarcodeManager.disable();
if (!progressOpened && !this.mCurrentProgress.isAdded() && !this.mCurrentProgress.isInLayout()) { executorService.execute(() -> {
this.progressOpened = true; this.mCurrentProgress.show(getSupportFragmentManager());
runOnUiThread(() -> {
try {
this.mCurrentProgress.show(getSupportFragmentManager(), "tag");
} catch (IllegalStateException ise) {
//ignored
}
}); });
} }
}
private void closeProgress() { private void closeProgress() {
BarcodeManager.enable(); BarcodeManager.enable();
if (progressOpened) { executorService.execute(() -> {
this.progressOpened = false; mCurrentProgress.dismissAllowingStateLoss();
runOnUiThread(() -> {
mCurrentProgress.dismiss();
}); });
} }
}
@Override @Override
public boolean dispatchKeyEvent(KeyEvent event) { public boolean dispatchKeyEvent(KeyEvent event) {

View File

@ -13,6 +13,8 @@ import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
import it.integry.integrywmsnative.MainApplication; import it.integry.integrywmsnative.MainApplication;
@ -24,7 +26,9 @@ public abstract class BaseDialogFragment extends DialogFragment implements Dialo
@Inject @Inject
public DialogProgressView mCurrentProgress; public DialogProgressView mCurrentProgress;
private boolean progressOpened;
@Inject
public ExecutorService executorService;
private boolean mBarcodeListener = false; private boolean mBarcodeListener = false;
@ -70,23 +74,20 @@ public abstract class BaseDialogFragment extends DialogFragment implements Dialo
BarcodeManager.enable(); BarcodeManager.enable();
} }
private void openProgress() { private void openProgress() {
if (!progressOpened && !this.mCurrentProgress.isAdded() && !this.mCurrentProgress.isInLayout()) { BarcodeManager.disable();
this.progressOpened = true; executorService.execute(() -> {
requireActivity().runOnUiThread(() -> { this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager(), "tag");
}); });
} }
}
private void closeProgress() { private void closeProgress() {
if (progressOpened) { BarcodeManager.enable();
this.progressOpened = false; executorService.execute(() -> {
requireActivity().runOnUiThread(() -> { mCurrentProgress.dismissAllowingStateLoss();
mCurrentProgress.dismiss();
}); });
} }
}
public void onError(Exception ex) { public void onError(Exception ex) {

View File

@ -33,7 +33,6 @@ public abstract class BaseFragment extends Fragment {
protected ElevatedToolbar mToolbar; protected ElevatedToolbar mToolbar;
protected final List<Runnable> mOnPreDestroyList = new ArrayList<>(); protected final List<Runnable> mOnPreDestroyList = new ArrayList<>();
private boolean progressOpened;
public void setScrollToolbar(ElevatedToolbar toolbar) { public void setScrollToolbar(ElevatedToolbar toolbar) {
@ -67,23 +66,17 @@ public abstract class BaseFragment extends Fragment {
private void openProgress() { private void openProgress() {
BarcodeManager.disable(); BarcodeManager.disable();
if (!progressOpened && !this.mCurrentProgress.isAdded() && !this.mCurrentProgress.isInLayout()) {
this.progressOpened = true;
executorService.execute(() -> { executorService.execute(() -> {
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager(), "tag"); this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
}); });
} }
}
private void closeProgress() { private void closeProgress() {
BarcodeManager.enable(); BarcodeManager.enable();
if (progressOpened) {
this.progressOpened = false;
executorService.execute(() -> { executorService.execute(() -> {
mCurrentProgress.dismissAllowingStateLoss(); mCurrentProgress.dismissAllowingStateLoss();
}); });
} }
}
public void onError(Exception ex) { public void onError(Exception ex) {
requireActivity().runOnUiThread(() -> { requireActivity().runOnUiThread(() -> {

View File

@ -329,9 +329,7 @@ public class PickingLiberoViewModel {
this.sendLULineaProdRequired(response -> { this.sendLULineaProdRequired(response -> {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, response.getPosizione(), response.getIdLotto(), onComplete); createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, response.getPosizione(), response.getIdLotto(), onComplete);
}, () -> { }, this::sendOnLoadingEnded);
this.sendOnLoadingEnded();
});
} else { } else {
createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, null, null, onComplete); createNewLU_PostLineaProdAsk(customNumCollo, customSerCollo, vtbDest, null, null, onComplete);
} }

View File

@ -88,10 +88,7 @@ public class PVOrdiniAcquistoGrigliaFragment extends BaseFragment implements ITi
} }
public static PVOrdiniAcquistoGrigliaFragment newInstance() { public static PVOrdiniAcquistoGrigliaFragment newInstance() {
PVOrdiniAcquistoGrigliaFragment fragment = new PVOrdiniAcquistoGrigliaFragment(); return new PVOrdiniAcquistoGrigliaFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
} }
@Override @Override

View File

@ -307,23 +307,18 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
} }
private void openProgress() { private void openProgress() {
if (!progressOpened && !this.mCurrentProgress.isAdded()) { executorService.execute(() -> {
this.progressOpened = true; this.mCurrentProgress.show(requireActivity().getSupportFragmentManager());
requireActivity().runOnUiThread(() -> {
this.mCurrentProgress.show(requireActivity().getSupportFragmentManager(), "tag");
}); });
} }
}
private void closeProgress() { private void closeProgress() {
if (progressOpened) { executorService.execute(() -> {
this.progressOpened = false; mCurrentProgress.dismissAllowingStateLoss();
requireActivity().runOnUiThread(() -> {
mCurrentProgress.dismiss();
}); });
} }
}
private String createAppLogAttachment(File logFile) { private String createAppLogAttachment(File logFile) {

View File

@ -3,11 +3,11 @@ package it.integry.integrywmsnative.view.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -26,6 +26,8 @@ public class DialogProgressView extends DialogFragment {
private String subtitle; private String subtitle;
private boolean indeterminateProgress; private boolean indeterminateProgress;
private boolean progressOpened;
public static DialogProgressView newInstance(String title, String subtitle, boolean indeterminate) { public static DialogProgressView newInstance(String title, String subtitle, boolean indeterminate) {
return new DialogProgressView(title, subtitle, indeterminate); return new DialogProgressView(title, subtitle, indeterminate);
} }
@ -43,7 +45,7 @@ public class DialogProgressView extends DialogFragment {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
mBindings = DialogProgressBinding.inflate(LayoutInflater.from(requireContext())); mBindings = DialogProgressBinding.inflate(getLayoutInflater());
mBindings.setTitle(UtilityString.isNullOrEmpty(title) ? requireContext().getString(R.string.loading) : title); mBindings.setTitle(UtilityString.isNullOrEmpty(title) ? requireContext().getString(R.string.loading) : title);
if (!UtilityString.isNullOrEmpty(subtitle)) mBindings.setSubtitle(subtitle); if (!UtilityString.isNullOrEmpty(subtitle)) mBindings.setSubtitle(subtitle);
@ -61,6 +63,21 @@ public class DialogProgressView extends DialogFragment {
return alertDialog; return alertDialog;
} }
public void show(@NonNull FragmentManager manager) {
if (!progressOpened && !isAdded() && !isInLayout()) {
this.progressOpened = true;
super.show(manager, "loading-dialog");
}
}
@Override
public void dismiss() {
if (progressOpened) {
this.progressOpened = false;
super.dismissAllowingStateLoss();
}
}
public String getTitle() { public String getTitle() {
return title; return title;
} }

View File

@ -145,7 +145,7 @@ public class DialogAskClienteView extends BaseDialogFragment {
viewModel2.setOnAbortClickListener(this::dismiss); viewModel2.setOnAbortClickListener(this::dismiss);
this.dialogProgressView.show(this.getParentFragmentManager(), "tag"); this.dialogProgressView.show(this.getParentFragmentManager());
this.initClienti(viewModel1, () -> { this.initClienti(viewModel1, () -> {
this.initDestinatari(viewModel2, () -> { this.initDestinatari(viewModel2, () -> {