From e8eb12532ae81219f8ce7db31eb2d377f34c5b80 Mon Sep 17 00:00:00 2001 From: Grishka Date: Thu, 28 Apr 2022 01:35:20 +0300 Subject: [PATCH] Fixes --- .../android/api/PushSubscriptionManager.java | 16 ++++++++++++---- .../api/session/AccountSessionManager.java | 11 +++++++++++ .../fragments/AccountTimelineFragment.java | 2 ++ .../android/fragments/ComposeFragment.java | 3 +++ .../android/fragments/ThreadFragment.java | 2 ++ .../ui/displayitems/HeaderStatusDisplayItem.java | 1 + 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java index 42ae204c0..f20be90bf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/PushSubscriptionManager.java @@ -141,7 +141,9 @@ public class PushSubscriptionManager{ encodedPublicKey=Base64.encodeToString(serializeRawPublicKey(publicKey), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING); authKey=new byte[16]; new SecureRandom().nextBytes(authKey); - AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); + if(session==null) + return; session.pushPrivateKey=Base64.encodeToString(privateKey.getEncoded(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING); session.pushPublicKey=Base64.encodeToString(publicKey.getEncoded(), Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING); session.pushAuthKey=encodedAuthKey=Base64.encodeToString(authKey, Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING); @@ -162,7 +164,9 @@ public class PushSubscriptionManager{ MastodonAPIController.runInBackground(()->{ serverKey=deserializeRawPublicKey(Base64.decode(result.serverKey, Base64.URL_SAFE)); - AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); + if(session==null) + return; session.pushSubscription=result; AccountSessionManager.getInstance().writeAccountsFile(); Log.d(TAG, "Successfully registered "+accountID+" for push notifications"); @@ -183,7 +187,9 @@ public class PushSubscriptionManager{ .setCallback(new Callback<>(){ @Override public void onSuccess(PushSubscription result){ - AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); + if(session==null) + return; if(result.policy!=subscription.policy) result.policy=subscription.policy; session.pushSubscription=result; @@ -196,7 +202,9 @@ public class PushSubscriptionManager{ if(((MastodonErrorResponse)error).httpStatus==404){ // Not registered for push, register now registerAccountForPush(subscription); }else{ - AccountSession session=AccountSessionManager.getInstance().getAccount(accountID); + AccountSession session=AccountSessionManager.getInstance().tryGetAccount(accountID); + if(session==null) + return; session.needUpdatePushSettings=true; session.pushSubscription=subscription; AccountSessionManager.getInstance().writeAccountsFile(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java index 8e5103a3c..fb1363857 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java @@ -133,10 +133,20 @@ public class AccountSessionManager{ return session; } + @Nullable + public AccountSession tryGetAccount(String id){ + return sessions.get(id); + } + @Nullable public AccountSession getLastActiveAccount(){ if(sessions.isEmpty() || lastActiveAccountID==null) return null; + if(!sessions.containsKey(lastActiveAccountID)){ + // TODO figure out why this happens. It should not be possible. + lastActiveAccountID=getLoggedInAccounts().get(0).getID(); + writeAccountsFile(); + } return getAccount(lastActiveAccountID); } @@ -197,6 +207,7 @@ public class AccountSessionManager{ new CustomTabsIntent.Builder() .setShareState(CustomTabsIntent.SHARE_STATE_OFF) + .setShowTitle(true) .build() .launchUrl(activity, uri); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java index f8d7c6b8c..7924e9c93 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java @@ -47,6 +47,8 @@ public class AccountTimelineFragment extends StatusListFragment{ @Override protected void doLoadData(int offset, int count){ + if(user==null) // TODO figure out why this happens + return; currentRequest=new GetAccountStatuses(user.id, offset>0 ? getMaxID() : null, null, count, filter) .setCallback(new SimpleCallback<>(this){ @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 5b727ee01..6b26ac44f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -1049,6 +1049,9 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr } private void updateVisibilityIcon(){ + if(statusVisibility==null){ // TODO find out why this happens + statusVisibility=StatusPrivacy.PUBLIC; + } visibilityBtn.setImageResource(switch(statusVisibility){ case PUBLIC -> R.drawable.ic_fluent_earth_24_filled; case UNLISTED -> R.drawable.ic_fluent_people_community_24_regular; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java index e3b00be33..f2b540ada 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -56,6 +56,8 @@ public class ThreadFragment extends StatusListFragment{ .setCallback(new SimpleCallback<>(this){ @Override public void onSuccess(StatusContext result){ + if(getActivity()==null) + return; if(refreshing){ data.clear(); displayItems.clear(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java index 06900e52a..468abe32f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java @@ -250,6 +250,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ Menu menu=optionsMenu.getMenu(); boolean isOwnPost=AccountSessionManager.getInstance().isSelf(item.parentFragment.getAccountID(), account); menu.findItem(R.id.delete).setVisible(item.status!=null && isOwnPost); + menu.findItem(R.id.open_in_browser).setVisible(item.status!=null); MenuItem blockDomain=menu.findItem(R.id.block_domain); MenuItem mute=menu.findItem(R.id.mute); MenuItem block=menu.findItem(R.id.block);