in java/app/app/src/main/java/com/example/app/components/DashboardFragment.java [39:103]
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_dashboard, container, false);
//Set up TextView with a default message.
welcomeUser = view.findViewById(R.id.textview_welcome_user);
APIInfo api = new APIInfo();
Amplify.Auth.fetchAuthSession(
result -> {
AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) result;
switch(cognitoAuthSession.getIdentityId().getType()) {
case SUCCESS:
// Get a valid user JWT.
String accessToken = cognitoAuthSession.getUserPoolTokens().getValue().getIdToken();
api.getPersonalInfo(getContext(), accessToken, new UserInfoRunInterface() {
@Override
public void run(User user) {
// Refresh the TextView with a personalized message with it's name.
welcomeUser.setText("Hola, " + user.getName().toUpperCase() + " \uD83D\uDC4B");
}
});
break;
case FAILURE:
Log.e("ExampleAPP", "IdentityId not present because: " + cognitoAuthSession.getIdentityId().getError().toString());
}
},
error -> {
Log.e("ExampleAPP", error.toString());
}
);
/** SUBJECTS LIST **/
ArrayList<Subject> subjectArrayList = new ArrayList<>();
RecyclerView subjectRecyclerView = view.findViewById(R.id.subject_list_recycler_view);
subjectRecyclerView.setHasFixedSize(true);
subjectRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false));
SubjectListRecyclerViewAdapter adapterSubjectLIst = new SubjectListRecyclerViewAdapter(subjectArrayList);
api.getSubjectList(getContext(), new SubjectListRunInterface() {
@Override
public void run(ArrayList<Subject> subject) {
for (Subject each : subject){
subjectArrayList.add(each);
}
subjectRecyclerView.setAdapter(adapterSubjectLIst);
adapterSubjectLIst.notifyDataSetChanged();
}
});
int largeSubjectsList = getResources().getDimensionPixelSize(R.dimen.grid_spacing);
int smallSubjectsLists = getResources().getDimensionPixelSize(R.dimen.grid_spacing_small);
subjectRecyclerView.addItemDecoration(new SubjectListGridItemDecoration(largeSubjectsList, smallSubjectsLists));
/** END SUBJECTS LIST **/
return view;
}