Search in sources :

Example 41 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project nucleus by konmik.

the class MainFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    check1.setText(MainPresenter.NAME_1);
    check2.setText(MainPresenter.NAME_2);
    pager = new RxPager(10, page -> {
        adapter.showProgress();
        getPresenter().requestNext(page);
    });
    adapter = new SimpleListAdapter<>(R.layout.recycler_view_progress, new ClassViewHolderType<>(ServerAPI.Item.class, R.layout.item, v -> new SimpleViewHolder<>(v, this::onItemClick)));
    recyclerView.setAdapter(adapter);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addOnScrollListener(new OnScrollPaging(layoutManager, adapter, pager::next));
}
Also used : ServerAPI(nucleus.example.network.ServerAPI) PageBundle(nucleus.example.util.PageBundle) BaseFragment(nucleus.example.ui.base.BaseFragment) Bundle(android.os.Bundle) SimpleListAdapter(nucleus.example.util.adapters.SimpleListAdapter) RequiresPresenter(nucleus.factory.RequiresPresenter) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) OnScrollPaging(nucleus.example.util.OnScrollPaging) SimpleViewHolder(nucleus.example.util.adapters.SimpleViewHolder) ClassViewHolderType(nucleus.example.util.adapters.ClassViewHolderType) ViewGroup(android.view.ViewGroup) OnClick(butterknife.OnClick) RxPager(nucleus.example.util.RxPager) RecyclerView(android.support.v7.widget.RecyclerView) Arrays.asList(java.util.Arrays.asList) CheckedTextView(android.widget.CheckedTextView) Toast(android.widget.Toast) View(android.view.View) R(nucleus.example.R) Bind(butterknife.Bind) Nullable(android.support.annotation.Nullable) ItemFragment(nucleus.example.ui.item.ItemFragment) RxPager(nucleus.example.util.RxPager) ClassViewHolderType(nucleus.example.util.adapters.ClassViewHolderType) ServerAPI(nucleus.example.network.ServerAPI) OnScrollPaging(nucleus.example.util.OnScrollPaging) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 42 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project android-oss by kickstarter.

the class ThanksActivity method onCreate.

@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.thanks_layout);
    ButterKnife.bind(this);
    ((KSApplication) getApplication()).component().inject(this);
    shareDialog = new ShareDialog(this);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recommendedProjectsRecyclerView.setLayoutManager(layoutManager);
    adapter = new ThanksAdapter(viewModel);
    recommendedProjectsRecyclerView.setAdapter(adapter);
    Observable.timer(500L, TimeUnit.MILLISECONDS, Schedulers.newThread()).compose(ignoreValues()).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> animateBackground());
    RxView.clicks(shareButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareClick());
    RxView.clicks(shareOnFacebookButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnFacebookClick());
    RxView.clicks(shareOnTwitterButton).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> viewModel.inputs.shareOnTwitterClick());
    viewModel.outputs.projectName().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showBackedProject);
    viewModel.outputs.showConfirmGamesNewsletterDialog().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showConfirmGamesNewsletterDialog());
    viewModel.outputs.showGamesNewsletterDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showGamesNewsletterDialog());
    viewModel.outputs.showRatingDialog().compose(bindToLifecycle()).take(1).delay(700L, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> showRatingDialog());
    viewModel.outputs.showRecommendations().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showRecommendations);
    viewModel.outputs.startDiscovery().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startDiscovery);
    viewModel.outputs.startProject().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startProject);
    viewModel.outputs.startShare().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShare);
    viewModel.outputs.startShareOnFacebook().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnFacebook);
    viewModel.outputs.startShareOnTwitter().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startShareOnTwitter);
}
Also used : ThanksAdapter(com.kickstarter.ui.adapters.ThanksAdapter) ShareDialog(com.facebook.share.widget.ShareDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 43 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project android-oss by kickstarter.

the class ViewPledgeActivity method onCreate.

@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_pledge_layout);
    ButterKnife.bind(this);
    final RewardsItemAdapter rewardsItemAdapter = new RewardsItemAdapter();
    rewardsItemRecyclerView.setAdapter(rewardsItemAdapter);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    rewardsItemRecyclerView.setLayoutManager(layoutManager);
    final Environment environment = environment();
    ksString = environment.ksString();
    RxView.clicks(projectContextView).compose(bindToLifecycle()).observeOn(mainThread()).subscribe(__ -> viewModel.inputs.projectClicked());
    viewModel.outputs.backerNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(backerNameTextView::setText);
    viewModel.outputs.backerNumberTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setBackerNumberTextViewText);
    viewModel.outputs.backingAmountAndDateTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ad -> setBackingAmountAndDateTextViewText(ad.first, ad.second));
    viewModel.outputs.backingStatus().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setBackingStatusTextViewText);
    viewModel.outputs.creatorNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::setCreatorNameTextViewText);
    viewModel.outputs.goBack().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(__ -> back());
    viewModel.outputs.loadBackerAvatar().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(this::loadBackerAvatar);
    viewModel.outputs.loadProjectPhoto().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(url -> Picasso.with(this).load(url).into(projectContextPhotoImageView));
    viewModel.outputs.projectNameTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(projectContextProjectNameTextView::setText);
    viewModel.outputs.rewardsItems().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(rewardsItemAdapter::rewardsItems);
    viewModel.outputs.rewardsItemsAreHidden().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ViewUtils.setGone(rewardsItemSection));
    viewModel.outputs.rewardMinimumAndDescriptionTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(md -> setRewardMinimumAndDescriptionTextViewText(md.first, md.second));
    viewModel.outputs.shippingAmountTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(shippingAmountTextView::setText);
    viewModel.outputs.shippingLocationTextViewText().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(shippingLocationTextView::setText);
    viewModel.outputs.shippingSectionIsHidden().compose(bindToLifecycle()).observeOn(mainThread()).subscribe(ViewUtils.setGone(shippingSection));
}
Also used : Environment(com.kickstarter.libs.Environment) RewardsItemAdapter(com.kickstarter.ui.adapters.RewardsItemAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 44 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project baseAdapter by hongyangAndroid.

the class WrapperUtils method onAttachedToRecyclerView.

public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) {
    innerAdapter.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView)

Example 45 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager 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)182 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)170 View (android.view.View)132 GridLayoutManager (android.support.v7.widget.GridLayoutManager)69 TextView (android.widget.TextView)60 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)44 ImageView (android.widget.ImageView)41 Bundle (android.os.Bundle)19 Nullable (android.support.annotation.Nullable)18 ViewGroup (android.view.ViewGroup)17 ArrayList (java.util.ArrayList)17 Intent (android.content.Intent)16 Toolbar (android.support.v7.widget.Toolbar)15 BindView (butterknife.BindView)15 Context (android.content.Context)14 Handler (android.os.Handler)13 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)13 DataSnapshot (com.google.firebase.database.DataSnapshot)11 DatabaseError (com.google.firebase.database.DatabaseError)11 Drawable (android.graphics.drawable.Drawable)10