Search in sources :

Example 1 with FavWelcomeAdapter

use of flying.grub.tamtime.adapter.FavWelcomeAdapter in project TamTime by flyingrub.

the class FavHomeView method getView.

public View getView(ViewGroup parent) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.footer_home, parent, false);
    favLayout = (LinearLayout) view.findViewById(R.id.fav_stop_recycler);
    LinearLayout linearLayout = (LinearLayout) favLayout.findViewById(R.id.progress);
    linearLayout.setVisibility(View.GONE);
    TextView textView = (TextView) favLayout.findViewById(R.id.empty_view);
    textView.setText(context.getString(R.string.no_favorite_stop));
    favStopRecyclerView = (RecyclerView) favLayout.findViewById(R.id.recycler_view);
    favStopRecyclerView.setHasFixedSize(false);
    RecyclerView.LayoutManager layoutManagerFav = new org.solovyev.android.views.llm.LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    favStopRecyclerView.setLayoutManager(layoutManagerFav);
    favStopRecyclerView.setItemAnimator(new DefaultItemAnimator());
    if (favoriteStops.getFavoriteStop().size() == 0) {
        textView.setVisibility(View.VISIBLE);
        favStopRecyclerView.setVisibility(View.GONE);
    } else {
        favStopAdapter = new FavWelcomeAdapter(favoriteStops.getFavoriteStop());
        favStopRecyclerView.setAdapter(favStopAdapter);
        favStopAdapter.SetOnItemClickListener(new FavWelcomeAdapter.OnItemClickListener() {

            @Override
            public void onItemClick(View v, int position) {
                selectitem(favoriteStops.getFavoriteStop().get(position));
            }
        });
        favStopAdapter.SetOnMenuClickListener(new FavWelcomeAdapter.OnMenuClickListener() {

            @Override
            public void onItemClick(View v, final int position) {
                // Creating the instance of PopupMenu
                PopupMenu popup = new PopupMenu(context, v);
                // Inflating the Popup using xml file
                popup.getMenuInflater().inflate(R.menu.add_to_home, popup.getMenu());
                // registering popup with OnMenuItemClickListener
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        ArrayList<CharSequence> lines = new ArrayList<>();
                        for (Line l : favoriteStops.getFavoriteStop().get(position).getLines()) {
                            lines.add("Ligne " + l.getLineNum());
                        }
                        CharSequence[] lineString = lines.toArray(new CharSequence[lines.size()]);
                        MaterialDialog dialog = new MaterialDialog.Builder(context).title(R.string.line_choice).items(lineString).itemsCallback(new MaterialDialog.ListCallback() {

                            @Override
                            public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                                StopZone s = favoriteStops.getFavoriteStop().get(position);
                                Line l = s.getLines().get(which);
                                updateStopLine.update(s, l);
                                dialog.dismiss();
                            }
                        }).build();
                        dialog.show();
                        return true;
                    }
                });
                popup.show();
            }
        });
    }
    return view;
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TextView(android.widget.TextView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MenuItem(android.view.MenuItem) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) FavWelcomeAdapter(flying.grub.tamtime.adapter.FavWelcomeAdapter) Line(flying.grub.tamtime.data.map.Line) RecyclerView(android.support.v7.widget.RecyclerView) StopZone(flying.grub.tamtime.data.map.StopZone) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PopupMenu (android.support.v7.widget.PopupMenu)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 FavWelcomeAdapter (flying.grub.tamtime.adapter.FavWelcomeAdapter)1 Line (flying.grub.tamtime.data.map.Line)1 StopZone (flying.grub.tamtime.data.map.StopZone)1 ArrayList (java.util.ArrayList)1