Search in sources :

Example 1 with RStation

use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.

the class StationActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            super.onBackPressed();
            return true;
        case R.id.menu_share_location:
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(String.format(Locale.ROOT, "geo:0,0?q=%f,%f(%s)", worldCoords[0], worldCoords[1], getTitle())));
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
            // oh well
            }
            return true;
        case R.id.menu_share_webprofile:
            // TODO: un-hardcode this URL, move it to strings
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(getString(R.string.link_format_station), stationId)));
            try {
                startActivity(browserIntent);
            } catch (ActivityNotFoundException e) {
            // oh well
            }
            return true;
        case R.id.menu_favorite:
            Realm realm = Application.getDefaultRealmInstance(this);
            realm.beginTransaction();
            RStation rstation = realm.where(RStation.class).equalTo("id", stationId).findFirst();
            boolean isFavorite = rstation.isFavorite();
            isFavorite = !isFavorite;
            rstation.setFavorite(isFavorite);
            realm.copyToRealm(rstation);
            realm.commitTransaction();
            realm.close();
            if (isFavorite) {
                item.setTitle(R.string.act_station_favorite);
                item.setIcon(R.drawable.ic_star_white_24dp);
            } else {
                item.setTitle(R.string.act_station_unfavorite);
                item.setIcon(R.drawable.ic_star_border_white_24dp);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) RStation(im.tny.segvault.disturbances.model.RStation) Intent(android.content.Intent) Realm(io.realm.Realm)

Example 2 with RStation

use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.

the class StationActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.station, menu);
    Realm realm = Application.getDefaultRealmInstance(this);
    RStation rstation = realm.where(RStation.class).equalTo("id", stationId).findFirst();
    boolean isFavorite = false;
    if (rstation != null) {
        isFavorite = rstation.isFavorite();
    }
    realm.close();
    MenuItem favItem = menu.findItem(R.id.menu_favorite);
    if (isFavorite) {
        favItem.setTitle(R.string.act_station_favorite);
        favItem.setIcon(R.drawable.ic_star_white_24dp);
    } else {
        favItem.setTitle(R.string.act_station_unfavorite);
        favItem.setIcon(R.drawable.ic_star_border_white_24dp);
    }
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) RStation(im.tny.segvault.disturbances.model.RStation) MenuItem(android.view.MenuItem) Realm(io.realm.Realm)

Example 3 with RStation

use of im.tny.segvault.disturbances.model.RStation in project underlx by underlx.

the class MainService method putNetwork.

private void putNetwork(final Network net) {
    synchronized (lock) {
        // create Realm stations for the network if they don't exist already
        Realm realm = Application.getDefaultRealmInstance(this);
        realm.executeTransaction(new Realm.Transaction() {

            @Override
            public void execute(Realm realm) {
                for (Station s : net.getStations()) {
                    if (realm.where(RStation.class).equalTo("id", s.getId()).count() == 0) {
                        RStation rs = new RStation();
                        rs.setStop(s);
                        rs.setNetwork(net.getId());
                        realm.copyToRealm(rs);
                    }
                }
            }
        });
        realm.close();
        net.setEdgeWeighter(cweighter);
        networks.put(net.getId(), net);
        S2LS loc = new S2LS(net, new S2LSChangeListener());
        locServices.put(net.getId(), loc);
        WiFiLocator wl = new WiFiLocator(net);
        wfc.setLocatorForNetwork(net, wl);
        loc.addNetworkDetector(wl);
        loc.addProximityDetector(wl);
        loc.addLocator(wl);
    }
}
Also used : RStation(im.tny.segvault.disturbances.model.RStation) Station(im.tny.segvault.subway.Station) S2LS(im.tny.segvault.s2ls.S2LS) RStation(im.tny.segvault.disturbances.model.RStation) Realm(io.realm.Realm) WiFiLocator(im.tny.segvault.s2ls.wifi.WiFiLocator)

Aggregations

RStation (im.tny.segvault.disturbances.model.RStation)3 Realm (io.realm.Realm)3 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 S2LS (im.tny.segvault.s2ls.S2LS)1 WiFiLocator (im.tny.segvault.s2ls.wifi.WiFiLocator)1 Station (im.tny.segvault.subway.Station)1