Skip to content

Instantly share code, notes, and snippets.

@MaartenS
Last active October 24, 2020 03:53
Show Gist options
  • Save MaartenS/a9bc8520c8e7b586bcd7 to your computer and use it in GitHub Desktop.
Save MaartenS/a9bc8520c8e7b586bcd7 to your computer and use it in GitHub Desktop.
Android snippets #android

##Flipboard style bottom sheet in Android

gradle dependecies

compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0' // optional

In view wrap your layout using the BottomSheetLayout

  <com.flipboard.bottomsheet.BottomSheetLayout
      android:id="@+id/bottomsheet"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

In your activity inflate a view

  mBottomSheet = (BottomSheetLayout) findViewById(R.id.bottomsheet);
  mBottomSheet.showWithSheetView(LayoutInflater.from(this).inflate(R.layout.sheet_deal, mBottomSheet, false));
  mBottomSheet.setShouldDimContentView(false);
  mBottomSheet.setInterceptContentTouch(false);
  mBottomSheet.setPeekOnDismiss(false);
  mBottomSheet.addOnSheetDismissedListener(new OnSheetDismissedListener() {
      @Override
      public void onDismissed(BottomSheetLayout bottomSheetLayout) {
          if (mCurrentPage == 0)
              onBackPressed();
          bottomSheetLayout.dismissSheet();
      }
  });
  
  mBuyNow = (LinearLayout) mBottomSheet.findViewById(R.id.lbtn_buy_now);
  mBuyNow.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          buyDeal();
      }
  });
  
  mSheetPrice = (TextView) mBottomSheet.findViewById(R.id.sheet_price);
  mSheetPrice.setText(mDeal.getPrice().getPrice());
  
  mSheetBuyNow = (TextView) mBottomSheet.findViewById(R.id.sheet_buy_now);
  mSheetBuyNow.setText(mDataService.getTranslation("2369.Buttons_stickyDealBuyNow").toUpperCase());
public class DealsAdapter extends RecyclerView.Adapter<DealsAdapter.DealViewHolder> {
private final String mCity;
public static class DealViewHolder extends RecyclerView.ViewHolder {
public CardView cv;
public TextView title;
public ImageView dealImage;
DealViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.cv);
title = (TextView) itemView.findViewById(R.id.txt_title);
dealImage = (ImageView) itemView.findViewById(R.id.image_deal);
}
}
private Context mContext;
private List<DealResource> mDeals;
public DealsAdapter(Context context, List<DealResource> deals, String city, String sold) {
mContext = context;
mCity = city;
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
@Override
public DealViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_deal, viewGroup, false);
DealViewHolder dvh = new DealViewHolder(v);
return dvh;
}
@Override
public void onBindViewHolder(DealViewHolder dealViewHolder, int i) {
Picasso.with(mContext)
.load(mDeals.get(i).getImage())
.resize(mContext.getResources().getDisplayMetrics().widthPixels, mContext.getResources().getDisplayMetrics().widthPixels * 378 / 640)
.into(dealViewHolder.dealImage);
dealViewHolder.title.setText(mDeals.get(i).getName());
dealViewHolder.city.setText(mCity);
}
@Override
public int getItemCount() {
return mDeals.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment