Search in sources :

Example 1 with NotificationsAdapter

use of com.keylesspalace.tusky.adapter.NotificationsAdapter in project Tusky by Vavassor.

the class NotificationsFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_timeline, container, false);
    // Setup the SwipeRefreshLayout.
    Context context = getContext();
    swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(this);
    // Setup the RecyclerView.
    recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(layoutManager);
    DividerItemDecoration divider = new DividerItemDecoration(context, layoutManager.getOrientation());
    Drawable drawable = ThemeUtils.getDrawable(context, R.attr.status_divider_drawable, R.drawable.status_divider_dark);
    divider.setDrawable(drawable);
    recyclerView.addItemDecoration(divider);
    adapter = new NotificationsAdapter(this, this);
    recyclerView.setAdapter(adapter);
    TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
    onTabSelectedListener = new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            jumpToTop();
        }
    };
    layout.addOnTabSelectedListener(onTabSelectedListener);
    return rootView;
}
Also used : Context(android.content.Context) NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) TabLayout(android.support.design.widget.TabLayout) Drawable(android.graphics.drawable.Drawable) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Nullable(android.support.annotation.Nullable)

Example 2 with NotificationsAdapter

use of com.keylesspalace.tusky.adapter.NotificationsAdapter in project Tusky by Vavassor.

the class NotificationsFragment method onActivityCreated.

@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.
         * Use a modified scroll listener that both loads more notifications as it goes, and hides
         * the compose button on down-scroll. */
    MainActivity activity = (MainActivity) getActivity();
    final FloatingActionButton composeButton = activity.composeButton;
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
    preferences.registerOnSharedPreferenceChangeListener(this);
    hideFab = preferences.getBoolean("fabHide", false);
    scrollListener = new EndlessOnScrollListener(layoutManager) {

        @Override
        public void onScrolled(RecyclerView view, int dx, int dy) {
            super.onScrolled(view, dx, dy);
            if (hideFab) {
                if (dy > 0 && composeButton.isShown()) {
                    // hides the button if we're scrolling down
                    composeButton.hide();
                } else if (dy < 0 && !composeButton.isShown()) {
                    // shows it if we are scrolling up
                    composeButton.show();
                }
            } else if (!composeButton.isShown()) {
                composeButton.show();
            }
        }

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            NotificationsAdapter adapter = (NotificationsAdapter) view.getAdapter();
            Notification notification = adapter.getItem(adapter.getItemCount() - 2);
            if (notification != null) {
                sendFetchNotificationsRequest(notification.id, null);
            } else {
                sendFetchNotificationsRequest();
            }
        }
    };
    recyclerView.addOnScrollListener(scrollListener);
}
Also used : NotificationsAdapter(com.keylesspalace.tusky.adapter.NotificationsAdapter) EndlessOnScrollListener(com.keylesspalace.tusky.view.EndlessOnScrollListener) SharedPreferences(android.content.SharedPreferences) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) MainActivity(com.keylesspalace.tusky.MainActivity) Notification(com.keylesspalace.tusky.entity.Notification)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 NotificationsAdapter (com.keylesspalace.tusky.adapter.NotificationsAdapter)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Drawable (android.graphics.drawable.Drawable)1 Nullable (android.support.annotation.Nullable)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 TabLayout (android.support.design.widget.TabLayout)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 MainActivity (com.keylesspalace.tusky.MainActivity)1 Notification (com.keylesspalace.tusky.entity.Notification)1 EndlessOnScrollListener (com.keylesspalace.tusky.view.EndlessOnScrollListener)1