Search in sources :

Example 51 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project UltimateAndroid by cymcsg.

the class MaterialTabTextActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.material_tab_text_activity_main);
    Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
    this.setSupportActionBar(toolbar);
    tabHost = (MaterialTabHost) this.findViewById(R.id.tabHost);
    pager = (ViewPager) this.findViewById(R.id.pager);
    // init view pager
    adapter = new ViewPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // when user do a swipe the selected tab change
            tabHost.setSelectedNavigationItem(position);
        }
    });
    // insert all tabs from pagerAdapter data
    for (int i = 0; i < adapter.getCount(); i++) {
        tabHost.addTab(tabHost.newTab().setText(adapter.getPageTitle(i)).setTabListener(this));
    }
}
Also used : ViewPager(android.support.v4.view.ViewPager) Toolbar(android.support.v7.widget.Toolbar)

Example 52 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project UltimateAndroid by cymcsg.

the class SnackbarRecyclerViewSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.snack_bar_activity_recyclerview_sample);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    List<String> data = new ArrayList<String>();
    for (int i = 0; i < 25; i++) {
        data.add(String.format("Item %d", (i + 1)));
    }
    SimpleDataAdapter adapter = new SimpleDataAdapter(android.R.layout.simple_list_item_1, data, this);
    mRecyclerView.setAdapter(adapter);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 53 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project kickmaterial by byoutline.

the class ProjectsListFragment method setUpAdapters.

private void setUpAdapters() {
    /** NEW ADAPTER **/
    layoutManager = new GridLayoutManager(getActivity(), 2);
    final boolean showHeader = sharedPreferences.getBoolean(PREFS_SHOW_HEADER, true);
    // TODO: decide when to hide it.
    sharedPreferences.edit().putBoolean(PREFS_SHOW_HEADER, false).apply();
    final ProjectsAdapter.ItemViewTypeProvider itemViewTypeProvider = new ProjectsAdapter.ItemViewTypeProvider(showHeader);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (itemViewTypeProvider.getViewType(position) == ProjectsAdapter.NORMAL_ITEM) {
                return 1;
            }
            return 2;
        }
    });
    projectListRv.setEndlessScrollListener(this);
    projectListRv.setLayoutManager(layoutManager);
    adapter = new ProjectsAdapter(getActivity(), this, showHeader, itemViewTypeProvider);
    projectListRv.setAdapter(adapter);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProjectsAdapter(com.byoutline.kickmaterial.adapters.ProjectsAdapter)

Example 54 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project kickmaterial by byoutline.

the class SearchListFragment method setUpAdapters.

private void setUpAdapters() {
    projectListRv.setEndlessScrollListener(this);
    layoutManager = new LinearLayoutManager(getActivity());
    projectListRv.setLayoutManager(layoutManager);
    projectListRv.addItemDecoration(new SearchListSeparator(getActivity().getApplicationContext()));
    adapter = new SearchAdapter(getActivity(), this);
    projectListRv.setAdapter(adapter);
}
Also used : SearchAdapter(com.byoutline.kickmaterial.adapters.SearchAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SearchListSeparator(com.byoutline.kickmaterial.views.SearchListSeparator)

Example 55 with Adapter

use of android.support.v7.widget.RecyclerView.Adapter in project plaid by nickbutcher.

the class PlayerActivity method bindPlayer.

void bindPlayer() {
    if (player == null)
        return;
    final Resources res = getResources();
    final NumberFormat nf = NumberFormat.getInstance();
    Glide.with(this).load(player.getHighQualityAvatarUrl()).placeholder(R.drawable.avatar_placeholder).transform(circleTransform).into(avatar);
    playerName.setText(player.name.toLowerCase());
    if (!TextUtils.isEmpty(player.bio)) {
        DribbbleUtils.parseAndSetText(bio, player.bio);
    } else {
        bio.setVisibility(View.GONE);
    }
    shotCount.setText(res.getQuantityString(R.plurals.shots, player.shots_count, nf.format(player.shots_count)));
    if (player.shots_count == 0) {
        shotCount.setCompoundDrawablesRelativeWithIntrinsicBounds(null, getDrawable(R.drawable.avd_no_shots), null, null);
    }
    setFollowerCount(player.followers_count);
    likesCount.setText(res.getQuantityString(R.plurals.likes, player.likes_count, nf.format(player.likes_count)));
    // load the users shots
    dataManager = new PlayerShotsDataManager(this, player) {

        @Override
        public void onDataLoaded(List<Shot> data) {
            if (data != null && data.size() > 0) {
                if (adapter.getDataItemCount() == 0) {
                    loading.setVisibility(View.GONE);
                    ViewUtils.setPaddingTop(shots, likesCount.getBottom());
                }
                adapter.addAndResort(data);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    shots.setAdapter(adapter);
    shots.setItemAnimator(new SlideInItemAnimator());
    shots.setVisibility(View.VISIBLE);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    shots.setLayoutManager(layoutManager);
    shots.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadData();
        }
    });
    shots.setHasFixedSize(true);
    // forward on any clicks above the first item in the grid (i.e. in the paddingTop)
    // to 'pass through' to the view behind
    shots.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int firstVisible = layoutManager.findFirstVisibleItemPosition();
            if (firstVisible > 0)
                return false;
            // if no data loaded then pass through
            if (adapter.getDataItemCount() == 0) {
                return container.dispatchTouchEvent(event);
            }
            final RecyclerView.ViewHolder vh = shots.findViewHolderForAdapterPosition(0);
            if (vh == null)
                return false;
            final int firstTop = vh.itemView.getTop();
            if (event.getY() < firstTop) {
                return container.dispatchTouchEvent(event);
            }
            return false;
        }
    });
    // check if following
    if (dataManager.getDribbblePrefs().isLoggedIn()) {
        if (player.id == dataManager.getDribbblePrefs().getUserId()) {
            TransitionManager.beginDelayedTransition(container);
            follow.setVisibility(View.GONE);
            ViewUtils.setPaddingTop(shots, container.getHeight() - follow.getHeight() - ((ViewGroup.MarginLayoutParams) follow.getLayoutParams()).bottomMargin);
        } else {
            final Call<Void> followingCall = dataManager.getDribbbleApi().following(player.id);
            followingCall.enqueue(new Callback<Void>() {

                @Override
                public void onResponse(Call<Void> call, Response<Void> response) {
                    following = response.isSuccessful();
                    if (!following)
                        return;
                    TransitionManager.beginDelayedTransition(container);
                    follow.setText(R.string.following);
                    follow.setActivated(true);
                }

                @Override
                public void onFailure(Call<Void> call, Throwable t) {
                }
            });
        }
    }
    if (player.shots_count > 0) {
        // kick off initial load
        dataManager.loadData();
    } else {
        loading.setVisibility(View.GONE);
    }
}
Also used : PlayerShotsDataManager(io.plaidapp.data.api.dribbble.PlayerShotsDataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideInItemAnimator(io.plaidapp.ui.recyclerview.SlideInItemAnimator) Resources(android.content.res.Resources) Shot(io.plaidapp.data.api.dribbble.model.Shot) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener) NumberFormat(java.text.NumberFormat)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)688 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)612 View (android.view.View)593 TextView (android.widget.TextView)245 ArrayList (java.util.ArrayList)179 Intent (android.content.Intent)148 ImageView (android.widget.ImageView)132 Toolbar (android.support.v7.widget.Toolbar)118 GridLayoutManager (android.support.v7.widget.GridLayoutManager)111 AdapterView (android.widget.AdapterView)109 ViewGroup (android.view.ViewGroup)97 AlertDialog (android.support.v7.app.AlertDialog)91 Bundle (android.os.Bundle)85 ListView (android.widget.ListView)85 BindView (butterknife.BindView)85 Nullable (android.support.annotation.Nullable)78 DialogInterface (android.content.DialogInterface)71 Context (android.content.Context)65 ArrayAdapter (android.widget.ArrayAdapter)65 LayoutInflater (android.view.LayoutInflater)64