Last active
May 11, 2019 14:43
-
-
Save Manikkumar1988/4a498adcd05bd642102a38c4cd71f847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ViewModelProvider.Factory fuelLogViewModelFactory; | |
private FuelLogViewModel fuelLogViewModel; | |
@Override | |
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
fuelLogViewModel = ViewModelProviders.of(getActivity(),fuelLogViewModelFactory) | |
.get(FuelLogViewModel.class); | |
observeForAverageConsumption(); | |
} | |
private void observeForAverageConsumption() { | |
fuelLogViewModel.getAverageFuelConsumption().observe(this, new Observer<FuelStat>() { | |
@Override | |
public void onChanged(FuelStat fuelStat) { | |
if(Objects.isNull(fuelStat)) { | |
averageConsumptionValue.setText(getText(R.string.empty_value)); | |
drivingCost.setText(getText(R.string.empty_value)); | |
totalDistance.setText(getText(R.string.empty_value)); | |
totalAmouunt.setText(getText(R.string.empty_value)); | |
totalFuelConsumption.setText(getText(R.string.empty_value)); | |
} else { | |
averageConsumptionValue.setText(String.valueOf(fuelStat.getAverageConsumption())); | |
drivingCost.setText(String.valueOf(fuelStat.getDrivingCost())); | |
totalDistance.setText(String.valueOf(fuelStat.getTotalDistance())); | |
totalAmouunt.setText(String.valueOf(fuelStat.getTotalAmount())); | |
totalFuelConsumption.setText(String.valueOf(fuelStat.getTotalFuelConsumption())); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment