This commit is contained in:
Thomas 2022-07-02 11:01:14 +02:00
parent 8aaf5bfb25
commit b039670d53
16 changed files with 66 additions and 44 deletions

View file

@ -27,9 +27,6 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.preference.PreferenceManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -255,10 +252,9 @@ public class CrossActionHelper {
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(Helper.getProxy(context))
.build();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonSearchService.class);

View file

@ -90,6 +90,12 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import com.jaredrummler.cyanea.Cyanea;
import org.conscrypt.Conscrypt;
@ -107,6 +113,7 @@ import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.security.Security;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
@ -116,6 +123,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -1583,4 +1591,36 @@ public class Helper {
void onAttachmentCopied(Attachment attachment);
}
public static Gson getDateBuilder() {
SimpleDateFormat[] formats = new SimpleDateFormat[]{
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault()),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()),
};
return new GsonBuilder()
.registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
@Override
public void write(JsonWriter out, Date value) {
}
@Override
public Date read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
String dateAsString = reader.nextString();
for (SimpleDateFormat format : formats) {
try {
format.setTimeZone(TimeZone.getTimeZone("UTC"));
return format.parse(dateAsString);
} catch (ParseException ignored) {
}
}
return null;
}
})
.create();
}
}

View file

@ -145,7 +145,7 @@ public class NotificationsHelper {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonNotificationsService.class);

View file

@ -26,9 +26,6 @@ import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@ -137,10 +134,9 @@ public class PushNotifications {
.connectTimeout(60, TimeUnit.SECONDS)
.proxy(Helper.getProxy(context.getApplicationContext()))
.build();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonNotificationsService.class);

View file

@ -1067,6 +1067,9 @@ public class SpannableHelper {
if (status.translationContent != null) {
status.span_translate = SpannableHelper.convert(context, status, status.translationContent);
}
if (status.account == null) {
return status;
}
status.account.span_display_name = SpannableHelper.convertA(context, status.account, status.account.display_name, true);
if (status.poll != null) {
for (Poll.PollItem pollItem : status.poll.options) {

View file

@ -31,9 +31,6 @@ import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -90,10 +87,9 @@ public class PostMessageService extends IntentService {
}
private static MastodonStatusesService init(Context context, @NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(getOkHttpClient(context))
.build();
return retrofit.create(MastodonStatusesService.class);

View file

@ -95,10 +95,10 @@ public class AccountsVM extends AndroidViewModel {
}
private MastodonAccountsService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAccountsService.class);

View file

@ -60,10 +60,10 @@ public class AdminVM extends AndroidViewModel {
}
private MastodonAdminService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAdminService.class);

View file

@ -55,10 +55,10 @@ public class AnnouncementsVM extends AndroidViewModel {
}
private MastodonAnnouncementsService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAnnouncementsService.class);

View file

@ -58,10 +58,10 @@ public class AppsVM extends AndroidViewModel {
}
private MastodonAppsService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAppsService.class);

View file

@ -61,10 +61,10 @@ public class InstancesVM extends AndroidViewModel {
}
private MastodonInstanceService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonInstanceService.class);

View file

@ -63,10 +63,10 @@ public class NotificationsVM extends AndroidViewModel {
}
private MastodonNotificationsService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonNotificationsService.class);

View file

@ -59,10 +59,10 @@ public class OauthVM extends AndroidViewModel {
}
private MastodonAppsService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonAppsService.class);

View file

@ -58,10 +58,10 @@ public class SearchVM extends AndroidViewModel {
}
private MastodonSearchService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonSearchService.class);

View file

@ -25,9 +25,6 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -90,10 +87,9 @@ public class StatusesVM extends AndroidViewModel {
}
private MastodonStatusesService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(getOkHttpClient())
.build();
return retrofit.create(MastodonStatusesService.class);

View file

@ -24,9 +24,6 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -84,10 +81,9 @@ public class TimelinesVM extends AndroidViewModel {
}
private MastodonTimelinesService initInstanceOnly(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance)
// .addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonTimelinesService.class);
@ -103,10 +99,9 @@ public class TimelinesVM extends AndroidViewModel {
}
private MastodonTimelinesService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create(gson))
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
.client(okHttpClient)
.build();
return retrofit.create(MastodonTimelinesService.class);