Search in sources :

Example 1 with Callback

use of fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback in project apps-android-commons by commons-app.

the class NearbyParentFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    isDarkTheme = systemThemeUtils.isDeviceInNightMode();
    if (Utils.isMonumentsEnabled(new Date())) {
        rlContainerWLMMonthMessage.setVisibility(View.VISIBLE);
    } else {
        rlContainerWLMMonthMessage.setVisibility(View.GONE);
    }
    cameraMoveListener = () -> presenter.onCameraMove(mapBox.getCameraPosition().target);
    addCheckBoxCallback();
    presenter.attachView(this);
    isPermissionDenied = false;
    recenterToUserLocation = false;
    initRvNearbyList();
    initThemePreferences();
    mapView.onCreate(savedInstanceState);
    mapView.getMapAsync(mapBoxMap -> {
        mapBox = mapBoxMap;
        initViews();
        presenter.setActionListeners(applicationKvStore);
        initNearbyFilter();
        mapBoxMap.setStyle(isDarkTheme ? Style.DARK : Style.OUTDOORS, style -> {
            final UiSettings uiSettings = mapBoxMap.getUiSettings();
            uiSettings.setCompassGravity(Gravity.BOTTOM | Gravity.LEFT);
            uiSettings.setCompassMargins(12, 0, 0, 24);
            uiSettings.setLogoEnabled(false);
            uiSettings.setAttributionEnabled(false);
            uiSettings.setRotateGesturesEnabled(false);
            isMapBoxReady = true;
            if (nearbyParentFragmentInstanceReadyCallback != null) {
                nearbyParentFragmentInstanceReadyCallback.onReady();
            }
            performMapReadyActions();
            final CameraPosition cameraPosition;
            if (applicationKvStore.getString("LastLocation") != null) {
                // Checking for last searched location
                String[] locationLatLng = applicationKvStore.getString("LastLocation").split(",");
                cameraPosition = new CameraPosition.Builder().target(new LatLng(Double.valueOf(locationLatLng[0]), Double.valueOf(locationLatLng[1]))).zoom(ZOOM_LEVEL).build();
            } else {
                cameraPosition = new CameraPosition.Builder().target(new LatLng(51.50550, -0.07520)).zoom(ZOOM_OUT).build();
            }
            mapBoxMap.setCameraPosition(cameraPosition);
            final ScaleBarPlugin scaleBarPlugin = new ScaleBarPlugin(mapView, mapBoxMap);
            final int color = isDarkTheme ? R.color.bottom_bar_light : R.color.bottom_bar_dark;
            final ScaleBarOptions scaleBarOptions = new ScaleBarOptions(getContext()).setTextColor(color).setTextSize(R.dimen.description_text_size).setBarHeight(R.dimen.tiny_gap).setBorderWidth(R.dimen.miniscule_margin).setMarginTop(R.dimen.tiny_padding).setMarginLeft(R.dimen.tiny_padding).setTextBarMargin(R.dimen.tiny_padding);
            scaleBarPlugin.create(scaleBarOptions);
            onResume();
        });
    });
    tvAttribution.setText(Html.fromHtml(getString(R.string.map_attribution)));
    tvAttribution.setMovementMethod(LinkMovementMethod.getInstance());
    btnAdvancedOptions.setOnClickListener(v -> {
        searchView.clearFocus();
        showHideAdvancedQueryFragment(true);
        final AdvanceQueryFragment fragment = new AdvanceQueryFragment();
        final Bundle bundle = new Bundle();
        try {
            bundle.putString("query", FileUtils.readFromResource("/queries/nearby_query.rq"));
        } catch (IOException e) {
            Timber.e(e);
        }
        fragment.setArguments(bundle);
        fragment.callback = new Callback() {

            @Override
            public void close() {
                showHideAdvancedQueryFragment(false);
            }

            @Override
            public void reset() {
                presenter.setAdvancedQuery(null);
                presenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
                showHideAdvancedQueryFragment(false);
            }

            @Override
            public void apply(@NotNull final String query) {
                presenter.setAdvancedQuery(query);
                presenter.updateMapAndList(CUSTOM_QUERY);
                showHideAdvancedQueryFragment(false);
            }
        };
        getChildFragmentManager().beginTransaction().replace(R.id.fl_container_nearby_children, fragment).commit();
    });
}
Also used : UiSettings(com.mapbox.mapboxsdk.maps.UiSettings) Bundle(android.os.Bundle) ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) IOException(java.io.IOException) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Callback(fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) ScaleBarPlugin(com.mapbox.pluginscalebar.ScaleBarPlugin)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 UiSettings (com.mapbox.mapboxsdk.maps.UiSettings)1 ScaleBarOptions (com.mapbox.pluginscalebar.ScaleBarOptions)1 ScaleBarPlugin (com.mapbox.pluginscalebar.ScaleBarPlugin)1 Callback (fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback)1 IOException (java.io.IOException)1 Date (java.util.Date)1