remove old emoji shortcodes

This commit is contained in:
Conny Duck 2017-10-19 15:54:08 +02:00
parent 3adef27bbb
commit 2666f81b96
7 changed files with 13 additions and 1969 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,8 +36,6 @@ import android.view.Menu;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.keylesspalace.tusky.json.SpannedTypeAdapter; import com.keylesspalace.tusky.json.SpannedTypeAdapter;
import com.keylesspalace.tusky.json.StringWithEmoji;
import com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter;
import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.network.MastodonApi;
import com.keylesspalace.tusky.network.TuskyApi; import com.keylesspalace.tusky.network.TuskyApi;
import com.keylesspalace.tusky.service.PullNotificationService; import com.keylesspalace.tusky.service.PullNotificationService;
@ -127,8 +125,8 @@ public class BaseActivity extends AppCompatActivity {
protected void createMastodonApi() { protected void createMastodonApi() {
mastodonApiDispatcher = new Dispatcher(); mastodonApiDispatcher = new Dispatcher();
Gson gson = new GsonBuilder().registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()) Gson gson = new GsonBuilder()
.registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter()) .registerTypeAdapter(Spanned.class, new SpannedTypeAdapter())
.create(); .create();
OkHttpClient.Builder okBuilder = OkHttpClient.Builder okBuilder =

View File

@ -21,7 +21,6 @@ import android.text.Spanned;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.keylesspalace.tusky.util.HtmlUtils; import com.keylesspalace.tusky.util.HtmlUtils;
import com.keylesspalace.tusky.json.StringWithEmoji;
public class Account implements Parcelable { public class Account implements Parcelable {
public String id; public String id;
@ -33,7 +32,7 @@ public class Account implements Parcelable {
public String username; public String username;
@SerializedName("display_name") @SerializedName("display_name")
public StringWithEmoji displayName; public String displayName;
public Spanned note; public Spanned note;
@ -71,10 +70,10 @@ public class Account implements Parcelable {
} }
public String getDisplayName() { public String getDisplayName() {
if (displayName.value.length() == 0) { if (displayName.length() == 0) {
return localUsername; return localUsername;
} }
return displayName.value; return displayName;
} }
@Override @Override
@ -87,7 +86,7 @@ public class Account implements Parcelable {
dest.writeString(id); dest.writeString(id);
dest.writeString(localUsername); dest.writeString(localUsername);
dest.writeString(username); dest.writeString(username);
dest.writeString(displayName.value); dest.writeString(displayName);
dest.writeString(HtmlUtils.toHtml(note)); dest.writeString(HtmlUtils.toHtml(note));
dest.writeString(url); dest.writeString(url);
dest.writeString(avatar); dest.writeString(avatar);
@ -104,7 +103,7 @@ public class Account implements Parcelable {
id = in.readString(); id = in.readString();
localUsername = in.readString(); localUsername = in.readString();
username = in.readString(); username = in.readString();
displayName = new StringWithEmoji(in.readString()); displayName = in.readString();
note = HtmlUtils.fromHtml(in.readString()); note = HtmlUtils.fromHtml(in.readString());
url = in.readString(); url = in.readString();
avatar = in.readString(); avatar = in.readString();

View File

@ -18,7 +18,6 @@ package com.keylesspalace.tusky.json;
import android.text.Spanned; import android.text.Spanned;
import android.text.SpannedString; import android.text.SpannedString;
import com.emojione.Emojione;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -33,7 +32,7 @@ public class SpannedTypeAdapter implements JsonDeserializer<Spanned> {
throws JsonParseException { throws JsonParseException {
String string = json.getAsString(); String string = json.getAsString();
if (string != null) { if (string != null) {
return HtmlUtils.fromHtml(Emojione.shortnameToUnicode(string, false)); return HtmlUtils.fromHtml(string);
} else { } else {
return new SpannedString(""); return new SpannedString("");
} }

View File

@ -1,31 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.json;
/**
* This is just a wrapper class for a String.
*
* It was designed to get around the limitation of a Json deserializer which only allows custom
* deserializing based on types, when special handling for a specific field was what was actually
* desired (in this case, display names). So, it was most expedient to just make up a type.
*/
public class StringWithEmoji {
public String value;
public StringWithEmoji(String value) {
this.value = value;
}
}

View File

@ -1,38 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.json;
import com.emojione.Emojione;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
/** This is a type-based workaround to allow for shortcode conversion when loading display names. */
public class StringWithEmojiTypeAdapter implements JsonDeserializer<StringWithEmoji> {
@Override
public StringWithEmoji deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
String value = json.getAsString();
if (value != null) {
return new StringWithEmoji(Emojione.shortnameToUnicode(value, false));
} else {
return new StringWithEmoji("");
}
}
}

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.text.Spanned; import android.text.Spanned;
import android.util.Log; import android.util.Log;
@ -28,8 +29,6 @@ import com.google.gson.GsonBuilder;
import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.entity.Notification; import com.keylesspalace.tusky.entity.Notification;
import com.keylesspalace.tusky.json.SpannedTypeAdapter; import com.keylesspalace.tusky.json.SpannedTypeAdapter;
import com.keylesspalace.tusky.json.StringWithEmoji;
import com.keylesspalace.tusky.json.StringWithEmojiTypeAdapter;
import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.network.MastodonApi;
import com.keylesspalace.tusky.util.OkHttpUtils; import com.keylesspalace.tusky.util.OkHttpUtils;
import com.keylesspalace.tusky.util.NotificationMaker; import com.keylesspalace.tusky.util.NotificationMaker;
@ -73,15 +72,15 @@ public class PullNotificationService extends IntentService {
mastodonApi.notifications(null, null, null).enqueue(new Callback<List<Notification>>() { mastodonApi.notifications(null, null, null).enqueue(new Callback<List<Notification>>() {
@Override @Override
public void onResponse(Call<List<Notification>> call, public void onResponse(@NonNull Call<List<Notification>> call,
Response<List<Notification>> response) { @NonNull Response<List<Notification>> response) {
if (response.isSuccessful()) { if (response.isSuccessful()) {
onNotificationsReceived(response.body()); onNotificationsReceived(response.body());
} }
} }
@Override @Override
public void onFailure(Call<List<Notification>> call, Throwable t) {} public void onFailure(@NonNull Call<List<Notification>> call, @NonNull Throwable t) {}
}); });
} }
@ -94,7 +93,7 @@ public class PullNotificationService extends IntentService {
OkHttpClient okHttpClient = OkHttpUtils.getCompatibleClientBuilder() OkHttpClient okHttpClient = OkHttpUtils.getCompatibleClientBuilder()
.addInterceptor(new Interceptor() { .addInterceptor(new Interceptor() {
@Override @Override
public okhttp3.Response intercept(Chain chain) throws IOException { public okhttp3.Response intercept(@NonNull Chain chain) throws IOException {
Request originalRequest = chain.request(); Request originalRequest = chain.request();
Request.Builder builder = originalRequest.newBuilder() Request.Builder builder = originalRequest.newBuilder()
@ -109,7 +108,6 @@ public class PullNotificationService extends IntentService {
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(Spanned.class, new SpannedTypeAdapter()) .registerTypeAdapter(Spanned.class, new SpannedTypeAdapter())
.registerTypeAdapter(StringWithEmoji.class, new StringWithEmojiTypeAdapter())
.create(); .create();
Retrofit retrofit = new Retrofit.Builder() Retrofit retrofit = new Retrofit.Builder()