Adds missing content descriptions and fixes a bit of the follow button hiding code.
This commit is contained in:
parent
bc8c2427fb
commit
2e45a0bbff
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -43,7 +44,7 @@
|
|||
android:layout_below="@+id/status_reblogged_bar"
|
||||
android:layout_marginTop="11dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:contentDescription="@null" />
|
||||
android:contentDescription="@string/action_view_profile" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<string name="action_view_preferences">Preferences</string>
|
||||
<string name="action_view_favourites">Favourites</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_submit">Submit</string>
|
||||
<string name="action_photo_pick">Add media</string>
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
<PreferenceCategory android:title="@string/pref_title_browser_settings">
|
||||
<CheckBoxPreference
|
||||
android:key="customTabs"
|
||||
android:title="@string/pre_title_custom_tabs"
|
||||
android:title="@string/pref_title_custom_tabs"
|
||||
android:defaultValue="true" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_title_notification_settings">
|
||||
|
|
Loading…
Reference in New Issue