From 2e45a0bbff62872c9849903836801be23a4e7c75 Mon Sep 17 00:00:00 2001 From: Vavassor Date: Wed, 12 Apr 2017 04:32:05 -0400 Subject: [PATCH] Adds missing content descriptions and fixes a bit of the follow button hiding code. --- .../com/keylesspalace/tusky/MainActivity.java | 32 ++++--- .../keylesspalace/tusky/StatusViewHolder.java | 1 - .../keylesspalace/tusky/TimelineFragment.java | 88 +++++++++++++------ .../tusky/TimelinePagerAdapter.java | 6 -- app/src/main/res/layout/item_status.xml | 5 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/preferences.xml | 2 +- 7 files changed, 84 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index e5717c99..32b43eb3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -78,7 +78,7 @@ public class MainActivity extends BaseActivity { @BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.pager) ViewPager viewPager; - static FloatingActionButton composeBtn; + FloatingActionButton composeButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -112,13 +112,6 @@ public class MainActivity extends BaseActivity { // Setup the tabs and timeline pager. TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); - String[] pageTitles = { - getString(R.string.title_home), - getString(R.string.title_notifications), - getString(R.string.title_public_local), - getString(R.string.title_public_federated), - }; - adapter.setPageTitles(pageTitles); int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin); viewPager.setPageMargin(pageMargin); @@ -129,10 +122,23 @@ public class MainActivity extends BaseActivity { tabLayout.setupWithViewPager(viewPager); - tabLayout.getTabAt(0).setIcon(R.drawable.ic_home_24dp); - tabLayout.getTabAt(1).setIcon(R.drawable.ic_notifications_24dp); - tabLayout.getTabAt(2).setIcon(R.drawable.ic_local_24dp); - tabLayout.getTabAt(3).setIcon(R.drawable.ic_public_24dp); + int[] tabIcons = { + R.drawable.ic_home_24dp, + R.drawable.ic_notifications_24dp, + R.drawable.ic_local_24dp, + R.drawable.ic_public_24dp, + }; + String[] pageTitles = { + getString(R.string.title_home), + getString(R.string.title_notifications), + getString(R.string.title_public_local), + getString(R.string.title_public_federated), + }; + for (int i = 0; i < 4; i++) { + TabLayout.Tab tab = tabLayout.getTabAt(i); + tab.setIcon(tabIcons[i]); + tab.setContentDescription(pageTitles[i]); + } tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override @@ -180,7 +186,7 @@ public class MainActivity extends BaseActivity { // Setup push notifications if (arePushNotificationsEnabled()) enablePushNotifications(); - composeBtn = floatingBtn; + composeButton = floatingBtn; } @Override diff --git a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java index 5dd1449d..930ec021 100644 --- a/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java @@ -16,7 +16,6 @@ package com.keylesspalace.tusky; import android.content.Context; -import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java index 1e9085f4..76f8fa46 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java @@ -57,6 +57,7 @@ public class TimelineFragment extends SFragment implements private TimelineAdapter adapter; private Kind kind; private String hashtagOrId; + private RecyclerView recyclerView; private LinearLayoutManager layoutManager; private EndlessOnScrollListener scrollListener; private TabLayout.OnTabSelectedListener onTabSelectedListener; @@ -95,7 +96,7 @@ public class TimelineFragment extends SFragment implements swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(this); // Setup the RecyclerView. - RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); + recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); layoutManager = new LinearLayoutManager(context); recyclerView.setLayoutManager(layoutManager); @@ -105,33 +106,6 @@ public class TimelineFragment extends SFragment implements R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); - scrollListener = new EndlessOnScrollListener(layoutManager) { - @Override - public void onScrolled(RecyclerView view, int dx, int dy) { - super.onScrolled(view, dx, dy); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); - - if (dy > 0 && prefs.getBoolean("fabHide", false) && MainActivity.composeBtn.isShown()) { - MainActivity.composeBtn.hide(); // hides the button if we're scrolling down - } else if (dy < 0 && prefs.getBoolean("fabHide", false) && !MainActivity.composeBtn.isShown()) { - MainActivity.composeBtn.show(); // shows it if we are scrolling up - } - - } - - @Override - public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { - TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); - Status status = adapter.getItem(adapter.getItemCount() - 2); - if (status != null) { - sendFetchTimelineRequest(status.id, null); - } else { - sendFetchTimelineRequest(); - } - } - }; - recyclerView.addOnScrollListener(scrollListener); adapter = new TimelineAdapter(this); recyclerView.setAdapter(adapter); @@ -155,6 +129,60 @@ public class TimelineFragment extends SFragment implements return rootView; } + private void onLoadMore(RecyclerView view) { + TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); + Status status = adapter.getItem(adapter.getItemCount() - 2); + if (status != null) { + sendFetchTimelineRequest(status.id, null); + } else { + sendFetchTimelineRequest(); + } + } + + @Override + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + /* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't + * guaranteed to be set until then. */ + if (followButtonPresent()) { + /* Use a modified scroll listener that both loads more statuses as it goes, and hides + * the follow button on down-scroll. */ + MainActivity activity = (MainActivity) getActivity(); + final FloatingActionButton composeButton = activity.composeButton; + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( + activity); + scrollListener = new EndlessOnScrollListener(layoutManager) { + @Override + public void onScrolled(RecyclerView view, int dx, int dy) { + super.onScrolled(view, dx, dy); + + if (preferences.getBoolean("fabHide", false)) { + if (dy > 0 && composeButton.isShown()) { + composeButton.hide(); // hides the button if we're scrolling down + } else if (dy < 0 && !composeButton.isShown()) { + composeButton.show(); // shows it if we are scrolling up + } + } + } + + @Override + public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { + TimelineFragment.this.onLoadMore(view); + } + }; + } else { + // Just use the basic scroll listener to load more statuses. + scrollListener = new EndlessOnScrollListener(layoutManager) { + @Override + public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { + TimelineFragment.this.onLoadMore(view); + } + }; + } + recyclerView.addOnScrollListener(scrollListener); + } + @Override public void onDestroy() { super.onDestroy(); @@ -174,6 +202,10 @@ public class TimelineFragment extends SFragment implements return kind != Kind.TAG && kind != Kind.FAVOURITES; } + private boolean followButtonPresent() { + return kind != Kind.TAG && kind != Kind.FAVOURITES; + } + private void jumpToTop() { layoutManager.scrollToPosition(0); scrollListener.reset(); diff --git a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java index 73318600..af9bc639 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java @@ -20,16 +20,10 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; class TimelinePagerAdapter extends FragmentPagerAdapter { - private String[] pageTitles; - TimelinePagerAdapter(FragmentManager manager) { super(manager); } - void setPageTitles(String[] titles) { - pageTitles = titles; - } - @Override public Fragment getItem(int i) { switch (i) { diff --git a/app/src/main/res/layout/item_status.xml b/app/src/main/res/layout/item_status.xml index c60b9920..eebdbab8 100644 --- a/app/src/main/res/layout/item_status.xml +++ b/app/src/main/res/layout/item_status.xml @@ -5,7 +5,8 @@ android:layout_height="wrap_content" android:paddingLeft="16dp" android:paddingRight="16dp" - android:id="@+id/status_container"> + android:id="@+id/status_container" + android:contentDescription="@string/action_view_thread"> + android:contentDescription="@string/action_view_profile" /> Preferences Favourites Blocked users + View thread Open in browser Submit Add media diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e149cc1b..b65497de 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -18,7 +18,7 @@