SpannedTypeAdapter.java 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /* Copyright 2017 Andrew Dawson
  2. *
  3. * This file is a part of Tusky.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it under the terms of the
  6. * GNU General Public License as published by the Free Software Foundation; either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  10. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  11. * Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with Tusky; if not,
  14. * see <http://www.gnu.org/licenses>. */
  15. package com.keylesspalace.tusky;
  16. import android.text.Spanned;
  17. import com.emojione.Emojione;
  18. import com.google.gson.JsonDeserializationContext;
  19. import com.google.gson.JsonDeserializer;
  20. import com.google.gson.JsonElement;
  21. import com.google.gson.JsonParseException;
  22. import java.lang.reflect.Type;
  23. class SpannedTypeAdapter implements JsonDeserializer<Spanned> {
  24. @Override
  25. public Spanned deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
  26. return HtmlUtils.fromHtml(Emojione.shortnameToUnicode(json.getAsString(), false));
  27. }
  28. }