[android] Use separate function to check for MapTooOldToEdit

Signed-off-by: map-per <map-per@gmx.de>
This commit is contained in:
map-per
2025-12-16 14:24:23 +01:00
committed by Konstantin Pastbin
parent 67d88b4fa9
commit 498dcc4240
5 changed files with 58 additions and 13 deletions

View File

@@ -700,22 +700,27 @@ public class PlacePageView extends Fragment
if (shouldEnableEditPlace)
{
mTvEditPlace.setEnabled(true);
mTvAddPlace.setEnabled(true);
mTvEditPlace.setOnClickListener(this);
mTvAddPlace.setOnClickListener(this);
}
else
{
mTvEditPlace.setOnClickListener((v) -> {
Utils.showSnackbar(v.getContext(), v.getRootView(), R.string.place_page_too_old_to_edit);
});
mTvAddPlace.setOnClickListener((v) -> {
Utils.showSnackbar(v.getContext(), v.getRootView(), R.string.place_page_too_old_to_edit);
});
String countryId = MapManager.nativeGetSelectedCountry();
if (countryId != null)
if (countryId != null && MapManager.nativeIsMapTooOldToEdit(countryId))
{
// map editing is disabled because the map is too old
mTvEditPlace.setEnabled(true);
mTvAddPlace.setEnabled(true);
mTvEditPlace.setOnClickListener((v) -> {
Utils.showSnackbar(v.getContext(), v.getRootView(), R.string.place_page_too_old_to_edit);
});
mTvAddPlace.setOnClickListener((v) -> {
Utils.showSnackbar(v.getContext(), v.getRootView(), R.string.place_page_too_old_to_edit);
});
CountryItem map = CountryItem.fill(countryId);
if (map.status == CountryItem.STATUS_UPDATABLE || map.status == CountryItem.STATUS_DONE
@@ -740,6 +745,12 @@ public class PlacePageView extends Fragment
mapTooOldDescription.setText(R.string.place_page_app_too_old_description);
}
}
else
{
// map editing is disabled for other reasons
mTvEditPlace.setEnabled(false);
mTvAddPlace.setEnabled(false);
}
}
final int editButtonColor =

View File

@@ -587,4 +587,11 @@ JNIEXPORT jstring JNICALL Java_app_organicmaps_sdk_downloader_MapManager_nativeG
storage::CountryId const & res = g_framework->GetPlacePageInfo().GetCountryId();
return (res == storage::kInvalidCountryId ? nullptr : jni::ToJavaString(env, res));
}
// static native boolean nativeIsMapTooOldToEdit(String countryId);
JNIEXPORT jboolean JNICALL Java_app_organicmaps_sdk_downloader_MapManager_nativeIsMapTooOldToEdit(JNIEnv *env, jclass clazz,
jstring country_id)
{
return GetStorage().IsMapTooOldToEdit(jni::ToNativeString(env, country_id));
}
} // extern "C"

View File

@@ -261,4 +261,9 @@ public final class MapManager
* Returns country ID which the current PP object points to, or {@code null}.
*/
public static native @Nullable String nativeGetSelectedCountry();
/**
* Returns true when the map exists and is too old for map editing.
*/
public static native boolean nativeIsMapTooOldToEdit(String countryId);
}