diff --git a/mastodon/src/main/java/org/joinmastodon/android/DomainManager.java b/mastodon/src/main/java/org/joinmastodon/android/DomainManager.java deleted file mode 100644 index ddd58c2ce..000000000 --- a/mastodon/src/main/java/org/joinmastodon/android/DomainManager.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.joinmastodon.android; - -public class DomainManager { - private static final String TAG="DomainManager"; - - private static final DomainManager instance=new DomainManager(); - - private String currentDomain = ""; - - - public static DomainManager getInstance(){ - return instance; - } - - private DomainManager(){ - - } - - public String getCurrentDomain() { - return currentDomain; - } - - public void setCurrentDomain(String domain) { - this.currentDomain = domain; - } -} \ No newline at end of file diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index dfab25f85..8850e5f5c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -5,7 +5,6 @@ import android.app.Fragment; import android.app.assist.AssistContent; import android.content.Intent; import android.content.pm.PackageManager; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.Log; @@ -22,12 +21,15 @@ import org.joinmastodon.android.fragments.onboarding.CustomWelcomeFragment; import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.updater.GithubSelfUpdater; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.parceler.Parcels; import androidx.annotation.Nullable; import me.grishka.appkit.FragmentStackActivity; -public class MainActivity extends FragmentStackActivity{ +public class MainActivity extends FragmentStackActivity implements ProvidesAssistContent { + private Fragment currentFragment; + @Override protected void onCreate(@Nullable Bundle savedInstanceState){ UiUtils.setUserPreferredTheme(this); @@ -106,7 +108,6 @@ public class MainActivity extends FragmentStackActivity{ Fragment fragment=new HomeFragment(); fragment.setArguments(args); showFragmentClearingBackStack(fragment); - DomainManager.getInstance().setCurrentDomain(accountSession.domain); } }else if(intent.getBooleanExtra("compose", false)){ showCompose(); @@ -200,10 +201,14 @@ public class MainActivity extends FragmentStackActivity{ } @Override - public void onProvideAssistContent(AssistContent outContent) { - super.onProvideAssistContent(outContent); - - outContent.setWebUri(Uri.parse(DomainManager.getInstance().getCurrentDomain())); + public void showFragment(Fragment fragment) { + super.showFragment(fragment); + this.currentFragment = fragment; } + @Override + public void onProvideAssistContent(AssistContent assistContent) { + super.onProvideAssistContent(assistContent); + callFragmentToProvideAssistContent(currentFragment, assistContent); + } } 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 cd9404d29..bf4d45ca9 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 @@ -1,5 +1,7 @@ package org.joinmastodon.android.api.session; +import android.net.Uri; + import org.joinmastodon.android.api.CacheController; import org.joinmastodon.android.api.MastodonAPIController; import org.joinmastodon.android.api.PushSubscriptionManager; @@ -93,4 +95,11 @@ public class AccountSession{ public Optional getInstance() { return Optional.ofNullable(AccountSessionManager.getInstance().getInstanceInfo(domain)); } + + public Uri getInstanceUri() { + return new Uri.Builder() + .scheme("https") + .authority(domain) + .build(); + } } 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 ade79f8c9..1db365282 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -130,4 +131,13 @@ public class AccountTimelineFragment extends StatusListFragment{ protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.ACCOUNT; } + + @Override + public Uri getWebUri(Uri.Builder base) { + // could return different uris based on filter (e.g. media -> "/media"), but i want to + // return the remote url to the user, and i don't know whether i'd need to append + // '#media' (akkoma/pleroma) or '/media' (glitch/mastodon) since i don't know anything + // about the remote instance. so, just returning the base url to the user instead + return Uri.parse(user.url); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java index a87b8c465..1b6b8ce2a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AnnouncementsFragment.java @@ -3,6 +3,7 @@ package org.joinmastodon.android.fragments; import static java.util.stream.Collectors.toList; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; @@ -103,4 +104,9 @@ public class AnnouncementsFragment extends BaseStatusListFragment }) .exec(accountID); } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? base.path("/announcements").build() : null; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 3ba365274..173ae6f82 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.app.assist.AssistContent; import android.content.res.Configuration; import android.graphics.Canvas; import android.graphics.Paint; @@ -25,6 +26,7 @@ import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.polls.SubmitPollVote; +import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.PollUpdatedEvent; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.DisplayItemsParent; @@ -45,6 +47,7 @@ import org.joinmastodon.android.ui.photoviewer.PhotoViewer; import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost; import org.joinmastodon.android.ui.utils.MediaAttachmentViewController; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.joinmastodon.android.utils.TypedObjectPool; import java.util.ArrayList; @@ -68,7 +71,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public abstract class BaseStatusListFragment extends RecyclerFragment implements PhotoViewerHost, ScrollableToTop, HasFab, DomainDisplay{ +public abstract class BaseStatusListFragment extends RecyclerFragment implements PhotoViewerHost, ScrollableToTop, HasFab, ProvidesAssistContent.ProvidesWebUri { protected ArrayList displayItems=new ArrayList<>(); protected DisplayItemsAdapter adapter; protected String accountID; @@ -570,6 +573,7 @@ public abstract class BaseStatusListFragment exten warning.getItem().status.filterRevealed = true; } + @Override public String getAccountID(){ return accountID; } @@ -703,6 +707,10 @@ public abstract class BaseStatusListFragment exten return attachmentViewsPool; } + @Override + public void onProvideAssistContent(AssistContent assistContent) { + assistContent.setWebUri(getWebUri(getSession().getInstanceUri().buildUpon())); + } protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter> implements ImageLoaderRecyclerAdapter{ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BookmarkedStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BookmarkedStatusListFragment.java index 6f863bdd2..c69967435 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BookmarkedStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BookmarkedStatusListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.statuses.GetBookmarkedStatuses; @@ -41,4 +42,9 @@ public class BookmarkedStatusListFragment extends StatusListFragment{ protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.ACCOUNT; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path("/bookmarks").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/DomainDisplay.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/DomainDisplay.java deleted file mode 100644 index 369014e69..000000000 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/DomainDisplay.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.joinmastodon.android.fragments; - -import org.joinmastodon.android.api.session.AccountSession; -import org.joinmastodon.android.api.session.AccountSessionManager; - -public interface DomainDisplay { - - default String getDomain(){ - AccountSession session = AccountSessionManager.getInstance().getLastActiveAccount(); - if (session != null) - return session.domain; - else - return ""; - } -} \ No newline at end of file diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FavoritedStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FavoritedStatusListFragment.java index 41e6e0c7f..e649bc7ba 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FavoritedStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FavoritedStatusListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.statuses.GetFavoritedStatuses; @@ -41,4 +42,11 @@ public class FavoritedStatusListFragment extends StatusListFragment{ protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.ACCOUNT; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.encodedPath(isInstanceAkkoma() + ? '/' + getSession().self.username + "#favorites" + : "/favourites").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java index 385a64084..9f144634d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowRequestsListFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.graphics.Rect; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -24,6 +25,7 @@ import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.ProgressBarButton; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.parceler.Parcels; import java.util.Collections; @@ -46,7 +48,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public class FollowRequestsListFragment extends RecyclerFragment implements ScrollableToTop{ +public class FollowRequestsListFragment extends RecyclerFragment implements ScrollableToTop, ProvidesAssistContent.ProvidesWebUri { private String accountID; private Map relationships=Collections.emptyMap(); private GetAccountRelationships relationshipsRequest; @@ -148,6 +150,16 @@ public class FollowRequestsListFragment extends RecyclerFragment implements ImageLoaderRecyclerAdapter{ public AccountsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java index 297d6427a..e2e6ae59c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments; +import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -14,14 +15,15 @@ import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.ui.DividerItemDecoration; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.views.UsableRecyclerView; -public class FollowedHashtagsFragment extends RecyclerFragment implements ScrollableToTop { +public class FollowedHashtagsFragment extends RecyclerFragment implements ScrollableToTop, ProvidesAssistContent.ProvidesWebUri { private String nextMaxID; - private String accountId; + private String accountID; public FollowedHashtagsFragment() { super(20); @@ -31,7 +33,7 @@ public class FollowedHashtagsFragment extends RecyclerFragment implemen public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args=getArguments(); - accountId=args.getString("account"); + accountID=args.getString("account"); setTitle(R.string.sk_hashtags_you_follow); } @@ -62,7 +64,7 @@ public class FollowedHashtagsFragment extends RecyclerFragment implemen onDataLoaded(result, nextMaxID!=null); } }) - .exec(accountId); + .exec(accountID); } @Override @@ -75,6 +77,16 @@ public class FollowedHashtagsFragment extends RecyclerFragment implemen smoothScrollRecyclerViewToTop(list); } + @Override + public String getAccountID() { + return accountID; + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? null : base.path("/followed_tags").build(); + } + private class HashtagsAdapter extends RecyclerView.Adapter{ @NonNull @Override @@ -109,7 +121,7 @@ public class FollowedHashtagsFragment extends RecyclerFragment implemen @Override public void onClick() { - UiUtils.openHashtagTimeline(getActivity(), accountId, item.name, item.following); + UiUtils.openHashtagTimeline(getActivity(), accountID, item.name, item.following); } } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HasAccountID.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HasAccountID.java new file mode 100644 index 000000000..39915878b --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HasAccountID.java @@ -0,0 +1,23 @@ +package org.joinmastodon.android.fragments; + +import org.joinmastodon.android.api.session.AccountSession; +import org.joinmastodon.android.api.session.AccountSessionManager; +import org.joinmastodon.android.model.Instance; + +import java.util.Optional; + +public interface HasAccountID { + String getAccountID(); + + default AccountSession getSession() { + return AccountSessionManager.getInstance().getAccount(getAccountID()); + } + + default boolean isInstanceAkkoma() { + return getInstance().map(Instance::isPleroma).orElse(false); + } + + default Optional getInstance() { + return getSession().getInstance(); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java index a4c8146f3..a69963dac 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HashtagTimelineFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.HapticFeedbackConstants; import android.view.Menu; @@ -8,10 +9,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageButton; import android.widget.Toast; -import org.joinmastodon.android.DomainManager; import org.joinmastodon.android.E; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.tags.GetHashtag; @@ -44,18 +43,12 @@ public class HashtagTimelineFragment extends PinnableStatusListFragment { return true; } - @Override - public String getDomain() { - return super.getDomain() + "/tags/" + hashtag; - } - @Override public void onAttach(Activity activity){ super.onAttach(activity); updateTitle(getArguments().getString("hashtag")); following=getArguments().getBoolean("following", false); setHasOptionsMenu(true); - DomainManager.getInstance().setCurrentDomain(getDomain()); } private void updateTitle(String hashtagName) { @@ -166,4 +159,9 @@ public class HashtagTimelineFragment extends PinnableStatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path((isInstanceAkkoma() ? "/tag/" : "/tags") + hashtag).build(); + } } 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 59134d529..0de5cae19 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -2,7 +2,7 @@ package org.joinmastodon.android.fragments; import android.app.Fragment; import android.app.NotificationManager; -import android.content.Intent; +import android.app.assist.AssistContent; import android.graphics.Outline; import android.os.Build; import android.os.Bundle; @@ -17,14 +17,12 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; -import org.joinmastodon.android.DomainManager; 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; @@ -38,6 +36,7 @@ import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.ui.AccountSwitcherSheet; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.TabBar; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.parceler.Parcels; import java.util.ArrayList; @@ -56,7 +55,7 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.FragmentRootLinearLayout; -public class HomeFragment extends AppKitFragment implements OnBackPressedListener{ +public class HomeFragment extends AppKitFragment implements OnBackPressedListener, ProvidesAssistContent, HasAccountID { private FragmentRootLinearLayout content; private HomeTabFragment homeTabFragment; private NotificationsFragment notificationsFragment; @@ -185,8 +184,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene @Override public void onHiddenChanged(boolean hidden){ super.onHiddenChanged(hidden); - if (!hidden && fragmentForTab(currentTab) instanceof DomainDisplay display) - DomainManager.getInstance().setCurrentDomain(display.getDomain()); fragmentForTab(currentTab).onHiddenChanged(hidden); } @@ -251,10 +248,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene currentTab=tab; ((FragmentStackActivity)getActivity()).invalidateSystemBarColors(this); if (tab == R.id.tab_search && isPleroma) searchFragment.selectSearch(); - - if (newFragment instanceof DomainDisplay display) { - DomainManager.getInstance().setCurrentDomain(display.getDomain()); - } } private void maybeTriggerLoading(Fragment newFragment){ @@ -355,7 +348,13 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene setNotificationBadge(false); } + @Override public String getAccountID() { return accountID; } + + @Override + public void onProvideAssistContent(AssistContent assistContent) { + callFragmentToProvideAssistContent(fragmentForTab(currentTab), assistContent); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index b95e5eea5..eca5a2a01 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -10,6 +10,7 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; +import android.app.assist.AssistContent; import android.content.Context; import android.os.Build; import android.os.Bundle; @@ -36,7 +37,6 @@ import androidx.viewpager2.widget.ViewPager2; import com.squareup.otto.Subscribe; -import org.joinmastodon.android.DomainManager; import org.joinmastodon.android.E; import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; @@ -55,6 +55,7 @@ import org.joinmastodon.android.model.TimelineDefinition; import org.joinmastodon.android.ui.SimpleViewHolder; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.updater.GithubSelfUpdater; +import org.joinmastodon.android.utils.ProvidesAssistContent; import java.util.Collection; import java.util.HashMap; @@ -72,7 +73,7 @@ import me.grishka.appkit.fragments.OnBackPressedListener; import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; -public class HomeTabFragment extends MastodonToolbarFragment implements ScrollableToTop, OnBackPressedListener, HasFab, DomainDisplay { +public class HomeTabFragment extends MastodonToolbarFragment implements ScrollableToTop, OnBackPressedListener, HasFab, ProvidesAssistContent { private static final int ANNOUNCEMENTS_RESULT = 654; private String accountID; @@ -204,10 +205,6 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab if (fragments[position] instanceof BaseRecyclerFragment page){ if(!page.loaded && !page.isDataLoading()) page.loadData(); } - - //update recent app list url - if (fragments[position] instanceof DomainDisplay page) - DomainManager.getInstance().setCurrentDomain(page.getDomain()); } }); @@ -292,15 +289,6 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab }).exec(accountID); } - - @Override - public String getDomain() { - if (fragments[pager.getCurrentItem()] instanceof DomainDisplay page) { - return page.getDomain(); - } - return DomainDisplay.super.getDomain(); - } - private void onFabClick(View v){ if (fragments[pager.getCurrentItem()] instanceof BaseStatusListFragment l) { l.onFabClick(v); @@ -707,6 +695,11 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab return fab; } + @Override + public void onProvideAssistContent(AssistContent assistContent) { + callFragmentToProvideAssistContent(fragments[pager.getCurrentItem()], assistContent); + } + private class HomePagerAdapter extends RecyclerView.Adapter { @NonNull @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 0c98f7d7e..35495f5ab 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -40,11 +41,6 @@ public class HomeTimelineFragment extends StatusListFragment { return true; } - @Override - public String getDomain() { - return super.getDomain() + "/home"; - } - @Override public void onAttach(Activity activity){ super.onAttach(activity); @@ -290,4 +286,9 @@ public class HomeTimelineFragment extends StatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.HOME; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path("/").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java index da6322a85..0e03a19e6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java @@ -1,13 +1,13 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageButton; import androidx.annotation.Nullable; @@ -168,4 +168,9 @@ public class ListTimelineFragment extends PinnableStatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.HOME; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path("/lists/" + listID).build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java deleted file mode 100644 index 301b61a93..000000000 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelinesFragment.java +++ /dev/null @@ -1,258 +0,0 @@ -package org.joinmastodon.android.fragments; - -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; - -import com.squareup.otto.Subscribe; - -import org.joinmastodon.android.E; -import org.joinmastodon.android.R; -import org.joinmastodon.android.api.MastodonAPIRequest; -import org.joinmastodon.android.api.requests.lists.AddAccountsToList; -import org.joinmastodon.android.api.requests.lists.CreateList; -import org.joinmastodon.android.api.requests.lists.GetLists; -import org.joinmastodon.android.api.requests.lists.RemoveAccountsFromList; -import org.joinmastodon.android.events.ListDeletedEvent; -import org.joinmastodon.android.events.ListUpdatedCreatedEvent; -import org.joinmastodon.android.model.ListTimeline; -import org.joinmastodon.android.ui.DividerItemDecoration; -import org.joinmastodon.android.ui.M3AlertDialogBuilder; -import org.joinmastodon.android.ui.views.ListTimelineEditor; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; - -import me.grishka.appkit.Nav; -import me.grishka.appkit.api.Callback; -import me.grishka.appkit.api.ErrorResponse; -import me.grishka.appkit.api.SimpleCallback; -import me.grishka.appkit.utils.BindableViewHolder; -import me.grishka.appkit.views.UsableRecyclerView; - -public class ListTimelinesFragment extends RecyclerFragment implements ScrollableToTop { - private String accountId; - private String profileAccountId; - private final HashMap userInListBefore = new HashMap<>(); - private final HashMap userInList = new HashMap<>(); - private ListsAdapter adapter; - - public ListTimelinesFragment() { - super(10); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Bundle args=getArguments(); - accountId=args.getString("account"); - setHasOptionsMenu(true); - E.register(this); - - if(args.containsKey("profileAccount")){ - profileAccountId=args.getString("profileAccount"); - String profileDisplayUsername = args.getString("profileDisplayUsername"); - setTitle(getString(R.string.sk_lists_with_user, profileDisplayUsername)); - } else { - setTitle(R.string.sk_your_lists); - } - } - - @Override - protected void onShown(){ - super.onShown(); - if(!getArguments().getBoolean("noAutoLoad") && !loaded && !dataLoading) - loadData(); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - list.addItemDecoration(new DividerItemDecoration(getActivity(), R.attr.colorPollVoted, 0.5f, 56, 16)); - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.menu_list, menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.create) { - ListTimelineEditor editor = new ListTimelineEditor(getContext()); - new M3AlertDialogBuilder(getActivity()) - .setTitle(R.string.sk_create_list_title) - .setIcon(R.drawable.ic_fluent_people_add_28_regular) - .setView(editor) - .setPositiveButton(R.string.sk_create, (d, which) -> - new CreateList(editor.getTitle(), editor.getRepliesPolicy()).setCallback(new Callback<>() { - @Override - public void onSuccess(ListTimeline list) { - data.add(0, list); - adapter.notifyItemRangeInserted(0, 1); - E.post(new ListUpdatedCreatedEvent(list.id, list.title, list.repliesPolicy)); - } - - @Override - public void onError(ErrorResponse error) { - error.showToast(getContext()); - } - }).exec(accountId) - ) - .setNegativeButton(R.string.cancel, (d, which) -> {}) - .show(); - } - return true; - } - - private void saveListMembership(String listId, boolean isMember) { - userInList.put(listId, isMember); - List accountIdList = Collections.singletonList(profileAccountId); - MastodonAPIRequest req = isMember ? new AddAccountsToList(listId, accountIdList) : new RemoveAccountsFromList(listId, accountIdList); - req.setCallback(new Callback<>() { - @Override - public void onSuccess(Object o) {} - - @Override - public void onError(ErrorResponse error) { - error.showToast(getContext()); - } - }).exec(accountId); - } - - @Override - protected void doLoadData(int offset, int count){ - userInListBefore.clear(); - userInList.clear(); - currentRequest=(profileAccountId != null ? new GetLists(profileAccountId) : new GetLists()) - .setCallback(new SimpleCallback<>(this) { - @Override - public void onSuccess(List lists) { - if (getActivity() == null) return; - for (ListTimeline l : lists) userInListBefore.put(l.id, true); - userInList.putAll(userInListBefore); - if (profileAccountId == null || !lists.isEmpty()) onDataLoaded(lists, false); - if (profileAccountId == null) return; - - currentRequest=new GetLists().setCallback(new SimpleCallback<>(ListTimelinesFragment.this) { - @Override - public void onSuccess(List allLists) { - if (getActivity() == null) return; - List newLists = new ArrayList<>(); - for (ListTimeline l : allLists) { - if (lists.stream().noneMatch(e -> e.id.equals(l.id))) newLists.add(l); - if (!userInListBefore.containsKey(l.id)) { - userInListBefore.put(l.id, false); - } - } - userInList.putAll(userInListBefore); - onDataLoaded(newLists, false); - } - }).exec(accountId); - } - }) - .exec(accountId); - } - - @Subscribe - public void onListDeletedEvent(ListDeletedEvent event) { - for (int i = 0; i < data.size(); i++) { - ListTimeline item = data.get(i); - if (item.id.equals(event.id)) { - data.remove(i); - adapter.notifyItemRemoved(i); - break; - } - } - } - - @Subscribe - public void onListUpdatedCreatedEvent(ListUpdatedCreatedEvent event) { - for (int i = 0; i < data.size(); i++) { - ListTimeline item = data.get(i); - if (item.id.equals(event.id)) { - item.title = event.title; - item.repliesPolicy = event.repliesPolicy; - adapter.notifyItemChanged(i); - break; - } - } - } - - @Override - protected RecyclerView.Adapter getAdapter() { - return adapter = new ListsAdapter(); - } - - @Override - public void scrollToTop() { - smoothScrollRecyclerViewToTop(list); - } - - private class ListsAdapter extends RecyclerView.Adapter{ - @NonNull - @Override - public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ - return new ListViewHolder(); - } - - @Override - public void onBindViewHolder(@NonNull ListViewHolder holder, int position) { - holder.bind(data.get(position)); - } - - @Override - public int getItemCount() { - return data.size(); - } - } - - private class ListViewHolder extends BindableViewHolder implements UsableRecyclerView.Clickable{ - private final TextView title; - private final CheckBox listToggle; - - public ListViewHolder(){ - super(getActivity(), R.layout.item_text, list); - title=findViewById(R.id.title); - listToggle=findViewById(R.id.list_toggle); - } - - @Override - public void onBind(ListTimeline item) { - title.setText(item.title); - title.setCompoundDrawablesRelativeWithIntrinsicBounds(itemView.getContext().getDrawable(R.drawable.ic_fluent_people_24_regular), null, null, null); - if (profileAccountId != null) { - Boolean checked = userInList.get(item.id); - listToggle.setVisibility(View.VISIBLE); - listToggle.setChecked(userInList.containsKey(item.id) && checked != null && checked); - listToggle.setOnClickListener(this::onClickToggle); - } else { - listToggle.setVisibility(View.GONE); - } - } - - private void onClickToggle(View view) { - saveListMembership(item.id, listToggle.isChecked()); - } - - @Override - public void onClick() { - Bundle args=new Bundle(); - args.putString("account", accountId); - args.putString("listID", item.id); - args.putString("listTitle", item.title); - if (item.repliesPolicy != null) args.putInt("repliesPolicy", item.repliesPolicy.ordinal()); - Nav.go(getActivity(), ListTimelineFragment.class, args); - } - } -} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java new file mode 100644 index 000000000..243a104c6 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java @@ -0,0 +1,270 @@ +package org.joinmastodon.android.fragments; + +import android.net.Uri; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.squareup.otto.Subscribe; + +import org.joinmastodon.android.E; +import org.joinmastodon.android.R; +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.api.requests.lists.AddAccountsToList; +import org.joinmastodon.android.api.requests.lists.CreateList; +import org.joinmastodon.android.api.requests.lists.GetLists; +import org.joinmastodon.android.api.requests.lists.RemoveAccountsFromList; +import org.joinmastodon.android.events.ListDeletedEvent; +import org.joinmastodon.android.events.ListUpdatedCreatedEvent; +import org.joinmastodon.android.model.ListTimeline; +import org.joinmastodon.android.ui.DividerItemDecoration; +import org.joinmastodon.android.ui.M3AlertDialogBuilder; +import org.joinmastodon.android.ui.views.ListTimelineEditor; +import org.joinmastodon.android.utils.ProvidesAssistContent; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import me.grishka.appkit.Nav; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; +import me.grishka.appkit.api.SimpleCallback; +import me.grishka.appkit.utils.BindableViewHolder; +import me.grishka.appkit.views.UsableRecyclerView; + +public class ListsFragment extends RecyclerFragment implements ScrollableToTop, ProvidesAssistContent.ProvidesWebUri { + private String accountID; + private String profileAccountId; + private final HashMap userInListBefore = new HashMap<>(); + private final HashMap userInList = new HashMap<>(); + private ListsAdapter adapter; + + public ListsFragment() { + super(10); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Bundle args = getArguments(); + accountID = args.getString("account"); + setHasOptionsMenu(true); + E.register(this); + + if(args.containsKey("profileAccount")){ + profileAccountId=args.getString("profileAccount"); + String profileDisplayUsername = args.getString("profileDisplayUsername"); + setTitle(getString(R.string.sk_lists_with_user, profileDisplayUsername)); + } else { + setTitle(R.string.sk_your_lists); + } + } + + @Override + protected void onShown(){ + super.onShown(); + if(!getArguments().getBoolean("noAutoLoad") && !loaded && !dataLoading) + loadData(); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + list.addItemDecoration(new DividerItemDecoration(getActivity(), R.attr.colorPollVoted, 0.5f, 56, 16)); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.menu_list, menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.create) { + ListTimelineEditor editor = new ListTimelineEditor(getContext()); + new M3AlertDialogBuilder(getActivity()) + .setTitle(R.string.sk_create_list_title) + .setIcon(R.drawable.ic_fluent_people_add_28_regular) + .setView(editor) + .setPositiveButton(R.string.sk_create, (d, which) -> + new CreateList(editor.getTitle(), editor.getRepliesPolicy()).setCallback(new Callback<>() { + @Override + public void onSuccess(ListTimeline list) { + data.add(0, list); + adapter.notifyItemRangeInserted(0, 1); + E.post(new ListUpdatedCreatedEvent(list.id, list.title, list.repliesPolicy)); + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + } + }).exec(accountID) + ) + .setNegativeButton(R.string.cancel, (d, which) -> {}) + .show(); + } + return true; + } + + private void saveListMembership(String listId, boolean isMember) { + userInList.put(listId, isMember); + List accountIdList = Collections.singletonList(profileAccountId); + MastodonAPIRequest req = isMember ? new AddAccountsToList(listId, accountIdList) : new RemoveAccountsFromList(listId, accountIdList); + req.setCallback(new Callback<>() { + @Override + public void onSuccess(Object o) {} + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + } + }).exec(accountID); + } + + @Override + protected void doLoadData(int offset, int count){ + userInListBefore.clear(); + userInList.clear(); + currentRequest=(profileAccountId != null ? new GetLists(profileAccountId) : new GetLists()) + .setCallback(new SimpleCallback<>(this) { + @Override + public void onSuccess(List lists) { + if (getActivity() == null) return; + for (ListTimeline l : lists) userInListBefore.put(l.id, true); + userInList.putAll(userInListBefore); + if (profileAccountId == null || !lists.isEmpty()) onDataLoaded(lists, false); + if (profileAccountId == null) return; + + currentRequest=new GetLists().setCallback(new SimpleCallback<>(ListsFragment.this) { + @Override + public void onSuccess(List allLists) { + if (getActivity() == null) return; + List newLists = new ArrayList<>(); + for (ListTimeline l : allLists) { + if (lists.stream().noneMatch(e -> e.id.equals(l.id))) newLists.add(l); + if (!userInListBefore.containsKey(l.id)) { + userInListBefore.put(l.id, false); + } + } + userInList.putAll(userInListBefore); + onDataLoaded(newLists, false); + } + }).exec(accountID); + } + }) + .exec(accountID); + } + + @Subscribe + public void onListDeletedEvent(ListDeletedEvent event) { + for (int i = 0; i < data.size(); i++) { + ListTimeline item = data.get(i); + if (item.id.equals(event.id)) { + data.remove(i); + adapter.notifyItemRemoved(i); + break; + } + } + } + + @Subscribe + public void onListUpdatedCreatedEvent(ListUpdatedCreatedEvent event) { + for (int i = 0; i < data.size(); i++) { + ListTimeline item = data.get(i); + if (item.id.equals(event.id)) { + item.title = event.title; + item.repliesPolicy = event.repliesPolicy; + adapter.notifyItemChanged(i); + break; + } + } + } + + @Override + protected RecyclerView.Adapter getAdapter() { + return adapter = new ListsAdapter(); + } + + @Override + public void scrollToTop() { + smoothScrollRecyclerViewToTop(list); + } + + @Override + public String getAccountID() { + return accountID; + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path("/lists").build(); + } + + private class ListsAdapter extends RecyclerView.Adapter{ + @NonNull + @Override + public ListViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ + return new ListViewHolder(); + } + + @Override + public void onBindViewHolder(@NonNull ListViewHolder holder, int position) { + holder.bind(data.get(position)); + } + + @Override + public int getItemCount() { + return data.size(); + } + } + + private class ListViewHolder extends BindableViewHolder implements UsableRecyclerView.Clickable{ + private final TextView title; + private final CheckBox listToggle; + + public ListViewHolder(){ + super(getActivity(), R.layout.item_text, list); + title=findViewById(R.id.title); + listToggle=findViewById(R.id.list_toggle); + } + + @Override + public void onBind(ListTimeline item) { + title.setText(item.title); + title.setCompoundDrawablesRelativeWithIntrinsicBounds(itemView.getContext().getDrawable(R.drawable.ic_fluent_people_24_regular), null, null, null); + if (profileAccountId != null) { + Boolean checked = userInList.get(item.id); + listToggle.setVisibility(View.VISIBLE); + listToggle.setChecked(userInList.containsKey(item.id) && checked != null && checked); + listToggle.setOnClickListener(this::onClickToggle); + } else { + listToggle.setVisibility(View.GONE); + } + } + + private void onClickToggle(View view) { + saveListMembership(item.id, listToggle.isChecked()); + } + + @Override + public void onClick() { + Bundle args=new Bundle(); + args.putString("account", accountID); + args.putString("listID", item.id); + args.putString("listTitle", item.title); + if (item.repliesPolicy != null) args.putInt("repliesPolicy", item.repliesPolicy.ordinal()); + Nav.go(getActivity(), ListTimelineFragment.class, args); + } + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java index ce5435a52..fb589f119 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java @@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; import android.app.Fragment; +import android.app.assist.AssistContent; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; @@ -30,6 +31,7 @@ import org.joinmastodon.android.ui.SimpleViewHolder; import org.joinmastodon.android.ui.tabs.TabLayout; import org.joinmastodon.android.ui.tabs.TabLayoutMediator; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; @@ -37,7 +39,7 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.fragments.BaseRecyclerFragment; import me.grishka.appkit.utils.V; -public class NotificationsFragment extends MastodonToolbarFragment implements ScrollableToTop, DomainDisplay { +public class NotificationsFragment extends MastodonToolbarFragment implements ScrollableToTop, ProvidesAssistContent { private TabLayout tabLayout; private ViewPager2 pager; @@ -47,12 +49,6 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc private NotificationsListFragment allNotificationsFragment, mentionsFragment; private String accountID; - - @Override - public String getDomain() { - return DomainDisplay.super.getDomain() + "/notifications"; - } - @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -232,6 +228,11 @@ public class NotificationsFragment extends MastodonToolbarFragment implements Sc }; } + @Override + public void onProvideAssistContent(AssistContent assistContent) { + callFragmentToProvideAssistContent(getFragmentForPage(pager.getCurrentItem()), assistContent); + } + private class DiscoverPagerAdapter extends RecyclerView.Adapter{ @NonNull @Override 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 9408cb8a2..97611f916 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; @@ -9,10 +10,8 @@ import com.squareup.otto.Subscribe; import org.joinmastodon.android.E; import org.joinmastodon.android.R; -import org.joinmastodon.android.api.MastodonErrorResponse; import org.joinmastodon.android.api.requests.markers.SaveMarkers; import org.joinmastodon.android.api.requests.notifications.PleromaMarkNotificationsRead; -import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.AllNotificationsSeenEvent; import org.joinmastodon.android.events.PollUpdatedEvent; @@ -45,7 +44,6 @@ import java.util.stream.Stream; import androidx.recyclerview.widget.RecyclerView; import me.grishka.appkit.Nav; -import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; public class NotificationsListFragment extends BaseStatusListFragment{ @@ -273,4 +271,11 @@ public class NotificationsListFragment extends BaseStatusListFragment implements ImageLoaderRecyclerAdapter { public MetadataAdapter(){ super(imgLoader); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java index 1fb25efbf..d882bb16f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScheduledStatusListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; @@ -181,4 +182,10 @@ public class ScheduledStatusListFragment extends BaseStatusListFragment items=new ArrayList<>(); private ThemeItem themeItem; @@ -740,6 +742,16 @@ public class SettingsFragment extends MastodonToolbarFragment{ } } + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? null : base.path("/settings").build(); + } + + @Override + public String getAccountID() { + return accountID; + } + private static abstract class Item{ public abstract int getViewType(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java index 4cf0e0639..5d592f7fd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -24,13 +25,13 @@ import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; public class StatusEditHistoryFragment extends StatusListFragment{ - private String id; - + private String id, url; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); id=getArguments().getString("id"); + url=getArguments().getString("url"); loadData(); } @@ -162,4 +163,9 @@ public class StatusEditHistoryFragment extends StatusListFragment{ protected Filter.FilterContext getFilterContext() { return null; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return Uri.parse(url); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java index dd879bb75..bf22056b3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments; +import android.app.assist.AssistContent; import android.content.res.Configuration; import android.os.Bundle; @@ -28,7 +29,7 @@ import java.util.stream.Stream; import androidx.recyclerview.widget.RecyclerView; import me.grishka.appkit.Nav; -public abstract class StatusListFragment extends BaseStatusListFragment implements DomainDisplay{ +public abstract class StatusListFragment extends BaseStatusListFragment { protected EventListener eventListener=new EventListener(); protected List buildDisplayItems(Status s){ @@ -182,7 +183,7 @@ public abstract class StatusListFragment extends BaseStatusListFragment } @Override - public void onConfigurationChanged(Configuration newConfig){ + public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (getParentFragment() instanceof HomeTabFragment home) home.updateToolbarLogo(); } 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 176e3d5b1..f51457dc4 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -1,9 +1,9 @@ package org.joinmastodon.android.fragments; +import android.net.Uri; import android.os.Bundle; import android.view.View; -import org.joinmastodon.android.DomainManager; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.statuses.GetStatusContext; import org.joinmastodon.android.api.session.AccountSession; @@ -20,6 +20,7 @@ import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.joinmastodon.android.utils.StatusFilterPredicate; import org.parceler.Parcels; @@ -30,14 +31,9 @@ import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; -public class ThreadFragment extends StatusListFragment implements DomainDisplay{ +public class ThreadFragment extends StatusListFragment implements ProvidesAssistContent { protected Status mainStatus; - @Override - public String getDomain() { - return mainStatus.url; - } - @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -48,7 +44,6 @@ public class ThreadFragment extends StatusListFragment implements DomainDisplay{ data.add(mainStatus); onAppendItems(Collections.singletonList(mainStatus)); setTitle(HtmlParser.parseCustomEmoji(getString(R.string.post_from_user, mainStatus.account.displayName), mainStatus.account.emojis)); - DomainManager.getInstance().setCurrentDomain(getDomain()); } @Override @@ -194,4 +189,9 @@ public class ThreadFragment extends StatusListFragment implements DomainDisplay{ protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.THREAD; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return Uri.parse(mainStatus.url); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/AccountRelatedAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/AccountRelatedAccountListFragment.java index 8277a5b41..3a27bca56 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/AccountRelatedAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/AccountRelatedAccountListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.account_list; +import android.net.Uri; import android.os.Bundle; import org.joinmastodon.android.model.Account; @@ -14,4 +15,11 @@ public abstract class AccountRelatedAccountListFragment extends PaginatedAccount account=Parcels.unwrap(getArguments().getParcelable("targetAccount")); setTitle("@"+account.acct); } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path(isInstanceAkkoma() + ? "/users/" + account.id + : '@' + account.acct).build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java index 4a247b0bf..312976597 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments.account_list; import android.app.ProgressDialog; +import android.app.assist.AssistContent; import android.content.Intent; import android.content.res.Configuration; import android.graphics.drawable.Animatable; @@ -23,7 +24,8 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed; import org.joinmastodon.android.api.session.AccountSessionManager; -import org.joinmastodon.android.fragments.ListTimelinesFragment; +import org.joinmastodon.android.fragments.HasAccountID; +import org.joinmastodon.android.fragments.ListsFragment; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.RecyclerFragment; import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment; @@ -34,6 +36,7 @@ import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.parceler.Parcels; import java.util.ArrayList; @@ -57,7 +60,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public abstract class BaseAccountListFragment extends RecyclerFragment { +public abstract class BaseAccountListFragment extends RecyclerFragment implements ProvidesAssistContent.ProvidesWebUri { protected HashMap relationships=new HashMap<>(); protected String accountID; protected ArrayList> relationshipsRequests=new ArrayList<>(); @@ -170,6 +173,16 @@ public abstract class BaseAccountListFragment extends RecyclerFragment implements ImageLoaderRecyclerAdapter{ public AccountsAdapter(){ super(imgLoader); @@ -387,7 +400,7 @@ public abstract class BaseAccountListFragment extends RecyclerFragment onCreateRequest(String maxID, int count){ return new GetAccountFollowers(account.id, maxID, count); } + + @Override + public Uri getWebUri(Uri.Builder base) { + return super.getWebUri(base).buildUpon() + .appendPath(isInstanceAkkoma() ? "#followers" : "/followers").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/FollowingListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/FollowingListFragment.java index 83351e751..a9b73e921 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/FollowingListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/FollowingListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.account_list; +import android.net.Uri; import android.os.Bundle; import org.joinmastodon.android.R; @@ -19,4 +20,10 @@ public class FollowingListFragment extends AccountRelatedAccountListFragment{ public HeaderPaginationRequest onCreateRequest(String maxID, int count){ return new GetAccountFollowing(account.id, maxID, count); } + + @Override + public Uri getWebUri(Uri.Builder base) { + return super.getWebUri(base).buildUpon() + .appendPath(isInstanceAkkoma() ? "#followees" : "/following").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusFavoritesListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusFavoritesListFragment.java index f62e40ac5..915a8766e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusFavoritesListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusFavoritesListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.account_list; +import android.net.Uri; import android.os.Bundle; import org.joinmastodon.android.R; @@ -18,4 +19,12 @@ public class StatusFavoritesListFragment extends StatusRelatedAccountListFragmen public HeaderPaginationRequest onCreateRequest(String maxID, int count){ return new GetStatusFavorites(status.id, maxID, count); } + + @Override + public Uri getWebUri(Uri.Builder base) { + Uri statusUri = super.getWebUri(base); + return isInstanceAkkoma() + ? statusUri + : statusUri.buildUpon().appendPath("favourites").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusReblogsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusReblogsListFragment.java index 6d494e198..1308a14a9 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusReblogsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusReblogsListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.account_list; +import android.net.Uri; import android.os.Bundle; import org.joinmastodon.android.R; @@ -18,4 +19,12 @@ public class StatusReblogsListFragment extends StatusRelatedAccountListFragment{ public HeaderPaginationRequest onCreateRequest(String maxID, int count){ return new GetStatusReblogs(status.id, maxID, count); } + + @Override + public Uri getWebUri(Uri.Builder base) { + Uri statusUri = super.getWebUri(base); + return isInstanceAkkoma() + ? statusUri + : statusUri.buildUpon().appendPath("reblogs").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusRelatedAccountListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusRelatedAccountListFragment.java index db54c4850..d0499afa6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusRelatedAccountListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/StatusRelatedAccountListFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.account_list; +import android.net.Uri; import android.os.Bundle; import org.joinmastodon.android.model.Status; @@ -18,4 +19,13 @@ public abstract class StatusRelatedAccountListFragment extends PaginatedAccountL protected boolean hasSubtitle(){ return false; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base + .encodedPath(isInstanceAkkoma() + ? "/notice/" + status.id + : '@' + status.account.acct + '/' + status.id) + .build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/BubbleTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/BubbleTimelineFragment.java index 22b746bbc..3dee85c25 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/BubbleTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/BubbleTimelineFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.discover; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -52,4 +53,9 @@ public class BubbleTimelineFragment extends StatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? base.path("/main/bubble").build() : null; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java index cca6ba389..524dce2a5 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverAccountsFragment.java @@ -3,6 +3,7 @@ package org.joinmastodon.android.fragments.discover; import android.graphics.Rect; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -15,7 +16,6 @@ import android.widget.TextView; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.accounts.GetFollowSuggestions; -import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.RecyclerFragment; @@ -28,6 +28,7 @@ import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.ProgressBarButton; +import org.joinmastodon.android.utils.ProvidesAssistContent; import org.parceler.Parcels; import java.util.Collections; @@ -50,7 +51,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public class DiscoverAccountsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, DomainDisplay { +public class DiscoverAccountsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, ProvidesAssistContent.ProvidesWebUri { private String accountID; private Map relationships=Collections.emptyMap(); private GetAccountRelationships relationshipsRequest; @@ -59,11 +60,6 @@ public class DiscoverAccountsFragment extends RecyclerFragment implements ImageLoaderRecyclerAdapter{ public AccountsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java index 61e4f678c..35717e7fa 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments.discover; import android.app.Fragment; +import android.app.assist.AssistContent; import android.os.Build; import android.os.Bundle; import android.text.Editable; @@ -17,10 +18,8 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import org.joinmastodon.android.DomainManager; import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; -import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.HomeFragment; import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.ScrollableToTop; @@ -28,6 +27,7 @@ import org.joinmastodon.android.ui.SimpleViewHolder; import org.joinmastodon.android.ui.tabs.TabLayout; import org.joinmastodon.android.ui.tabs.TabLayoutMediator; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -39,7 +39,7 @@ import me.grishka.appkit.fragments.BaseRecyclerFragment; import me.grishka.appkit.fragments.OnBackPressedListener; import me.grishka.appkit.utils.V; -public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, OnBackPressedListener, IsOnTop, DomainDisplay { +public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, OnBackPressedListener, IsOnTop, ProvidesAssistContent { private TabLayout tabLayout; private ViewPager2 pager; @@ -52,7 +52,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, private ProgressBar searchProgress; private DiscoverPostsFragment postsFragment; - private TrendingHashtagsFragment hashtagsFragment; + private DiscoverHashtagsFragment hashtagsFragment; private DiscoverNewsFragment newsFragment; private DiscoverAccountsFragment accountsFragment; private SearchFragment searchFragment; @@ -69,18 +69,6 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, accountID=getArguments().getString("account"); } - - @Override - public String getDomain() { - if (searchActive) { - return searchFragment.getDomain(); - } - if (tabViews[tabLayout.getSelectedTabPosition()] instanceof DomainDisplay page) { - return page.getDomain(); - } - return DomainDisplay.super.getDomain() + "/explore"; - } - @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState){ @@ -121,10 +109,6 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, if(!page.loaded && !page.isDataLoading()) page.loadData(); } - - - if (_page instanceof DomainDisplay display) - DomainManager.getInstance().setCurrentDomain(display.getDomain()); } }); @@ -136,7 +120,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, postsFragment=new DiscoverPostsFragment(); postsFragment.setArguments(args); - hashtagsFragment=new TrendingHashtagsFragment(); + hashtagsFragment=new DiscoverHashtagsFragment(); hashtagsFragment.setArguments(args); newsFragment=new DiscoverNewsFragment(); @@ -170,9 +154,7 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, tabLayoutMediator.attach(); tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){ @Override - public void onTabSelected(TabLayout.Tab tab){ - DomainManager.getInstance().setCurrentDomain(getDomain()); - } + public void onTabSelected(TabLayout.Tab tab){} @Override public void onTabUnselected(TabLayout.Tab tab){} @@ -341,6 +323,13 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, V.setVisibilityAnimated(searchClear, visible ? View.INVISIBLE : View.VISIBLE); } + @Override + public void onProvideAssistContent(AssistContent assistContent) { + callFragmentToProvideAssistContent(searchActive + ? searchFragment + : getFragmentForPage(pager.getCurrentItem()), assistContent); + } + private class DiscoverPagerAdapter extends RecyclerView.Adapter{ @NonNull @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverHashtagsFragment.java similarity index 89% rename from mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java rename to mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverHashtagsFragment.java index 8a4ab38f9..aedd41e6e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/TrendingHashtagsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverHashtagsFragment.java @@ -3,6 +3,7 @@ package org.joinmastodon.android.fragments.discover; import static org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem.Holder.withHistoryParams; import static org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem.Holder.withoutHistoryParams; +import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; @@ -10,7 +11,6 @@ import android.widget.TextView; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.trends.GetTrendingHashtags; -import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.RecyclerFragment; import org.joinmastodon.android.fragments.ScrollableToTop; @@ -19,6 +19,7 @@ import org.joinmastodon.android.ui.DividerItemDecoration; import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper; import org.joinmastodon.android.ui.utils.UiUtils; import org.joinmastodon.android.ui.views.HashtagChartView; +import org.joinmastodon.android.utils.ProvidesAssistContent; import java.util.List; @@ -28,11 +29,11 @@ import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.views.UsableRecyclerView; -public class TrendingHashtagsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, DomainDisplay { +public class DiscoverHashtagsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, ProvidesAssistContent.ProvidesWebUri { private String accountID; private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.TRENDING_HASHTAGS); - public TrendingHashtagsFragment(){ + public DiscoverHashtagsFragment(){ super(10); } @@ -42,11 +43,6 @@ public class TrendingHashtagsFragment extends RecyclerFragment implemen accountID=getArguments().getString("account"); } - @Override - public String getDomain() { - return DomainDisplay.super.getDomain() + "/explore/tags"; - } - @Override protected void doLoadData(int offset, int count){ currentRequest=new GetTrendingHashtags(10) @@ -82,6 +78,16 @@ public class TrendingHashtagsFragment extends RecyclerFragment implemen return isRecyclerViewOnTop(list); } + @Override + public String getAccountID() { + return accountID; + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? null : base.path("/explore/tags").build(); + } + private class HashtagsAdapter extends RecyclerView.Adapter{ @NonNull @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java index b0eb31a17..67e030514 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverNewsFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments.discover; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.view.View; @@ -10,7 +11,6 @@ import android.widget.TextView; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.trends.GetTrendingLinks; -import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.RecyclerFragment; import org.joinmastodon.android.fragments.ScrollableToTop; @@ -20,6 +20,7 @@ import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.drawables.BlurhashCrossfadeDrawable; import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.utils.ProvidesAssistContent; import java.util.Collections; import java.util.List; @@ -36,7 +37,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public class DiscoverNewsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, DomainDisplay { +public class DiscoverNewsFragment extends RecyclerFragment implements ScrollableToTop, IsOnTop, ProvidesAssistContent.ProvidesWebUri { private String accountID; private List imageRequests=Collections.emptyList(); private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.TRENDING_LINKS); @@ -45,11 +46,6 @@ public class DiscoverNewsFragment extends RecyclerFragment implements Scro super(10); } - @Override - public String getDomain() { - return DomainDisplay.super.getDomain() + "/explore/links"; - } - @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -94,6 +90,16 @@ public class DiscoverNewsFragment extends RecyclerFragment implements Scro return isRecyclerViewOnTop(list); } + @Override + public String getAccountID() { + return accountID; + } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? null : base.path("/explore/links").build(); + } + private class LinksAdapter extends UsableRecyclerView.Adapter implements ImageLoaderRecyclerAdapter{ public LinksAdapter(){ super(imgLoader); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java index 2f6522179..e6d7c4a4c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.discover; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -19,12 +20,6 @@ import me.grishka.appkit.api.SimpleCallback; public class DiscoverPostsFragment extends StatusListFragment implements IsOnTop { private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.TRENDING_POSTS); - @Override - public String getDomain() { - return super.getDomain() + "/explore/posts"; - } - - @Override protected void doLoadData(int offset, int count){ currentRequest=new GetTrendingStatuses(offset, count) @@ -49,9 +44,13 @@ public class DiscoverPostsFragment extends StatusListFragment implements IsOnTop return isRecyclerViewOnTop(list); } - @Override protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return isInstanceAkkoma() ? null : base.path("/explore/posts").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java index 86f54d8ab..5fb7da53f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/FederatedTimelineFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.discover; +import android.net.Uri; import android.os.Bundle; import android.view.View; @@ -25,11 +26,6 @@ public class FederatedTimelineFragment extends StatusListFragment { return true; } - @Override - public String getDomain() { - return super.getDomain() + "/public"; - } - @Override protected void doLoadData(int offset, int count){ currentRequest=new GetPublicTimeline(false, false, refreshing ? null : maxID, count) @@ -56,4 +52,9 @@ public class FederatedTimelineFragment extends StatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path(isInstanceAkkoma() ? "/main/all" : "/public").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java index 631a8d64f..8cde7b7df 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/LocalTimelineFragment.java @@ -1,9 +1,11 @@ package org.joinmastodon.android.fragments.discover; +import android.net.Uri; import android.os.Bundle; import android.view.View; import org.joinmastodon.android.api.requests.timelines.GetPublicTimeline; +import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.Status; @@ -24,11 +26,6 @@ public class LocalTimelineFragment extends StatusListFragment { return true; } - @Override - public String getDomain() { - return super.getDomain() + "/public/local"; - } - @Override protected void doLoadData(int offset, int count){ currentRequest=new GetPublicTimeline(true, false, refreshing ? null : maxID, count) @@ -55,4 +52,9 @@ public class LocalTimelineFragment extends StatusListFragment { protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; } + + @Override + public Uri getWebUri(Uri.Builder base) { + return base.path(isInstanceAkkoma() ? "/main/public" : "/public/local").build(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java index 77b2f1212..e4a375e83 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments.discover; import android.app.Activity; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; @@ -11,7 +12,6 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.BaseStatusListFragment; -import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.ThreadFragment; @@ -43,7 +43,7 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.utils.MergeRecyclerAdapter; import me.grishka.appkit.utils.V; -public class SearchFragment extends BaseStatusListFragment implements IsOnTop, DomainDisplay { +public class SearchFragment extends BaseStatusListFragment implements IsOnTop { private String currentQuery; private List prevDisplayItems; private EnumSet currentFilter=EnumSet.allOf(SearchResult.Type.class); @@ -58,11 +58,6 @@ public class SearchFragment extends BaseStatusListFragment impleme setLayout(R.layout.fragment_search); } - @Override - public String getDomain() { - return super.getDomain() + "/search"; - } - @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -322,6 +317,14 @@ public class SearchFragment extends BaseStatusListFragment impleme return isRecyclerViewOnTop(list); } + @Override + public Uri getWebUri(Uri.Builder base) { + Uri.Builder searchUri = base.path("/search"); + return isInstanceAkkoma() + ? searchUri.appendQueryParameter("query", currentQuery).build() + : searchUri.build(); + } + @FunctionalInterface public interface ProgressVisibilityListener{ void onProgressVisibilityChanged(boolean visible); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java index a04d0a9a8..1a9ff0605 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java @@ -5,6 +5,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.util.SparseIntArray; @@ -267,4 +268,11 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{ protected Filter.FilterContext getFilterContext() { return null; } + + @Override + public Uri getWebUri(Uri.Builder base) { + if (reportStatus != null) return Uri.parse(reportStatus.url); + if (reportAccount != null) return Uri.parse(reportAccount.url); + return null; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java index 25ded6608..45600abbf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java @@ -131,6 +131,7 @@ public class ExtendedFooterStatusDisplayItem extends StatusDisplayItem{ Bundle args=new Bundle(); args.putString("account", item.parentFragment.getAccountID()); args.putString("id", item.status.id); + args.putString("url", item.status.url); Nav.go(item.parentFragment.getActivity(), StatusEditHistoryFragment.class, args); } } 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 95e062971..5a30834f3 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 @@ -1,11 +1,9 @@ package org.joinmastodon.android.ui.displayitems; -import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; import android.graphics.Outline; import android.graphics.Paint; -import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; @@ -24,8 +22,6 @@ import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; -import androidx.annotation.StringRes; - import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; @@ -36,7 +32,7 @@ import org.joinmastodon.android.api.session.AccountSession; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.fragments.ComposeFragment; -import org.joinmastodon.android.fragments.ListTimelinesFragment; +import org.joinmastodon.android.fragments.ListsFragment; import org.joinmastodon.android.fragments.NotificationsListFragment; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.ThreadFragment; @@ -44,12 +40,10 @@ import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Announcement; import org.joinmastodon.android.model.Attachment; -import org.joinmastodon.android.model.ContentType; import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.model.Relationship; import org.joinmastodon.android.model.ScheduledStatus; import org.joinmastodon.android.model.Status; -import org.joinmastodon.android.model.StatusPrivacy; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.UiUtils; @@ -59,7 +53,6 @@ import java.time.Instant; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -284,7 +277,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{ args.putString("account", item.parentFragment.getAccountID()); args.putString("profileAccount", account.id); args.putString("profileDisplayUsername", account.getDisplayUsername()); - Nav.go(item.parentFragment.getActivity(), ListTimelinesFragment.class, args); + Nav.go(item.parentFragment.getActivity(), ListsFragment.class, args); } return true; }); diff --git a/mastodon/src/main/java/org/joinmastodon/android/utils/ProvidesAssistContent.java b/mastodon/src/main/java/org/joinmastodon/android/utils/ProvidesAssistContent.java new file mode 100644 index 000000000..ab82b44e8 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/utils/ProvidesAssistContent.java @@ -0,0 +1,32 @@ +package org.joinmastodon.android.utils; + +import android.app.Fragment; +import android.app.assist.AssistContent; +import android.net.Uri; + +import org.joinmastodon.android.fragments.HasAccountID; + +public interface ProvidesAssistContent { + void onProvideAssistContent(AssistContent assistContent); + + default boolean callFragmentToProvideAssistContent(Fragment fragment, AssistContent assistContent) { + if (fragment instanceof ProvidesAssistContent assistiveFragment) { + assistiveFragment.onProvideAssistContent(assistContent); + return true; + } else { + return false; + } + } + + interface ProvidesWebUri extends ProvidesAssistContent, HasAccountID { + Uri getWebUri(Uri.Builder base); + + default Uri.Builder getUriBuilder() { + return getSession().getInstanceUri().buildUpon(); + } + + default void onProvideAssistContent(AssistContent assistContent) { + assistContent.setWebUri(getWebUri(getUriBuilder())); + } + } +}