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);
}
}
});
}
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();
}
}
}
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());
}
}
});
}
Aggregations