Search in sources :

Example 6 with MainService

use of im.tny.segvault.disturbances.MainService in project underlx by underlx.

the class HomeFragment method refreshCurrentTrip.

private void refreshCurrentTrip() {
    if (mListener == null)
        return;
    final MainService m = mListener.getMainService();
    if (m == null)
        return;
    S2LS loc = m.getS2LS(MainService.PRIMARY_NETWORK_ID);
    if (loc == null || loc.getCurrentTrip() == null) {
        ongoingTripCard.setVisibility(View.GONE);
    } else {
        final Station station = loc.getCurrentTrip().getCurrentStop().getStation();
        curStationNameView.setText(station.getName());
        Stop direction = loc.getCurrentTrip().getDirection();
        Stop next = loc.getCurrentTrip().getNextStop();
        if (direction != null && next != null) {
            directionView.setText(String.format(getString(R.string.frag_home_trip_direction), direction.getStation().getName()));
            nextStationView.setText(String.format(getString(R.string.frag_home_trip_next_station), next.getStation().getName()));
            Stop likelyExit = m.getLikelyNextExit(loc.getCurrentTrip().getEdgeList(), 1);
            int resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Small;
            if (next == likelyExit) {
                resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Medium;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                nextStationView.setTextAppearance(resId);
            } else {
                nextStationView.setTextAppearance(getContext(), resId);
            }
            directionView.setVisibility(View.VISIBLE);
            nextStationView.setVisibility(View.VISIBLE);
        } else {
            directionView.setVisibility(View.GONE);
            nextStationView.setVisibility(View.GONE);
        }
        redrawCurrentStationLineIcons(station);
        curStationLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getContext(), StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, MainService.PRIMARY_NETWORK_ID);
                startActivity(intent);
            }
        });
        curTripIncorrectLocationButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new FeedbackUtil.IncorrectLocation(getContext(), m, station).showReportWizard();
            }
        });
        if (loc.canRequestEndOfTrip()) {
            curTripEndButton.setVisibility(View.VISIBLE);
            curTripIncorrectLocationButton.setVisibility(View.GONE);
        } else {
            curTripEndButton.setVisibility(View.GONE);
            curTripIncorrectLocationButton.setVisibility(View.VISIBLE);
        }
        ongoingTripCard.setVisibility(View.VISIBLE);
    }
}
Also used : MainService(im.tny.segvault.disturbances.MainService) S2LS(im.tny.segvault.s2ls.S2LS) Station(im.tny.segvault.subway.Station) Stop(im.tny.segvault.subway.Stop) StationActivity(im.tny.segvault.disturbances.ui.activity.StationActivity) Intent(android.content.Intent) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView)

Example 7 with MainService

use of im.tny.segvault.disturbances.MainService in project underlx by underlx.

the class HomeFragment method refresh.

private void refresh(boolean requestOnlineUpdate) {
    Realm realm = Application.getDefaultRealmInstance(getContext());
    boolean hasTripsToConfirm = Trip.getMissingConfirmTrips(realm).size() > 0;
    realm.close();
    if (hasTripsToConfirm) {
        if (unconfirmedTripsCard.getVisibility() == View.GONE) {
            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
            Fragment newFragment = UnconfirmedTripsFragment.newInstance(1);
            transaction.replace(R.id.unconfirmed_trips_card, newFragment);
            transaction.commitAllowingStateLoss();
            unconfirmedTripsCard.setVisibility(View.VISIBLE);
        }
    } else {
        unconfirmedTripsCard.setVisibility(View.GONE);
    }
    if (mListener == null)
        return;
    MainService m = mListener.getMainService();
    if (m == null)
        return;
    if (requestOnlineUpdate) {
        m.getLineStatusCache().updateLineStatus();
        m.getStatsCache().updateStats();
    }
    Network net = m.getNetwork(MainService.PRIMARY_NETWORK_ID);
    if (net == null) {
        networkClosedCard.setVisibility(View.GONE);
        unconfirmedTripsCard.setVisibility(View.GONE);
        m.checkForTopologyUpdates();
    } else if (net.isOpen()) {
        networkClosedCard.setVisibility(View.GONE);
    } else {
        Formatter f = new Formatter();
        DateUtils.formatDateRange(getContext(), f, net.getNextOpenTime(), net.getNextOpenTime(), DateUtils.FORMAT_SHOW_TIME, net.getTimezone().getID());
        networkClosedView.setText(String.format(getString(R.string.warning_network_closed), f.toString()));
        networkClosedCard.setVisibility(View.VISIBLE);
    }
    recomputeShortcutVisibility();
}
Also used : MainService(im.tny.segvault.disturbances.MainService) FragmentTransaction(android.support.v4.app.FragmentTransaction) Formatter(java.util.Formatter) Network(im.tny.segvault.subway.Network) Realm(io.realm.Realm) TopFragment(im.tny.segvault.disturbances.ui.fragment.TopFragment) Fragment(android.support.v4.app.Fragment) UnconfirmedTripsFragment(im.tny.segvault.disturbances.ui.fragment.UnconfirmedTripsFragment) HomeStatsFragment(im.tny.segvault.disturbances.ui.fragment.HomeStatsFragment) HomeLinesFragment(im.tny.segvault.disturbances.ui.fragment.HomeLinesFragment)

Example 8 with MainService

use of im.tny.segvault.disturbances.MainService in project underlx by underlx.

the class TripFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_trip, container, false);
    layoutRoute = (LinearLayout) view.findViewById(R.id.layout_route);
    stationNamesView = (TextView) view.findViewById(R.id.station_names_view);
    dateView = (TextView) view.findViewById(R.id.date_view);
    correctButton = (Button) view.findViewById(R.id.correct_button);
    deleteButton = (Button) view.findViewById(R.id.delete_button);
    statsLayout = (LinearLayout) view.findViewById(R.id.layout_stats);
    statsView = (TextView) view.findViewById(R.id.stats_view);
    if (mListener == null)
        return view;
    MainService service = mListener.getMainService();
    if (service == null)
        return view;
    network = service.getNetwork(networkId);
    correctButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getContext(), TripCorrectionActivity.class);
            intent.putExtra(TripCorrectionActivity.EXTRA_NETWORK_ID, networkId);
            intent.putExtra(TripCorrectionActivity.EXTRA_TRIP_ID, tripId);
            startActivity(intent);
        }
    });
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle(R.string.frag_trip_delete_confirm_title).setMessage(R.string.frag_trip_delete_confirm_desc).setPositiveButton(R.string.frag_trip_delete, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    deleteTrip();
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            }).show();
        }
    });
    this.inflater = inflater;
    refreshUI();
    return view;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) SpannableStringBuilder(android.text.SpannableStringBuilder) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MainService(im.tny.segvault.disturbances.MainService) TripCorrectionActivity(im.tny.segvault.disturbances.ui.activity.TripCorrectionActivity)

Example 9 with MainService

use of im.tny.segvault.disturbances.MainService in project underlx by underlx.

the class StationGeneralFragment method update.

private void update() {
    if (mListener == null)
        return;
    MainService service = mListener.getMainService();
    if (service == null)
        return;
    Network net = service.getNetwork(networkId);
    if (net == null)
        return;
    final Station station = net.getStation(stationId);
    if (station == null)
        return;
    if (station.isAlwaysClosed()) {
        LinearLayout closedLayout = (LinearLayout) view.findViewById(R.id.closed_info_layout);
        closedLayout.setVisibility(View.VISIBLE);
    } else if (station.isExceptionallyClosed(net, new Date())) {
        TextView closedView = (TextView) view.findViewById(R.id.closed_info_view);
        Formatter f = new Formatter();
        DateUtils.formatDateRange(getContext(), f, station.getNextOpenTime(net), station.getNextOpenTime(net), DateUtils.FORMAT_SHOW_TIME, net.getTimezone().getID());
        closedView.setText(String.format(getString(R.string.frag_station_closed_schedule), f.toString()));
        LinearLayout closedLayout = (LinearLayout) view.findViewById(R.id.closed_info_layout);
        closedLayout.setVisibility(View.VISIBLE);
    }
    // Connections
    TextView connectionsTitleView = (TextView) view.findViewById(R.id.connections_title_view);
    // buttons
    Button busButton = (Button) view.findViewById(R.id.connections_bus_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BUS)) {
        busButton.setVisibility(View.VISIBLE);
        busButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BUS, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    Button boatButton = (Button) view.findViewById(R.id.connections_boat_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BOAT)) {
        boatButton.setVisibility(View.VISIBLE);
        boatButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BOAT, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    Button trainButton = (Button) view.findViewById(R.id.connections_train_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_TRAIN)) {
        trainButton.setVisibility(View.VISIBLE);
        trainButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_TRAIN, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    // icons
    LinearLayout busLayout = (LinearLayout) view.findViewById(R.id.feature_bus_layout);
    if (station.getFeatures().bus) {
        busLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout boatLayout = (LinearLayout) view.findViewById(R.id.feature_boat_layout);
    if (station.getFeatures().boat) {
        boatLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout trainLayout = (LinearLayout) view.findViewById(R.id.feature_train_layout);
    if (station.getFeatures().train) {
        trainLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout airportLayout = (LinearLayout) view.findViewById(R.id.feature_airport_layout);
    if (station.getFeatures().airport) {
        airportLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    // Accessibility
    TextView accessibilityTitleView = (TextView) view.findViewById(R.id.accessibility_title_view);
    LinearLayout liftLayout = (LinearLayout) view.findViewById(R.id.feature_lift_layout);
    if (station.getFeatures().lift) {
        liftLayout.setVisibility(View.VISIBLE);
        accessibilityTitleView.setVisibility(View.VISIBLE);
    }
    // Services
    TextView servicesTitleView = (TextView) view.findViewById(R.id.services_title_view);
    Button parkButton = (Button) view.findViewById(R.id.connections_park_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_PARK)) {
        parkButton.setVisibility(View.VISIBLE);
        parkButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_PARK, station);
            }
        });
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    Button bikeButton = (Button) view.findViewById(R.id.connections_bike_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BIKE)) {
        bikeButton.setVisibility(View.VISIBLE);
        bikeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BIKE, station);
            }
        });
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout wifiLayout = (LinearLayout) view.findViewById(R.id.service_wifi_layout);
    if (station.getFeatures().wifi) {
        wifiLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout parkLayout = (LinearLayout) view.findViewById(R.id.service_park_layout);
    if (station.getFeatures().parking) {
        parkLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout bikeLayout = (LinearLayout) view.findViewById(R.id.service_bike_layout);
    if (station.getFeatures().bike) {
        bikeLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    // Statistics
    Realm realm = Application.getDefaultRealmInstance(getContext());
    TextView statsEntryCountView = (TextView) view.findViewById(R.id.station_entry_count_view);
    long entryCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.NETWORK_ENTRY.name()).count();
    statsEntryCountView.setText(String.format(getString(R.string.frag_station_stats_entry), entryCount));
    TextView statsExitCountView = (TextView) view.findViewById(R.id.station_exit_count_view);
    long exitCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.NETWORK_EXIT.name()).count();
    statsExitCountView.setText(String.format(getString(R.string.frag_station_stats_exit), exitCount));
    TextView statsGoneThroughCountView = (TextView) view.findViewById(R.id.station_gone_through_count_view);
    long goneThroughCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.GONE_THROUGH.name()).count();
    statsGoneThroughCountView.setText(String.format(getString(R.string.frag_station_stats_gone_through), goneThroughCount));
    TextView statsTransferCountView = (TextView) view.findViewById(R.id.station_transfer_count_view);
    if (station.getLines().size() > 1) {
        long transferCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.INTERCHANGE.name()).count();
        statsTransferCountView.setText(String.format(getString(R.string.frag_station_stats_transfer), transferCount));
        statsTransferCountView.setVisibility(View.VISIBLE);
    } else {
        statsTransferCountView.setVisibility(View.GONE);
    }
    realm.close();
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Formatter(java.util.Formatter) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) Button(android.widget.Button) Network(im.tny.segvault.subway.Network) TextView(android.widget.TextView) Realm(io.realm.Realm) LinearLayout(android.widget.LinearLayout)

Example 10 with MainService

use of im.tny.segvault.disturbances.MainService in project underlx by underlx.

the class FinishIntroSlide method refresh.

private void refresh() {
    if (mListener == null || mListener.getMainService() == null) {
        return;
    }
    final MainService m = mListener.getMainService();
    if (m.getNetworks().size() == 0) {
        title.setText(R.string.intro_finish_wait_title);
        if (!Connectivity.isConnected(getContext())) {
            image.setImageResource(R.drawable.ic_frowning_intro);
            description.setText(R.string.intro_finish_connect_desc);
            button.setText(R.string.intro_finish_try_again);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    m.updateTopology();
                }
            });
            button.setVisibility(View.VISIBLE);
        } else {
            image.setImageResource(R.drawable.ic_hourglass_flowing_sand_intro);
            description.setText(String.format(getString(R.string.intro_finish_downloading), lastKnownPercentage));
            button.setVisibility(View.GONE);
        }
        canLeave = false;
    } else {
        title.setText(R.string.intro_finish_done_title);
        image.setImageResource(R.drawable.ic_ok_hand_intro);
        description.setText(R.string.intro_finish_done_desc);
        button.setText(R.string.intro_finish_get_started);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mListener.onDonePressed(FinishIntroSlide.this);
            }
        });
        button.setVisibility(View.VISIBLE);
        canLeave = true;
    }
}
Also used : MainService(im.tny.segvault.disturbances.MainService) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

MainService (im.tny.segvault.disturbances.MainService)10 Network (im.tny.segvault.subway.Network)5 Station (im.tny.segvault.subway.Station)5 View (android.view.View)4 TextView (android.widget.TextView)4 Intent (android.content.Intent)2 ViewTreeObserver (android.view.ViewTreeObserver)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)2 Marker (com.google.android.gms.maps.model.Marker)2 Realm (io.realm.Realm)2 Formatter (java.util.Formatter)2 DialogInterface (android.content.DialogInterface)1 Fragment (android.support.v4.app.Fragment)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 CardView (android.support.v7.widget.CardView)1