From 90ce3ef3a2ec2f48c238a9f6f40cc56ba4e02b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Mon, 23 Dec 2024 11:46:45 -0300 Subject: [PATCH] Using global caches for instance stats --- .../dcav2gui/ui/home/HomeFragment.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java b/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java index 08dbd3b..4211a89 100644 --- a/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java +++ b/app/src/main/java/com/example/dcav2gui/ui/home/HomeFragment.java @@ -412,27 +412,29 @@ public class HomeFragment extends Fragment { } private void fetchExchangeDetails(String exchange) { - new Thread(() -> { - try { - InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); - new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result)); - } catch (IOException e) { - e.printStackTrace(); - new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); - } - }).start(); + showInstanceDetailsDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); +// new Thread(() -> { +// try { +// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); +// new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result)); +// } catch (IOException e) { +// e.printStackTrace(); +// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); +// } +// }).start(); } private void fetchPausedTraders(String exchange) { - new Thread(() -> { - try { - InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); - new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result)); - } catch (IOException e) { - e.printStackTrace(); - new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); - } - }).start(); + showPausedTradersDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); +// new Thread(() -> { +// try { +// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); +// new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result)); +// } catch (IOException e) { +// e.printStackTrace(); +// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); +// } +// }).start(); } private void fetchMissingPairs(String exchange) { @@ -472,15 +474,16 @@ public class HomeFragment extends Fragment { } private void fetchExchangeConfig(String exchange) { - new Thread(() -> { - try { - InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); - new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result)); - } catch (IOException e) { - e.printStackTrace(); - new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); - } - }).start(); + showInstanceConfigDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); +// new Thread(() -> { +// try { +// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); +// new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result)); +// } catch (IOException e) { +// e.printStackTrace(); +// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); +// } +// }).start(); } private void showInstanceDetailsDialog(InstanceInterface.InstanceGlobalStatsData result) {