| 2 |
gabriel |
1 |
package com.cesams.twogetskills.fragment;
|
|
|
2 |
|
|
|
3 |
import android.os.Bundle;
|
|
|
4 |
|
|
|
5 |
import androidx.fragment.app.Fragment;
|
|
|
6 |
import androidx.lifecycle.LifecycleOwner;
|
|
|
7 |
import androidx.lifecycle.Observer;
|
|
|
8 |
import androidx.lifecycle.ViewModelProvider;
|
|
|
9 |
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
10 |
import androidx.recyclerview.widget.RecyclerView;
|
|
|
11 |
|
|
|
12 |
import android.util.Log;
|
| 8 |
gabriel |
13 |
import android.view.DragEvent;
|
| 2 |
gabriel |
14 |
import android.view.LayoutInflater;
|
|
|
15 |
import android.view.View;
|
|
|
16 |
import android.view.ViewGroup;
|
| 8 |
gabriel |
17 |
import android.widget.EditText;
|
| 2 |
gabriel |
18 |
import android.widget.TextView;
|
| 8 |
gabriel |
19 |
import android.widget.Toast;
|
| 2 |
gabriel |
20 |
|
|
|
21 |
import com.cesams.twogetskills.R;
|
| 8 |
gabriel |
22 |
import com.cesams.twogetskills.activity.MainActivity;
|
| 2 |
gabriel |
23 |
import com.cesams.twogetskills.adapter.CapsuleListViewAdapter;
|
|
|
24 |
import com.cesams.twogetskills.adapter.CardViewAdapter;
|
| 4 |
gabriel |
25 |
import com.cesams.twogetskills.adapter.TabsCapsulesAdapter;
|
| 2 |
gabriel |
26 |
import com.cesams.twogetskills.dao.CapsuleDao;
|
|
|
27 |
import com.cesams.twogetskills.dao.ProgressDao;
|
|
|
28 |
import com.cesams.twogetskills.dao.TopicDao;
|
|
|
29 |
import com.cesams.twogetskills.entity.Capsule;
|
|
|
30 |
import com.cesams.twogetskills.entity.Progress;
|
|
|
31 |
import com.cesams.twogetskills.entity.Topic;
|
|
|
32 |
import com.cesams.twogetskills.skeleton.ITwoGetSkills;
|
|
|
33 |
import com.cesams.twogetskills.viewmodel.CapsuleViewModel;
|
|
|
34 |
|
|
|
35 |
import java.util.ArrayList;
|
|
|
36 |
import java.util.HashMap;
|
|
|
37 |
import java.util.List;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* A simple {@link Fragment} subclass.
|
|
|
41 |
* Use the {@link WelcomeFragment#newInstance} factory method to
|
|
|
42 |
* create an instance of this fragment.
|
|
|
43 |
*/
|
|
|
44 |
public class WelcomeFragment extends Fragment implements CapsuleListViewAdapter.ItemClickListener, LifecycleOwner {
|
|
|
45 |
|
|
|
46 |
TextView username;
|
|
|
47 |
private ITwoGetSkills iTwoGetSkills;
|
|
|
48 |
ArrayList<HashMap<String, String>> capsuleList;
|
|
|
49 |
private CardViewAdapter adapter;
|
| 4 |
gabriel |
50 |
private TabsCapsulesAdapter adapter2;
|
|
|
51 |
RecyclerView capsulas, categorizados;
|
| 8 |
gabriel |
52 |
EditText busqueda; TextView textowelcome;
|
| 2 |
gabriel |
53 |
|
|
|
54 |
|
|
|
55 |
public WelcomeFragment() {
|
|
|
56 |
// Required empty public constructor
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public static WelcomeFragment newInstance() {
|
|
|
60 |
WelcomeFragment fragment = new WelcomeFragment();
|
|
|
61 |
return fragment;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
@Override
|
|
|
65 |
public void onCreate(Bundle savedInstanceState) {
|
|
|
66 |
super.onCreate(savedInstanceState);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
@Override
|
|
|
70 |
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
71 |
Bundle savedInstanceState) {
|
|
|
72 |
|
| 8 |
gabriel |
73 |
|
| 2 |
gabriel |
74 |
iTwoGetSkills = (ITwoGetSkills) getActivity();
|
| 8 |
gabriel |
75 |
iTwoGetSkills.showNavigationAndToolbar();
|
| 2 |
gabriel |
76 |
|
|
|
77 |
View view= inflater.inflate(R.layout.fragment_welcome, container, false);
|
|
|
78 |
|
|
|
79 |
username=view.findViewById(R.id.textView14);
|
| 8 |
gabriel |
80 |
textowelcome= view.findViewById(R.id.textView15);
|
|
|
81 |
busqueda=view.findViewById(R.id.busqueda);
|
|
|
82 |
capsuleList = new ArrayList<>();
|
| 2 |
gabriel |
83 |
|
|
|
84 |
username.setText("¡Hola, "+(iTwoGetSkills.getPreference().getFirstName() +"!"));
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
loadData();
|
|
|
88 |
|
| 8 |
gabriel |
89 |
busqueda.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
90 |
@Override
|
|
|
91 |
public void onFocusChange(View v, boolean hasFocus) {
|
|
|
92 |
if(hasFocus)
|
|
|
93 |
{
|
|
|
94 |
capsulas.setVisibility(View.GONE);
|
|
|
95 |
username.setVisibility(View.GONE);
|
|
|
96 |
textowelcome.setVisibility(View.GONE);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
});
|
|
|
101 |
|
|
|
102 |
|
| 2 |
gabriel |
103 |
adapter = new CardViewAdapter(getContext(),capsuleList);
|
| 4 |
gabriel |
104 |
adapter2 = new TabsCapsulesAdapter(getContext(),capsuleList);
|
| 2 |
gabriel |
105 |
|
|
|
106 |
capsulas = view.findViewById(R.id.capsulescontinuos);
|
|
|
107 |
GridLayoutManager layoutausar = new GridLayoutManager(getContext(),1,GridLayoutManager.HORIZONTAL, false);
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
capsulas.setLayoutManager(layoutausar);
|
|
|
111 |
capsulas.setAdapter(adapter);
|
|
|
112 |
|
| 4 |
gabriel |
113 |
categorizados = view.findViewById(R.id.categorizados);
|
|
|
114 |
GridLayoutManager layoutcategoria = new GridLayoutManager(getContext(),1,GridLayoutManager.VERTICAL, false);
|
|
|
115 |
categorizados.setLayoutManager(layoutcategoria);
|
|
|
116 |
categorizados.setAdapter(adapter2);
|
|
|
117 |
|
| 8 |
gabriel |
118 |
categorizados.setOnFlingListener(new RecyclerView.OnFlingListener() {
|
|
|
119 |
@Override
|
|
|
120 |
public boolean onFling(int velocityX, int velocityY) {
|
|
|
121 |
|
|
|
122 |
if (categorizados.canScrollVertically(-1) ) {
|
|
|
123 |
|
|
|
124 |
Log.e("Se activa", "On fling");
|
|
|
125 |
capsulas.setVisibility(View.GONE);
|
|
|
126 |
username.setVisibility(View.GONE);
|
|
|
127 |
textowelcome.setVisibility(View.GONE);
|
|
|
128 |
}else
|
|
|
129 |
{
|
|
|
130 |
capsulas.setVisibility(View.VISIBLE);
|
|
|
131 |
username.setVisibility(View.VISIBLE);
|
|
|
132 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
return false;
|
|
|
136 |
}
|
|
|
137 |
});
|
|
|
138 |
|
|
|
139 |
/* categorizados.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
|
|
140 |
@Override
|
|
|
141 |
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
|
|
142 |
|
|
|
143 |
if (!categorizados.canScrollVertically(-1)) {
|
|
|
144 |
// Toast.makeText(getActivity(), "Last", Toast.LENGTH_LONG).show();
|
|
|
145 |
capsulas.setVisibility(View.VISIBLE);
|
|
|
146 |
username.setVisibility(View.VISIBLE);
|
|
|
147 |
textowelcome.setVisibility(View.VISIBLE);
|
|
|
148 |
Log.e("On scroll"," se activa");
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
}
|
|
|
152 |
});
|
|
|
153 |
*/
|
| 2 |
gabriel |
154 |
return view;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
private void loadData()
|
|
|
159 |
{
|
|
|
160 |
|
|
|
161 |
TopicDao topicDao = iTwoGetSkills.getDatabase().getTopicDao();
|
|
|
162 |
ArrayList<Topic> dbTopics = (ArrayList<Topic>) topicDao.selectAll();
|
|
|
163 |
|
|
|
164 |
List<Capsule> dbCapsules;
|
|
|
165 |
CapsuleDao capsuleDao = iTwoGetSkills.getDatabase().getCapsuleDao();
|
|
|
166 |
|
|
|
167 |
for (Topic dbTopic : dbTopics) {
|
|
|
168 |
|
|
|
169 |
dbCapsules = capsuleDao.selectAllByTopicUuid(dbTopic.getUuid());
|
|
|
170 |
|
|
|
171 |
Capsule capsule;
|
|
|
172 |
Progress progress;
|
|
|
173 |
ProgressDao progressDao = iTwoGetSkills.getDatabase().getProgressDao();
|
|
|
174 |
|
|
|
175 |
HashMap<String, String> m_li;
|
|
|
176 |
|
|
|
177 |
for(Capsule dbCapsule : dbCapsules)
|
|
|
178 |
{
|
|
|
179 |
capsule = new Capsule();
|
|
|
180 |
capsule.setTopicUuid(dbCapsule.getTopicUuid());
|
|
|
181 |
capsule.setUuid(dbCapsule.getUuid());
|
|
|
182 |
capsule.setName(dbCapsule.getName());
|
|
|
183 |
capsule.setDescription(dbCapsule.getDescription());
|
|
|
184 |
capsule.setImage(dbCapsule.getImage());
|
|
|
185 |
capsule.setPosition(dbCapsule.getPosition());
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
m_li = new HashMap<>();
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
//m_li.put("copyright",copy);
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
progress = progressDao.selectByCapsuleUuid(capsule.getUuid());
|
|
|
196 |
if(progress != null) {
|
|
|
197 |
capsule.setCompleted( progress.getCompleted());
|
|
|
198 |
capsule.setViewSlides(progress.getViewSlides());
|
|
|
199 |
|
|
|
200 |
capsule.setTotalSlides( progress.getTotalSlides());
|
|
|
201 |
capsule.setProgress(progress.getProgress());
|
|
|
202 |
|
|
|
203 |
m_li.put("view", String.valueOf(progress.getViewSlides()));
|
|
|
204 |
m_li.put("total", String.valueOf(progress.getTotalSlides()));
|
|
|
205 |
m_li.put("progress", String.valueOf(progress.getProgress()));
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
m_li.put("imagen",capsule.getImage());
|
|
|
210 |
m_li.put("nombre",capsule.getName());
|
|
|
211 |
|
|
|
212 |
capsuleList.add(m_li);
|
|
|
213 |
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
@Override
|
|
|
224 |
public void onItemClick(View view, int position) {
|
|
|
225 |
|
|
|
226 |
}
|
|
|
227 |
}
|