diff --git a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java index ff0fda8d9..6a980791f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java @@ -28,14 +28,23 @@ public class ExternalShareActivity extends FragmentStackActivity{ UiUtils.setUserPreferredTheme(this); super.onCreate(savedInstanceState); if(savedInstanceState==null){ + + String text = getIntent().getStringExtra(Intent.EXTRA_TEXT); + boolean isMastodonURL = UiUtils.looksLikeMastodonUrl(text); + List sessions=AccountSessionManager.getInstance().getLoggedInAccounts(); if(sessions.isEmpty()){ Toast.makeText(this, R.string.err_not_logged_in, Toast.LENGTH_SHORT).show(); finish(); - }else if(sessions.size()==1){ + }else if(sessions.size()==1 && !isMastodonURL){ openComposeFragment(sessions.get(0).getID()); }else{ - new AccountSwitcherSheet(this, false, false, accountSession -> openComposeFragment(accountSession.getID())).show(); + new AccountSwitcherSheet(this, false, false, isMastodonURL, accountSession -> { + if(accountSession!=null) + openComposeFragment(accountSession.getID()); + else + UiUtils.openURL(this, AccountSessionManager.getInstance().getLastActiveAccountID(), text); + }).show(); } } } 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 c0bf0381f..aeb2a45a8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -265,7 +265,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene for(AccountSession session:AccountSessionManager.getInstance().getLoggedInAccounts()){ options.add(session.self.displayName+"\n("+session.self.username+"@"+session.domain+")"); } - new AccountSwitcherSheet(getActivity(), true, true, accountSession -> { + new AccountSwitcherSheet(getActivity(), true, true, false, accountSession -> { getActivity().finish(); getActivity().startActivity(new Intent(getActivity(), MainActivity.class)); }).show(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java index 66c63d6f8..dfff1c201 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/AccountActivationFragment.java @@ -110,7 +110,7 @@ public class AccountActivationFragment extends ToolbarFragment{ @Override public void onToolbarNavigationClick(){ - new AccountSwitcherSheet(getActivity(), true, true, accountSession -> { + new AccountSwitcherSheet(getActivity(), true, true, false, accountSession -> { getActivity().finish(); getActivity().startActivity(new Intent(getActivity(), MainActivity.class)); }).show(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java index f819e8107..d41714ba4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java @@ -2,13 +2,11 @@ package org.joinmastodon.android.ui; import android.annotation.SuppressLint; import android.app.Activity; -import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.drawable.Animatable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Build; -import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; @@ -18,22 +16,21 @@ import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.LinearLayoutManager; + import org.joinmastodon.android.GlobalUserPreferences; -import org.joinmastodon.android.MainActivity; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.oauth.RevokeOauthToken; import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.onboarding.CustomWelcomeFragment; import org.joinmastodon.android.ui.utils.UiUtils; -import org.w3c.dom.Text; import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; @@ -58,7 +55,7 @@ public class AccountSwitcherSheet extends BottomSheet{ private final boolean logOutEnabled; private final Consumer onClick; - public AccountSwitcherSheet(@NonNull Activity activity, boolean logOutEnabled, boolean addAccountEnabled, Consumer onClick){ + public AccountSwitcherSheet(@NonNull Activity activity, boolean logOutEnabled, boolean addAccountEnabled, boolean showOpenURL, Consumer onClick){ super(activity); this.activity=activity; this.logOutEnabled=logOutEnabled; @@ -92,6 +89,22 @@ public class AccountSwitcherSheet extends BottomSheet{ })); } + if(showOpenURL) { + AccountViewHolder holder = new AccountViewHolder(); + holder.more.setVisibility(View.GONE); + holder.currentIcon.setVisibility(View.GONE); + holder.display_name.setVisibility(View.VISIBLE); + holder.display_add_account.setVisibility(View.VISIBLE); + holder.display_add_account.setText(R.string.sk_share_open_url); + holder.avatar.setScaleType(ImageView.ScaleType.CENTER); + holder.avatar.setImageResource(R.drawable.ic_fluent_open_24_regular); + holder.avatar.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(activity, android.R.attr.textColorPrimary))); + adapter.addAdapter(new ClickableSingleViewRecyclerAdapter(holder.itemView, () -> { + onClick.accept(null); + dismiss(); + })); + } + list.setAdapter(adapter); DividerItemDecoration divider=new DividerItemDecoration(activity, R.attr.colorPollVoted, .5f, 72, 16, DividerItemDecoration.NOT_FIRST); divider.setDrawBelowLastItem(true); diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 06cf3eeb4..0eec8b84d 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”. + Open in App \ No newline at end of file