[android] Refactored editor to get/set metadata fields separately.

This commit is contained in:
Dmitry Yunitsky 2016-04-19 13:35:37 +03:00
parent d2277c2d04
commit 5ddb411fb1
4 changed files with 172 additions and 97 deletions

View file

@ -56,71 +56,148 @@ Java_com_mapswithme_maps_editor_Editor_nativeInit(JNIEnv * env, jclass)
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetMetadata(JNIEnv * env, jclass, jint type)
Java_com_mapswithme_maps_editor_Editor_nativeGetOpeningHours(JNIEnv * env, jclass)
{
// TODO(yunikkk): Switch to osm::Props enum instead of metadata, and use separate getters instead a generic one.
return jni::ToJavaString(env, g_editableMapObject.GetMetadata().Get(static_cast<feature::Metadata::EType>(type)));
return jni::ToJavaString(env, g_editableMapObject.GetOpeningHours());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetMetadata(JNIEnv * env, jclass clazz, jint type, jstring value)
Java_com_mapswithme_maps_editor_Editor_nativeSetOpeningHours(JNIEnv * env, jclass, jstring value)
{
// TODO(yunikkk): I would recommend to use separate setters/getters for each metadata field.
string const v = jni::ToNativeString(env, value);
using feature::Metadata;
switch (type)
{
case Metadata::FMD_OPEN_HOURS: g_editableMapObject.SetOpeningHours(v); break;
case Metadata::FMD_PHONE_NUMBER: g_editableMapObject.SetPhone(v); break;
case Metadata::FMD_FAX_NUMBER: g_editableMapObject.SetFax(v); break;
case Metadata::FMD_STARS:
{
// TODO(yunikkk): Pass stars in a separate integer setter.
int stars;
if (strings::to_int(v, stars))
g_editableMapObject.SetStars(stars);
break;
}
case Metadata::FMD_OPERATOR: g_editableMapObject.SetOperator(v); break;
case Metadata::FMD_URL: // We don't allow url in UI. Website should be used instead.
case Metadata::FMD_WEBSITE: g_editableMapObject.SetWebsite(v); break;
case Metadata::FMD_INTERNET: // TODO(yunikkk): use separate setter for Internet.
{
osm::Internet inet = osm::Internet::Unknown;
if (v == DebugPrint(osm::Internet::Wlan))
inet = osm::Internet::Wlan;
if (v == DebugPrint(osm::Internet::Wired))
inet = osm::Internet::Wired;
if (v == DebugPrint(osm::Internet::No))
inet = osm::Internet::No;
if (v == DebugPrint(osm::Internet::Yes))
inet = osm::Internet::Yes;
g_editableMapObject.SetInternet(inet);
}
break;
case Metadata::FMD_ELE:
{
double ele;
if (strings::to_double(v, ele))
g_editableMapObject.SetElevation(ele);
break;
}
case Metadata::FMD_EMAIL: g_editableMapObject.SetEmail(v); break;
case Metadata::FMD_POSTCODE: g_editableMapObject.SetPostcode(v); break;
case Metadata::FMD_WIKIPEDIA: g_editableMapObject.SetWikipedia(v); break;
case Metadata::FMD_FLATS: g_editableMapObject.SetFlats(v); break;
case Metadata::FMD_BUILDING_LEVELS: g_editableMapObject.SetBuildingLevels(v); break;
case Metadata::FMD_TURN_LANES:
case Metadata::FMD_TURN_LANES_FORWARD:
case Metadata::FMD_TURN_LANES_BACKWARD:
case Metadata::FMD_MAXSPEED:
case Metadata::FMD_HEIGHT:
case Metadata::FMD_MIN_HEIGHT:
case Metadata::FMD_DENOMINATION:
case Metadata::FMD_TEST_ID:
case Metadata::FMD_COUNT:
break;
}
g_editableMapObject.SetOpeningHours(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetPhone(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetPhone());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetPhone(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetPhone(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetWebsite(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetWebsite());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetWebsite(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetWebsite(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetEmail(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetEmail());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetEmail(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetEmail(jni::ToNativeString(env, value));
}
JNIEXPORT jint JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetStars(JNIEnv * env, jclass)
{
return g_editableMapObject.GetStars();
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetStars(JNIEnv * env, jclass, jint value)
{
g_editableMapObject.SetStars(value);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetOperator(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetOperator());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetOperator(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetOperator(jni::ToNativeString(env, value));
}
JNIEXPORT jdouble JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetElevation(JNIEnv * env, jclass)
{
double elevation;
return g_editableMapObject.GetElevation(elevation) ? elevation : -1;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetElevation(JNIEnv * env, jclass, jdouble value)
{
g_editableMapObject.SetElevation(value);
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetWikipedia(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetWikipedia());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetWikipedia(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetWikipedia(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetFlats(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetFlats());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetFlats(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetFlats(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetBuildingLevels(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetBuildingLevels());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetBuildingLevels(JNIEnv * env, jclass, jstring value)
{
g_editableMapObject.SetBuildingLevels(jni::ToNativeString(env, value));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetZipCode(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, g_editableMapObject.GetPostcode());
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetZipCode(JNIEnv * env, jclass clazz, jstring value)
{
g_editableMapObject.SetPostcode(jni::ToNativeString(env, value));
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeHasWifi(JNIEnv *, jclass)
{
return g_editableMapObject.GetInternet() == osm::Internet::Wlan;
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeSetHasWifi(JNIEnv *, jclass, jboolean hasWifi)
{
g_editableMapObject.SetInternet(osm::Internet::Wlan);
}
JNIEXPORT jboolean JNICALL
@ -220,13 +297,6 @@ Java_com_mapswithme_maps_editor_Editor_nativeGetNearbyStreets(JNIEnv * env, jcla
return jStreets;
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeHasWifi(JNIEnv *, jclass)
{
// TODO(AlexZ): Support 3-state: yes, no, unknown.
return g_editableMapObject.GetMetadata().Get(feature::Metadata::FMD_INTERNET) == "wlan";
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeHasSomethingToUpload(JNIEnv * env, jclass clazz)
{
@ -374,7 +444,6 @@ Java_com_mapswithme_maps_editor_Editor_nativeIsHouseValid(JNIEnv * env, jclass c
return osm::EditableMapObject::ValidateHouseNumber(jni::ToNativeString(env, houseNumber));
}
// static boolean nativeGetCategory();
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_editor_Editor_nativeGetCategory(JNIEnv * env, jclass clazz)
{

View file

@ -54,19 +54,31 @@ public final class Editor
@NonNull
public static native int[] nativeGetEditableFields();
public static String getMetadata(Metadata.MetadataType type)
{
return nativeGetMetadata(type.toInt());
}
public static void setMetadata(Metadata.MetadataType type, String value)
{
nativeSetMetadata(type.toInt(), value);
}
private static native String nativeGetMetadata(int type);
private static native void nativeSetMetadata(int type, String value);
public static native String nativeGetCategory();
public static native String nativeGetOpeningHours();
public static native void nativeSetOpeningHours(String openingHours);
public static native String nativeGetPhone();
public static native void nativeSetPhone(String phone);
public static native String nativeGetWebsite();
public static native void nativeSetWebsite(String website);
public static native String nativeGetEmail();
public static native void nativeSetEmail(String email);
public static native int nativeGetStars();
public static native void nativeSetStars(String stars);
public static native String nativeGetOperator();
public static native void nativeSetOperator(String operator);
public static native String nativeGetWikipedia();
public static native void nativeSetWikipedia(String wikipedia);
public static native String nativeGetFlats();
public static native void nativeSetFlats(String flats);
public static native String nativeGetBuildingLevels();
public static native void nativeSetBuildingLevels(String levels);
public static native String nativeGetZipCode();
public static native void nativeSetZipCode(String zipCode);
public static native boolean nativeHasWifi();
public static native boolean nativeSetHasWifi(boolean hasWifi);
public static native boolean nativeIsAddressEditable();
public static native boolean nativeIsNameEditable();
@NonNull
@ -84,9 +96,6 @@ public final class Editor
public static native String nativeGetHouseNumber();
public static native void nativeSetHouseNumber(String houseNumber);
// TODO(AlexZ): Support 3-state: Yes, No, Unknown.
public static native boolean nativeHasWifi();
public static native boolean nativeHasSomethingToUpload();
@WorkerThread
private static native void nativeUploadChanges(String token, String secret, String appVersion, String appId);
@ -144,6 +153,4 @@ public final class Editor
public static native void nativePlaceDoesNotExist(double lat, double lon);
public static native boolean nativeIsHouseValid(String houseNumber);
public static native String nativeGetCategory();
}

View file

@ -85,9 +85,9 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
mInputHouseNumber.setError(null);
}
});
mEtPhone.setText(Editor.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
mEtWebsite.setText(Editor.getMetadata(Metadata.MetadataType.FMD_WEBSITE));
mEtEmail.setText(Editor.getMetadata(Metadata.MetadataType.FMD_EMAIL));
mEtPhone.setText(Editor.nativeGetPhone());
mEtWebsite.setText(Editor.nativeGetWebsite());
mEtEmail.setText(Editor.nativeGetEmail());
mTvCuisine.setText(Editor.nativeGetFormattedCuisine());
mSwWifi.setChecked(Editor.nativeHasWifi());
refreshOpeningTime();
@ -107,10 +107,10 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
if (!validateFields())
return false;
Editor.setMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER, getPhone());
Editor.setMetadata(Metadata.MetadataType.FMD_WEBSITE, getWebsite());
Editor.setMetadata(Metadata.MetadataType.FMD_EMAIL, getEmail());
Editor.setMetadata(Metadata.MetadataType.FMD_INTERNET, getWifi());
Editor.nativeSetPhone(getPhone());
Editor.nativeSetWebsite(getWebsite());
Editor.nativeSetEmail(getEmail());
Editor.nativeSetHasWifi(hasWifi());
Editor.nativeSetDefaultName(getName());
Editor.nativeSetHouseNumber(getHouseNumber());
@ -165,9 +165,9 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
return mTvCuisine.getText().toString();
}
public String getWifi()
public boolean hasWifi()
{
return mSwWifi.isChecked() ? "wlan" : "";
return mSwWifi.isChecked();
}
private void refreshEditableFields()
@ -221,7 +221,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private void refreshOpeningTime()
{
final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(Editor.getMetadata(Metadata.MetadataType.FMD_OPEN_HOURS));
final Timetable[] timetables = OpeningHours.nativeTimetablesFromString(Editor.nativeGetOpeningHours());
if (timetables == null)
{
UiUtils.show(mEmptyOpeningHours);

View file

@ -16,7 +16,6 @@ import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.bookmarks.data.Metadata;
import com.mapswithme.maps.widget.SearchToolbarController;
import com.mapswithme.maps.widget.ToolbarController;
import com.mapswithme.util.ConnectionState;
@ -121,7 +120,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
mMode = Mode.OPENING_HOURS;
mToolbarController.setTitle(R.string.editor_time_title);
final Bundle args = new Bundle();
args.putString(TimetableFragment.EXTRA_TIME, Editor.getMetadata(Metadata.MetadataType.FMD_OPEN_HOURS));
args.putString(TimetableFragment.EXTRA_TIME, Editor.nativeGetOpeningHours());
final Fragment editorFragment = Fragment.instantiate(getActivity(), TimetableFragment.class.getName(), args);
getChildFragmentManager().beginTransaction()
.replace(R.id.fragment_container, editorFragment, TimetableFragment.class.getName())
@ -181,7 +180,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
final String timetables = ((TimetableFragment) getChildFragmentManager().findFragmentByTag(TimetableFragment.class.getName())).getTimetable();
if (OpeningHours.nativeIsTimetableStringValid(timetables))
{
Editor.setMetadata(Metadata.MetadataType.FMD_OPEN_HOURS, timetables);
Editor.nativeSetOpeningHours(timetables);
editMapObject();
}
else