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);
show_art_nsfw = sharedpreferences.getBoolean(getString(R.string.SET_ART_WITH_NSFW) + currentUserID + currentInstance, false);
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));
if (currentAccount.mastodon_account.display_name == null || currentAccount.mastodon_account.display_name.isEmpty()) {
currentAccount.mastodon_account.display_name = currentAccount.mastodon_account.acct;
}
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);
/*
* Some general data are loaded when the app starts such;

View File

@ -870,7 +870,7 @@ public class ProfileActivity extends BaseActivity {
i++;
}
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)
.observe(ProfileActivity.this, newRelationShip -> {
relationship = newRelationShip;

View File

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

View File

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

View File

@ -622,8 +622,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
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
//Pinned messages are ignored because their date can be older
//if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) {
if (notificationReceived.created_at.after(notificationsAlreadyPresent.created_at)) {
if (Helper.compareTo(notificationReceived.id, notificationsAlreadyPresent.id) > 0) {
if (!notificationList.contains(notificationReceived)) {
notificationList.add(position, notificationReceived);
notificationAdapter.notifyItemInserted(position);

View File

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