Search in sources :

Example 1 with UriDeserializer

use of fr.free.nrw.commons.utils.UriDeserializer in project apps-android-commons by commons-app.

the class NearbyListFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Check that this is the first time view is created,
    // to avoid double list when screen orientation changed
    Bundle bundle = this.getArguments();
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriDeserializer()).create();
    if (bundle != null) {
        String gsonPlaceList = bundle.getString("PlaceList");
        String gsonLatLng = bundle.getString("CurLatLng");
        Type listType = new TypeToken<List<Place>>() {
        }.getType();
        placeList = gson.fromJson(gsonPlaceList, listType);
        Type curLatLngType = new TypeToken<LatLng>() {
        }.getType();
        LatLng curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
        placeList = NearbyController.loadAttractionsFromLocationToPlaces(curLatLng, placeList);
    }
    if (savedInstanceState == null) {
        adapter.clear();
        Timber.d("Saved instance state is null, populating ListView");
    }
    adapter.clear();
    adapter.addAll(placeList);
    adapter.notifyDataSetChanged();
}
Also used : Type(java.lang.reflect.Type) GsonBuilder(com.google.gson.GsonBuilder) Bundle(android.os.Bundle) Gson(com.google.gson.Gson) List(java.util.List) LatLng(fr.free.nrw.commons.location.LatLng) Uri(android.net.Uri) UriDeserializer(fr.free.nrw.commons.utils.UriDeserializer)

Example 2 with UriDeserializer

use of fr.free.nrw.commons.utils.UriDeserializer in project apps-android-commons by commons-app.

the class NearbyMapFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = this.getArguments();
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriDeserializer()).create();
    if (bundle != null) {
        String gsonPlaceList = bundle.getString("PlaceList");
        String gsonLatLng = bundle.getString("CurLatLng");
        Type listType = new TypeToken<List<Place>>() {
        }.getType();
        List<Place> placeList = gson.fromJson(gsonPlaceList, listType);
        Type curLatLngType = new TypeToken<fr.free.nrw.commons.location.LatLng>() {
        }.getType();
        curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
        baseMarkerOptions = NearbyController.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, placeList, getActivity());
    }
    Mapbox.getInstance(getActivity(), getString(R.string.mapbox_commons_app_token));
    MapboxTelemetry.getInstance().setTelemetryEnabled(false);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Bundle(android.os.Bundle) Gson(com.google.gson.Gson) Uri(android.net.Uri) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) UriDeserializer(fr.free.nrw.commons.utils.UriDeserializer)

Aggregations

Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 UriDeserializer (fr.free.nrw.commons.utils.UriDeserializer)2 Type (java.lang.reflect.Type)2 List (java.util.List)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLng (fr.free.nrw.commons.location.LatLng)1 ArrayList (java.util.ArrayList)1