|
|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
package com.example.dcav2gui.ui.home;
|
|
|
|
|
|
|
|
|
|
import static androidx.core.content.res.ResourcesCompat.getColor;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
@ -11,13 +9,17 @@ import android.text.SpannableString;
|
|
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
|
import android.text.style.ForegroundColorSpan;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
@ -28,6 +30,7 @@ import com.example.dcav2gui.InstanceInterface;
|
|
|
|
|
import com.example.dcav2gui.MainActivity;
|
|
|
|
|
import com.example.dcav2gui.R;
|
|
|
|
|
import com.example.dcav2gui.TickerTracker;
|
|
|
|
|
import com.example.dcav2gui.databinding.FragmentHomeBinding;
|
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
@ -43,7 +46,7 @@ import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
public class HomeFragment extends Fragment {
|
|
|
|
|
private HomeViewModel homeViewModel;
|
|
|
|
|
//private FragmentHomeBinding binding;
|
|
|
|
|
private FragmentHomeBinding binding;
|
|
|
|
|
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
|
|
|
|
|
|
|
|
|
private Handler handler = new Handler();
|
|
|
|
|
@ -53,6 +56,7 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
private TextView progressBarText;
|
|
|
|
|
private ScrollView mainHomeScrollView;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Tickers
|
|
|
|
|
private TextView pricePair1;
|
|
|
|
|
private TextView pricePair124hPercentage ;
|
|
|
|
|
@ -118,8 +122,8 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
|
|
|
|
ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
|
|
|
|
|
//binding = FragmentHomeBinding.inflate(inflater, container, false);
|
|
|
|
|
//View root = binding.getRoot();
|
|
|
|
|
// binding = FragmentHomeBinding.inflate(inflater, container, false);
|
|
|
|
|
// View root = binding.getRoot();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For the cache
|
|
|
|
|
@ -133,6 +137,16 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
progressBarText = root.findViewById(R.id.progressBarText);
|
|
|
|
|
mainHomeScrollView = root.findViewById(R.id.mainHomeScrollView);
|
|
|
|
|
|
|
|
|
|
LinearLayout todayThisMonthCard = root.findViewById(R.id.todayThisMonthCard);
|
|
|
|
|
LinearLayout exchange1View = root.findViewById(R.id.exchangeStats1Card);
|
|
|
|
|
LinearLayout exchange2View = root.findViewById(R.id.exchangeStats2Card);
|
|
|
|
|
LinearLayout exchange3View = root.findViewById(R.id.exchangeStats3Card);
|
|
|
|
|
LinearLayout exchange4View = root.findViewById(R.id.exchangeStats4Card);
|
|
|
|
|
LinearLayout log1View = root.findViewById(R.id.log1Card);
|
|
|
|
|
LinearLayout log2View = root.findViewById(R.id.log2Card);
|
|
|
|
|
LinearLayout log3View = root.findViewById(R.id.log3Card);
|
|
|
|
|
LinearLayout log4View = root.findViewById(R.id.log4Card);
|
|
|
|
|
|
|
|
|
|
// Bind text views
|
|
|
|
|
// Tickers
|
|
|
|
|
pricePair1 = root.findViewById(R.id.pricesCardPrice1);
|
|
|
|
|
@ -213,81 +227,88 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
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);
|
|
|
|
|
pricePair17dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
pricePair130dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
|
|
|
|
|
pricePair224hPercentage.setText(R.string.percentage_example);
|
|
|
|
|
pricePair27dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
pricePair230dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
|
|
|
|
|
pricePair324hPercentage.setText(R.string.percentage_example);
|
|
|
|
|
pricePair37dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
pricePair330dPercentage.setText(R.string.percentage_example);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pricePair124hPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair17dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair130dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
|
|
|
|
|
pricePair224hPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair27dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair230dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
|
|
|
|
|
pricePair324hPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair37dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
pricePair330dPercentage.setTextColor(Color.GREEN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Profits today and this month
|
|
|
|
|
profitsToday.setText(R.string.profits_today_example);
|
|
|
|
|
profitsThisMonth.setText(R.string.profits_this_month_example);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Exchange status
|
|
|
|
|
exchange1Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
|
|
|
exchange2Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
|
|
|
exchange3Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
|
|
|
exchange4Status.setImageResource(R.drawable.ic_green_circle_48);
|
|
|
|
|
|
|
|
|
|
exchange1Funds.setText(R.string.exchange_funds_example);
|
|
|
|
|
exchange2Funds.setText(R.string.exchange_funds_example);
|
|
|
|
|
exchange3Funds.setText(R.string.exchange_funds_example);
|
|
|
|
|
exchange4Funds.setText(R.string.exchange_funds_example);
|
|
|
|
|
|
|
|
|
|
exchange1FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
|
|
|
exchange2FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
|
|
|
exchange3FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
|
|
|
exchange4FundsPercentage.setText(R.string.exchange_funds_percentage_example);
|
|
|
|
|
|
|
|
|
|
exchange1WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
|
|
|
exchange2WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
|
|
|
exchange3WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
|
|
|
exchange4WorkersOnline.setText(R.string.exchange_workers_online_example);
|
|
|
|
|
|
|
|
|
|
exchange1WorkersLongShort.setText(R.string.exchange_workers_long_short_example);
|
|
|
|
|
exchange2WorkersLongShort.setText(R.string.exchange_workers_long_short_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
|
|
|
|
|
log1Content.setText(R.string.log_example);
|
|
|
|
|
log2Content.setText(R.string.log_example);
|
|
|
|
|
log3Content.setText(R.string.log_example);
|
|
|
|
|
log4Content.setText(R.string.log_example);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Listener for priceCard
|
|
|
|
|
todayThisMonthCard.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showTodayThisMonthPopupMenu(v);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Listener for exchanges card
|
|
|
|
|
exchange1View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showExchangePopupMenu(v, "binance");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
exchange2View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showExchangePopupMenu(v, "gateio");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
exchange3View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showExchangePopupMenu(v, "kucoin");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//Listener for exchanges card
|
|
|
|
|
exchange4View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showExchangePopupMenu(v, "okex");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Listener for last deals
|
|
|
|
|
lastTrades.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showLastTradesPopupMenu(v);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//Listener for log views
|
|
|
|
|
log1View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showLogPopupMenu(v, "binance");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log2View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showLogPopupMenu(v, "gateio");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log3View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showLogPopupMenu(v, "kucoin");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
log4View.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
|
showLogPopupMenu(v, "okex");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup task
|
|
|
|
|
handler = new Handler();
|
|
|
|
|
updateRunnable = new Runnable() {
|
|
|
|
|
@ -306,6 +327,81 @@ public class HomeFragment extends Fragment {
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showTodayThisMonthPopupMenu(View anchorView) {
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.today_this_month_menu, popupMenu.getMenu());
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
if (item.getItemId() == R.id.today_this_month_details) {
|
|
|
|
|
// Handle the "Details..." option
|
|
|
|
|
// For example, navigate to a details fragment
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
popupMenu.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showExchangePopupMenu(View anchorView, String exchange) {
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.exchange_popup_menu, popupMenu.getMenu());
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
if (item.getItemId() == R.id.exchangeStatus) {
|
|
|
|
|
// Handle the "Details..." option
|
|
|
|
|
// For example, navigate to a details fragment
|
|
|
|
|
return true;
|
|
|
|
|
} else if (item.getItemId() == R.id.exchangeCommands) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
popupMenu.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showLastTradesPopupMenu(View anchorView) {
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.last_trades_menu, popupMenu.getMenu());
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
if (item.getItemId() == R.id.last_trades_details) {
|
|
|
|
|
// Handle the "Details..." option
|
|
|
|
|
// For example, navigate to a details fragment
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
popupMenu.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showLogPopupMenu(View anchorView, String exchange) {
|
|
|
|
|
PopupMenu popupMenu = new PopupMenu(requireContext(), anchorView);
|
|
|
|
|
popupMenu.getMenuInflater().inflate(R.menu.logs_menu, popupMenu.getMenu());
|
|
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
if (item.getItemId() == R.id.log_details) {
|
|
|
|
|
// Handle the "Details..." option
|
|
|
|
|
// For example, navigate to a details fragment
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
popupMenu.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adds a plus sign if the percentage is positive
|
|
|
|
|
private String formatPercentage(double value) {
|
|
|
|
|
if (value>=0) {
|
|
|
|
|
|