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 {
minSdk 21
targetSdk 31
versionCode 16
versionName "beta-16"
versionCode 17
versionName "beta-17"
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) {
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);

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
*/
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) {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);