Search in sources :

Example 1 with Line

use of flying.grub.tamtime.data.map.Line in project TamTime by flyingrub.

the class OneStopActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_favorite:
            if (favoriteStops.isInFav(stop)) {
                favoriteStops.remove(stop);
                item.setIcon(R.drawable.ic_star_border_white_24dp);
            } else {
                favoriteStops.add(stop);
                item.setIcon(R.drawable.ic_star_white_24dp);
            }
            return true;
        case R.id.report:
            choiceReportDialog();
            return true;
        case R.id.report_warn:
            createAllReportDialog();
            return true;
        case R.id.action_add_line_on_home:
            ArrayList<CharSequence> lines = new ArrayList<>();
            for (Line l : stop.getLines()) {
                lines.add("Ligne " + l.getShortName());
            }
            CharSequence[] lineString = lines.toArray(new CharSequence[lines.size()]);
            MaterialDialog dialog = new MaterialDialog.Builder(OneStopActivity.this).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 = stop;
                    Line l = s.getLines().get(which);
                    favoriteStopLine.addLineStop(l, s);
                    dialog.dismiss();
                }
            }).build();
            dialog.show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : Line(flying.grub.tamtime.data.map.Line) FavoriteStopLine(flying.grub.tamtime.data.persistence.FavoriteStopLine) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) StopZone(flying.grub.tamtime.data.map.StopZone)

Example 2 with Line

use of flying.grub.tamtime.data.map.Line in project TamTime by flyingrub.

the class HomeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holderParam, int position) {
    if (holderParam instanceof ViewHolderCustom) {
        return;
    }
    ViewHolder holder = (ViewHolder) holderParam;
    LineStop lineStop = favoriteStopLine.get(position - 1);
    StopZone s = lineStop.getStopZone();
    Line l = lineStop.getLine();
    holder.title.setText(s.getName() + " - Ligne " + l.getLineNum());
    holder.recyclerView.setHasFixedSize(true);
    RecyclerView.LayoutManager layoutManager = new org.solovyev.android.views.llm.LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    holder.recyclerView.setLayoutManager(layoutManager);
    holder.recyclerView.setItemAnimator(new DefaultItemAnimator());
    AllDirectionStopLine adapter = new AllDirectionStopLine(s.getStops(l), context);
    final StopZone finalS = s;
    adapter.SetOnItemClickListener(new AllDirectionStopLine.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            Intent intent = new Intent(context, OneStopActivity.class);
            Bundle bundle = new Bundle();
            bundle.putInt("stop_zone_id", finalS.getID());
            intent.putExtras(bundle);
            context.startActivity(intent);
            context.overridePendingTransition(R.anim.slide_from_right, R.anim.fade_scale_out);
        }
    });
    holder.recyclerView.setAdapter(adapter);
}
Also used : LineStop(flying.grub.tamtime.data.persistence.LineStop) Bundle(android.os.Bundle) Intent(android.content.Intent) OneStopActivity(flying.grub.tamtime.activity.OneStopActivity) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SearchView(flying.grub.tamtime.layout.SearchView) FavHomeView(flying.grub.tamtime.layout.FavHomeView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Line(flying.grub.tamtime.data.map.Line) RecyclerView(android.support.v7.widget.RecyclerView) StopZone(flying.grub.tamtime.data.map.StopZone)

Example 3 with Line

use of flying.grub.tamtime.data.map.Line in project TamTime by flyingrub.

the class DisruptEventHandler method setDisruptEvent.

public void setDisruptEvent(ArrayList<JSONObject> jsonEventList) throws JSONException {
    Line line;
    String title;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // Clear all the disrupt event
    while (this.disruptList.size() > 0) this.disruptList.get(0).destroy();
    for (JSONObject eventJson : jsonEventList) {
        line = Data.getData().getMap().getLineByNum(eventJson.getJSONObject("DisruptedLine").getInt("number"));
        Calendar beginDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();
        try {
            beginDate.setTime(sdf.parse(eventJson.getString("beginValidityDate").replace("T", " ")));
            endDate.setTime(sdf.parse(eventJson.getString("endValidityDate").replace("T", " ")));
            title = eventJson.getString("title");
            // The event put himself in Data & Line ArrayList
            new DisruptEvent(line, beginDate, endDate, title);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Line(flying.grub.tamtime.data.map.Line) JSONObject(org.json.JSONObject) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) JSONException(org.json.JSONException)

Example 4 with Line

use of flying.grub.tamtime.data.map.Line in project TamTime by flyingrub.

the class HomeFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_recycler, container, false);
    setHasOptionsMenu(true);
    getActivity().setTitle(getString(R.string.home));
    favoriteStopLine = new FavoriteStopLine(getContext());
    favHomeView = new FavHomeView(getActivity());
    favHomeView.setUpdateStopLine(new FavHomeView.AddStopLine() {

        @Override
        public void update(StopZone stop, Line line) {
            favoriteStopLine.addLineStop(line, stop);
            setupFavStopLine();
        }
    });
    searchView = new SearchView(getActivity());
    favStopLinesRecycler = (RecyclerView) view.findViewById(R.id.recycler_view);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
    favStopLinesRecycler.setLayoutManager(layoutManager);
    favStopLinesRecycler.setItemAnimator(new DefaultItemAnimator());
    favStopLinesRecycler.setHasFixedSize(false);
    favStopLinesRecycler.setBackgroundColor(getResources().getColor(R.color.windowBackgroundCard));
    setupFavStopLine();
    return view;
}
Also used : FavoriteStopLine(flying.grub.tamtime.data.persistence.FavoriteStopLine) Line(flying.grub.tamtime.data.map.Line) SearchView(flying.grub.tamtime.layout.SearchView) FavHomeView(flying.grub.tamtime.layout.FavHomeView) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SearchView(flying.grub.tamtime.layout.SearchView) FavHomeView(flying.grub.tamtime.layout.FavHomeView) StopZone(flying.grub.tamtime.data.map.StopZone) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) FavoriteStopLine(flying.grub.tamtime.data.persistence.FavoriteStopLine)

Example 5 with Line

use of flying.grub.tamtime.data.map.Line 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

Line (flying.grub.tamtime.data.map.Line)6 StopZone (flying.grub.tamtime.data.map.StopZone)5 RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 TextView (android.widget.TextView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 FavoriteStopLine (flying.grub.tamtime.data.persistence.FavoriteStopLine)2 FavHomeView (flying.grub.tamtime.layout.FavHomeView)2 SearchView (flying.grub.tamtime.layout.SearchView)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 OneStopActivity (flying.grub.tamtime.activity.OneStopActivity)1