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