Home page cache
This commit is contained in:
parent
b3d9ed2a0f
commit
a82ebd54a7
|
|
@ -32,6 +32,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
public static SettingsData globalSettings;
|
public static SettingsData globalSettings;
|
||||||
public HomeFragment.HomeCache homeViewCache;
|
public HomeFragment.HomeCache homeViewCache;
|
||||||
|
|
||||||
|
|
||||||
|
public HomeFragment.HomeCache getHomeViewCache() {
|
||||||
|
return homeViewCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHomeViewCache(HomeFragment.HomeCache newCache) {
|
||||||
|
this.homeViewCache = newCache;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
||||||
|
|
@ -99,12 +99,19 @@ public class HomeFragment extends Fragment {
|
||||||
private TextView log4Content;
|
private TextView log4Content;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
//binding = FragmentHomeBinding.inflate(inflater, container, false);
|
//binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||||
//View root = binding.getRoot();
|
//View root = binding.getRoot();
|
||||||
|
|
||||||
|
// For the cache
|
||||||
|
MainActivity mainActivity = (MainActivity) requireActivity();
|
||||||
|
HomeFragment.HomeCache homeViewCache = mainActivity.getHomeViewCache();
|
||||||
|
|
||||||
homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
|
homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
|
||||||
View root = inflater.inflate(R.layout.fragment_home, container, false);
|
View root = inflater.inflate(R.layout.fragment_home, container, false);
|
||||||
|
|
@ -164,12 +171,7 @@ public class HomeFragment extends Fragment {
|
||||||
// Last deals
|
// Last deals
|
||||||
lastTrades = root.findViewById(R.id.lastTrades);
|
lastTrades = root.findViewById(R.id.lastTrades);
|
||||||
|
|
||||||
// Log entries
|
// Logs
|
||||||
// TextView log1Title = root.findViewById(R.id.log1CardTitle);
|
|
||||||
// TextView log2Title = root.findViewById(R.id.log2CardTitle);
|
|
||||||
// TextView log3Title = root.findViewById(R.id.log3CardTitle);
|
|
||||||
// TextView log4Title = root.findViewById(R.id.log4CardTitle);
|
|
||||||
|
|
||||||
log1Content = root.findViewById(R.id.log1CardContent);
|
log1Content = root.findViewById(R.id.log1CardContent);
|
||||||
log2Content = root.findViewById(R.id.log2CardContent);
|
log2Content = root.findViewById(R.id.log2CardContent);
|
||||||
log3Content = root.findViewById(R.id.log3CardContent);
|
log3Content = root.findViewById(R.id.log3CardContent);
|
||||||
|
|
@ -177,95 +179,96 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
|
||||||
* LOAD CACHED VALUES
|
* LOAD CACHED VALUES
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (homeViewCache!=null) {
|
||||||
//Prices
|
populateHome(homeViewCache.getFirstTickerChangeData(),
|
||||||
pricePair1.setText(R.string.default_price_ticker_1);
|
homeViewCache.getSecondTickerChangeData(),
|
||||||
pricePair2.setText(R.string.default_price_ticker_2);
|
homeViewCache.getThirdTickerChangeData(),
|
||||||
pricePair3.setText(R.string.default_price_ticker_3);
|
homeViewCache.getProfitsData(),
|
||||||
|
homeViewCache.getBinanceData(),
|
||||||
|
homeViewCache.getGateioData(),
|
||||||
|
homeViewCache.getKucoinData(),
|
||||||
|
homeViewCache.getOkexData(),
|
||||||
|
homeViewCache.getDealData(),
|
||||||
|
homeViewCache.getBinanceLogs(),
|
||||||
|
homeViewCache.getGateioLogs(),
|
||||||
|
homeViewCache.getKucoinLogs(),
|
||||||
|
homeViewCache.getOkexLogs());
|
||||||
|
} else {
|
||||||
|
//Prices
|
||||||
|
pricePair1.setText(R.string.default_price_ticker_1);
|
||||||
|
pricePair2.setText(R.string.default_price_ticker_2);
|
||||||
|
pricePair3.setText(R.string.default_price_ticker_3);
|
||||||
|
|
||||||
|
|
||||||
pricePair124hPercentage.setText(R.string.percentage_example);
|
pricePair124hPercentage.setText(R.string.percentage_example);
|
||||||
pricePair17dPercentage.setText(R.string.percentage_example);
|
pricePair17dPercentage.setText(R.string.percentage_example);
|
||||||
pricePair130dPercentage.setText(R.string.percentage_example);
|
pricePair130dPercentage.setText(R.string.percentage_example);
|
||||||
|
|
||||||
pricePair224hPercentage.setText(R.string.percentage_example);
|
pricePair224hPercentage.setText(R.string.percentage_example);
|
||||||
pricePair27dPercentage.setText(R.string.percentage_example);
|
pricePair27dPercentage.setText(R.string.percentage_example);
|
||||||
pricePair230dPercentage.setText(R.string.percentage_example);
|
pricePair230dPercentage.setText(R.string.percentage_example);
|
||||||
|
|
||||||
pricePair324hPercentage.setText(R.string.percentage_example);
|
pricePair324hPercentage.setText(R.string.percentage_example);
|
||||||
pricePair37dPercentage.setText(R.string.percentage_example);
|
pricePair37dPercentage.setText(R.string.percentage_example);
|
||||||
pricePair330dPercentage.setText(R.string.percentage_example);
|
pricePair330dPercentage.setText(R.string.percentage_example);
|
||||||
|
|
||||||
|
|
||||||
pricePair124hPercentage.setTextColor(Color.GREEN);
|
pricePair124hPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair17dPercentage.setTextColor(Color.GREEN);
|
pricePair17dPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair130dPercentage.setTextColor(Color.GREEN);
|
pricePair130dPercentage.setTextColor(Color.GREEN);
|
||||||
|
|
||||||
pricePair224hPercentage.setTextColor(Color.GREEN);
|
pricePair224hPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair27dPercentage.setTextColor(Color.GREEN);
|
pricePair27dPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair230dPercentage.setTextColor(Color.GREEN);
|
pricePair230dPercentage.setTextColor(Color.GREEN);
|
||||||
|
|
||||||
pricePair324hPercentage.setTextColor(Color.GREEN);
|
pricePair324hPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair37dPercentage.setTextColor(Color.GREEN);
|
pricePair37dPercentage.setTextColor(Color.GREEN);
|
||||||
pricePair330dPercentage.setTextColor(Color.GREEN);
|
pricePair330dPercentage.setTextColor(Color.GREEN);
|
||||||
|
|
||||||
|
|
||||||
// Profits today and this month
|
// Profits today and this month
|
||||||
profitsToday.setText(R.string.profits_today_example);
|
profitsToday.setText(R.string.profits_today_example);
|
||||||
profitsThisMonth.setText(R.string.profits_this_month_example);
|
profitsThisMonth.setText(R.string.profits_this_month_example);
|
||||||
|
|
||||||
|
|
||||||
//Exchange status
|
//Exchange status
|
||||||
exchange1Status.setImageResource(R.drawable.ic_green_circle_48);
|
exchange1Status.setImageResource(R.drawable.ic_green_circle_48);
|
||||||
exchange2Status.setImageResource(R.drawable.ic_green_circle_48);
|
exchange2Status.setImageResource(R.drawable.ic_green_circle_48);
|
||||||
exchange3Status.setImageResource(R.drawable.ic_green_circle_48);
|
exchange3Status.setImageResource(R.drawable.ic_green_circle_48);
|
||||||
exchange4Status.setImageResource(R.drawable.ic_green_circle_48);
|
exchange4Status.setImageResource(R.drawable.ic_green_circle_48);
|
||||||
|
|
||||||
// exchange1Name.setText(R.string.exchange_1_name);
|
exchange1Funds.setText(R.string.exchange_funds_example);
|
||||||
// exchange2Name.setText(R.string.exchange_2_name);
|
exchange2Funds.setText(R.string.exchange_funds_example);
|
||||||
// exchange3Name.setText(R.string.exchange_3_name);
|
exchange3Funds.setText(R.string.exchange_funds_example);
|
||||||
// exchange4Name.setText(R.string.exchange_4_name);
|
exchange4Funds.setText(R.string.exchange_funds_example);
|
||||||
|
|
||||||
exchange1Funds.setText(R.string.exchange_funds_example);
|
exchange1FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
||||||
exchange2Funds.setText(R.string.exchange_funds_example);
|
exchange2FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
||||||
exchange3Funds.setText(R.string.exchange_funds_example);
|
exchange3FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
||||||
exchange4Funds.setText(R.string.exchange_funds_example);
|
exchange4FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
||||||
|
|
||||||
exchange1FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
exchange1WorkersOnline.setText(R.string.exchange_workers_online_example);
|
||||||
exchange2FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
exchange2WorkersOnline.setText(R.string.exchange_workers_online_example);
|
||||||
exchange3FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
exchange3WorkersOnline.setText(R.string.exchange_workers_online_example);
|
||||||
exchange4FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
exchange4WorkersOnline.setText(R.string.exchange_workers_online_example);
|
||||||
|
|
||||||
exchange1WorkersOnline.setText(R.string.exchange_workers_online_example);
|
exchange1WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
||||||
exchange2WorkersOnline.setText(R.string.exchange_workers_online_example);
|
exchange2WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
||||||
exchange3WorkersOnline.setText(R.string.exchange_workers_online_example);
|
exchange3WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
||||||
exchange4WorkersOnline.setText(R.string.exchange_workers_online_example);
|
exchange4WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
||||||
|
|
||||||
exchange1WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
// Last trades
|
||||||
exchange2WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
lastTrades.setText(R.string.last_trades_example);
|
||||||
exchange3WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
exchange4WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
||||||
|
|
||||||
// Last trades
|
|
||||||
lastTrades.setText(R.string.last_trades_example);
|
|
||||||
|
|
||||||
// Log entries
|
|
||||||
// log1Title.setText(R.string.exchange_1_log_title);
|
|
||||||
// log2Title.setText(R.string.exchange_2_log_title);
|
|
||||||
// log3Title.setText(R.string.exchange_3_log_title);
|
|
||||||
// log4Title.setText(R.string.exchange_4_log_title);
|
|
||||||
|
|
||||||
// Log entries
|
|
||||||
log1Content.setText(R.string.log_example);
|
|
||||||
log2Content.setText(R.string.log_example);
|
|
||||||
log3Content.setText(R.string.log_example);
|
|
||||||
log4Content.setText(R.string.log_example);
|
|
||||||
|
|
||||||
|
// Log entries
|
||||||
|
log1Content.setText(R.string.log_example);
|
||||||
|
log2Content.setText(R.string.log_example);
|
||||||
|
log3Content.setText(R.string.log_example);
|
||||||
|
log4Content.setText(R.string.log_example);
|
||||||
|
}
|
||||||
|
|
||||||
// Setup task
|
// Setup task
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
|
|
@ -306,6 +309,10 @@ public class HomeFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchAndDisplayData() {
|
private void fetchAndDisplayData() {
|
||||||
|
// For the cache
|
||||||
|
MainActivity mainActivity = (MainActivity) requireActivity();
|
||||||
|
//HomeFragment.HomeCache homeViewCache = mainActivity.getHomeViewCache();
|
||||||
|
|
||||||
executorService.execute(() -> {
|
executorService.execute(() -> {
|
||||||
try {
|
try {
|
||||||
CompletableFuture<TickerTracker.PriceChangeData> future1 = CompletableFuture.supplyAsync(() -> {
|
CompletableFuture<TickerTracker.PriceChangeData> future1 = CompletableFuture.supplyAsync(() -> {
|
||||||
|
|
@ -475,6 +482,9 @@ public class HomeFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
populateHome(priceData, priceData2, priceData3, profitsData, binanceStats, gateioStats, kucoinStats, okexStats, deals, logs1, logs2, logs3, logs4);
|
populateHome(priceData, priceData2, priceData3, profitsData, binanceStats, gateioStats, kucoinStats, okexStats, deals, logs1, logs2, logs3, logs4);
|
||||||
|
mainActivity.setHomeViewCache(
|
||||||
|
new HomeCache (priceData, priceData2, priceData3, profitsData, binanceStats, gateioStats, kucoinStats, okexStats, deals, logs1, logs2, logs3, logs4)
|
||||||
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -694,19 +704,19 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
public static class HomeCache {
|
public static class HomeCache {
|
||||||
private TickerTracker.PriceChangeData firstTickerChangeData;
|
private final TickerTracker.PriceChangeData firstTickerChangeData;
|
||||||
private TickerTracker.PriceChangeData secondTickerChangeData;
|
private final TickerTracker.PriceChangeData secondTickerChangeData;
|
||||||
private TickerTracker.PriceChangeData thirdTickerChangeData;
|
private final TickerTracker.PriceChangeData thirdTickerChangeData;
|
||||||
private InstanceInterface.ProfitStatsData profitsData;
|
private final InstanceInterface.ProfitStatsData profitsData;
|
||||||
private InstanceInterface.ExchangeStatsData binanceData;
|
private final InstanceInterface.ExchangeStatsData binanceData;
|
||||||
private InstanceInterface.ExchangeStatsData gateioData;
|
private final InstanceInterface.ExchangeStatsData gateioData;
|
||||||
private InstanceInterface.ExchangeStatsData kucoinData;
|
private final InstanceInterface.ExchangeStatsData kucoinData;
|
||||||
private InstanceInterface.ExchangeStatsData okexData;
|
private final InstanceInterface.ExchangeStatsData okexData;
|
||||||
private List<InstanceInterface.DealData> dealData;
|
private final List<InstanceInterface.DealData> dealData;
|
||||||
private String binanceLogs;
|
private final String binanceLogs;
|
||||||
private String gateioLogs;
|
private final String gateioLogs;
|
||||||
private String kucoinLogs;
|
private final String kucoinLogs;
|
||||||
private String okexLogs;
|
private final String okexLogs;
|
||||||
|
|
||||||
public HomeCache(TickerTracker.PriceChangeData firstTickerChangeData, TickerTracker.PriceChangeData secondTickerChangeData, TickerTracker.PriceChangeData thirdTickerChangeData, InstanceInterface.ProfitStatsData profitsData, InstanceInterface.ExchangeStatsData binanceData, InstanceInterface.ExchangeStatsData gateioData, InstanceInterface.ExchangeStatsData kucoinData, InstanceInterface.ExchangeStatsData okexData, List<InstanceInterface.DealData> dealData, String binanceLogs, String gateioLogs, String kucoinLogs, String okexLogs) {
|
public HomeCache(TickerTracker.PriceChangeData firstTickerChangeData, TickerTracker.PriceChangeData secondTickerChangeData, TickerTracker.PriceChangeData thirdTickerChangeData, InstanceInterface.ProfitStatsData profitsData, InstanceInterface.ExchangeStatsData binanceData, InstanceInterface.ExchangeStatsData gateioData, InstanceInterface.ExchangeStatsData kucoinData, InstanceInterface.ExchangeStatsData okexData, List<InstanceInterface.DealData> dealData, String binanceLogs, String gateioLogs, String kucoinLogs, String okexLogs) {
|
||||||
this.firstTickerChangeData = firstTickerChangeData;
|
this.firstTickerChangeData = firstTickerChangeData;
|
||||||
|
|
@ -724,20 +734,6 @@ public class HomeFragment extends Fragment {
|
||||||
this.okexLogs = okexLogs;
|
this.okexLogs = okexLogs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstTickerChangeData(TickerTracker.PriceChangeData firstTickerChangeData) { this.firstTickerChangeData = firstTickerChangeData; }
|
|
||||||
public void setSecondTickerChangeData(TickerTracker.PriceChangeData secondTickerChangeData) { this.secondTickerChangeData = secondTickerChangeData; }
|
|
||||||
public void setThirdTickerChangeData(TickerTracker.PriceChangeData thirdTickerChangeData) { this.thirdTickerChangeData = thirdTickerChangeData; }
|
|
||||||
public void setProfitsData(InstanceInterface.ProfitStatsData profitsData) { this.profitsData = profitsData; }
|
|
||||||
public void setBinanceData(InstanceInterface.ExchangeStatsData binanceData) { this.binanceData = binanceData; }
|
|
||||||
public void setGateioData(InstanceInterface.ExchangeStatsData gateioData) { this.gateioData = gateioData; }
|
|
||||||
public void setKucoinData(InstanceInterface.ExchangeStatsData kucoinData) { this.kucoinData = kucoinData; }
|
|
||||||
public void setOkexData(InstanceInterface.ExchangeStatsData okexData) { this.okexData = okexData; }
|
|
||||||
public void setDealData(List<InstanceInterface.DealData> dealData) { this.dealData = dealData; }
|
|
||||||
public void setBinanceLogs(String binanceLogs) { this.binanceLogs = binanceLogs; }
|
|
||||||
public void setGateioLogs(String gateioLogs) { this.gateioLogs = gateioLogs; }
|
|
||||||
public void setKucoinLogs(String kucoinLogs) { this.kucoinLogs = kucoinLogs; }
|
|
||||||
public void setOkexLogs(String okexLogs) { this.okexLogs = okexLogs; }
|
|
||||||
|
|
||||||
public TickerTracker.PriceChangeData getFirstTickerChangeData() { return firstTickerChangeData; }
|
public TickerTracker.PriceChangeData getFirstTickerChangeData() { return firstTickerChangeData; }
|
||||||
public TickerTracker.PriceChangeData getSecondTickerChangeData() { return secondTickerChangeData; }
|
public TickerTracker.PriceChangeData getSecondTickerChangeData() { return secondTickerChangeData; }
|
||||||
public TickerTracker.PriceChangeData getThirdTickerChangeData() { return thirdTickerChangeData; }
|
public TickerTracker.PriceChangeData getThirdTickerChangeData() { return thirdTickerChangeData; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue