Fix some crashes

This commit is contained in:
Thomas 2022-10-22 11:53:09 +02:00
parent 4dc8695c75
commit da887298df
9 changed files with 63 additions and 34 deletions

View file

@ -612,6 +612,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
.makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp)); .makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp));
startActivity(intent, options.toBundle()); startActivity(intent, options.toBundle());
}); });
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick()); headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
headerMainBinding.changeAccount.setOnClickListener(v -> { headerMainBinding.changeAccount.setOnClickListener(v -> {
headerMenuOpen = !headerMenuOpen; headerMenuOpen = !headerMenuOpen;
@ -858,12 +859,28 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
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;
* - Pinned timelines (in app feature)
* - Instance info (for limits) * - Instance info (for limits)
* - Emoji for picker * - Emoji for picker
* - Filters for timelines * - Filters for timelines
* - Pinned timelines (in app feature)
*/ */
//Update pinned timelines
new ViewModelProvider(BaseMainActivity.this).get(TopBarVM.class).getDBPinned()
.observe(this, pinned -> {
this.pinned = pinned;
//Initialize the slug of the first fragment
slugOfFirstFragment = PinnedTimelineHelper.firstTimelineSlug(BaseMainActivity.this, pinned, bottomMenu);
//First it's taken from db (last stored values)
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null);
//Fetch remote lists for the authenticated account and update them
new ViewModelProvider(BaseMainActivity.this).get(TimelinesVM.class).getLists(currentInstance, currentToken)
.observe(this, mastodonLists ->
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, mastodonLists)
);
});
//Update emoji in db for the current instance //Update emoji in db for the current instance
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance); new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
//Retrieve instance info //Retrieve instance info
@ -891,20 +908,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} }
}).start(); }).start();
}); });
//Update pinned timelines
new ViewModelProvider(BaseMainActivity.this).get(TopBarVM.class).getDBPinned()
.observe(this, pinned -> {
this.pinned = pinned;
//Initialize the slug of the first fragment
slugOfFirstFragment = PinnedTimelineHelper.firstTimelineSlug(BaseMainActivity.this, pinned, bottomMenu);
//First it's taken from db (last stored values)
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, null);
//Fetch remote lists for the authenticated account and update them
new ViewModelProvider(BaseMainActivity.this).get(TimelinesVM.class).getLists(currentInstance, currentToken)
.observe(this, mastodonLists ->
PinnedTimelineHelper.redrawTopBarPinned(BaseMainActivity.this, binding, pinned, bottomMenu, mastodonLists)
);
});
}; };
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
}).start(); }).start();

View file

@ -873,7 +873,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
private boolean canBeSent(StatusDraft statusDraft) { private boolean canBeSent(StatusDraft statusDraft) {
if (statusDraft == null || statusDraft.statusDraftList == null || statusDraft.statusDraftList.size() == 0) { if (statusDraft == null || statusDraft.statusDraftList == null || statusDraft.statusDraftList.isEmpty()) {
return false; return false;
} }
Status statusCheck = statusDraft.statusDraftList.get(0); Status statusCheck = statusDraft.statusDraftList.get(0);

View file

@ -666,7 +666,7 @@ public class ProfileActivity extends BaseActivity {
String[] splitAcct = account.acct.split("@"); String[] splitAcct = account.acct.split("@");
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
AlertDialog.Builder builderInner = null; AlertDialog.Builder builderInner = null;
final boolean isOwner = account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0; final boolean isOwner = account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0;
final String[] stringArrayConf; final String[] stringArrayConf;
if (isOwner) { if (isOwner) {
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm); stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);

View file

@ -151,7 +151,7 @@ public class CrossActionHelper {
} else if (targetedStatus != null) { } else if (targetedStatus != null) {
searchVM.search(ownerAccount.instance, ownerAccount.token, targetedStatus.uri, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(ownerAccount.instance, ownerAccount.token, targetedStatus.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) { if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status status = results.statuses.get(0); Status status = results.statuses.get(0);
applyAction(context, actionType, ownerAccount, null, status); applyAction(context, actionType, ownerAccount, null, status);
} else { } else {

View file

@ -252,7 +252,7 @@ public class Helper {
public static final String ARG_MEDIA_ATTACHMENT = "ARG_MEDIA_ATTACHMENT"; public static final String ARG_MEDIA_ATTACHMENT = "ARG_MEDIA_ATTACHMENT";
public static final String ARG_SHOW_REPLIES = "ARG_SHOW_REPLIES"; public static final String ARG_SHOW_REPLIES = "ARG_SHOW_REPLIES";
public static final String ARG_SHOW_REBLOGS = "ARG_SHOW_REBLOGS"; public static final String ARG_SHOW_REBLOGS = "ARG_SHOW_REBLOGS";
public static final String ARG_INITIALIZE_VIEW = "ARG_INITIALIZE_VIEW";
public static final String ARG_SHOW_PINNED = "ARG_SHOW_PINNED"; public static final String ARG_SHOW_PINNED = "ARG_SHOW_PINNED";
public static final String ARG_SHOW_MEDIA_ONY = "ARG_SHOW_MEDIA_ONY"; public static final String ARG_SHOW_MEDIA_ONY = "ARG_SHOW_MEDIA_ONY";
public static final String ARG_MENTION = "ARG_MENTION"; public static final String ARG_MENTION = "ARG_MENTION";

View file

@ -155,13 +155,17 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class); AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id) holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
.observe((LifecycleOwner) context, relationShip -> { .observe((LifecycleOwner) context, relationShip -> {
if (notificationList.size() > position) {
notificationList.remove(position); notificationList.remove(position);
notifyItemRemoved(position); notifyItemRemoved(position);
}
})); }));
holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id) holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
.observe((LifecycleOwner) context, relationShip -> { .observe((LifecycleOwner) context, relationShip -> {
if (notificationList.size() > position) {
notificationList.remove(position); notificationList.remove(position);
notifyItemRemoved(position); notifyItemRemoved(position);
}
})); }));
holderFollow.binding.avatar.setOnClickListener(v -> { holderFollow.binding.avatar.setOnClickListener(v -> {
Intent intent = new Intent(context, ProfileActivity.class); Intent intent = new Intent(context, ProfileActivity.class);

View file

@ -221,7 +221,13 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl
try { try {
int value = sharedPreferences.getInt(key, 0); int value = sharedPreferences.getInt(key, 0);
sharedPreferences.edit().putInt(getString(R.string.SET_LED_COLOUR_VAL), value).apply(); sharedPreferences.edit().putInt(getString(R.string.SET_LED_COLOUR_VAL), value).apply();
} catch (NumberFormatException e) { } catch (Exception e) {
try {
String value = sharedPreferences.getString(key, "0");
sharedPreferences.edit().putInt(getString(R.string.SET_LED_COLOUR_VAL), Integer.parseInt(value)).apply();
} catch (Exception e2) {
e.printStackTrace();
}
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -145,7 +145,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (slug.compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) { if (slug != null && slugOfFirstFragment != null && slug.compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) {
isViewInitialized = true; isViewInitialized = true;
initializeStatusesCommonView(initialStatuses); initializeStatusesCommonView(initialStatuses);
} }
@ -220,7 +220,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
canBeFederated = false; canBeFederated = false;
} }
} }
isViewInitialized = getArguments().getBoolean(Helper.ARG_INITIALIZE_VIEW, true);
tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE); tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE);
accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT);
exclude_replies = !getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, true); exclude_replies = !getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, true);
@ -252,8 +252,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (timelineType != null) { if (timelineType != null) {
slug = timelineType.getValue() + (ident != null ? "|" + ident : ""); slug = timelineType.getValue() + (ident != null ? "|" + ident : "");
} }
//Only the first fragment will initialize its view //Only fragment in main view pager should not have the view initialized
//AND Only the first fragment will initialize its view
if (!isViewInitialized) {
if (slug != null && slugOfFirstFragment != null) {
isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0; isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0;
} else {
isViewInitialized = timelineType.compareTo(Timeline.TimeLineEnum.HOME) == 0;
}
}
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
//Retrieve the max_id to keep position //Retrieve the max_id to keep position
@ -541,7 +548,7 @@ 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 routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) { private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) {
if (direction == null) { if (direction == null && !isViewInitialized) {
isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0; isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0;
} }
if (binding == null || getActivity() == null || !isAdded()) { if (binding == null || getActivity() == null || !isAdded()) {
@ -626,7 +633,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (isAdded()) { if (isAdded()) {
storeMarker(); storeMarker();
} }
try {
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action); LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action);
} catch (Exception ignored) {
}
super.onDestroyView(); super.onDestroyView();
} }

View file

@ -90,7 +90,7 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
FragmentMastodonTimeline fragment = new FragmentMastodonTimeline(); FragmentMastodonTimeline fragment = new FragmentMastodonTimeline();
fragment.update = activity; fragment.update = activity;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
//Position 3 is for notifications bundle.putBoolean(Helper.ARG_INITIALIZE_VIEW, false);
if (position < (BOTTOM_TIMELINE_COUNT - toRemove) && !singleBar) { if (position < (BOTTOM_TIMELINE_COUNT - toRemove) && !singleBar) {
if (bottomMenu != null) { if (bottomMenu != null) {
BottomMenu.ItemMenuType type = BottomMenu.getType(bottomMenu, position); BottomMenu.ItemMenuType type = BottomMenu.getType(bottomMenu, position);
@ -98,9 +98,13 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
return fragment; return fragment;
} }
if (type == BottomMenu.ItemMenuType.NOTIFICATION) { if (type == BottomMenu.ItemMenuType.NOTIFICATION) {
return new FragmentNotificationContainer(); FragmentNotificationContainer fragmentNotificationContainer = new FragmentNotificationContainer();
fragmentNotificationContainer.setArguments(bundle);
return fragmentNotificationContainer;
} else if (type == BottomMenu.ItemMenuType.DIRECT) { } else if (type == BottomMenu.ItemMenuType.DIRECT) {
return new FragmentMastodonConversation(); FragmentMastodonConversation fragmentMastodonConversation = new FragmentMastodonConversation();
fragmentMastodonConversation.setArguments(bundle);
return fragmentMastodonConversation;
} }
if (type == BottomMenu.ItemMenuType.HOME) { //Home timeline if (type == BottomMenu.ItemMenuType.HOME) { //Home timeline
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.HOME); bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.HOME);
@ -120,12 +124,13 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
if (pinnedTimeline.type == Timeline.TimeLineEnum.NOTIFICATION) { if (pinnedTimeline.type == Timeline.TimeLineEnum.NOTIFICATION) {
FragmentNotificationContainer fragmentNotificationContainer = new FragmentNotificationContainer(); FragmentNotificationContainer fragmentNotificationContainer = new FragmentNotificationContainer();
FragmentNotificationContainer.update = activity; FragmentNotificationContainer.update = activity;
fragmentNotificationContainer.setArguments(bundle);
return fragmentNotificationContainer; return fragmentNotificationContainer;
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.DIRECT) { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.DIRECT) {
FragmentMastodonConversation fragmentMastodonConversation = new FragmentMastodonConversation(); FragmentMastodonConversation fragmentMastodonConversation = new FragmentMastodonConversation();
fragmentMastodonConversation.update = activity; fragmentMastodonConversation.update = activity;
fragmentMastodonConversation.setArguments(bundle);
return fragmentMastodonConversation; return fragmentMastodonConversation;
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) {
bundle.putString(Helper.ARG_LIST_ID, pinnedTimeline.mastodonList.id); bundle.putString(Helper.ARG_LIST_ID, pinnedTimeline.mastodonList.id);
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) { } else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) {