definitions
This commit is contained in:
parent
40537982e5
commit
d98e066264
|
|
@ -1,6 +1,5 @@
|
||||||
package com.example.dcav2gui.ui.home;
|
package com.example.dcav2gui.ui.home;
|
||||||
|
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
@ -12,7 +11,6 @@ import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
|
@ -50,6 +48,51 @@ public class HomeFragment extends Fragment {
|
||||||
private TextView pricePair37dPercentage;
|
private TextView pricePair37dPercentage;
|
||||||
private TextView pricePair330dPercentage;
|
private TextView pricePair330dPercentage;
|
||||||
|
|
||||||
|
private TextView profitsToday;
|
||||||
|
private TextView profitsThisMonth;
|
||||||
|
|
||||||
|
private ImageView exchange1Status;
|
||||||
|
private ImageView exchange2Status;
|
||||||
|
private ImageView exchange3Status;
|
||||||
|
private ImageView exchange4Status;
|
||||||
|
|
||||||
|
private TextView exchange1Name;
|
||||||
|
private TextView exchange2Name;
|
||||||
|
private TextView exchange3Name;
|
||||||
|
private TextView exchange4Name;
|
||||||
|
|
||||||
|
private TextView exchange1Funds;
|
||||||
|
private TextView exchange2Funds;
|
||||||
|
private TextView exchange3Funds;
|
||||||
|
private TextView exchange4Funds;
|
||||||
|
|
||||||
|
private TextView exchange1FundsNeeded;
|
||||||
|
private TextView exchange2FundsNeeded;
|
||||||
|
private TextView exchange3FundsNeeded;
|
||||||
|
private TextView exchange4FundsNeeded;
|
||||||
|
|
||||||
|
private TextView exchange1FundsPercentage;
|
||||||
|
private TextView exchange2FundsPercentage;
|
||||||
|
private TextView exchange3FundsPercentage;
|
||||||
|
private TextView exchange4FundsPercentage;
|
||||||
|
|
||||||
|
private TextView exchange1WorkersOnline;
|
||||||
|
private TextView exchange2WorkersOnline;
|
||||||
|
private TextView exchange3WorkersOnline;
|
||||||
|
private TextView exchange4WorkersOnline;
|
||||||
|
|
||||||
|
private TextView exchange1WorkersLongShort;
|
||||||
|
private TextView exchange2WorkersLongShort;
|
||||||
|
private TextView exchange3WorkersLongShort;
|
||||||
|
private TextView exchange4WorkersLongShort;
|
||||||
|
|
||||||
|
private TextView lastTrades;
|
||||||
|
|
||||||
|
private TextView log1Content;
|
||||||
|
private TextView log2Content;
|
||||||
|
private TextView log3Content;
|
||||||
|
private TextView log4Content;
|
||||||
|
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
@ -79,58 +122,58 @@ public class HomeFragment extends Fragment {
|
||||||
pricePair330dPercentage = root.findViewById(R.id.pricesCard30dText3);
|
pricePair330dPercentage = root.findViewById(R.id.pricesCard30dText3);
|
||||||
|
|
||||||
// Profits today and this month
|
// Profits today and this month
|
||||||
TextView profitsToday = root.findViewById(R.id.profitsTodayValue);
|
profitsToday = root.findViewById(R.id.profitsTodayValue);
|
||||||
TextView profitsThisMonth = root.findViewById(R.id.profitsThisMonthValue);
|
profitsThisMonth = root.findViewById(R.id.profitsThisMonthValue);
|
||||||
|
|
||||||
// Exchange status
|
// Exchange status
|
||||||
ImageView exchange1Status = root.findViewById(R.id.exchangeStats1Icon);
|
exchange1Status = root.findViewById(R.id.exchangeStats1Icon);
|
||||||
ImageView exchange2Status = root.findViewById(R.id.exchangeStats2Icon);
|
exchange2Status = root.findViewById(R.id.exchangeStats2Icon);
|
||||||
ImageView exchange3Status = root.findViewById(R.id.exchangeStats3Icon);
|
exchange3Status = root.findViewById(R.id.exchangeStats3Icon);
|
||||||
ImageView exchange4Status = root.findViewById(R.id.exchangeStats4Icon);
|
exchange4Status = root.findViewById(R.id.exchangeStats4Icon);
|
||||||
|
|
||||||
TextView exchange1Name = root.findViewById(R.id.exchangeStats1Label);
|
exchange1Name = root.findViewById(R.id.exchangeStats1Label);
|
||||||
TextView exchange2Name = root.findViewById(R.id.exchangeStats2Label);
|
exchange2Name = root.findViewById(R.id.exchangeStats2Label);
|
||||||
TextView exchange3Name = root.findViewById(R.id.exchangeStats3Label);
|
exchange3Name = root.findViewById(R.id.exchangeStats3Label);
|
||||||
TextView exchange4Name = root.findViewById(R.id.exchangeStats4Label);
|
exchange4Name = root.findViewById(R.id.exchangeStats4Label);
|
||||||
|
|
||||||
TextView exchange1Funds = root.findViewById(R.id.exchangeStats1Funds);
|
exchange1Funds = root.findViewById(R.id.exchangeStats1Funds);
|
||||||
TextView exchange2Funds = root.findViewById(R.id.exchangeStats2Funds);
|
exchange2Funds = root.findViewById(R.id.exchangeStats2Funds);
|
||||||
TextView exchange3Funds = root.findViewById(R.id.exchangeStats3Funds);
|
exchange3Funds = root.findViewById(R.id.exchangeStats3Funds);
|
||||||
TextView exchange4Funds = root.findViewById(R.id.exchangeStats4Funds);
|
exchange4Funds = root.findViewById(R.id.exchangeStats4Funds);
|
||||||
|
|
||||||
TextView exchange1FundsNeeded = root.findViewById(R.id.exchangeStats1FundsNeeded);
|
exchange1FundsNeeded = root.findViewById(R.id.exchangeStats1FundsNeeded);
|
||||||
TextView exchange2FundsNeeded = root.findViewById(R.id.exchangeStats2FundsNeeded);
|
exchange2FundsNeeded = root.findViewById(R.id.exchangeStats2FundsNeeded);
|
||||||
TextView exchange3FundsNeeded = root.findViewById(R.id.exchangeStats3FundsNeeded);
|
exchange3FundsNeeded = root.findViewById(R.id.exchangeStats3FundsNeeded);
|
||||||
TextView exchange4FundsNeeded = root.findViewById(R.id.exchangeStats4FundsNeeded);
|
exchange4FundsNeeded = root.findViewById(R.id.exchangeStats4FundsNeeded);
|
||||||
|
|
||||||
TextView exchange1FundsPercentage = root.findViewById(R.id.exchangeStats1FundsPercentage);
|
exchange1FundsPercentage = root.findViewById(R.id.exchangeStats1FundsPercentage);
|
||||||
TextView exchange2FundsPercentage = root.findViewById(R.id.exchangeStats2FundsPercentage);
|
exchange2FundsPercentage = root.findViewById(R.id.exchangeStats2FundsPercentage);
|
||||||
TextView exchange3FundsPercentage = root.findViewById(R.id.exchangeStats3FundsPercentage);
|
exchange3FundsPercentage = root.findViewById(R.id.exchangeStats3FundsPercentage);
|
||||||
TextView exchange4FundsPercentage = root.findViewById(R.id.exchangeStats4FundsPercentage);
|
exchange4FundsPercentage = root.findViewById(R.id.exchangeStats4FundsPercentage);
|
||||||
|
|
||||||
TextView exchange1WorkersOnline = root.findViewById(R.id.exchangeStats1WorkersOnline);
|
exchange1WorkersOnline = root.findViewById(R.id.exchangeStats1WorkersOnline);
|
||||||
TextView exchange2WorkersOnline = root.findViewById(R.id.exchangeStats2WorkersOnline);
|
exchange2WorkersOnline = root.findViewById(R.id.exchangeStats2WorkersOnline);
|
||||||
TextView exchange3WorkersOnline = root.findViewById(R.id.exchangeStats3WorkersOnline);
|
exchange3WorkersOnline = root.findViewById(R.id.exchangeStats3WorkersOnline);
|
||||||
TextView exchange4WorkersOnline = root.findViewById(R.id.exchangeStats4WorkersOnline);
|
exchange4WorkersOnline = root.findViewById(R.id.exchangeStats4WorkersOnline);
|
||||||
|
|
||||||
TextView exchange1WorkersLongShort = root.findViewById(R.id.exchangeStats1WorkersLongShort);
|
exchange1WorkersLongShort = root.findViewById(R.id.exchangeStats1WorkersLongShort);
|
||||||
TextView exchange2WorkersLongShort = root.findViewById(R.id.exchangeStats2WorkersLongShort);
|
exchange2WorkersLongShort = root.findViewById(R.id.exchangeStats2WorkersLongShort);
|
||||||
TextView exchange3WorkersLongShort = root.findViewById(R.id.exchangeStats3WorkersLongShort);
|
exchange3WorkersLongShort = root.findViewById(R.id.exchangeStats3WorkersLongShort);
|
||||||
TextView exchange4WorkersLongShort = root.findViewById(R.id.exchangeStats4WorkersLongShort);
|
exchange4WorkersLongShort = root.findViewById(R.id.exchangeStats4WorkersLongShort);
|
||||||
|
|
||||||
// Last deals
|
// Last deals
|
||||||
TextView lastTrades = root.findViewById(R.id.lastTrades);
|
lastTrades = root.findViewById(R.id.lastTrades);
|
||||||
|
|
||||||
// Log entries
|
// Log entries
|
||||||
TextView log1Title = root.findViewById(R.id.log1CardTitle);
|
// TextView log1Title = root.findViewById(R.id.log1CardTitle);
|
||||||
TextView log2Title = root.findViewById(R.id.log2CardTitle);
|
// TextView log2Title = root.findViewById(R.id.log2CardTitle);
|
||||||
TextView log3Title = root.findViewById(R.id.log3CardTitle);
|
// TextView log3Title = root.findViewById(R.id.log3CardTitle);
|
||||||
TextView log4Title = root.findViewById(R.id.log4CardTitle);
|
// TextView log4Title = root.findViewById(R.id.log4CardTitle);
|
||||||
|
|
||||||
TextView log1Content = root.findViewById(R.id.log1CardContent);
|
log1Content = root.findViewById(R.id.log1CardContent);
|
||||||
TextView log2Content = root.findViewById(R.id.log2CardContent);
|
log2Content = root.findViewById(R.id.log2CardContent);
|
||||||
TextView log3Content = root.findViewById(R.id.log3CardContent);
|
log3Content = root.findViewById(R.id.log3CardContent);
|
||||||
TextView log4Content = root.findViewById(R.id.log4CardContent);
|
log4Content = root.findViewById(R.id.log4CardContent);
|
||||||
|
|
||||||
|
|
||||||
// Profits today and this month
|
// Profits today and this month
|
||||||
|
|
@ -138,7 +181,7 @@ public class HomeFragment extends Fragment {
|
||||||
profitsThisMonth.setText(R.string.profits_this_month_example);
|
profitsThisMonth.setText(R.string.profits_this_month_example);
|
||||||
|
|
||||||
|
|
||||||
//Load cached values
|
// LOAD CACHED VALUES
|
||||||
//Prices
|
//Prices
|
||||||
pricePair1.setText(R.string.default_price_ticker_1);
|
pricePair1.setText(R.string.default_price_ticker_1);
|
||||||
pricePair2.setText(R.string.default_price_ticker_2);
|
pricePair2.setText(R.string.default_price_ticker_2);
|
||||||
|
|
@ -208,10 +251,10 @@ public class HomeFragment extends Fragment {
|
||||||
lastTrades.setText(R.string.last_trades_example);
|
lastTrades.setText(R.string.last_trades_example);
|
||||||
|
|
||||||
// Log entries
|
// Log entries
|
||||||
log1Title.setText(R.string.exchange_1_log_title);
|
// log1Title.setText(R.string.exchange_1_log_title);
|
||||||
log2Title.setText(R.string.exchange_2_log_title);
|
// log2Title.setText(R.string.exchange_2_log_title);
|
||||||
log3Title.setText(R.string.exchange_3_log_title);
|
// log3Title.setText(R.string.exchange_3_log_title);
|
||||||
log4Title.setText(R.string.exchange_4_log_title);
|
// log4Title.setText(R.string.exchange_4_log_title);
|
||||||
|
|
||||||
// Log entries
|
// Log entries
|
||||||
log1Content.setText(R.string.log_example);
|
log1Content.setText(R.string.log_example);
|
||||||
|
|
@ -227,7 +270,7 @@ public class HomeFragment extends Fragment {
|
||||||
updateRunnable = new Runnable() {
|
updateRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
fetchAndDisplayPriceData();
|
fetchAndDisplayData();
|
||||||
long delay = 5000;
|
long delay = 5000;
|
||||||
if (MainActivity.getGlobalSettings() != null) {
|
if (MainActivity.getGlobalSettings() != null) {
|
||||||
delay = (long) MainActivity.getGlobalSettings().timeBetweenQueries * 1000;
|
delay = (long) MainActivity.getGlobalSettings().timeBetweenQueries * 1000;
|
||||||
|
|
@ -260,18 +303,13 @@ public class HomeFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchAndDisplayPriceData() {
|
private void fetchAndDisplayData() {
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
try {
|
try {
|
||||||
// Fetch price data in background
|
|
||||||
String ticker1 = getString(R.string.ticker_1);
|
|
||||||
String ticker2 = getString(R.string.ticker_2);
|
|
||||||
String ticker3 = getString(R.string.ticker_3);
|
|
||||||
|
|
||||||
// Fetch price data in background using CompletableFuture
|
// Fetch price data in background using CompletableFuture
|
||||||
CompletableFuture<TickerTracker.PriceChangeData> future1 = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<TickerTracker.PriceChangeData> future1 = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return TickerTracker.getPriceChanges(ticker1);
|
return TickerTracker.getPriceChanges(getString(R.string.ticker_1));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -280,7 +318,7 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
CompletableFuture<TickerTracker.PriceChangeData> future2 = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<TickerTracker.PriceChangeData> future2 = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return TickerTracker.getPriceChanges(ticker2);
|
return TickerTracker.getPriceChanges(getString(R.string.ticker_2));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -289,7 +327,7 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
CompletableFuture<TickerTracker.PriceChangeData> future3 = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<TickerTracker.PriceChangeData> future3 = CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return TickerTracker.getPriceChanges(ticker3);
|
return TickerTracker.getPriceChanges(getString(R.string.ticker_3));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -300,9 +338,7 @@ public class HomeFragment extends Fragment {
|
||||||
CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3);
|
CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3);
|
||||||
|
|
||||||
|
|
||||||
|
// Update UI
|
||||||
// Update UI on the main thread
|
|
||||||
requireActivity().runOnUiThread(() -> {
|
|
||||||
try {
|
try {
|
||||||
TickerTracker.PriceChangeData priceData = future1.get();
|
TickerTracker.PriceChangeData priceData = future1.get();
|
||||||
TickerTracker.PriceChangeData priceData2 = future2.get();
|
TickerTracker.PriceChangeData priceData2 = future2.get();
|
||||||
|
|
@ -335,7 +371,6 @@ public class HomeFragment extends Fragment {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Toast.makeText(getContext(), "Error updating UI", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Error updating UI", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
requireActivity().runOnUiThread(() ->
|
requireActivity().runOnUiThread(() ->
|
||||||
Toast.makeText(getContext(), "Failed to fetch price data. Check your connection.", Toast.LENGTH_SHORT).show()
|
Toast.makeText(getContext(), "Failed to fetch price data. Check your connection.", Toast.LENGTH_SHORT).show()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue