Added cache toggle to some requests

This commit is contained in:
Nicolás Sánchez 2024-12-23 12:00:37 -03:00
parent 90ce3ef3a2
commit f45a9e2840
1 changed files with 44 additions and 36 deletions

View File

@ -313,8 +313,7 @@ public class HomeFragment extends Fragment {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.today_this_month_details) { if (item.getItemId() == R.id.today_this_month_details) {
// Handle the "Details..." option // Implement as in profit_report.py
// For example, navigate to a details fragment
return true; return true;
} }
return false; return false;
@ -330,7 +329,7 @@ public class HomeFragment extends Fragment {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.exchangeMenuGlobalStatus) { if (item.getItemId() == R.id.exchangeMenuGlobalStatus) {
fetchExchangeDetails(exchange); fetchExchangeDetails(exchange, true);
return true; return true;
} else if (item.getItemId() == R.id.exchangeMenuMissingPairs) { } else if (item.getItemId() == R.id.exchangeMenuMissingPairs) {
fetchMissingPairs(exchange); fetchMissingPairs(exchange);
@ -342,10 +341,10 @@ public class HomeFragment extends Fragment {
fetchTraderTime(exchange); fetchTraderTime(exchange);
return true; return true;
} else if (item.getItemId() == R.id.exchangeMenuPausedTraders) { } else if (item.getItemId() == R.id.exchangeMenuPausedTraders) {
fetchPausedTraders(exchange); fetchPausedTraders(exchange, true);
return true; return true;
} else if (item.getItemId() == R.id.exchangeMenuConfigFile) { } else if (item.getItemId() == R.id.exchangeMenuConfigFile) {
fetchExchangeConfig(exchange); fetchExchangeConfig(exchange, true);
return true; return true;
} }
return false; return false;
@ -411,30 +410,36 @@ public class HomeFragment extends Fragment {
} }
} }
private void fetchExchangeDetails(String exchange) { private void fetchExchangeDetails(String exchange, boolean cached) {
if (cached) {
showInstanceDetailsDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); showInstanceDetailsDialog(MainActivity.getInstanceCache(exchange).getGlobalStats());
// new Thread(() -> { } else {
// try { new Thread(() -> {
// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); try {
// new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result)); InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true);
// } catch (IOException e) { new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result));
// e.printStackTrace(); } catch (IOException e) {
// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); e.printStackTrace();
// } new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
// }).start(); }
}).start();
}
} }
private void fetchPausedTraders(String exchange) { private void fetchPausedTraders(String exchange, boolean cached) {
if (cached) {
showPausedTradersDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); showPausedTradersDialog(MainActivity.getInstanceCache(exchange).getGlobalStats());
// new Thread(() -> { } else {
// try { new Thread(() -> {
// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); try {
// new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result)); InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true);
// } catch (IOException e) { new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result));
// e.printStackTrace(); } catch (IOException e) {
// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); e.printStackTrace();
// } new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
// }).start(); }
}).start();
}
} }
private void fetchMissingPairs(String exchange) { private void fetchMissingPairs(String exchange) {
@ -473,17 +478,20 @@ public class HomeFragment extends Fragment {
}).start(); }).start();
} }
private void fetchExchangeConfig(String exchange) { private void fetchExchangeConfig(String exchange, boolean cached) {
if (cached) {
showInstanceConfigDialog(MainActivity.getInstanceCache(exchange).getGlobalStats()); showInstanceConfigDialog(MainActivity.getInstanceCache(exchange).getGlobalStats());
// new Thread(() -> { } else {
// try { new Thread(() -> {
// InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true); try {
// new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result)); InstanceInterface.InstanceGlobalStatsData result = InstanceInterface.getInstanceGlobalStatus(exchange, true);
// } catch (IOException e) { new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result));
// e.printStackTrace(); } catch (IOException e) {
// new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show()); e.printStackTrace();
// } new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
// }).start(); }
}).start();
}
} }
private void showInstanceDetailsDialog(InstanceInterface.InstanceGlobalStatsData result) { private void showInstanceDetailsDialog(InstanceInterface.InstanceGlobalStatsData result) {