Panagiotis Triantafyllou

my coupons filtering

......@@ -32,10 +32,11 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
// ===========================================================
private ImageView mIvBack;
private LinearLayout mLlFilterActive, mLlFilterExpired;
private LinearLayout mLlFilterActive, mLlFilterExpired, mLlActiveCount, mLlExpiredCount;
private RecyclerView mRvCoupons;
private CouponAdapter mCouponsAdapter;
private TextView mBtnFilterActive, mBtnFilterExpired, mTvHeaderTitle;
private TextView mBtnFilterActive, mBtnFilterExpired, mTvHeaderTitle,
mTvActiveCount, mTvExpiredCount;
// ===========================================================
// Methods for/from SuperClass/Interfaces
......@@ -66,9 +67,9 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
if (id == R.id.iv_back) {
onBackPressed();
} else if (id == R.id.ll_filter_active) {
// filterCoupons(CouponItem.STATUS_ACTIVE);
filterCoupons(1);
} else if (id == R.id.ll_filter_redeemed) {
// filterCoupons(CouponItem.STATUS_REDEEMED);
filterCoupons(-1);
}
}
......@@ -79,11 +80,6 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
startActivity(myIntent);
}
@Override
public void onFavoriteClick(Coupon couponItem, int position) {
// Handle favorite click if needed
}
// ===========================================================
// Methods
// ===========================================================
......@@ -99,12 +95,16 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
mLlFilterExpired = findViewById(R.id.ll_filter_redeemed);
mBtnFilterExpired = findViewById(R.id.btn_filter_redeemed);
mTvHeaderTitle = findViewById(R.id.tv_header_title);
mLlActiveCount = findViewById(R.id.ll_active_count);
mLlExpiredCount = findViewById(R.id.ll_expired_count);
mTvActiveCount = findViewById(R.id.tv_active_count);
mTvExpiredCount = findViewById(R.id.tv_expired_count);
// Set click listeners for filter buttons
mLlFilterActive.setOnClickListener(this);
mLlFilterExpired.setOnClickListener(this);
WarpUtils.renderCustomFont(this, R.font.ping_lcg_bold, mTvHeaderTitle,
mBtnFilterActive, mBtnFilterExpired);
mBtnFilterActive, mBtnFilterExpired, mTvActiveCount, mTvExpiredCount);
}
private void setupMyCouponsSection() {
......@@ -114,34 +114,44 @@ public class CouponsActivity extends Activity implements View.OnClickListener,
mCouponsAdapter = new CouponAdapter(this, WarplyManagerHelper.getCoupons());
mCouponsAdapter.setOnCouponClickListener(this);
filterCoupons(1);
mRvCoupons.setAdapter(mCouponsAdapter);
int verticalSpacingInPixels = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
mRvCoupons.addItemDecoration(new VerticalSpaceItemDecoration(verticalSpacingInPixels));
// filterCoupons(CouponItem.STATUS_ACTIVE);
int activeCount = 0, expiredCount = 0;
for (Coupon c : WarplyManagerHelper.getCoupons()) {
if (c.getStatus() == 1) activeCount++;
else if (c.getStatus() == -1) expiredCount++;
}
mTvActiveCount.setText(String.valueOf(activeCount));
mTvExpiredCount.setText(String.valueOf(expiredCount));
}
private void filterCoupons(String status) {
// Reset all filter button styles
// mBtnFilterActive.setBackgroundResource(R.drawable.shape_transparent_black_border);
// mBtnFilterActive.setTextColor(getResources().getColor(R.color.custom_black2));
// mBtnFilterRedeemed.setBackgroundResource(R.drawable.shape_transparent_black_border);
// mBtnFilterRedeemed.setTextColor(getResources().getColor(R.color.custom_black2));
// Set selected filter button style
// if (CouponItem.STATUS_ACTIVE.equals(status)) {
// mBtnFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_black);
// mBtnFilterActive.setTextColor(Color.WHITE);
// } else if (CouponItem.STATUS_REDEEMED.equals(status)) {
// mBtnFilterRedeemed.setBackgroundResource(R.drawable.shape_rectangle_rounded_black);
// mBtnFilterRedeemed.setTextColor(Color.WHITE);
// }
// Apply filter to adapter
// mCouponsAdapter.filterByStatus(status);
private void filterCoupons(int status) {
mCouponsAdapter.filterByStatus(status);
if (status == 1) {
mLlFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_black2);
mBtnFilterActive.setTextColor(getColor(R.color.white));
mLlActiveCount.setBackgroundResource(R.drawable.shape_rounded_transparent_white_border);
mTvActiveCount.setTextColor(getColor(R.color.white));
mLlFilterExpired.setBackgroundResource(R.drawable.shape_rectangle_rounded_grey4);
mBtnFilterExpired.setTextColor(getColor(R.color.custom_black6));
mLlExpiredCount.setBackgroundResource(R.drawable.shape_rounded_transparent_black_border);
mTvExpiredCount.setTextColor(getColor(R.color.custom_black6));
} else {
mLlFilterExpired.setBackgroundResource(R.drawable.shape_rectangle_rounded_black2);
mBtnFilterExpired.setTextColor(getColor(R.color.white));
mLlExpiredCount.setBackgroundResource(R.drawable.shape_rounded_transparent_white_border);
mTvExpiredCount.setTextColor(getColor(R.color.white));
mLlFilterActive.setBackgroundResource(R.drawable.shape_rectangle_rounded_grey4);
mBtnFilterActive.setTextColor(getColor(R.color.custom_black6));
mLlActiveCount.setBackgroundResource(R.drawable.shape_rounded_transparent_black_border);
mTvActiveCount.setTextColor(getColor(R.color.custom_black6));
}
}
// ===========================================================
......
......@@ -2,7 +2,6 @@ package ly.warp.sdk.activities;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.TypedValue;
......@@ -110,11 +109,6 @@ public class ProfileActivity extends Activity implements View.OnClickListener, O
startActivity(myIntent);
}
@Override
public void onFavoriteClick(Coupon couponItem, int position) {
// Handle favorite click if needed
}
// ===========================================================
// Methods
// ===========================================================
......
......@@ -43,8 +43,6 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
*/
public interface OnCouponClickListener {
void onCouponClick(Coupon couponItem, int position);
void onFavoriteClick(Coupon couponItem, int position);
}
/**
......@@ -56,7 +54,7 @@ public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponView
public CouponAdapter(Context context, ArrayList<Coupon> couponItems) {
this.context = context;
this.allCouponItems = couponItems;
this.filteredCouponItems = couponItems;
this.filteredCouponItems = new ArrayList<>(couponItems);
}
/**
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="@android:color/transparent" />
<stroke
android:width="2dp"
android:color="@color/custom_black6" />
</shape>
\ No newline at end of file
......@@ -97,6 +97,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="@drawable/shape_rectangle_rounded_black2"
android:gravity="center"
android:paddingHorizontal="20dp"
android:paddingVertical="12dp">
......@@ -108,6 +109,28 @@
android:text="@string/demo_active"
android:textColor="@color/white"
android:textSize="14sp" />
<View
android:layout_width="12dp"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/ll_active_count"
android:layout_width="21dp"
android:layout_height="21dp"
android:background="@drawable/shape_rounded_transparent_white_border"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_active_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="0"
android:textColor="@color/white"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
......@@ -116,18 +139,41 @@
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="@drawable/shape_rectangle_rounded_grey4"
android:gravity="center"
android:paddingHorizontal="20dp"
android:paddingVertical="12dp">
<TextView
android:id="@+id/btn_filter_redeemed"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:includeFontPadding="false"
android:text="@string/demo_expired"
android:textColor="@color/custom_black6"
android:textSize="14sp" />
<View
android:layout_width="12dp"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/ll_expired_count"
android:layout_width="21dp"
android:layout_height="21dp"
android:background="@drawable/shape_rounded_transparent_black_border"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_expired_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="0"
android:textColor="@color/custom_black6"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
......