fix null pointer exception

This commit is contained in:
sk 2023-06-02 19:03:22 +02:00
parent 1ce49c68fe
commit 02e3421f98
1 changed files with 5 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import org.jsoup.internal.StringUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import me.grishka.appkit.FragmentStackActivity; import me.grishka.appkit.FragmentStackActivity;
@ -29,8 +30,8 @@ public class ExternalShareActivity extends FragmentStackActivity{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if(savedInstanceState==null){ if(savedInstanceState==null){
String text = getIntent().getStringExtra(Intent.EXTRA_TEXT); Optional<String> text = Optional.ofNullable(getIntent().getStringExtra(Intent.EXTRA_TEXT));
boolean isMastodonURL = UiUtils.looksLikeMastodonUrl(text); boolean isMastodonURL = text.map(UiUtils::looksLikeMastodonUrl).orElse(false);
List<AccountSession> sessions=AccountSessionManager.getInstance().getLoggedInAccounts(); List<AccountSession> sessions=AccountSessionManager.getInstance().getLoggedInAccounts();
if(sessions.isEmpty()){ if(sessions.isEmpty()){
@ -40,8 +41,8 @@ public class ExternalShareActivity extends FragmentStackActivity{
openComposeFragment(sessions.get(0).getID()); openComposeFragment(sessions.get(0).getID());
}else{ }else{
new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> { new AccountSwitcherSheet(this, null, true, isMastodonURL, (accountId, open) -> {
if (open) { if (open && text.isPresent()) {
UiUtils.lookupURL(this, accountId, text, false, (clazz, args) -> { UiUtils.lookupURL(this, accountId, text.get(), false, (clazz, args) -> {
if (clazz == null) { if (clazz == null) {
finish(); finish();
return; return;