1 |
efrain |
1 |
package com.cesams.twogetskills.fragment;
|
|
|
2 |
|
|
|
3 |
import android.content.Context;
|
|
|
4 |
import android.os.Build;
|
|
|
5 |
import android.os.Bundle;
|
|
|
6 |
import android.text.Html;
|
|
|
7 |
import android.util.Log;
|
|
|
8 |
import android.view.LayoutInflater;
|
|
|
9 |
import android.view.View;
|
|
|
10 |
import android.view.ViewGroup;
|
5 |
gabriel |
11 |
import android.widget.TextView;
|
1 |
efrain |
12 |
|
|
|
13 |
import androidx.annotation.NonNull;
|
|
|
14 |
import androidx.annotation.Nullable;
|
|
|
15 |
import androidx.fragment.app.Fragment;
|
|
|
16 |
import androidx.lifecycle.LifecycleOwner;
|
|
|
17 |
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
18 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
19 |
|
|
|
20 |
import com.cesams.twogetskills.Constants;
|
|
|
21 |
import com.cesams.twogetskills.R;
|
|
|
22 |
import com.cesams.twogetskills.adapter.QuizRangeSimpleAnswerListViewAdapter;
|
|
|
23 |
import com.cesams.twogetskills.pojo.AnswerRange;
|
|
|
24 |
import com.cesams.twogetskills.entity.Question;
|
|
|
25 |
import com.cesams.twogetskills.pojo.QuizResponse;
|
|
|
26 |
import com.cesams.twogetskills.skeleton.IQuizActivity;
|
|
|
27 |
|
|
|
28 |
import java.util.ArrayList;
|
|
|
29 |
import java.util.List;
|
|
|
30 |
|
|
|
31 |
public class QuizRangeSimpleFragment extends Fragment implements LifecycleOwner {
|
|
|
32 |
private final String TAG = "C2GS - QuizRangeFrag";
|
|
|
33 |
private IQuizActivity iQuizActivity;
|
|
|
34 |
private RecyclerView recyclerView;
|
|
|
35 |
private QuizRangeSimpleAnswerListViewAdapter adapter;
|
|
|
36 |
private Question mQuestion;
|
|
|
37 |
private List<AnswerRange> mAnswers;
|
|
|
38 |
private List<QuizResponse> mQuizResponses;
|
5 |
gabriel |
39 |
private TextView preguntas;
|
1 |
efrain |
40 |
|
5 |
gabriel |
41 |
|
1 |
efrain |
42 |
// data is passed into the constructor
|
|
|
43 |
public QuizRangeSimpleFragment(Context context) {
|
|
|
44 |
iQuizActivity = (IQuizActivity) context ;
|
|
|
45 |
this.mQuestion = iQuizActivity.getQuestionActive();
|
|
|
46 |
this.mQuizResponses = iQuizActivity.getQuizResponses();
|
|
|
47 |
this.mAnswers = new ArrayList<>();
|
|
|
48 |
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
@Override
|
|
|
52 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
53 |
|
|
|
54 |
return inflater.inflate(R.layout.fragment_quiz_range_simple_answer, container, false);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
@Override
|
|
|
58 |
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
59 |
super.onViewCreated(view, savedInstanceState);
|
|
|
60 |
|
|
|
61 |
mAnswers = new ArrayList<>();
|
|
|
62 |
|
|
|
63 |
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
|
|
|
64 |
adapter = new QuizRangeSimpleAnswerListViewAdapter(getActivity(), mQuestion, mAnswers, mQuizResponses);
|
|
|
65 |
|
|
|
66 |
|
5 |
gabriel |
67 |
//justifyTextView = getView().findViewById(R.id.justifytext_quiz_range_simple_answer);
|
|
|
68 |
preguntas =getView().findViewById(R.id.textView8);
|
1 |
efrain |
69 |
recyclerView = (RecyclerView) getView().findViewById(R.id.list_quiz_range_simple_answer);
|
|
|
70 |
recyclerView.setAdapter(adapter);
|
|
|
71 |
recyclerView.setLayoutManager( gridLayoutManager);
|
|
|
72 |
recyclerView.setHasFixedSize(true);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
@Override
|
|
|
76 |
public void onResume() {
|
|
|
77 |
super.onResume();
|
|
|
78 |
|
|
|
79 |
Log.d(TAG, "onResume");
|
|
|
80 |
loadData();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
@Override
|
|
|
87 |
public void onHiddenChanged(boolean hidden) {
|
|
|
88 |
super.onHiddenChanged(hidden);
|
|
|
89 |
|
|
|
90 |
Log.d(TAG, "onHiddenChanged : " + (hidden ? "true" : "false"));
|
|
|
91 |
|
|
|
92 |
if(!hidden) {
|
|
|
93 |
loadData();
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
private void loadData()
|
|
|
98 |
{
|
|
|
99 |
if(adapter != null) {
|
|
|
100 |
|
|
|
101 |
mQuestion = iQuizActivity.getQuestionActive();
|
5 |
gabriel |
102 |
preguntas.setText(Html.fromHtml(mQuestion.getText(), Html.FROM_HTML_MODE_COMPACT));
|
1 |
efrain |
103 |
|
|
|
104 |
mAnswers.clear();
|
|
|
105 |
int max = 0;
|
5 |
gabriel |
106 |
switch (mQuestion.getType()) {
|
|
|
107 |
case Constants.QUESTION_TYPE_RANGE_1_5:
|
|
|
108 |
max = 5;
|
|
|
109 |
break;
|
|
|
110 |
case Constants.QUESTION_TYPE_RANGE_1_6:
|
|
|
111 |
max = 6;
|
|
|
112 |
break;
|
|
|
113 |
case Constants.QUESTION_TYPE_RANGE_1_10:
|
|
|
114 |
max = 10;
|
|
|
115 |
break;
|
|
|
116 |
default:
|
|
|
117 |
max = 0;
|
|
|
118 |
break;
|
1 |
efrain |
119 |
}
|
|
|
120 |
for (int i = 1; i <= max; i++) {
|
|
|
121 |
AnswerRange answerRange = new AnswerRange(i, String.valueOf(i));
|
|
|
122 |
|
|
|
123 |
mAnswers.add(answerRange);
|
|
|
124 |
}
|
|
|
125 |
adapter.resetSelection();
|
|
|
126 |
adapter.notifyDataSetChanged();
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
}
|
|
|
130 |
}
|