forked from mirrors/Fedilab
Fix some crashes
This commit is contained in:
parent
4dc8695c75
commit
da887298df
9 changed files with 63 additions and 34 deletions
|
@ -612,6 +612,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
.makeSceneTransitionAnimation(BaseMainActivity.this, headerMainBinding.instanceInfoContainer, getString(R.string.activity_porfile_pp));
|
||||
startActivity(intent, options.toBundle());
|
||||
});
|
||||
|
||||
headerMainBinding.accountAcc.setOnClickListener(v -> headerMainBinding.changeAccount.callOnClick());
|
||||
headerMainBinding.changeAccount.setOnClickListener(v -> {
|
||||
headerMenuOpen = !headerMenuOpen;
|
||||
|
@ -858,12 +859,28 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
MastodonHelper.loadProfileMediaMastodon(headerMainBinding.backgroundImage, currentAccount.mastodon_account, MastodonHelper.MediaAccountType.HEADER);
|
||||
/*
|
||||
* Some general data are loaded when the app starts such;
|
||||
* - Pinned timelines (in app feature)
|
||||
* - Instance info (for limits)
|
||||
* - Emoji for picker
|
||||
* - 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
|
||||
new ViewModelProvider(BaseMainActivity.this).get(InstancesVM.class).getEmoji(currentInstance);
|
||||
//Retrieve instance info
|
||||
|
@ -891,20 +908,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
}
|
||||
}).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);
|
||||
}).start();
|
||||
|
|
|
@ -873,7 +873,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
|||
|
||||
|
||||
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;
|
||||
}
|
||||
Status statusCheck = statusDraft.statusDraftList.get(0);
|
||||
|
|
|
@ -666,7 +666,7 @@ public class ProfileActivity extends BaseActivity {
|
|||
String[] splitAcct = account.acct.split("@");
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this);
|
||||
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;
|
||||
if (isOwner) {
|
||||
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);
|
||||
|
|
|
@ -151,7 +151,7 @@ public class CrossActionHelper {
|
|||
} else if (targetedStatus != null) {
|
||||
searchVM.search(ownerAccount.instance, ownerAccount.token, targetedStatus.uri, null, "statuses", false, true, false, 0, null, null, 1)
|
||||
.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);
|
||||
applyAction(context, actionType, ownerAccount, null, status);
|
||||
} else {
|
||||
|
|
|
@ -252,7 +252,7 @@ public class Helper {
|
|||
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_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_MEDIA_ONY = "ARG_SHOW_MEDIA_ONY";
|
||||
public static final String ARG_MENTION = "ARG_MENTION";
|
||||
|
|
|
@ -155,13 +155,17 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
|
||||
holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
|
||||
.observe((LifecycleOwner) context, relationShip -> {
|
||||
notificationList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
if (notificationList.size() > position) {
|
||||
notificationList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
}));
|
||||
holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, notification.account.id)
|
||||
.observe((LifecycleOwner) context, relationShip -> {
|
||||
notificationList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
if (notificationList.size() > position) {
|
||||
notificationList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
}));
|
||||
holderFollow.binding.avatar.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(context, ProfileActivity.class);
|
||||
|
|
|
@ -221,7 +221,13 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl
|
|||
try {
|
||||
int value = sharedPreferences.getInt(key, 0);
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (slug.compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) {
|
||||
if (slug != null && slugOfFirstFragment != null && slug.compareTo(slugOfFirstFragment) != 0 && !isViewInitialized) {
|
||||
isViewInitialized = true;
|
||||
initializeStatusesCommonView(initialStatuses);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
canBeFederated = false;
|
||||
}
|
||||
}
|
||||
|
||||
isViewInitialized = getArguments().getBoolean(Helper.ARG_INITIALIZE_VIEW, true);
|
||||
tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE);
|
||||
accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT);
|
||||
exclude_replies = !getArguments().getBoolean(Helper.ARG_SHOW_REPLIES, true);
|
||||
|
@ -252,8 +252,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
if (timelineType != null) {
|
||||
slug = timelineType.getValue() + (ident != null ? "|" + ident : "");
|
||||
}
|
||||
//Only the first fragment will initialize its view
|
||||
isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0;
|
||||
//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;
|
||||
} else {
|
||||
isViewInitialized = timelineType.compareTo(Timeline.TimeLineEnum.HOME) == 0;
|
||||
}
|
||||
}
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||
//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
|
||||
*/
|
||||
private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status status) {
|
||||
if (direction == null) {
|
||||
if (direction == null && !isViewInitialized) {
|
||||
isViewInitialized = slug.compareTo(slugOfFirstFragment) == 0;
|
||||
}
|
||||
if (binding == null || getActivity() == null || !isAdded()) {
|
||||
|
@ -626,7 +633,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|||
if (isAdded()) {
|
||||
storeMarker();
|
||||
}
|
||||
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action);
|
||||
try {
|
||||
LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
|
|||
FragmentMastodonTimeline fragment = new FragmentMastodonTimeline();
|
||||
fragment.update = activity;
|
||||
Bundle bundle = new Bundle();
|
||||
//Position 3 is for notifications
|
||||
bundle.putBoolean(Helper.ARG_INITIALIZE_VIEW, false);
|
||||
if (position < (BOTTOM_TIMELINE_COUNT - toRemove) && !singleBar) {
|
||||
if (bottomMenu != null) {
|
||||
BottomMenu.ItemMenuType type = BottomMenu.getType(bottomMenu, position);
|
||||
|
@ -98,9 +98,13 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
|
|||
return fragment;
|
||||
}
|
||||
if (type == BottomMenu.ItemMenuType.NOTIFICATION) {
|
||||
return new FragmentNotificationContainer();
|
||||
FragmentNotificationContainer fragmentNotificationContainer = new FragmentNotificationContainer();
|
||||
fragmentNotificationContainer.setArguments(bundle);
|
||||
return fragmentNotificationContainer;
|
||||
} 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
|
||||
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.HOME);
|
||||
|
@ -120,12 +124,13 @@ public class FedilabPageAdapter extends FragmentStatePagerAdapter {
|
|||
if (pinnedTimeline.type == Timeline.TimeLineEnum.NOTIFICATION) {
|
||||
FragmentNotificationContainer fragmentNotificationContainer = new FragmentNotificationContainer();
|
||||
FragmentNotificationContainer.update = activity;
|
||||
fragmentNotificationContainer.setArguments(bundle);
|
||||
return fragmentNotificationContainer;
|
||||
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.DIRECT) {
|
||||
FragmentMastodonConversation fragmentMastodonConversation = new FragmentMastodonConversation();
|
||||
fragmentMastodonConversation.update = activity;
|
||||
fragmentMastodonConversation.setArguments(bundle);
|
||||
return fragmentMastodonConversation;
|
||||
|
||||
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.LIST) {
|
||||
bundle.putString(Helper.ARG_LIST_ID, pinnedTimeline.mastodonList.id);
|
||||
} else if (pinnedTimeline.type == Timeline.TimeLineEnum.TAG) {
|
||||
|
|
Loading…
Reference in a new issue