Fix some crashes

This commit is contained in:
Thomas 2022-06-02 19:15:12 +02:00
parent b9efa41750
commit a64244bf11
8 changed files with 33 additions and 8 deletions

View file

@ -9,8 +9,8 @@ android {
defaultConfig { defaultConfig {
minSdk 21 minSdk 21
targetSdk 31 targetSdk 31
versionCode 16 versionCode 17
versionName "beta-16" versionName "beta-17"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View file

@ -253,6 +253,9 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd
if (popupAddListBinding.addList.getText() != null && popupAddListBinding.addList.getText().toString().trim().length() > 0) { if (popupAddListBinding.addList.getText() != null && popupAddListBinding.addList.getText().toString().trim().length() > 0) {
timelinesVM.createList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, popupAddListBinding.addList.getText().toString().trim(), null) timelinesVM.createList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, popupAddListBinding.addList.getText().toString().trim(), null)
.observe(MastodonListActivity.this, newMastodonList -> { .observe(MastodonListActivity.this, newMastodonList -> {
if (mastodonListList == null) {
mastodonListList = new ArrayList<>();
}
if (newMastodonList != null) { if (newMastodonList != null) {
mastodonListList.add(0, newMastodonList); mastodonListList.add(0, newMastodonList);
mastodonListAdapter.notifyItemInserted(0); mastodonListAdapter.notifyItemInserted(0);

View file

@ -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 * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
*/ */
private void route(DIRECTION direction, boolean fetchingMissing) { private void route(DIRECTION direction, boolean fetchingMissing) {
if (!isAdded()) {
return;
}
new Thread(() -> { new Thread(() -> {
QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident); QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident);
if (binding == null) { if (binding == null) {

View file

@ -24,6 +24,9 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -92,9 +95,10 @@ public class AccountsVM extends AndroidViewModel {
} }
private MastodonAccountsService init(String instance) { private MastodonAccountsService init(String instance) {
Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder() Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/") .baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient) .client(okHttpClient)
.build(); .build();
return retrofit.create(MastodonAccountsService.class); return retrofit.create(MastodonAccountsService.class);

View file

@ -23,6 +23,9 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -60,9 +63,10 @@ public class NotificationsVM extends AndroidViewModel {
} }
private MastodonNotificationsService init(@NonNull String instance) { private MastodonNotificationsService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder() Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v1/") .baseUrl("https://" + instance + "/api/v1/")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient) .client(okHttpClient)
.build(); .build();
return retrofit.create(MastodonNotificationsService.class); return retrofit.create(MastodonNotificationsService.class);

View file

@ -23,6 +23,9 @@ import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -55,9 +58,10 @@ public class SearchVM extends AndroidViewModel {
} }
private MastodonSearchService init(@NonNull String instance) { private MastodonSearchService init(@NonNull String instance) {
Gson gson = new GsonBuilder().setDateFormat("MMM dd, yyyy HH:mm:ss").create();
Retrofit retrofit = new Retrofit.Builder() Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://" + instance + "/api/v2/") .baseUrl("https://" + instance + "/api/v2/")
.addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient) .client(okHttpClient)
.build(); .build();
return retrofit.create(MastodonSearchService.class); return retrofit.create(MastodonSearchService.class);

View file

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

View file

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