Fix some crashes

This commit is contained in:
Thomas 2022-11-23 12:13:24 +01:00
parent 1c19b8815e
commit 80023219b3
6 changed files with 24 additions and 22 deletions

View File

@ -654,13 +654,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null); regex_public = sharedpreferences.getString(getString(R.string.SET_FILTER_REGEX_PUBLIC) + currentUserID + currentInstance, null);
show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false); show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false);
binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START)); binding.profilePicture.setOnClickListener(v -> binding.drawerLayout.openDrawer(GravityCompat.START));
Helper.loadPP(binding.profilePicture, currentAccount); Helper.loadPP(BaseMainActivity.this, binding.profilePicture, currentAccount);
headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance)); headerMainBinding.accountAcc.setText(String.format("%s@%s", currentAccount.mastodon_account.username, currentAccount.instance));
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) { if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct; currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
} }
headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name); headerMainBinding.accountName.setText(currentAccount.mastodon_account.display_name);
Helper.loadPP(headerMainBinding.accountProfilePicture, currentAccount, false); Helper.loadPP(BaseMainActivity.this, headerMainBinding.accountProfilePicture, currentAccount, false);
MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER); MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
/* /*
* Some general data are loaded when the app starts such; * Some general data are loaded when the app starts such;

View File

@ -870,7 +870,7 @@ public class ProfileActivity extends BaseActivity {
i++; i++;
} }
builderSingle.setMultiChoiceItems(listsArray, presentArray, (dialog, which, isChecked) -> { builderSingle.setMultiChoiceItems(listsArray, presentArray, (dialog, which, isChecked) -> {
if (!relationship.following) { if (relationship == null || !relationship.following) {
accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false) accountsVM.follow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id, true, false)
.observe(ProfileActivity.this, newRelationShip -> { .observe(ProfileActivity.this, newRelationShip -> {
relationship = newRelationShip; relationship = newRelationShip;

View File

@ -1132,8 +1132,8 @@ public class Helper {
* @param view ImageView - the view where the image will be loaded * @param view ImageView - the view where the image will be loaded
* @param account - {@link Account} * @param account - {@link Account}
*/ */
public static void loadPP(ImageView view, BaseAccount account) { public static void loadPP(Activity activity, ImageView view, BaseAccount account) {
loadPP(view, account, false); loadPP(activity, view, account, false);
} }
/** /**
@ -1142,15 +1142,14 @@ public class Helper {
* @param view ImageView - the view where the image will be loaded * @param view ImageView - the view where the image will be loaded
* @param account - {@link Account} * @param account - {@link Account}
*/ */
public static void loadPP(ImageView view, BaseAccount account, boolean crop) { public static void loadPP(Activity activity, ImageView view, BaseAccount account, boolean crop) {
Context context = view.getContext(); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean disableGif = sharedpreferences.getBoolean(activity.getString(R.string.SET_DISABLE_GIF), false);
boolean disableGif = sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_GIF), false);
String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar;
if (targetedUrl != null && Helper.isValidContextForGlide(context)) { if (targetedUrl != null && Helper.isValidContextForGlide(activity)) {
if (disableGif || (!targetedUrl.endsWith(".gif"))) { if (disableGif || (!targetedUrl.endsWith(".gif"))) {
try { try {
RequestBuilder<Drawable> requestBuilder = Glide.with(context) RequestBuilder<Drawable> requestBuilder = Glide.with(activity)
.asDrawable() .asDrawable()
.load(targetedUrl) .load(targetedUrl)
.thumbnail(0.1f); .thumbnail(0.1f);
@ -1161,7 +1160,7 @@ public class Helper {
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} else { } else {
RequestBuilder<GifDrawable> requestBuilder = Glide.with(context) RequestBuilder<GifDrawable> requestBuilder = Glide.with(activity)
.asGif() .asGif()
.load(targetedUrl) .load(targetedUrl)
.thumbnail(0.1f); .thumbnail(0.1f);
@ -1170,8 +1169,8 @@ public class Helper {
} }
requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))).into(view); requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))).into(view);
} }
} else if (Helper.isValidContextForGlide(context)) { } else if (Helper.isValidContextForGlide(activity)) {
Glide.with(context) Glide.with(activity)
.asDrawable() .asDrawable()
.load(R.drawable.ic_person) .load(R.drawable.ic_person)
.thumbnail(0.1f) .thumbnail(0.1f)

View File

@ -170,8 +170,10 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
holder.binding.delete.setOnClickListener(v -> { holder.binding.delete.setOnClickListener(v -> {
if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) { if (item.type == Timeline.TimeLineEnum.TAG || item.type == Timeline.TimeLineEnum.REMOTE || item.type == Timeline.TimeLineEnum.LIST) {
mUndoListener.onUndo(item, position); mUndoListener.onUndo(item, position);
pinned.pinnedTimelines.remove(position); if (position < pinned.pinnedTimelines.size()) {
notifyItemRemoved(position); pinned.pinnedTimelines.remove(position);
notifyItemRemoved(position);
}
} }
}); });
} }

View File

@ -622,8 +622,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
for (Notification notificationsAlreadyPresent : notificationList) { for (Notification notificationsAlreadyPresent : notificationList) {
//We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position //We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position
//Pinned messages are ignored because their date can be older //Pinned messages are ignored because their date can be older
//if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) { if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) {
if (notificationReceived.created_at.after(notificationsAlreadyPresent.created_at)) {
if (!notificationList.contains(notificationReceived)) { if (!notificationList.contains(notificationReceived)) {
notificationList.add(position, notificationReceived); notificationList.add(position, notificationReceived);
notificationAdapter.notifyItemInserted(position); notificationAdapter.notifyItemInserted(position);

View File

@ -661,22 +661,24 @@ public class TimelinesVM extends AndroidViewModel {
public LiveData<List<MastodonList>> getLists(@NonNull String instance, String token) { public LiveData<List<MastodonList>> getLists(@NonNull String instance, String token) {
mastodonListListMutableLiveData = new MutableLiveData<>(); mastodonListListMutableLiveData = new MutableLiveData<>();
MastodonTimelinesService mastodonTimelinesService = init(instance); MastodonTimelinesService mastodonTimelinesService = init(instance);
List<MastodonList> mastodonListList = new ArrayList<>();
new Thread(() -> { new Thread(() -> {
List<MastodonList> mastodonListList = null;
Call<List<MastodonList>> getListsCall = mastodonTimelinesService.getLists(token); Call<List<MastodonList>> getListsCall = mastodonTimelinesService.getLists(token);
if (getListsCall != null) { if (getListsCall != null) {
try { try {
Response<List<MastodonList>> getListsResponse = getListsCall.execute(); Response<List<MastodonList>> getListsResponse = getListsCall.execute();
if (getListsResponse.isSuccessful()) { if (getListsResponse.isSuccessful()) {
mastodonListList = getListsResponse.body(); List<MastodonList> mastodonLists = getListsResponse.body();
if (mastodonLists != null) {
mastodonListList.addAll(mastodonLists);
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
List<MastodonList> finalMastodonListList = mastodonListList; Runnable myRunnable = () -> mastodonListListMutableLiveData.setValue(mastodonListList);
Runnable myRunnable = () -> mastodonListListMutableLiveData.setValue(finalMastodonListList);
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
}).start(); }).start();
return mastodonListListMutableLiveData; return mastodonListListMutableLiveData;