Search in sources :

Example 36 with Event

use of com.eventyay.organizer.data.event.Event in project open-event-orga-app by fossasia.

the class EventDetailsStepOne method setupPlacesAutocomplete.

private void setupPlacesAutocomplete() {
    ApplicationInfo ai = null;
    try {
        ai = getContext().getPackageManager().getApplicationInfo(getContext().getPackageName(), PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    Bundle bundle = ai.metaData;
    String placesApiKey = bundle.getString("com.google.android.geo.API_KEY");
    Places.initialize(getActivity().getApplicationContext(), placesApiKey);
    AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getChildFragmentManager().findFragmentById(R.id.autocomplete_fragment);
    autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG, Place.Field.ADDRESS));
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

        @Override
        public void onPlaceSelected(Place place) {
            Timber.d(place.getAddress());
            Event event = binding.getEvent();
            event.latitude = place.getLatLng().latitude;
            event.longitude = place.getLatLng().longitude;
            event.locationName = place.getAddress();
            event.searchableLocationName = place.getName();
        }

        @Override
        public void onError(Status status) {
            ViewUtils.showSnackbar(binding.getRoot(), status.getStatusMessage());
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) PackageManager(android.content.pm.PackageManager) Bundle(android.os.Bundle) ApplicationInfo(android.content.pm.ApplicationInfo) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Event(com.eventyay.organizer.data.event.Event) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) Place(com.google.android.libraries.places.api.model.Place)

Aggregations

Event (com.eventyay.organizer.data.event.Event)36 LiveData (androidx.lifecycle.LiveData)15 ViewModel (androidx.lifecycle.ViewModel)15 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)15 Inject (javax.inject.Inject)15 ErrorUtils (com.eventyay.organizer.utils.ErrorUtils)14 Test (org.junit.Test)14 SingleEventLiveData (com.eventyay.organizer.common.livedata.SingleEventLiveData)13 ContextManager (com.eventyay.organizer.common.ContextManager)10 StringUtils (com.eventyay.organizer.utils.StringUtils)8 DateUtils (com.eventyay.organizer.utils.DateUtils)5 LocalDateTime (org.threeten.bp.LocalDateTime)5 ZonedDateTime (org.threeten.bp.ZonedDateTime)5 DateTimeParseException (org.threeten.bp.format.DateTimeParseException)5 VisibleForTesting (androidx.annotation.VisibleForTesting)4 MutableLiveData (androidx.lifecycle.MutableLiveData)4 Track (com.eventyay.organizer.data.tracks.Track)4 InOrder (org.mockito.InOrder)4 Logger (com.eventyay.organizer.common.rx.Logger)3 Ticket (com.eventyay.organizer.data.ticket.Ticket)3