Earner display complete
This commit is contained in:
parent
6963e31dc8
commit
b8f6cf1b4c
|
|
@ -8,6 +8,7 @@ import android.widget.TextView;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.dcav2gui.EarnerInterface;
|
||||
|
|
@ -26,37 +27,21 @@ public class EarnFragment extends Fragment {
|
|||
ViewGroup container, Bundle savedInstanceState) {
|
||||
com.example.dcav2gui.databinding.FragmentEarnersBinding binding = FragmentEarnersBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
EarnerInterface.EarnerGlobalData earnerData;
|
||||
|
||||
//Initialize status bar
|
||||
statusBar = root.findViewById(R.id.earners_status_bar);
|
||||
|
||||
EarnerViewModel earnerViewModel = new ViewModelProvider(this).get(EarnerViewModel.class);
|
||||
|
||||
earnerCardAdapter = new EarnerCardAdapter(binding.earnersCardsContainer);
|
||||
|
||||
// try {
|
||||
// earnerData = EarnerInterface.getEarnerGlobalData(true);
|
||||
// earnerCardAdapter.populateStatusBar(statusBar, earnerData);
|
||||
// earnerCardAdapter.updateData(earnerData.getEarnerList());
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
|
||||
|
||||
earnerViewModel.getEarnerData().observe(getViewLifecycleOwner(), earnerDataList -> {
|
||||
if (earnerDataList != null) {
|
||||
try {
|
||||
EarnerInterface.EarnerGlobalData earnerNewData = EarnerInterface.getEarnerGlobalData(true);
|
||||
if (earnerNewData != null) {
|
||||
earnerCardAdapter.populateStatusBar(statusBar, earnerNewData);
|
||||
earnerCardAdapter.updateData(earnerNewData.getEarnerList());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
earnerViewModel.getEarnerData().observe(getViewLifecycleOwner(), new Observer<EarnerInterface.EarnerGlobalData>() {
|
||||
@Override
|
||||
public void onChanged(EarnerInterface.EarnerGlobalData earnerGlobalData) {
|
||||
if (earnerGlobalData != null) {
|
||||
earnerCardAdapter.populateStatusBar(statusBar, earnerGlobalData);
|
||||
earnerCardAdapter.updateData(earnerGlobalData.getEarnerList());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.widget.TextView;
|
|||
import com.example.dcav2gui.EarnerInterface;
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
import com.example.dcav2gui.R;
|
||||
import com.example.dcav2gui.ui.home.HomeFragment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -57,9 +58,15 @@ public class EarnerCardAdapter {
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill the data fields with the earner's values
|
||||
*/
|
||||
broker.setText(earner.getBrokerName().toUpperCase(Locale.ROOT));
|
||||
tradingBalance.setText(String.format(Locale.ROOT,"%.2f", earner.getTradingBalance()));
|
||||
earningBalance.setText(String.format(Locale.ROOT, "%.2f", earner.getEarningBalance()));
|
||||
double occupation = earner.getEarningBalance()/(earner.getEarningBalance() + earner.getTradingBalance()) * 100;
|
||||
String percentageString = String.format(Locale.ROOT, "%.2f", occupation) + "%";
|
||||
percentage.setText(percentageString);
|
||||
|
||||
lastSubscription.setText(HomeFragment.timeStampConverter(earner.getLastSubscription().getAsJsonObject().get(earner.getBrokerName()).getAsDouble(), false));
|
||||
lastRedemption.setText(HomeFragment.timeStampConverter(earner.getLastRedemption().getAsJsonObject().get(earner.getBrokerName()).getAsDouble(), false));
|
||||
|
||||
cardLayout.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
|
|
@ -83,7 +90,6 @@ public class EarnerCardAdapter {
|
|||
|
||||
}
|
||||
|
||||
//Refactor for earners' status bar
|
||||
public void populateStatusBar(TextView statusBar, EarnerInterface.EarnerGlobalData earnerData) {
|
||||
double uptime = earnerData.getUptime();
|
||||
List<EarnerData> earnerList = earnerData.getEarnerList();
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@
|
|||
android:textSize="10sp" />
|
||||
<TextView
|
||||
android:id="@+id/earnerCardLastSubscriptionDateTime"
|
||||
android:layout_width="84dp"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="18dp"
|
||||
android:text="2025/03/08 04:20"
|
||||
android:textColor="@color/bright_green"
|
||||
|
|
@ -118,7 +118,7 @@
|
|||
android:textSize="10sp" />
|
||||
<TextView
|
||||
android:id="@+id/earnerCardLastRedemptionDateTime"
|
||||
android:layout_width="84dp"
|
||||
android:layout_width="96dp"
|
||||
android:layout_height="18dp"
|
||||
android:text="2025/03/08 04:20"
|
||||
android:textColor="@color/red"
|
||||
|
|
|
|||
Loading…
Reference in New Issue