Created
December 2, 2017 12:51
-
-
Save satadii11/45f049fbc44417aaa8355a0be09b44d0 to your computer and use it in GitHub Desktop.
This file contains 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
public class UserInfoFragment extends Fragment { | |
@Override | |
public void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mViewModel = ViewModelProviders.of(getActivity()).get(UserInfoViewModel.class); | |
mTvUserName.setText(mViewModel.getUserName()); | |
mTvWallet.setText(Formatter.formatCurrency(mViewModel.getWallet())); | |
ArrayAdapter<String> adapter = new ArrayAdapter<>( | |
getActivity(), | |
android.R.layout.simple_spinner_item, | |
mViewModel.getMonths() | |
); | |
adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); | |
mSpExpenses.setAdapter(adapter); | |
mSpExpenses.setOnItemClickListener((parent, view1, position, id) -> { | |
String month = parent.getItemAtPosition(position).toString(); | |
mTvExpense.setText(mViewModel.getAmountOn(month, Transaction.EXPENSE_TYPE)); | |
}); | |
mSpIncome.setAdapter(adapter); | |
mSpIncome.setOnItemClickListener((parent, view1, position, id) -> { | |
String month = parent.getItemAtPosition(position).toString(); | |
mTvIncome.setText(mViewModel.getAmountOn(month, Transaction.INCOME_TYPE)); | |
}); | |
} | |
} | |
public class UserInfoViewModel extends AndroidViewModel { | |
public UserInfoViewModel(Application app){ | |
super(app); | |
AppDatabase database = AppDatabase.getInstance(app); | |
mReports = database.getTransactionTable().getReports(); | |
mPref = new PreferenceManager(app); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment