From a64244bf116fc6ad2db4438f79b789fae70b75f3 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 2 Jun 2022 19:15:12 +0200 Subject: [PATCH] Fix some crashes --- app/build.gradle | 4 ++-- .../fedilab/android/activities/MastodonListActivity.java | 3 +++ .../ui/fragment/timeline/FragmentMastodonTimeline.java | 4 +++- .../app/fedilab/android/viewmodel/mastodon/AccountsVM.java | 6 +++++- .../fedilab/android/viewmodel/mastodon/NotificationsVM.java | 6 +++++- .../app/fedilab/android/viewmodel/mastodon/SearchVM.java | 6 +++++- .../app/fedilab/android/viewmodel/mastodon/StatusesVM.java | 6 +++++- .../app/fedilab/android/viewmodel/mastodon/TimelinesVM.java | 6 +++++- 8 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4eeba64d..df014722 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdk 21 targetSdk 31 - versionCode 16 - versionName "beta-16" + versionCode 17 + versionName "beta-17" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java index 890db373..74d125fd 100644 --- a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java @@ -253,6 +253,9 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd if (popupAddListBinding.addList.getText() != null && popupAddListBinding.addList.getText().toString().trim().length() > 0) { timelinesVM.createList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, popupAddListBinding.addList.getText().toString().trim(), null) .observe(MastodonListActivity.this, newMastodonList -> { + if (mastodonListList == null) { + mastodonListList = new ArrayList<>(); + } if (newMastodonList != null) { mastodonListList.add(0, newMastodonList); mastodonListAdapter.notifyItemInserted(0); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 6d607d1d..44acdfcd 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -481,7 +481,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll */ private void route(DIRECTION direction, boolean fetchingMissing) { - + if (!isAdded()) { + return; + } new Thread(() -> { QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident); if (binding == null) { diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java index 7a7ad78e..105004f1 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java @@ -24,6 +24,9 @@ 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.LinkedHashMap; import java.util.List; import java.util.concurrent.TimeUnit; @@ -92,9 +95,10 @@ public class AccountsVM extends AndroidViewModel { } private MastodonAccountsService init(String instance) { + Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + instance + "/api/v1/") - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(okHttpClient) .build(); return retrofit.create(MastodonAccountsService.class); diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java index 15faaf60..b72976cc 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NotificationsVM.java @@ -23,6 +23,9 @@ 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.List; import java.util.concurrent.TimeUnit; @@ -60,9 +63,10 @@ public class NotificationsVM extends AndroidViewModel { } private MastodonNotificationsService init(@NonNull String instance) { + Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + instance + "/api/v1/") - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(okHttpClient) .build(); return retrofit.create(MastodonNotificationsService.class); diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/SearchVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/SearchVM.java index c1b09761..53772b81 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/SearchVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/SearchVM.java @@ -23,6 +23,9 @@ 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; @@ -55,9 +58,10 @@ public class SearchVM extends AndroidViewModel { } private MastodonSearchService init(@NonNull String instance) { + Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + instance + "/api/v2/") - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(okHttpClient) .build(); return retrofit.create(MastodonSearchService.class); diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/StatusesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/StatusesVM.java index 71d68934..a773fc0e 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/StatusesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/StatusesVM.java @@ -25,6 +25,9 @@ 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; @@ -86,9 +89,10 @@ public class StatusesVM extends AndroidViewModel { } private MastodonStatusesService init(@NonNull String instance) { + Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + instance + "/api/v1/") - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(getOkHttpClient()) .build(); return retrofit.create(MastodonStatusesService.class); diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index d40df65e..e1aa9d99 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -24,6 +24,9 @@ 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.List; import java.util.concurrent.TimeUnit; @@ -75,9 +78,10 @@ public class TimelinesVM extends AndroidViewModel { private MastodonTimelinesService init(String instance) { + Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://" + instance + "/api/v1/") - .addConverterFactory(GsonConverterFactory.create()) + .addConverterFactory(GsonConverterFactory.create(gson)) .client(okHttpClient) .build(); return retrofit.create(MastodonTimelinesService.class);