Search in sources :

Example 1 with PlaceModel

use of com.hypertrack.live.models.PlaceModel in project hypertrack-live-android by hypertrack.

the class PlacesAdapter method onBindViewHolder.

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
    // - get element from your dataset at this position
    // - replace the contents of the view with that element
    final PlaceModel item = dataset.get(position);
    holder.icon.setImageResource(item.isRecent ? R.drawable.history : R.drawable.ic_place);
    holder.name.setText(item.primaryText);
    holder.address.setText(item.secondaryText);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(PlacesAdapter.this, view, position);
            }
        }
    });
}
Also used : PlaceModel(com.hypertrack.live.models.PlaceModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with PlaceModel

use of com.hypertrack.live.models.PlaceModel in project hypertrack-live-android by hypertrack.

the class SearchPlacePresenter method setMapDestinationModeEnable.

public void setMapDestinationModeEnable(boolean enable) {
    if (state.mapDestinationMode != enable) {
        state.mapDestinationMode = enable;
        if (enable) {
            final Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    if (googleMap != null) {
                        state.setDestination(null);
                        view.updateAddress(context.getString(R.string.searching_));
                        disposables.add(MapUtils.getAddress(context, googleMap.getCameraPosition().target).subscribe(new io.reactivex.functions.Consumer<String>() {

                            @Override
                            public void accept(String s) {
                                PlaceModel destination = new PlaceModel();
                                destination.address = s;
                                destination.latLng = googleMap.getCameraPosition().target;
                                state.setDestination(destination);
                                view.updateAddress(s);
                            }
                        }));
                    }
                }
            };
            googleMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {

                @Override
                public void onCameraMove() {
                    handler.removeCallbacks(runnable);
                    handler.postDelayed(runnable, 500);
                }
            });
            runnable.run();
            view.updateList(Collections.<PlaceModel>emptyList());
            view.showSetOnMap();
        } else {
            googleMap.setOnCameraMoveListener(null);
            state.setDestination(null);
            view.updateAddress("");
            view.hideSetOnMap();
        }
    }
}
Also used : PlaceModel(com.hypertrack.live.models.PlaceModel) GoogleMap(com.google.android.gms.maps.GoogleMap)

Example 3 with PlaceModel

use of com.hypertrack.live.models.PlaceModel in project hypertrack-live-android by hypertrack.

the class SearchPlacePresenter method selectItem.

public void selectItem(PlaceModel placeModel) {
    view.showProgressBar();
    if (!placeModel.isRecent) {
        state.addPlaceToRecent(placeModel);
    }
    List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS);
    FetchPlaceRequest request = FetchPlaceRequest.builder(placeModel.placeId, fields).setSessionToken(token).build();
    placesClient.fetchPlace(request).addOnSuccessListener(new OnSuccessListener<FetchPlaceResponse>() {

        @Override
        public void onSuccess(FetchPlaceResponse fetchPlaceResponse) {
            view.hideProgressBar();
            PlaceModel destination = new PlaceModel();
            destination.address = fetchPlaceResponse.getPlace().getAddress();
            destination.latLng = fetchPlaceResponse.getPlace().getLatLng();
            state.setDestination(destination);
            providePlace(destination);
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            view.hideProgressBar();
            if (e instanceof ApiException) {
                ApiException apiException = (ApiException) e;
                Log.e(TAG, "Place not found: " + apiException.getStatusCode());
            }
        }
    });
}
Also used : FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) PlaceModel(com.hypertrack.live.models.PlaceModel) FetchPlaceResponse(com.google.android.libraries.places.api.net.FetchPlaceResponse) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ApiException(com.google.android.gms.common.api.ApiException) ApiException(com.google.android.gms.common.api.ApiException)

Aggregations

PlaceModel (com.hypertrack.live.models.PlaceModel)3 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ApiException (com.google.android.gms.common.api.ApiException)1 GoogleMap (com.google.android.gms.maps.GoogleMap)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 FetchPlaceRequest (com.google.android.libraries.places.api.net.FetchPlaceRequest)1 FetchPlaceResponse (com.google.android.libraries.places.api.net.FetchPlaceResponse)1