Search in sources :

Example 1 with ExpandableListAdapter

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());
    }
}
Also used : AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ArrayList(java.util.ArrayList) ExpandableListAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper)

Example 2 with ExpandableListAdapter

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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) SQLException(java.sql.SQLException) QueryBuilder(com.j256.ormlite.stmt.QueryBuilder) ExpandableListAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper) OnClickListener(android.view.View.OnClickListener)

Example 3 with ExpandableListAdapter

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;
}
Also used : ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) ExpandableListAdapter(ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter) FicheEmploye(ca.etsmtl.applets.etsmobile.model.FicheEmploye) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) View(android.view.View) SearchView(androidx.appcompat.widget.SearchView) ExpandableListView(android.widget.ExpandableListView) BottinDetailsActivity(ca.etsmtl.applets.etsmobile.ui.activity.BottinDetailsActivity) OnChildClickListener(android.widget.ExpandableListView.OnChildClickListener) ExpandableListView(android.widget.ExpandableListView)

Aggregations

FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)3 ExpandableListAdapter (ca.etsmtl.applets.etsmobile.ui.adapter.ExpandableListAdapter)3 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)2 QueryBuilder (com.j256.ormlite.stmt.QueryBuilder)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 ExpandableListView (android.widget.ExpandableListView)1 OnChildClickListener (android.widget.ExpandableListView.OnChildClickListener)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 SearchView (androidx.appcompat.widget.SearchView)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 BottinDetailsActivity (ca.etsmtl.applets.etsmobile.ui.activity.BottinDetailsActivity)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1