Search in sources :

Example 1 with FavoriteStops

use of flying.grub.tamtime.data.persistence.FavoriteStops in project TamTime by flyingrub.

the class OneStopActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_slidingtabs);
    Bundle bundle = getIntent().getExtras();
    stop_zone_id = bundle.getInt("stop_zone_id");
    stop = Data.getData().getMap().getStopZoneById(stop_zone_id);
    toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setTitle(stop.getName());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(new OneStopPageAdapter(getSupportFragmentManager()));
    favoriteStops = new FavoriteStops(getApplicationContext());
    favoriteStopLine = new FavoriteStopLine(getApplicationContext());
    slidingTabLayout = new SlidingTabLayout(getApplicationContext());
    slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.textClearColor));
    slidingTabLayout.setDividerColors(getResources().getColor(R.color.primaryColor));
    slidingTabLayout.setViewPager(viewPager);
}
Also used : Bundle(android.os.Bundle) SlidingTabLayout(flying.grub.tamtime.slidingTab.SlidingTabLayout) FavoriteStops(flying.grub.tamtime.data.persistence.FavoriteStops) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FavoriteStopLine(flying.grub.tamtime.data.persistence.FavoriteStopLine)

Example 2 with FavoriteStops

use of flying.grub.tamtime.data.persistence.FavoriteStops in project TamTime by flyingrub.

the class FavoriteStopsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_recycler_load, container, false);
    setHasOptionsMenu(true);
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.progress);
    linearLayout.setVisibility(View.GONE);
    TextView textView = (TextView) view.findViewById(R.id.empty_view);
    textView.setText(getString(R.string.no_favorite_stop));
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(false);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setBackgroundColor(getResources().getColor(R.color.windowBackgroundCard));
    favoriteStops = new FavoriteStops(getActivity());
    getActivity().setTitle(getString(R.string.all_stops_favs));
    if (favoriteStops.getFavoriteStop().size() == 0) {
        textView.setVisibility(View.VISIBLE);
        recyclerView.setVisibility(View.GONE);
        return view;
    }
    adapter = new FavoriteAdapter(favoriteStops.getFavoriteStop());
    recyclerView.setAdapter(adapter);
    adapter.SetOnItemClickListener(new FavoriteAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View v, int position) {
            selectitem(position);
        }
    });
    adapter.SetOnMenuClickListener(new FavoriteAdapter.OnMenuClickListener() {

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

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    favoriteStops.remove(position);
                    recyclerView.swapAdapter(new FavoriteAdapter(favoriteStops.getFavoriteStop()), false);
                    return true;
                }
            });
            // showing popup menu
            popup.show();
        }
    });
    return view;
}
Also used : MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TextView(android.widget.TextView) FavoriteStops(flying.grub.tamtime.data.persistence.FavoriteStops) FavoriteAdapter(flying.grub.tamtime.adapter.FavoriteAdapter) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 FavoriteStops (flying.grub.tamtime.data.persistence.FavoriteStops)2 Bundle (android.os.Bundle)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 FavoriteAdapter (flying.grub.tamtime.adapter.FavoriteAdapter)1 FavoriteStopLine (flying.grub.tamtime.data.persistence.FavoriteStopLine)1 SlidingTabLayout (flying.grub.tamtime.slidingTab.SlidingTabLayout)1