diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java index d94e11d41..cd9404d29 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java @@ -15,6 +15,7 @@ import org.joinmastodon.android.model.Token; import java.util.ArrayList; import java.util.List; +import java.util.Optional; public class AccountSession{ public Token token; @@ -89,7 +90,7 @@ public class AccountSession{ return pushSubscriptionManager; } - public Instance getInstance() { - return AccountSessionManager.getInstance().getInstanceInfo(domain); + public Optional getInstance() { + return Optional.ofNullable(AccountSessionManager.getInstance().getInstanceInfo(domain)); } } 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 1a174099a..c7054310e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -263,9 +263,6 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr Nav.finish(this); return; } - if(customEmojis.isEmpty()){ - AccountSessionManager.getInstance().updateInstanceInfo(instanceDomain); - } Bundle bundle = savedInstanceState != null ? savedInstanceState : getArguments(); if (bundle.containsKey("scheduledStatus")) scheduledStatus=Parcels.unwrap(bundle.getParcelable("scheduledStatus")); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index 8a24dad36..a260c2111 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -35,6 +35,7 @@ import org.parceler.Parcels; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; +import java.util.Optional; import androidx.annotation.IdRes; import androidx.annotation.Nullable; @@ -74,8 +75,9 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene E.register(this); accountID=getArguments().getString("account"); setTitle(R.string.sk_app_name); - Instance instance = AccountSessionManager.getInstance().getAccount(accountID).getInstance(); - isPleroma = instance.isPleroma(); + isPleroma = AccountSessionManager.getInstance().getAccount(accountID).getInstance() + .map(Instance::isPleroma) + .orElse(false); if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N) setRetainInstance(true); @@ -296,10 +298,10 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene public void updateNotificationBadge() { AccountSession session = AccountSessionManager.getInstance().getAccount(accountID); - Instance instance = session.getInstance(); - if (instance == null) return; + Optional instance = session.getInstance(); + if (instance.isEmpty()) return; // avoiding incompatibility with akkoma - new GetNotifications(null, 1, EnumSet.allOf(Notification.Type.class), instance != null && instance.isPleroma()) + new GetNotifications(null, 1, EnumSet.allOf(Notification.Type.class), instance.get().isPleroma()) .setCallback(new Callback<>() { @Override public void onSuccess(List notifications) { diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index ba30cf5a6..2b6d4bdf5 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -164,7 +164,7 @@ public class NotificationsListFragment extends BaseStatusListFragment instance = session.getInstance(); String instanceName = UiUtils.getInstanceName(accountID); if(GithubSelfUpdater.needSelfUpdating()){ @@ -223,7 +223,7 @@ public class SettingsFragment extends MastodonToolbarFragment{ GlobalUserPreferences.showReplies=i.checked; GlobalUserPreferences.save(); })); - if (instance.isPleroma()) { + if (instance.map(Instance::isPleroma).orElse(false)) { items.add(new ButtonItem(R.string.sk_settings_reply_visibility, R.drawable.ic_fluent_chat_24_regular, b->{ PopupMenu popupMenu=new PopupMenu(getActivity(), b, Gravity.CENTER_HORIZONTAL); popupMenu.inflate(R.menu.reply_visibility); @@ -299,7 +299,9 @@ public class SettingsFragment extends MastodonToolbarFragment{ GlobalUserPreferences.save(); needAppRestart=true; })); - boolean translationAvailable = instance.v2 != null && instance.v2.configuration.translation != null && instance.v2.configuration.translation.enabled; + boolean translationAvailable = instance + .map(i -> i.v2 != null && i.v2.configuration.translation != null && i.v2.configuration.translation.enabled) + .orElse(false); items.add(new SmallTextItem(getString(translationAvailable ? R.string.sk_settings_translation_availability_note_available : R.string.sk_settings_translation_availability_note_unavailable, instanceName))); @@ -333,7 +335,9 @@ public class SettingsFragment extends MastodonToolbarFragment{ items.add(new TextItem(R.string.settings_tos, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms"), R.drawable.ic_fluent_open_24_regular)); items.add(new TextItem(R.string.settings_privacy_policy, ()->UiUtils.launchWebBrowser(getActivity(), "https://"+session.domain+"/terms"), R.drawable.ic_fluent_open_24_regular)); items.add(new TextItem(R.string.log_out, this::confirmLogOut, R.drawable.ic_fluent_sign_out_24_regular)); - if (!TextUtils.isEmpty(instance.version)) items.add(new SmallTextItem(getString(R.string.sk_settings_server_version, instance.version))); + items.add(new SmallTextItem(instance + .map(i -> getString(R.string.sk_settings_server_version, i.version)) + .orElse(getString(R.string.sk_instance_info_unavailable)))); items.add(new HeaderItem(R.string.sk_instance_features)); items.add(new SwitchItem(R.string.sk_settings_content_types, 0, GlobalUserPreferences.accountsWithContentTypesEnabled.contains(accountID), (i)->{ @@ -361,14 +365,16 @@ public class SettingsFragment extends MastodonToolbarFragment{ b.setText(getContentTypeString(contentType)); contentTypeMenu = popupMenu.getMenu(); contentTypeMenu.findItem(ContentType.getContentTypeRes(contentType)).setChecked(true); - ContentType.adaptMenuToInstance(contentTypeMenu, instance); + instance.ifPresent(i -> ContentType.adaptMenuToInstance(contentTypeMenu, i)); })); items.add(new SmallTextItem(getString(R.string.sk_settings_default_content_type_explanation))); items.add(new SwitchItem(R.string.sk_settings_support_local_only, 0, GlobalUserPreferences.accountsWithLocalOnlySupport.contains(accountID), i->{ glitchModeItem.enabled = i.checked; if (i.checked) { GlobalUserPreferences.accountsWithLocalOnlySupport.add(accountID); - if (instance.pleroma == null) GlobalUserPreferences.accountsInGlitchMode.add(accountID); + if (!instance.map(Instance::isPleroma).orElse(false)) { + GlobalUserPreferences.accountsInGlitchMode.add(accountID); + } } else { GlobalUserPreferences.accountsWithLocalOnlySupport.remove(accountID); GlobalUserPreferences.accountsInGlitchMode.remove(accountID); diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java b/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java index bff0046b3..210e649d1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java @@ -259,13 +259,14 @@ public class TimelineDefinition { public boolean isCompatible(AccountSession session) { // still enabling the bubble timeline for all pleroma/akkoma instances since i know of // at least one instance that supports it, but doesn't list "bubble_timeline" - return session.getInstance().isPleroma(); + return session.getInstance().map(Instance::isPleroma).orElse(false); } @Override public boolean wantsDefault(AccountSession session) { - Instance instance = session.getInstance(); - return instance.isPleroma() && instance.pleroma.metadata.features.contains("bubble_timeline"); + return session.getInstance() + .map(i -> i.isPleroma() && i.pleroma.metadata.features.contains("bubble_timeline")) + .orElse(false); } }; diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java index ffc3c7b38..fce5be674 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java @@ -948,8 +948,8 @@ public class UiUtils { public static String getInstanceName(String accountID) { AccountSession session = AccountSessionManager.getInstance().getAccount(accountID); - Instance instance = session.getInstance(); - return instance != null && !instance.title.isBlank() ? instance.title : session.domain; + Optional instance = session.getInstance(); + return instance.isPresent() && !instance.get().title.isBlank() ? instance.get().title : session.domain; } public static void pickAccount(Context context, String exceptFor, @StringRes int titleRes, @DrawableRes int iconRes, Consumer sessionConsumer, Consumer transformDialog) { diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 06cf3eeb4..228a276c9 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -288,4 +288,5 @@ Allows setting a content type like Markdown when creating a post. Keep in mind that not all instances support this. Default content type This lets you have a content type be pre-selected when creating new posts, overriding the value set in “Posting preferences”. + Instance info temporarily unavailable \ No newline at end of file