Plain text displayed as html in edit fragment fix.

This commit is contained in:
Dmitry Yunitsky 2015-06-06 08:16:50 +03:00 committed by Alex Zolotarev
parent e0195cfc2e
commit cfcdb16a54
3 changed files with 32 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,6 +13,7 @@ import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.util.StringUtils;
import com.mapswithme.util.UiUtils;
public class EditDescriptionFragment extends BaseMwmDialogFragment
@ -49,6 +51,14 @@ public class EditDescriptionFragment extends BaseMwmDialogFragment
super.onViewCreated(view, savedInstanceState);
String description = getArguments().getString(EXTRA_DESCRIPTION);
if (StringUtils.isHtml(description))
{
final String descriptionNoSimpleTags = StringUtils.removeEditTextHtmlTags(description);
if (!StringUtils.isHtml(descriptionNoSimpleTags))
description = Html.fromHtml(description).toString();
}
mEtDescription = (EditText) view.findViewById(R.id.et__description);
mEtDescription.setText(description);
initToolbar(view);

View file

@ -663,10 +663,7 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
@Override
public void onSave(String description)
{
bookmark.setParams(bookmark.getName(), null, description);
final Bookmark updatedBookmark = BookmarkManager.INSTANCE.getBookmark(bookmark.getCategoryId(), bookmark.getBookmarkId());
setMapObject(updatedBookmark);
Statistics.INSTANCE.trackDescriptionChanged();
updateDescription(bookmark, description);
}
});
fragment.show(((FragmentActivity) getContext()).getSupportFragmentManager(), null);
@ -676,6 +673,14 @@ public class PlacePageView extends RelativeLayout implements View.OnClickListene
}
}
private void updateDescription(Bookmark bookmark, String description)
{
bookmark.setParams(bookmark.getName(), null, description);
final Bookmark updatedBookmark = BookmarkManager.INSTANCE.getBookmark(bookmark.getCategoryId(), bookmark.getBookmarkId());
setMapObject(updatedBookmark);
Statistics.INSTANCE.trackDescriptionChanged();
}
private void toggleIsBookmark()
{
if (mMapObject == null)

View file

@ -55,5 +55,18 @@ public class StringUtils
public static native boolean isHtml(String text);
/**
* Removes html tags, generated from edittext content after it's transformed to html.
* In version 4.3.1 we converted descriptions, entered by users, to html automatically. Later html conversion was cancelled, but those converted descriptions should be converted back to
* plain text, that's why that ugly util is introduced.
* @param text source text
* @return result text
*/
public static String removeEditTextHtmlTags(String text)
{
return text.replaceAll("</p>", "").replaceAll("<br>", "").replaceAll("<p dir=\"ltr\">", "");
}
private StringUtils() {}
}