Skeleton EarnerCardAdapter
This commit is contained in:
parent
48e2eaa125
commit
8bc3fe4cfc
|
|
@ -1,4 +1,99 @@
|
|||
package com.example.dcav2gui.ui.earners;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.example.dcav2gui.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class EarnerCardAdapter {
|
||||
|
||||
private final ViewGroup container;
|
||||
|
||||
public EarnerCardAdapter(ViewGroup container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public void updateData(List<EarnerData> earnerDataList) {
|
||||
container.removeAllViews(); // Clear existing views
|
||||
for (EarnerData earner : earnerDataList) {
|
||||
View cardView = LayoutInflater.from(container.getContext()).inflate(R.layout.earner_card, container, false);
|
||||
addCard(earner, cardView);
|
||||
container.addView(cardView);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface OnCardLongClickListener {
|
||||
void onCardLongClick(String pair, View v);
|
||||
}
|
||||
|
||||
private EarnerCardAdapter.OnCardLongClickListener onCardLongClickListener;
|
||||
|
||||
public void setOnCardLongClickListener(EarnerCardAdapter.OnCardLongClickListener listener) {
|
||||
this.onCardLongClickListener = listener;
|
||||
}
|
||||
|
||||
private void addCard(EarnerData earner, View view) {
|
||||
TextView broker = view.findViewById(R.id.earnerCardExchange);
|
||||
TextView tradingBalance = view.findViewById(R.id.earnerCardTradingBalanceValue);
|
||||
TextView earningBalance = view.findViewById(R.id.earnerCardEarningBalanceValue);
|
||||
TextView percentage = view.findViewById(R.id.earnerCardPercentage);
|
||||
TextView lastSubscription = view.findViewById(R.id.earnerCardLastSubscriptionDateTime);
|
||||
TextView lastRedemption = view.findViewById(R.id.earnerCardLastRedemptionDateTime);
|
||||
LinearLayout cardLayout = view.findViewById(R.id.earnerCard);
|
||||
|
||||
if (broker == null || tradingBalance == null || earningBalance == null || lastSubscription == null ||
|
||||
lastRedemption == null || percentage == null ||cardLayout == null) {
|
||||
System.out.println("One or more views are null");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill the data fields with the earner's values
|
||||
*/
|
||||
|
||||
cardLayout.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (onCardLongClickListener != null) {
|
||||
onCardLongClickListener.onCardLongClick(earner.getBrokerName(), v);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static String formatSeconds(double seconds) {
|
||||
long days = TimeUnit.SECONDS.toDays((long) seconds);
|
||||
long hours = TimeUnit.SECONDS.toHours((long) seconds) % 24;
|
||||
long minutes = TimeUnit.SECONDS.toMinutes((long) seconds) % 60;
|
||||
long secs = (long) (seconds % 60);
|
||||
|
||||
return String.format(Locale.ROOT,"%03d:%02d:%02d:%02d", days, hours, minutes, secs);
|
||||
|
||||
}
|
||||
|
||||
//Refactor for earners' status bar
|
||||
public static void populateStatusBar(TextView statusBar, InstanceInterface.ExchangeStatsData exchangeData) {
|
||||
int amountOfWorkers = exchangeData.getOnlineWorkers();
|
||||
//double lastSeen = exchangeData.getLastSeen();
|
||||
int longWorkers = exchangeData.getLongWorkers();
|
||||
int shortWorkers = exchangeData.getShortWorkers();
|
||||
int safetyOrdersSent = exchangeData.getSafetyOrdersSent();
|
||||
int maxSafetyOrders = exchangeData.getMaxSafetyOrders();
|
||||
|
||||
String percentage = String.format(Locale.ROOT, "%.2f", (double) safetyOrdersSent/maxSafetyOrders*100);
|
||||
String statusBarText = amountOfWorkers + " traders online (" + longWorkers + "/" + shortWorkers + ") - Occupancy " + percentage + "%";
|
||||
statusBar.setText(statusBarText);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
android:clickable="true"
|
||||
android:longClickable="true">
|
||||
<LinearLayout
|
||||
android:id="@+id/EarnerCard"
|
||||
android:id="@+id/earnerCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="vertical"
|
||||
|
|
|
|||
Loading…
Reference in New Issue