Adds missing content descriptions and fixes a bit of the follow button hiding code.

main
Vavassor 8 years ago
parent bc8c2427fb
commit 2e45a0bbff
  1. 32
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java
  2. 1
      app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java
  3. 84
      app/src/main/java/com/keylesspalace/tusky/TimelineFragment.java
  4. 6
      app/src/main/java/com/keylesspalace/tusky/TimelinePagerAdapter.java
  5. 5
      app/src/main/res/layout/item_status.xml
  6. 1
      app/src/main/res/values/strings.xml
  7. 2
      app/src/main/res/xml/preferences.xml

@ -78,7 +78,7 @@ public class MainActivity extends BaseActivity {
@BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.tab_layout) TabLayout tabLayout;
@BindView(R.id.pager) ViewPager viewPager; @BindView(R.id.pager) ViewPager viewPager;
static FloatingActionButton composeBtn; FloatingActionButton composeButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -112,13 +112,6 @@ public class MainActivity extends BaseActivity {
// Setup the tabs and timeline pager. // Setup the tabs and timeline pager.
TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager()); 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); int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
viewPager.setPageMargin(pageMargin); viewPager.setPageMargin(pageMargin);
@ -129,10 +122,23 @@ public class MainActivity extends BaseActivity {
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.ic_home_24dp); int[] tabIcons = {
tabLayout.getTabAt(1).setIcon(R.drawable.ic_notifications_24dp); R.drawable.ic_home_24dp,
tabLayout.getTabAt(2).setIcon(R.drawable.ic_local_24dp); R.drawable.ic_notifications_24dp,
tabLayout.getTabAt(3).setIcon(R.drawable.ic_public_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() { tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override @Override
@ -180,7 +186,7 @@ public class MainActivity extends BaseActivity {
// Setup push notifications // Setup push notifications
if (arePushNotificationsEnabled()) enablePushNotifications(); if (arePushNotificationsEnabled()) enablePushNotifications();
composeBtn = floatingBtn; composeButton = floatingBtn;
} }
@Override @Override

@ -16,7 +16,6 @@
package com.keylesspalace.tusky; package com.keylesspalace.tusky;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;

@ -57,6 +57,7 @@ public class TimelineFragment extends SFragment implements
private TimelineAdapter adapter; private TimelineAdapter adapter;
private Kind kind; private Kind kind;
private String hashtagOrId; private String hashtagOrId;
private RecyclerView recyclerView;
private LinearLayoutManager layoutManager; private LinearLayoutManager layoutManager;
private EndlessOnScrollListener scrollListener; private EndlessOnScrollListener scrollListener;
private TabLayout.OnTabSelectedListener onTabSelectedListener; private TabLayout.OnTabSelectedListener onTabSelectedListener;
@ -95,7 +96,7 @@ public class TimelineFragment extends SFragment implements
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);
swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setOnRefreshListener(this);
// Setup the RecyclerView. // Setup the RecyclerView.
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context); layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
@ -105,23 +106,30 @@ public class TimelineFragment extends SFragment implements
R.drawable.status_divider_dark); R.drawable.status_divider_dark);
divider.setDrawable(drawable); divider.setDrawable(drawable);
recyclerView.addItemDecoration(divider); recyclerView.addItemDecoration(divider);
scrollListener = new EndlessOnScrollListener(layoutManager) { adapter = new TimelineAdapter(this);
recyclerView.setAdapter(adapter);
if (jumpToTopAllowed()) {
TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
@Override @Override
public void onScrolled(RecyclerView view, int dx, int dy) { public void onTabSelected(TabLayout.Tab tab) {}
super.onScrolled(view, dx, dy);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); @Override
public void onTabUnselected(TabLayout.Tab tab) {}
if (dy > 0 && prefs.getBoolean("fabHide", false) && MainActivity.composeBtn.isShown()) { @Override
MainActivity.composeBtn.hide(); // hides the button if we're scrolling down public void onTabReselected(TabLayout.Tab tab) {
} else if (dy < 0 && prefs.getBoolean("fabHide", false) && !MainActivity.composeBtn.isShown()) { jumpToTop();
MainActivity.composeBtn.show(); // shows it if we are scrolling up }
};
layout.addOnTabSelectedListener(onTabSelectedListener);
} }
return rootView;
} }
@Override private void onLoadMore(RecyclerView view) {
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); TimelineAdapter adapter = (TimelineAdapter) view.getAdapter();
Status status = adapter.getItem(adapter.getItemCount() - 2); Status status = adapter.getItem(adapter.getItemCount() - 2);
if (status != null) { if (status != null) {
@ -130,29 +138,49 @@ public class TimelineFragment extends SFragment implements
sendFetchTimelineRequest(); sendFetchTimelineRequest();
} }
} }
};
recyclerView.addOnScrollListener(scrollListener);
adapter = new TimelineAdapter(this);
recyclerView.setAdapter(adapter);
if (jumpToTopAllowed()) {
TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
onTabSelectedListener = new TabLayout.OnTabSelectedListener() {
@Override @Override
public void onTabSelected(TabLayout.Tab tab) {} 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 @Override
public void onTabUnselected(TabLayout.Tab tab) {} 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 @Override
public void onTabReselected(TabLayout.Tab tab) { public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
jumpToTop(); TimelineFragment.this.onLoadMore(view);
} }
}; };
layout.addOnTabSelectedListener(onTabSelectedListener); } 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);
} }
};
return rootView; }
recyclerView.addOnScrollListener(scrollListener);
} }
@Override @Override
@ -174,6 +202,10 @@ public class TimelineFragment extends SFragment implements
return kind != Kind.TAG && kind != Kind.FAVOURITES; return kind != Kind.TAG && kind != Kind.FAVOURITES;
} }
private boolean followButtonPresent() {
return kind != Kind.TAG && kind != Kind.FAVOURITES;
}
private void jumpToTop() { private void jumpToTop() {
layoutManager.scrollToPosition(0); layoutManager.scrollToPosition(0);
scrollListener.reset(); scrollListener.reset();

@ -20,16 +20,10 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
class TimelinePagerAdapter extends FragmentPagerAdapter { class TimelinePagerAdapter extends FragmentPagerAdapter {
private String[] pageTitles;
TimelinePagerAdapter(FragmentManager manager) { TimelinePagerAdapter(FragmentManager manager) {
super(manager); super(manager);
} }
void setPageTitles(String[] titles) {
pageTitles = titles;
}
@Override @Override
public Fragment getItem(int i) { public Fragment getItem(int i) {
switch (i) { switch (i) {

@ -5,7 +5,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"
android:id="@+id/status_container"> android:id="@+id/status_container"
android:contentDescription="@string/action_view_thread">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -43,7 +44,7 @@
android:layout_below="@+id/status_reblogged_bar" android:layout_below="@+id/status_reblogged_bar"
android:layout_marginTop="11dp" android:layout_marginTop="11dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:contentDescription="@null" /> android:contentDescription="@string/action_view_profile" />
<RelativeLayout <RelativeLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"

@ -72,6 +72,7 @@
<string name="action_view_preferences">Preferences</string> <string name="action_view_preferences">Preferences</string>
<string name="action_view_favourites">Favourites</string> <string name="action_view_favourites">Favourites</string>
<string name="action_view_blocks">Blocked users</string> <string name="action_view_blocks">Blocked users</string>
<string name="action_view_thread">View thread</string>
<string name="action_open_in_web">Open in browser</string> <string name="action_open_in_web">Open in browser</string>
<string name="action_submit">Submit</string> <string name="action_submit">Submit</string>
<string name="action_photo_pick">Add media</string> <string name="action_photo_pick">Add media</string>

@ -18,7 +18,7 @@
<PreferenceCategory android:title="@string/pref_title_browser_settings"> <PreferenceCategory android:title="@string/pref_title_browser_settings">
<CheckBoxPreference <CheckBoxPreference
android:key="customTabs" android:key="customTabs"
android:title="@string/pre_title_custom_tabs" android:title="@string/pref_title_custom_tabs"
android:defaultValue="true" /> android:defaultValue="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_notification_settings"> <PreferenceCategory android:title="@string/pref_title_notification_settings">

Loading…
Cancel
Save