diff --git a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java index c65ec98cf..ff0fda8d9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ExternalShareActivity.java @@ -11,6 +11,7 @@ import android.widget.Toast; import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.ComposeFragment; +import org.joinmastodon.android.ui.AccountSwitcherSheet; import org.joinmastodon.android.ui.utils.UiUtils; import org.jsoup.internal.StringUtil; @@ -34,10 +35,7 @@ public class ExternalShareActivity extends FragmentStackActivity{ }else if(sessions.size()==1){ openComposeFragment(sessions.get(0).getID()); }else{ - UiUtils.pickAccount(this, null, R.string.choose_account, 0, - session -> openComposeFragment(session.getID()), - b -> b.setOnCancelListener(d -> finish()) - ); + new AccountSwitcherSheet(this, false, false, accountSession -> openComposeFragment(accountSession.getID())).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 8a24dad36..c0bf0381f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments; import android.app.Fragment; import android.app.NotificationManager; +import android.content.Intent; import android.graphics.Outline; import android.os.Build; import android.os.Bundle; @@ -16,7 +17,13 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import androidx.annotation.IdRes; +import androidx.annotation.Nullable; + +import com.squareup.otto.Subscribe; + import org.joinmastodon.android.E; +import org.joinmastodon.android.MainActivity; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.notifications.GetNotifications; import org.joinmastodon.android.api.session.AccountSession; @@ -36,11 +43,6 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import androidx.annotation.IdRes; -import androidx.annotation.Nullable; - -import com.squareup.otto.Subscribe; - import me.grishka.appkit.FragmentStackActivity; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; @@ -263,7 +265,10 @@ 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()).show(); + new AccountSwitcherSheet(getActivity(), true, true, accountSession -> { + getActivity().finish(); + getActivity().startActivity(new Intent(getActivity(), MainActivity.class)); + }).show(); return true; } return false; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 174d3d19b..fb952eacf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -85,13 +85,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.viewpager2.widget.ViewPager2; + import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; 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 92eb026ad..66c63d6f8 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,10 @@ public class AccountActivationFragment extends ToolbarFragment{ @Override public void onToolbarNavigationClick(){ - new AccountSwitcherSheet(getActivity()).show(); + new AccountSwitcherSheet(getActivity(), true, true, accountSession -> { + getActivity().finish(); + getActivity().startActivity(new Intent(getActivity(), MainActivity.class)); + }).show(); } @Override 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 42e373f61..e259b9861 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/AccountSwitcherSheet.java @@ -27,6 +27,7 @@ import org.joinmastodon.android.fragments.onboarding.CustomWelcomeFragment; import org.joinmastodon.android.ui.utils.UiUtils; import java.util.List; +import java.util.function.Consumer; import java.util.stream.Collectors; import androidx.annotation.NonNull; @@ -52,10 +53,14 @@ public class AccountSwitcherSheet extends BottomSheet{ private UsableRecyclerView list; private List accounts; private ListImageLoaderWrapper imgLoader; + private final boolean logOutEnabled; + private final Consumer onClick; - public AccountSwitcherSheet(@NonNull Activity activity){ + public AccountSwitcherSheet(@NonNull Activity activity, boolean logOutEnabled, boolean addAccountEnabled, Consumer onClick){ super(activity); this.activity=activity; + this.logOutEnabled=logOutEnabled; + this.onClick=onClick; accounts=AccountSessionManager.getInstance().getLoggedInAccounts().stream().map(WrappedAccount::new).collect(Collectors.toList()); @@ -69,17 +74,20 @@ public class AccountSwitcherSheet extends BottomSheet{ handle.setBackgroundResource(R.drawable.bg_bottom_sheet_handle); adapter.addAdapter(new SingleViewRecyclerAdapter(handle)); adapter.addAdapter(new AccountsAdapter()); - AccountViewHolder holder=new AccountViewHolder(); - holder.more.setVisibility(View.GONE); - holder.currentIcon.setVisibility(View.GONE); - holder.name.setText(R.string.add_account); - holder.avatar.setScaleType(ImageView.ScaleType.CENTER); - holder.avatar.setImageResource(R.drawable.ic_fluent_add_circle_24_filled); - holder.avatar.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(activity, android.R.attr.textColorPrimary))); - adapter.addAdapter(new ClickableSingleViewRecyclerAdapter(holder.itemView, ()->{ - Nav.go(activity, CustomWelcomeFragment.class, null); - dismiss(); - })); + + if(addAccountEnabled){ + AccountViewHolder holder = new AccountViewHolder(); + holder.more.setVisibility(View.GONE); + holder.currentIcon.setVisibility(View.GONE); + holder.name.setText(R.string.add_account); + holder.avatar.setScaleType(ImageView.ScaleType.CENTER); + holder.avatar.setImageResource(R.drawable.ic_fluent_add_circle_24_filled); + holder.avatar.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(activity, android.R.attr.textColorPrimary))); + adapter.addAdapter(new ClickableSingleViewRecyclerAdapter(holder.itemView, () -> { + Nav.go(activity, CustomWelcomeFragment.class, null); + dismiss(); + })); + } list.setAdapter(adapter); DividerItemDecoration divider=new DividerItemDecoration(activity, R.attr.colorPollVoted, .5f, 72, 16, DividerItemDecoration.NOT_FIRST); @@ -210,6 +218,11 @@ public class AccountSwitcherSheet extends BottomSheet{ more.setVisibility(View.VISIBLE); currentIcon.setVisibility(View.GONE); } + + if(!logOutEnabled){ + more.setVisibility(View.GONE); + currentIcon.setVisibility(View.GONE); + } menu.getMenu().findItem(R.id.log_out).setTitle(activity.getString(R.string.log_out_account, "@"+item.self.username)); UiUtils.enablePopupMenuIcons(activity, menu); } @@ -229,8 +242,8 @@ public class AccountSwitcherSheet extends BottomSheet{ @Override public void onClick(){ AccountSessionManager.getInstance().setLastActiveAccountID(item.getID()); - activity.finish(); - activity.startActivity(new Intent(activity, MainActivity.class)); + dismiss(); + onClick.accept(AccountSessionManager.getInstance().getAccount(item.getID())); } }