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