Panagiotis Triantafyllou

added filter dialog part1

......@@ -10,6 +10,7 @@ import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
......@@ -24,6 +25,8 @@ import androidx.viewpager2.widget.ViewPager2;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import java.util.ArrayList;
import java.util.LinkedHashMap;
......@@ -58,7 +61,7 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
private RelativeLayout mPbLoading;
private TextView mTvHeaderTitle, mTvMyCouponsTitle, mTvMyCouponsValue, mTvSearchTitle;
private LinearLayout mLlUserTags, mLlMyCoupons;
private LinearLayout mLlUserTags, mLlMyCoupons, mLlSearchFilterButton;
/* View Pager */
// private ViewPager2 mBannerViewPager;
private RecyclerView mRvBannerViewPager;
......@@ -114,6 +117,10 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
startActivity(myIntent);
return;
}
if (v.getId() == R.id.ll_search_filter_button) {
showFilterDialog();
return;
}
if (v.getId() == R.id.ll_all) {
String categoryName = (String) v.getTag();
Intent myIntent = new Intent(HomeActivity.this, CouponsetsActivity.class);
......@@ -138,6 +145,8 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
mPbLoading.setOnTouchListener((v, event) -> true);
mLlMyCoupons = findViewById(R.id.ll_my_coupons);
mLlMyCoupons.setOnClickListener(this);
mLlSearchFilterButton = findViewById(R.id.ll_search_filter_button);
mLlSearchFilterButton.setOnClickListener(this);
mViewPager = findViewById(R.id.cl_viewpager);
mSectionsContainer = findViewById(R.id.ll_sections_container);
mSectionsLoading = findViewById(R.id.rl_sections_loading);
......@@ -355,6 +364,122 @@ public class HomeActivity extends Activity implements View.OnClickListener, Coup
mSectionsLoading.setVisibility(View.GONE);
}
private void showFilterDialog() {
Filter filter = WarplyManagerHelper.getFilter();
if (filter == null || filter.getOfferCategories() == null || filter.getOfferCategories().isEmpty()) {
return;
}
BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this, R.style.FullScreenBottomSheetDialog);
View dialogView = LayoutInflater.from(this).inflate(R.layout.dl_filter, null);
bottomSheetDialog.setContentView(dialogView);
LinearLayout llFilterContainer = dialogView.findViewById(R.id.ll_filter_container);
// Static "Top Offers" row
View topOffersRow = LayoutInflater.from(this).inflate(R.layout.item_filter_category, llFilterContainer, false);
TextView tvTopOffers = topOffersRow.findViewById(R.id.tv_category_name);
tvTopOffers.setText(getString(R.string.lbl_top_offers));
WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvTopOffers);
topOffersRow.setTag(R.string.lbl_top_offers);
topOffersRow.setOnClickListener(v -> {
// TODO: filter action
bottomSheetDialog.dismiss();
});
llFilterContainer.addView(topOffersRow);
// Divider after Top Offers
View divider = new View(this);
LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, 1);
int dividerMarginPx = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics());
dividerParams.setMarginStart(dividerMarginPx);
dividerParams.setMarginEnd(dividerMarginPx);
divider.setLayoutParams(dividerParams);
divider.setBackgroundColor(getColor(R.color.custom_grey12));
llFilterContainer.addView(divider);
// Dynamic categories from Filter
for (Filter.OfferCategory parent : filter.getOfferCategories()) {
if (parent.getAdminName() == null) continue;
View categoryRow = LayoutInflater.from(this).inflate(R.layout.item_filter_category, llFilterContainer, false);
TextView tvCategoryName = categoryRow.findViewById(R.id.tv_category_name);
ImageView ivArrow = categoryRow.findViewById(R.id.iv_arrow);
tvCategoryName.setText(parent.getAdminName());
WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvCategoryName);
boolean hasChildren = parent.getChildren() != null && !parent.getChildren().isEmpty();
if (!hasChildren) {
ivArrow.setVisibility(View.GONE);
categoryRow.setTag(parent.getAdminName());
categoryRow.setOnClickListener(v -> {
// TODO: filter action
bottomSheetDialog.dismiss();
});
llFilterContainer.addView(categoryRow);
} else {
ivArrow.setVisibility(View.VISIBLE);
// Child container (collapsed by default)
LinearLayout childContainer = new LinearLayout(this);
childContainer.setOrientation(LinearLayout.VERTICAL);
childContainer.setVisibility(View.GONE);
childContainer.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
for (Filter.OfferCategory child : parent.getChildren()) {
if (child.getAdminName() == null) continue;
View childRow = LayoutInflater.from(this).inflate(R.layout.item_filter_subcategory, childContainer, false);
TextView tvSubcategoryName = childRow.findViewById(R.id.tv_subcategory_name);
tvSubcategoryName.setText(child.getAdminName());
WarpUtils.renderCustomFont(this, R.font.ping_lcg_regular, tvSubcategoryName);
childRow.setTag(child.getAdminName());
childRow.setOnClickListener(v -> {
// TODO: filter action
bottomSheetDialog.dismiss();
});
childContainer.addView(childRow);
}
categoryRow.setOnClickListener(v -> {
boolean isExpanded = childContainer.getVisibility() == View.VISIBLE;
if (isExpanded) {
childContainer.setVisibility(View.GONE);
ivArrow.animate().rotation(0f).setDuration(200).start();
} else {
childContainer.setVisibility(View.VISIBLE);
ivArrow.animate().rotation(180f).setDuration(200).start();
}
});
llFilterContainer.addView(categoryRow);
llFilterContainer.addView(childContainer);
}
}
bottomSheetDialog.setOnShowListener(dialog -> {
View bottomSheet = bottomSheetDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
if (bottomSheet != null) {
bottomSheet.post(() -> {
int screenHeight = getResources().getDisplayMetrics().heightPixels;
ViewGroup.LayoutParams lp = bottomSheet.getLayoutParams();
lp.height = screenHeight;
bottomSheet.setLayoutParams(lp);
BottomSheetBehavior<View> behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setSkipCollapsed(true);
behavior.setPeekHeight(screenHeight);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
});
}
});
bottomSheetDialog.show();
}
private Couponset findCouponsetByUuid(String uuid) {
LinkedHashMap<String, ArrayList<Couponset>> categorizedMap = WarplyManagerHelper.getCouponsetCategorizedMap();
if (categorizedMap != null) {
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/custom_black7"
android:orientation="vertical">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_filter_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</androidx.core.widget.NestedScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/custom_black7"
android:paddingHorizontal="24dp">
<TextView
android:id="@+id/tv_category_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:includeFontPadding="false"
android:textColor="@color/white"
android:textSize="16sp" />
<ImageView
android:id="@+id/iv_arrow"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_arrow_down_white"
android:visibility="gone" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="@color/custom_black7"
android:paddingHorizontal="24dp">
<TextView
android:id="@+id/tv_subcategory_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_marginStart="32dp"
android:includeFontPadding="false"
android:textColor="@color/custom_skyblue4"
android:textSize="16sp" />
</RelativeLayout>
......@@ -44,4 +44,5 @@
<color name="custom_grey10">#ECEDEF</color>
<color name="custom_grey11">#E7E7E7</color>
<color name="custom_blue">#004E6E</color>
<color name="custom_grey12">#EBEDEF</color>
</resources>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="bottom_sheet_full_height">2000dp</dimen>
</resources>
......@@ -42,4 +42,5 @@
<string name="demo_partners_title">Partner businesses</string>
<string name="demo_search_title">Αναζήτηση</string>
<string name="lbl_directions">Οδηγίες</string>
<string name="lbl_top_offers">Top Offers</string>
</resources>
......
......@@ -47,4 +47,22 @@
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeBottomRight">0dp</item>
</style>
<style name="FullScreenBottomSheetDialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="bottomSheetStyle">@style/FullScreenBottomSheetStyle</item>
</style>
<style name="FullScreenBottomSheetStyle" parent="Widget.MaterialComponents.BottomSheet.Modal">
<item name="android:layout_height">match_parent</item>
<item name="shapeAppearanceOverlay">@style/NoCornerShapeAppearance</item>
<item name="behavior_peekHeight">@dimen/bottom_sheet_full_height</item>
<item name="behavior_skipCollapsed">true</item>
</style>
<style name="NoCornerShapeAppearance" parent="">
<item name="cornerSize">0dp</item>
</style>
</resources>
......