(mostly) decent worker card view

This commit is contained in:
Nicolás Sánchez 2024-12-17 11:00:33 -03:00
parent 692f833ec5
commit d5e3a3406a
5 changed files with 46 additions and 16 deletions

View File

@ -418,6 +418,8 @@ public class InstanceInterface {
JsonObject value = jsonObject.get(key).getAsJsonObject(); JsonObject value = jsonObject.get(key).getAsJsonObject();
try { try {
boolean isShort = value.has("is_short") && value.get("is_short").isJsonPrimitive() && value.get("is_short").getAsBoolean(); boolean isShort = value.has("is_short") && value.get("is_short").isJsonPrimitive() && value.get("is_short").getAsBoolean();
boolean isBoosted = value.has("is_boosted") && value.get("is_boosted").isJsonPrimitive() && value.get("is_boosted").getAsBoolean();
boolean isAutoSwitchEnabled = value.has("is_auto_switch_enabled") && value.get("is_auto_switch_enabled").isJsonPrimitive() && value.get("is_auto_switch_enabled").getAsBoolean();
boolean stopWhenProfit = value.has("stop_when_profit") && value.get("stop_when_profit").isJsonPrimitive() && value.get("stop_when_profit").getAsBoolean(); boolean stopWhenProfit = value.has("stop_when_profit") && value.get("stop_when_profit").isJsonPrimitive() && value.get("stop_when_profit").getAsBoolean();
double orderSize = value.has("order_size") && value.get("order_size").isJsonPrimitive() ? value.get("order_size").getAsDouble() : 0.0; double orderSize = value.has("order_size") && value.get("order_size").isJsonPrimitive() ? value.get("order_size").getAsDouble() : 0.0;
double quoteSpent = value.has("quote_spent") && value.get("quote_spent").isJsonPrimitive() ? value.get("quote_spent").getAsDouble() : 0.0; double quoteSpent = value.has("quote_spent") && value.get("quote_spent").isJsonPrimitive() ? value.get("quote_spent").getAsDouble() : 0.0;
@ -464,6 +466,8 @@ public class InstanceInterface {
valueToReturn.add(new WorkerStatsData( valueToReturn.add(new WorkerStatsData(
key, key,
isShort, isShort,
isBoosted,
isAutoSwitchEnabled,
stopWhenProfit, stopWhenProfit,
orderSize, orderSize,
quoteSpent, quoteSpent,
@ -635,6 +639,7 @@ public class InstanceInterface {
false, false,
false, false,
false, false,
workerStatsData.getStopWhenProfit(),
workerStatsData.getOldLongDictionary()); workerStatsData.getOldLongDictionary());
workerDataList.add(workerData); workerDataList.add(workerData);
} }
@ -788,6 +793,8 @@ public class InstanceInterface {
public static class WorkerStatsData { public static class WorkerStatsData {
private final String pair; private final String pair;
private final boolean isShort; private final boolean isShort;
private final boolean isBoosted;
private final boolean autoSwitchEnabled;
private final boolean stopWhenProfit; private final boolean stopWhenProfit;
private final double orderSize; private final double orderSize;
private final double quoteSpent; private final double quoteSpent;
@ -818,9 +825,11 @@ public class InstanceInterface {
private final OldLongDictionary oldLongDictionary; //Change type private final OldLongDictionary oldLongDictionary; //Change type
private final String statusString; private final String statusString;
public WorkerStatsData(String pair, boolean isShort, boolean stopWhenProfit, double orderSize, double quoteSpent, double baseBought, int soAmount, int numberOfSafetyOrders, int tpMode, String profitTable, double startTime, double startPrice, double dealStartTime, double dealUptime, double totalUptime, double price, double takeProfitPrice, double nextSoPrice, String tpOrderId, JsonObject takeProfitOrder, String soOrderId, JsonObject safetyOrder, double feesPaidInBase, double feesPaidInQuote, double partialProfit, String safetyPriceTable, String dealOrderHistory, String pauseReason, OldLongDictionary oldLong, String statusString) { public WorkerStatsData(String pair, boolean isShort, boolean isBoosted, boolean autoSwitchEnabled, boolean stopWhenProfit, double orderSize, double quoteSpent, double baseBought, int soAmount, int numberOfSafetyOrders, int tpMode, String profitTable, double startTime, double startPrice, double dealStartTime, double dealUptime, double totalUptime, double price, double takeProfitPrice, double nextSoPrice, String tpOrderId, JsonObject takeProfitOrder, String soOrderId, JsonObject safetyOrder, double feesPaidInBase, double feesPaidInQuote, double partialProfit, String safetyPriceTable, String dealOrderHistory, String pauseReason, OldLongDictionary oldLong, String statusString) {
this.pair = pair; this.pair = pair;
this.isShort = isShort; this.isShort = isShort;
this.isBoosted = isBoosted;
this.autoSwitchEnabled = autoSwitchEnabled;
this.stopWhenProfit = stopWhenProfit; this.stopWhenProfit = stopWhenProfit;
this.orderSize = orderSize; this.orderSize = orderSize;
this.quoteSpent = quoteSpent; this.quoteSpent = quoteSpent;
@ -853,6 +862,8 @@ public class InstanceInterface {
public String getPair() {return pair; } public String getPair() {return pair; }
public boolean getIsShort() { return isShort; } public boolean getIsShort() { return isShort; }
public boolean getIsBoosted() { return isBoosted; }
public boolean getAutoSwitchEnabled() { return autoSwitchEnabled; }
public boolean getStopWhenProfit() { return stopWhenProfit; } public boolean getStopWhenProfit() { return stopWhenProfit; }
public double getOrderSize() { return orderSize; } public double getOrderSize() { return orderSize; }
public double getQuoteSpent() { return quoteSpent; } public double getQuoteSpent() { return quoteSpent; }

View File

@ -16,11 +16,12 @@ public class WorkerData {
private final boolean isBoosted; private final boolean isBoosted;
private final boolean isAuto; private final boolean isAuto;
private final boolean isPaused; private final boolean isPaused;
private final boolean stopWhenProfit;
private final InstanceInterface.OldLongDictionary oldLongDictionary; private final InstanceInterface.OldLongDictionary oldLongDictionary;
public WorkerData(String pair, int amountOfSafetyOrders, int maxSafetyOrders, double uptime, public WorkerData(String pair, int amountOfSafetyOrders, int maxSafetyOrders, double uptime,
double nextSoPrice, double price, double takeProfitPrice, double totalAmountOfQuote, double totalAmountOfBase, boolean isShort, double nextSoPrice, double price, double takeProfitPrice, double totalAmountOfQuote, double totalAmountOfBase, boolean isShort,
boolean isBoosted, boolean isAuto, boolean isPaused, boolean isBoosted, boolean isAuto, boolean isPaused, boolean stopWhenProfit,
InstanceInterface.OldLongDictionary oldLongDictionary) { InstanceInterface.OldLongDictionary oldLongDictionary) {
// TODO: Add total_amount_of_quote and total_amount_of_base // TODO: Add total_amount_of_quote and total_amount_of_base
@ -37,6 +38,7 @@ public class WorkerData {
this.isBoosted = isBoosted; this.isBoosted = isBoosted;
this.isAuto = isAuto; this.isAuto = isAuto;
this.isPaused = isPaused; this.isPaused = isPaused;
this.stopWhenProfit = stopWhenProfit;
this.oldLongDictionary = oldLongDictionary; this.oldLongDictionary = oldLongDictionary;
} }
@ -53,5 +55,6 @@ public class WorkerData {
public boolean isBoosted() { return isBoosted; } public boolean isBoosted() { return isBoosted; }
public boolean isAuto() { return isAuto; } public boolean isAuto() { return isAuto; }
public boolean isPaused() { return isPaused; } public boolean isPaused() { return isPaused; }
public boolean getStopWhenProfit() { return stopWhenProfit; }
public InstanceInterface.OldLongDictionary getOldLongDictionary() { return oldLongDictionary; } public InstanceInterface.OldLongDictionary getOldLongDictionary() { return oldLongDictionary; }
} }

View File

@ -1,23 +1,15 @@
package com.example.dcav2gui.ui.exchanges.adapters; package com.example.dcav2gui.ui.exchanges.adapters;
import static java.lang.Math.abs; import static java.lang.Math.abs;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.shapes.Shape;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.view.menu.MenuView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.example.dcav2gui.R; import com.example.dcav2gui.R;
import com.example.dcav2gui.ui.exchanges.WorkerData; import com.example.dcav2gui.ui.exchanges.WorkerData;
@ -25,7 +17,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import android.graphics.drawable.Drawable;
public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.WorkerViewHolder> { public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.WorkerViewHolder> {
@ -45,8 +36,6 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
@Override @Override
public void onBindViewHolder(@NonNull WorkerViewHolder holder, int position) { public void onBindViewHolder(@NonNull WorkerViewHolder holder, int position) {
//TODO: progress bar color //TODO: progress bar color
//TODO: auto-switch
//TODO: is_boosted
WorkerData worker = workerDataList.get(position); WorkerData worker = workerDataList.get(position);
holder.pair.setText(worker.getPair()); holder.pair.setText(worker.getPair());
@ -63,7 +52,7 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
String percentage = String.format(Locale.ROOT, "%.2f",abs(worker.getTakeProfitPrice()- worker.getPrice())/worker.getPrice()*100)+"%"; String percentage = String.format(Locale.ROOT, "%.2f",abs(worker.getTakeProfitPrice()- worker.getPrice())/worker.getPrice()*100)+"%";
holder.percentage.setText(percentage); holder.percentage.setText(percentage);
String safetyOrders = worker.getAmountOfSafetyOrders() + " / " + worker.getMaxSafetyOrders(); String safetyOrders = worker.getAmountOfSafetyOrders()-1 + " / " + worker.getMaxSafetyOrders();
holder.safetyOrders.setText(safetyOrders); holder.safetyOrders.setText(safetyOrders);
holder.uptime.setText(formatSeconds(worker.getUptime())); holder.uptime.setText(formatSeconds(worker.getUptime()));
@ -73,6 +62,22 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
double breakEven = worker.getTotalAmountOfQuote()/worker.getTotalAmountOfBase(); double breakEven = worker.getTotalAmountOfQuote()/worker.getTotalAmountOfBase();
System.err.println("breakEven: "+breakEven); System.err.println("breakEven: "+breakEven);
if (worker.isBoosted()) {
holder.workerCardIcon.setVisibility(View.VISIBLE);
} else {
holder.workerCardIcon.setVisibility(View.INVISIBLE);
}
if (worker.getStopWhenProfit()) {
holder.workerStatusString.setText("LAST DEAL");
} else if (worker.isPaused()) {
holder.cardLayout.setBackgroundColor(Color.parseColor("#C5C281"));
} else if (worker.isAuto()) {
holder.workerStatusString.setText("AUTO");
} else {
holder.workerStatusString.setText("");
}
// int color; // int color;
// if (worker.getNextSoPrice()< worker.getTakeProfitPrice()) { // if (worker.getNextSoPrice()< worker.getTakeProfitPrice()) {
// if (worker.getPrice()>=breakEven){ // if (worker.getPrice()>=breakEven){
@ -95,7 +100,7 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
long minutes = TimeUnit.SECONDS.toMinutes((long) seconds) % 60; long minutes = TimeUnit.SECONDS.toMinutes((long) seconds) % 60;
long secs = (long) (seconds % 60); long secs = (long) (seconds % 60);
return String.format(Locale.ROOT,"%03d:%02d:%02d:%02d", days, hours, minutes, secs); return String.format(Locale.ROOT,"%03d:%02d:%02d:%02d", days, hours, minutes, secs).replaceFirst("^0+(?!$)", "");
} }
@ -120,6 +125,7 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
ProgressBar progressBar; ProgressBar progressBar;
TextView workerStatusString; TextView workerStatusString;
ImageView workerCardIcon; ImageView workerCardIcon;
LinearLayout cardLayout;
public WorkerViewHolder(@NonNull View itemView) { public WorkerViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -133,6 +139,8 @@ public class WorkerCardAdapter extends RecyclerView.Adapter<WorkerCardAdapter.Wo
progressBar = itemView.findViewById(R.id.workerCardProgressBar); progressBar = itemView.findViewById(R.id.workerCardProgressBar);
workerStatusString = itemView.findViewById(R.id.workerCardStatusString); workerStatusString = itemView.findViewById(R.id.workerCardStatusString);
workerCardIcon = itemView.findViewById(R.id.workerCardIcon); workerCardIcon = itemView.findViewById(R.id.workerCardIcon);
cardLayout = itemView.findViewById(R.id.workerCard);
} }
} }
} }

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/paused_trader_background"/>
<corners android:radius="8dp"/>
<stroke android:color="@color/stroke_color" android:width="1dp"/>
</shape>

View File

@ -17,5 +17,6 @@
<color name="dark_green">#006A00</color> <color name="dark_green">#006A00</color>
<color name="secondary_text_color">#FF424242</color> <color name="secondary_text_color">#FF424242</color>
<color name="card_background_color">#FFF6F6F6</color> <color name="card_background_color">#FFF6F6F6</color>
<color name="paused_trader_background">#C5C281</color>
<color name="stroke_color">#FF000000</color> <color name="stroke_color">#FF000000</color>
</resources> </resources>