From 908d9b4693b4441daffca2861a2181275703003d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 1 Jun 2023 19:33:11 -0500 Subject: [PATCH] Disallow pressing actions during loading, do show a patience message --- .../res/layout/command_progress_bar.xml | 23 +++++++++++++++- .../conversations/entities/Conversation.java | 26 ++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/cheogram/res/layout/command_progress_bar.xml b/src/cheogram/res/layout/command_progress_bar.xml index 33ea77ec8226e62af356aa55faeea093443e2df2..f9ae5766cea9fb728e9cb142e83631bef3408746 100644 --- a/src/cheogram/res/layout/command_progress_bar.xml +++ b/src/cheogram/res/layout/command_progress_bar.xml @@ -2,7 +2,13 @@ - + + + + + + + diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 02f5f79160d165d13f874c33fff99cf4b619da1f..9fbe1da9a9b368655f263c9d1295de98c60ea3f2 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -2121,9 +2121,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public View getView(int position, View convertView, ViewGroup parent) { Button v = (Button) super.getView(position, convertView, parent); v.setOnClickListener((view) -> { - loading = true; mValue.setContent(getItem(position).getValue()); execute(); + loading = true; }); final SVG icon = getItem(position).getIcon(); @@ -2179,12 +2179,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(dialogBinding.inputEditText)); dialog.show(); View.OnClickListener clickListener = v -> { - loading = true; String value = dialogBinding.inputEditText.getText().toString(); mValue.setContent(value); SoftKeyboardUtils.hideSoftKeyboard(dialogBinding.inputEditText); dialog.dismiss(); execute(); + loading = true; }; dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener); dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> { @@ -2230,9 +2230,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl binding.defaultButton.setText(defaultOption.toString()); binding.defaultButton.setOnClickListener((view) -> { - loading = true; mValue.setContent(defaultOption.getValue()); execute(); + loading = true; }); } @@ -2350,7 +2350,9 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl public ProgressBarViewHolder(CommandProgressBarBinding binding) { super(binding); } @Override - public void bind(Item item) { } + public void bind(Item item) { + binding.text.setVisibility(loadingHasBeenLong ? View.VISIBLE : View.GONE); + } } class Item { @@ -2570,6 +2572,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl final int TYPE_BUTTON_GRID_FIELD = 13; protected boolean loading = false; + protected boolean loadingHasBeenLong = false; protected Timer loadingTimer = new Timer(); protected String mTitle; protected String mNode; @@ -2625,6 +2628,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl this.loadingTimer.cancel(); this.loadingTimer = new Timer(); this.loading = false; + this.loadingHasBeenLong = false; this.responseElement = null; this.fillableFieldCount = 0; this.reported = null; @@ -2986,6 +2990,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public boolean execute(String action) { + if (!"cancel".equals(action) && loading) { + loadingHasBeenLong = true; + notifyDataSetChanged(); + return false; + } if (!action.equals("cancel") && !action.equals("prev") && !validate()) return false; if (response == null) return true; @@ -3061,6 +3070,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl View v2 = getView(); loading = true; + loadingTimer.schedule(new TimerTask() { + @Override + public void run() { + loadingHasBeenLong = true; + if (v == null && v2 == null) return; + (v == null ? v2 : v).post(() -> notifyDataSetChanged()); + } + }, 3000); + if (v == null && v2 == null) return; (v == null ? v2 : v).post(() -> notifyDataSetChanged()); }