use of ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter in project ETSMobile-Android2 by ApplETS.
the class BottinFragment method updateUI.
@SuppressWarnings({ "rawtypes", "unchecked" })
void updateUI() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
try {
DatabaseHelper dbHelper = new DatabaseHelper(activity);
// Création du queryBuilder, permettant de lister les employés par leur nom de service
QueryBuilder<FicheEmploye, String> queryBuilder = (QueryBuilder<FicheEmploye, String>) dbHelper.getDao(FicheEmploye.class).queryBuilder();
queryBuilder.orderBy("Service", true);
PreparedQuery<FicheEmploye> preparedQuery = queryBuilder.prepare();
List<FicheEmploye> listEmployes = dbHelper.getDao(FicheEmploye.class).query(preparedQuery);
// Si le contenu n'est pas vide, l'ajouter au listDataHeader et listDataChild
if (listEmployes.size() > 0) {
String nomService = "";
String previousNomService = "";
listDataHeader.clear();
ArrayList<FicheEmploye> listEmployesOfService = new ArrayList<>();
// Pour le premier élément dans la liste
FicheEmploye employe = listEmployes.get(0);
nomService = employe.Service;
listDataHeader.add(nomService);
listEmployesOfService.add(employe);
previousNomService = nomService;
// Pour les prochains éléments dans la liste
for (int i = 1; i < listEmployes.size(); i++) {
employe = listEmployes.get(i);
nomService = employe.Service;
if (!listDataHeader.contains(nomService)) {
listDataHeader.add(nomService);
Collections.sort(listEmployesOfService, new Comparator<FicheEmploye>() {
@Override
public int compare(FicheEmploye f1, FicheEmploye f2) {
return f1.Nom.compareTo(f2.Nom);
}
});
listDataChild.put(previousNomService, listEmployesOfService);
listEmployesOfService = new ArrayList<>();
previousNomService = nomService;
}
listEmployesOfService.add(employe);
}
// Pour les derniers éléments dans la liste
listDataChild.put(previousNomService, listEmployesOfService);
if (activity != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
}
});
}
// Rétablissement du filtre de recherche
CharSequence searchText = searchView.getQuery();
if (searchText.length() != 0)
onQueryTextChange(searchText.toString());
// Si le contenu est vide, télécharger le bottin
} else {
// Le contenu est vide.
afficherRafraichissementEtRechargerBottin();
}
} catch (Exception e) {
Log.e("BD FicheEmploye", "" + e.getMessage());
}
}
use of ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter in project ETSMobile-Android2 by ApplETS.
the class BottinFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_item_update:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.menu_bottin_refresh).setView(getActivity().getLayoutInflater().inflate(R.layout.dialog_bottin, null)).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Suppression du bottin
DatabaseHelper dbHelper = new DatabaseHelper(getActivity());
try {
Dao<FicheEmploye, ?> ficheEmployeDao = dbHelper.getDao(FicheEmploye.class);
List<FicheEmploye> ficheEmployeList = ficheEmployeDao.queryForAll();
for (FicheEmploye ficheEmploye : ficheEmployeList) {
ficheEmployeDao.delete(ficheEmploye);
}
} catch (SQLException e) {
e.printStackTrace();
}
//Mise à jour de la liste
listDataHeader = new ArrayList<>();
listDataChild = new HashMap<>();
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
expListView.setAdapter(listAdapter);
updateUI();
dialogInterface.dismiss();
}
}).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
builder.create().show();
return true;
}
return super.onOptionsItemSelected(item);
}
use of ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter in project ETSMobile-Android2 by ApplETS.
the class BottinFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup v = (ViewGroup) inflater.inflate(R.layout.fragment_bottin, container, false);
mSwipeRefreshLayout = v.findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout.setColorSchemeColors(ContextCompat.getColor(getContext(), R.color.ets_red));
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
if (!Utility.isNetworkAvailable(getActivity())) {
afficherMsgHorsLigne();
mSwipeRefreshLayout.setRefreshing(false);
} else {
afficherRafraichissementEtRechargerBottin();
}
}
});
// get the listview
expListView = v.findViewById(R.id.expandableListView_service_employe);
// Ouverture du détail
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
FicheEmploye ficheEmploye = (FicheEmploye) listAdapter.getChild(groupPosition, childPosition);
Intent i = new Intent(getActivity(), BottinDetailsActivity.class);
i.putExtra("nom", ficheEmploye.Nom);
i.putExtra("prenom", ficheEmploye.Prenom);
i.putExtra("telBureau", ficheEmploye.TelBureau);
i.putExtra("emplacement", ficheEmploye.Emplacement);
i.putExtra("courriel", ficheEmploye.Courriel);
i.putExtra("service", ficheEmploye.Service);
i.putExtra("titre", ficheEmploye.Titre);
getActivity().startActivity(i);
return true;
}
});
// create empty data
listDataChild = new HashMap<>();
listDataHeader = new ArrayList<>();
// create custom adapter
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
updateUI();
return v;
}
Aggregations