Search in sources :

Example 1 with FavoriteHelper

use of cl.smartcities.isci.transportinspector.database.FavoriteHelper in project androidApp by InspectorIncognito.

the class FavouritesManger method getFavouriteBusStops.

static List<BusStop> getFavouriteBusStops(Context context) {
    FavoriteHelper helper = new FavoriteHelper(context);
    BusStopHelper busStopHelper = new BusStopHelper(context);
    List<String> busStops = helper.getFavoriteBusStops();
    List<BusStop> favouriteBusStops = new ArrayList<>();
    if (!busStops.isEmpty()) {
        List<BusStop> favourites = busStopHelper.getAllBusStopsIn(busStops.toArray(new String[busStops.size()]));
        favouriteBusStops.addAll(favourites);
    }
    return favouriteBusStops;
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) ArrayList(java.util.ArrayList) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 2 with FavoriteHelper

use of cl.smartcities.isci.transportinspector.database.FavoriteHelper in project androidApp by InspectorIncognito.

the class BusStopPlugin method onFavIconClick.

@Override
public void onFavIconClick(final String busStopId) {
    final FavoriteHelper helper = new FavoriteHelper(getContext());
    final boolean isFavorite = helper.isFavorite(busStopId);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    final GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            }
            refreshBusStopSource();
        }
    }, viewMap, buildingList);
    new Thread(new Runnable() {

        @Override
        public void run() {
            if (isFavorite) {
                helper.removeFavoriteBusStop(busStopId);
            } else {
                helper.addFavoriteBusStop(busStopId);
            }
            task.execute();
        }
    }).start();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) Bitmap(android.graphics.Bitmap) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)

Example 3 with FavoriteHelper

use of cl.smartcities.isci.transportinspector.database.FavoriteHelper in project androidApp by InspectorIncognito.

the class BusStopIconsBuilder method setIconsAndViews.

public void setIconsAndViews(LayoutInflater inflater, HashMap<String, Bitmap> imagesMap, HashMap<String, View> viewMap) {
    for (Feature feature : featureCollection.getFeatures()) {
        String id = feature.getStringProperty(Marker.PROPERTY_ID);
        BusStopMarker marker = (BusStopMarker) feature;
        BusStop busStop = marker.getBusStop();
        View view = inflater.inflate(R.layout.bus_stop_bubble, null);
        TextView code = view.findViewById(R.id.bubble_bus_stop_code);
        TextView name = view.findViewById(R.id.bubble_bus_stop_name);
        code.setText(id);
        name.setText(busStop.getName());
        AppCompatImageView favIcon = view.findViewById(R.id.fav_icon);
        final FavoriteHelper helper = new FavoriteHelper(view.getContext());
        boolean isFavorite = helper.isFavorite(busStop.getId());
        if (isFavorite) {
            favIcon.setColorFilter(ContextCompat.getColor(view.getContext(), R.color.yellow_fav));
        }
        List<ServerSentBus> buses = Bus.filterDummyPlates(busStop.getIncomingBuses());
        buses = ServerSentBus.orderBusesByDistance(buses);
        if (!buses.isEmpty()) {
            view.findViewById(R.id.bus_layout).setVisibility(View.VISIBLE);
            view.findViewById(R.id.bus_empty_layout).setVisibility(View.GONE);
            setupNearBusLayout(view, getNearestVisibleBus(buses, busStop));
        } else {
            view.findViewById(R.id.bus_layout).setVisibility(View.GONE);
            view.findViewById(R.id.bus_empty_layout).setVisibility(View.VISIBLE);
        }
        setEventLayout(view, marker.getEvents());
        Bitmap bitmap = GenerateViewIconTask.SymbolGenerator.generate(view);
        imagesMap.put(id + "-max", bitmap);
        viewMap.put("busStop-max", view);
        View viewMin = inflater.inflate(R.layout.bus_stop_minimize_bubble, null);
        TextView nameMin = viewMin.findViewById(R.id.bubble_bus_stop_code);
        nameMin.setText(id);
        ((ImageView) viewMin.findViewById(R.id.maximize)).setImageDrawable(new GreenButtonUp(viewMin.getContext()));
        imagesMap.put(id + "-min", GenerateViewIconTask.SymbolGenerator.generate(viewMin));
        viewMap.put("busStop-min", viewMin);
    }
}
Also used : Feature(com.mapbox.services.commons.geojson.Feature) AppCompatImageView(android.support.v7.widget.AppCompatImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AppCompatImageView(android.support.v7.widget.AppCompatImageView) GreenButtonUp(cl.smartcities.isci.transportinspector.drawables.greenButton.GreenButtonUp) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) ImageView(android.widget.ImageView) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Aggregations

FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)3 Bitmap (android.graphics.Bitmap)2 View (android.view.View)2 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 AppCompatImageView (android.support.v7.widget.AppCompatImageView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BusStopHelper (cl.smartcities.isci.transportinspector.database.BusStopHelper)1 GreenButtonUp (cl.smartcities.isci.transportinspector.drawables.greenButton.GreenButtonUp)1 BusStopIconsBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)1 IconBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder)1 GenerateViewIconTask (cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask)1 ServerSentBus (cl.smartcities.isci.transportinspector.model.gson.ServerSentBus)1